Removed System.Windows.Forms dependancy from Common. Almost done removing NLog dependancy.

This commit is contained in:
LukePulverenti
2013-02-21 20:26:35 -05:00
parent 931c0ea455
commit fdafa59683
88 changed files with 1025 additions and 767 deletions

View File

@@ -1,8 +1,7 @@
using System.Collections.Specialized;
using MediaBrowser.Common.Logging;
using MediaBrowser.Common.Win32;
using MediaBrowser.Common.Win32;
using System;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.IO;
using System.Runtime.InteropServices;
using System.Text;

View File

@@ -9,9 +9,6 @@ using MediaBrowser.Common.Serialization;
using MediaBrowser.Model.Configuration;
using MediaBrowser.Model.Logging;
using MediaBrowser.Model.System;
using NLog;
using NLog.Config;
using NLog.Targets;
using System;
using System.Collections.Generic;
using System.ComponentModel.Composition;
@@ -40,11 +37,6 @@ namespace MediaBrowser.Common.Kernel
/// </summary>
public event EventHandler HasPendingRestartChanged;
/// <summary>
/// Notifiies the containing application that a restart has been requested
/// </summary>
public event EventHandler ApplicationRestartRequested;
#region ConfigurationUpdated Event
/// <summary>
/// Occurs when [configuration updated].
@@ -341,6 +333,12 @@ namespace MediaBrowser.Common.Kernel
/// <value>The logger.</value>
protected ILogger Logger { get; private set; }
/// <summary>
/// Gets or sets the application host.
/// </summary>
/// <value>The application host.</value>
protected IApplicationHost ApplicationHost { get; private set; }
/// <summary>
/// Gets the assemblies.
/// </summary>
@@ -350,10 +348,17 @@ namespace MediaBrowser.Common.Kernel
/// <summary>
/// Initializes a new instance of the <see cref="BaseKernel{TApplicationPathsType}" /> class.
/// </summary>
/// <param name="appHost">The app host.</param>
/// <param name="isoManager">The iso manager.</param>
/// <param name="logger">The logger.</param>
protected BaseKernel(IIsoManager isoManager, ILogger logger)
/// <exception cref="System.ArgumentNullException">isoManager</exception>
protected BaseKernel(IApplicationHost appHost, IIsoManager isoManager, ILogger logger)
{
if (appHost == null)
{
throw new ArgumentNullException("appHost");
}
if (isoManager == null)
{
throw new ArgumentNullException("isoManager");
@@ -363,7 +368,8 @@ namespace MediaBrowser.Common.Kernel
{
throw new ArgumentNullException("logger");
}
ApplicationHost = appHost;
IsoManager = isoManager;
Logger = logger;
}
@@ -440,42 +446,11 @@ namespace MediaBrowser.Common.Kernel
/// </summary>
public void ReloadLogger()
{
DisposeLogger();
LogFilePath = Path.Combine(ApplicationPaths.LogDirectoryPath, KernelContext + "-" + DateTime.Now.Ticks + ".log");
var logFile = new FileTarget();
logFile.FileName = LogFilePath;
logFile.Layout = "${longdate}, ${level}, ${logger}, ${message}";
AddLogTarget(logFile, "ApplicationLogFile");
ApplicationHost.ReloadLogger();
OnLoggerLoaded();
}
/// <summary>
/// Adds the log target.
/// </summary>
/// <param name="target">The target.</param>
/// <param name="name">The name.</param>
private void AddLogTarget(Target target, string name)
{
var config = LogManager.Configuration;
config.RemoveTarget(name);
target.Name = name;
config.AddTarget(name, target);
var level = Configuration.EnableDebugLevelLogging ? LogLevel.Debug : LogLevel.Info;
var rule = new LoggingRule("*", level, target);
config.LoggingRules.Add(rule);
LogManager.Configuration = config;
}
/// <summary>
/// Uses MEF to locate plugins
/// Subclasses can use this to locate types within plugins
@@ -588,7 +563,7 @@ namespace MediaBrowser.Common.Kernel
foreach (var task in ScheduledTasks)
{
task.Initialize(this);
task.Initialize(this, Logger);
}
// Start-up each plugin
@@ -707,23 +682,6 @@ namespace MediaBrowser.Common.Kernel
}
}
/// <summary>
/// Disposes all logger resources
/// </summary>
private void DisposeLogger()
{
// Dispose all current loggers
var listeners = Trace.Listeners.OfType<TraceListener>().ToList();
Trace.Listeners.Clear();
foreach (var listener in listeners)
{
listener.Dispose();
}
}
/// <summary>
/// Gets the current application version
/// </summary>
@@ -759,7 +717,7 @@ namespace MediaBrowser.Common.Kernel
{
Logger.Info("Restarting the application");
EventHelper.QueueEventIfNotNull(ApplicationRestartRequested, this, EventArgs.Empty, Logger);
ApplicationHost.Restart();
}
/// <summary>

View File

@@ -1,12 +1,11 @@
using MediaBrowser.Common.Logging;
using MediaBrowser.Common.Net;
using MediaBrowser.Common.Net;
using MediaBrowser.Model.Logging;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.WebSockets;
using System.Threading;
using System.Threading.Tasks;
using MediaBrowser.Model.Logging;
namespace MediaBrowser.Common.Kernel
{

View File

@@ -0,0 +1,19 @@

namespace MediaBrowser.Common.Kernel
{
/// <summary>
/// An interface to be implemented by the applications hosting a kernel
/// </summary>
public interface IApplicationHost
{
/// <summary>
/// Restarts this instance.
/// </summary>
void Restart();
/// <summary>
/// Reloads the logger.
/// </summary>
void ReloadLogger();
}
}

View File

@@ -1,6 +1,4 @@
using MediaBrowser.Common.IO;
using MediaBrowser.Common.Net;
using MediaBrowser.Common.Net.Handlers;
using MediaBrowser.Common.Net;
using MediaBrowser.Common.Plugins;
using MediaBrowser.Common.ScheduledTasks;
using MediaBrowser.Common.Serialization;
@@ -18,11 +16,6 @@ namespace MediaBrowser.Common.Kernel
/// </summary>
public interface IKernel
{
/// <summary>
/// Occurs when [application restart requested].
/// </summary>
event EventHandler ApplicationRestartRequested;
/// <summary>
/// Gets the application paths.
/// </summary>

View File

@@ -1,90 +0,0 @@
using System;
using System.Text;
namespace MediaBrowser.Common.Logging
{
/// <summary>
/// Class LogHelper
/// </summary>
public static class LogHelper
{
/// <summary>
/// Gets the log message.
/// </summary>
/// <param name="exception">The exception.</param>
/// <returns>StringBuilder.</returns>
public static StringBuilder GetLogMessage(Exception exception)
{
var messageText = new StringBuilder();
messageText.AppendLine(exception.Message);
messageText.AppendLine(exception.GetType().FullName);
LogExceptionData(messageText, exception);
messageText.AppendLine(exception.StackTrace ?? "No Stack Trace Available");
// Log the InnerExceptions, if any
AppendInnerExceptions(messageText, exception);
messageText.AppendLine(string.Empty);
return messageText;
}
/// <summary>
/// Appends the inner exceptions.
/// </summary>
/// <param name="messageText">The message text.</param>
/// <param name="e">The e.</param>
private static void AppendInnerExceptions(StringBuilder messageText, Exception e)
{
var aggregate = e as AggregateException;
if (aggregate != null && aggregate.InnerExceptions != null)
{
foreach (var ex in aggregate.InnerExceptions)
{
AppendInnerException(messageText, ex);
}
}
else if (e.InnerException != null)
{
AppendInnerException(messageText, e.InnerException);
}
}
/// <summary>
/// Appends the inner exception.
/// </summary>
/// <param name="messageText">The message text.</param>
/// <param name="e">The e.</param>
private static void AppendInnerException(StringBuilder messageText, Exception e)
{
messageText.AppendLine("InnerException: " + e.GetType().FullName);
messageText.AppendLine(e.Message);
LogExceptionData(messageText, e);
if (e.StackTrace != null)
{
messageText.AppendLine(e.StackTrace);
}
}
/// <summary>
/// Logs the exception data.
/// </summary>
/// <param name="messageText">The message text.</param>
/// <param name="e">The e.</param>
private static void LogExceptionData(StringBuilder messageText, Exception e)
{
foreach (var key in e.Data.Keys)
{
messageText.AppendLine(key + ": " + e.Data[key]);
}
}
}
}

View File

@@ -1,20 +0,0 @@
using MediaBrowser.Model.Logging;
namespace MediaBrowser.Common.Logging
{
/// <summary>
/// Class LogManager
/// </summary>
public static class LogManager
{
/// <summary>
/// Gets the logger.
/// </summary>
/// <param name="name">The name.</param>
/// <returns>ILogger.</returns>
public static ILogger GetLogger(string name)
{
return new NLogger(name);
}
}
}

View File

@@ -1,8 +0,0 @@
<Window x:Class="MediaBrowser.Common.Logging.LogWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Media Browser Log" Height="300" Width="968">
<Grid>
<ListBox x:Name="lbxLogData" Margin="10,10,0,0"/>
</Grid>
</Window>

View File

@@ -1,128 +0,0 @@
using MediaBrowser.Common.Kernel;
using NLog;
using NLog.Config;
using NLog.Targets;
using System.ComponentModel;
using System.Threading;
using System.Threading.Tasks;
using System.Windows;
namespace MediaBrowser.Common.Logging
{
/// <summary>
/// Interaction logic for LogWindow.xaml
/// </summary>
public partial class LogWindow : Window
{
/// <summary>
/// The _ui thread
/// </summary>
private readonly TaskScheduler _uiThread;
/// <summary>
/// The _kernel
/// </summary>
private readonly IKernel _kernel;
/// <summary>
/// Initializes a new instance of the <see cref="LogWindow" /> class.
/// </summary>
/// <param name="kernel">The kernel.</param>
public LogWindow(IKernel kernel)
{
InitializeComponent();
_uiThread = TaskScheduler.FromCurrentSynchronizationContext();
_kernel = kernel;
Loaded += LogWindow_Loaded;
}
/// <summary>
/// Handles the Loaded event of the LogWindow control.
/// </summary>
/// <param name="sender">The source of the event.</param>
/// <param name="e">The <see cref="RoutedEventArgs" /> instance containing the event data.</param>
void LogWindow_Loaded(object sender, RoutedEventArgs e)
{
var target = new TraceTarget
{
Layout = "${longdate}, ${level}, ${logger}, ${message}"
};
AddLogTarget(target, "LogWindowTraceTarget");
}
/// <summary>
/// Raises the <see cref="E:System.Windows.Window.Closing" /> event.
/// </summary>
/// <param name="e">A <see cref="T:System.ComponentModel.CancelEventArgs" /> that contains the event data.</param>
protected override void OnClosing(CancelEventArgs e)
{
base.OnClosing(e);
RemoveLogTarget("LogWindowTraceTarget");
}
/// <summary>
/// Logs the message.
/// </summary>
/// <param name="msg">The MSG.</param>
public async void LogMessage(string msg)
{
await Task.Factory.StartNew(() => lbxLogData.Items.Insert(0, msg.TrimEnd('\n')), CancellationToken.None, TaskCreationOptions.None, _uiThread);
}
/// <summary>
/// The log layout
/// </summary>
/// <value>The log layout.</value>
public string LogLayout
{
get { return "${longdate}, ${level}, ${logger}, ${message}"; }
}
/// <summary>
/// Adds the log target.
/// </summary>
/// <param name="target">The target.</param>
/// <param name="name">The name.</param>
private void AddLogTarget(Target target, string name)
{
var config = NLog.LogManager.Configuration;
config.RemoveTarget(name);
target.Name = name;
config.AddTarget(name, target);
var level = _kernel.Configuration.EnableDebugLevelLogging ? LogLevel.Debug : LogLevel.Info;
var rule = new LoggingRule("*", level, target);
config.LoggingRules.Add(rule);
NLog.LogManager.Configuration = config;
}
/// <summary>
/// Removes the log target.
/// </summary>
/// <param name="name">The name.</param>
private void RemoveLogTarget(string name)
{
var config = NLog.LogManager.Configuration;
config.RemoveTarget(name);
NLog.LogManager.Configuration = config;
}
/// <summary>
/// Shuts down.
/// </summary>
public async void ShutDown()
{
await Task.Factory.StartNew(Close, CancellationToken.None, TaskCreationOptions.None, _uiThread);
}
}
}

View File

@@ -1,201 +0,0 @@
using MediaBrowser.Model.Logging;
using System;
using System.Text;
namespace MediaBrowser.Common.Logging
{
/// <summary>
/// Class NLogger
/// </summary>
internal class NLogger : ILogger
{
/// <summary>
/// The _logger
/// </summary>
private readonly NLog.Logger _logger;
/// <summary>
/// The _lock object
/// </summary>
private static readonly object LockObject = new object();
/// <summary>
/// Initializes a new instance of the <see cref="NLogger" /> class.
/// </summary>
/// <param name="name">The name.</param>
public NLogger(string name)
{
lock (LockObject)
{
_logger = NLog.LogManager.GetLogger(name);
}
}
/// <summary>
/// Infoes the specified message.
/// </summary>
/// <param name="message">The message.</param>
/// <param name="paramList">The param list.</param>
public void Info(string message, params object[] paramList)
{
_logger.Info(message, paramList);
}
/// <summary>
/// Errors the specified message.
/// </summary>
/// <param name="message">The message.</param>
/// <param name="paramList">The param list.</param>
public void Error(string message, params object[] paramList)
{
_logger.Error(message, paramList);
}
/// <summary>
/// Warns the specified message.
/// </summary>
/// <param name="message">The message.</param>
/// <param name="paramList">The param list.</param>
public void Warn(string message, params object[] paramList)
{
_logger.Warn(message, paramList);
}
/// <summary>
/// Debugs the specified message.
/// </summary>
/// <param name="message">The message.</param>
/// <param name="paramList">The param list.</param>
public void Debug(string message, params object[] paramList)
{
_logger.Debug(message, paramList);
}
/// <summary>
/// Logs the exception.
/// </summary>
/// <param name="message">The message.</param>
/// <param name="exception">The exception.</param>
/// <param name="paramList">The param list.</param>
/// <exception cref="System.NotImplementedException"></exception>
public void ErrorException(string message, Exception exception, params object[] paramList)
{
LogException(LogSeverity.Error, message, exception, paramList);
}
/// <summary>
/// Logs the exception.
/// </summary>
/// <param name="level">The level.</param>
/// <param name="message">The message.</param>
/// <param name="exception">The exception.</param>
/// <param name="paramList">The param list.</param>
private void LogException(LogSeverity level, string message, Exception exception, params object[] paramList)
{
message = FormatMessage(message, paramList).Replace(Environment.NewLine, ". ");
var messageText = LogHelper.GetLogMessage(exception);
LogMultiline(message, level, messageText);
}
/// <summary>
/// Formats the message.
/// </summary>
/// <param name="message">The message.</param>
/// <param name="paramList">The param list.</param>
/// <returns>System.String.</returns>
private static string FormatMessage(string message, params object[] paramList)
{
if (paramList != null)
{
for (var i = 0; i < paramList.Length; i++)
{
message = message.Replace("{" + i + "}", paramList[i].ToString());
}
}
return message;
}
/// <summary>
/// Logs the multiline.
/// </summary>
/// <param name="message">The message.</param>
/// <param name="severity">The severity.</param>
/// <param name="additionalContent">Content of the additional.</param>
public void LogMultiline(string message, LogSeverity severity, StringBuilder additionalContent)
{
additionalContent.Insert(0, message + Environment.NewLine);
const char tabChar = '\t';
var text = additionalContent.ToString()
.Replace(Environment.NewLine, Environment.NewLine + tabChar)
.TrimEnd(tabChar);
if (text.EndsWith(Environment.NewLine))
{
text = text.Substring(0, text.LastIndexOf(Environment.NewLine, StringComparison.OrdinalIgnoreCase));
}
_logger.Log(GetLogLevel(severity), text);
}
/// <summary>
/// Gets the log level.
/// </summary>
/// <param name="severity">The severity.</param>
/// <returns>NLog.LogLevel.</returns>
private NLog.LogLevel GetLogLevel(LogSeverity severity)
{
switch (severity)
{
case LogSeverity.Debug:
return NLog.LogLevel.Debug;
case LogSeverity.Error:
return NLog.LogLevel.Error;
case LogSeverity.Warn:
return NLog.LogLevel.Warn;
case LogSeverity.Fatal:
return NLog.LogLevel.Fatal;
case LogSeverity.Info:
return NLog.LogLevel.Info;
default:
throw new ArgumentException("Unknown LogSeverity: " + severity.ToString());
}
}
/// <summary>
/// Logs the specified severity.
/// </summary>
/// <param name="severity">The severity.</param>
/// <param name="message">The message.</param>
/// <param name="paramList">The param list.</param>
public void Log(LogSeverity severity, string message, params object[] paramList)
{
_logger.Log(GetLogLevel(severity), message, paramList);
}
/// <summary>
/// Fatals the specified message.
/// </summary>
/// <param name="message">The message.</param>
/// <param name="paramList">The param list.</param>
public void Fatal(string message, params object[] paramList)
{
_logger.Fatal(message, paramList);
}
/// <summary>
/// Fatals the exception.
/// </summary>
/// <param name="message">The message.</param>
/// <param name="exception">The exception.</param>
/// <param name="paramList">The param list.</param>
public void FatalException(string message, Exception exception, params object[] paramList)
{
LogException(LogSeverity.Fatal, message, exception, paramList);
}
}
}

View File

@@ -1,75 +0,0 @@
using System.Diagnostics;
namespace MediaBrowser.Common.Logging
{
/// <summary>
/// Class WindowTraceListener
/// </summary>
public class WindowTraceListener : DefaultTraceListener
{
/// <summary>
/// The _window
/// </summary>
private readonly LogWindow _window;
/// <summary>
/// Initializes a new instance of the <see cref="WindowTraceListener" /> class.
/// </summary>
/// <param name="window">The window.</param>
public WindowTraceListener(LogWindow window)
{
_window = window;
_window.Show();
Name = "MBLogWindow";
}
/// <summary>
/// Writes the value of the object's <see cref="M:System.Object.ToString" /> method to the listener you create when you implement the <see cref="T:System.Diagnostics.TraceListener" /> class.
/// </summary>
/// <param name="o">An <see cref="T:System.Object" /> whose fully qualified class name you want to write.</param>
public override void Write(object o)
{
var str = o as string;
if (str != null)
Write(str);
else
base.Write(o);
}
/// <summary>
/// Writes the output to the OutputDebugString function and to the <see cref="M:System.Diagnostics.Debugger.Log(System.Int32,System.String,System.String)" /> method.
/// </summary>
/// <param name="message">The message to write to OutputDebugString and <see cref="M:System.Diagnostics.Debugger.Log(System.Int32,System.String,System.String)" />.</param>
/// <PermissionSet>
/// <IPermission class="System.Security.Permissions.FileIOPermission, mscorlib, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Unrestricted="true" />
/// <IPermission class="System.Security.Permissions.SecurityPermission, mscorlib, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Flags="ControlEvidence" />
/// </PermissionSet>
public override void Write(string message)
{
_window.LogMessage(message);
}
/// <summary>
/// Writes the output to the OutputDebugString function and to the <see cref="M:System.Diagnostics.Debugger.Log(System.Int32,System.String,System.String)" /> method, followed by a carriage return and line feed (\r\n).
/// </summary>
/// <param name="message">The message to write to OutputDebugString and <see cref="M:System.Diagnostics.Debugger.Log(System.Int32,System.String,System.String)" />.</param>
/// <PermissionSet>
/// <IPermission class="System.Security.Permissions.FileIOPermission, mscorlib, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Unrestricted="true" />
/// <IPermission class="System.Security.Permissions.SecurityPermission, mscorlib, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Flags="ControlEvidence" />
/// </PermissionSet>
public override void WriteLine(string message)
{
Write(message+"\n");
}
/// <summary>
/// Releases the unmanaged resources used by the <see cref="T:System.Diagnostics.TraceListener" /> and optionally releases the managed resources.
/// </summary>
/// <param name="disposing">true to release both managed and unmanaged resources; false to release only unmanaged resources.</param>
protected override void Dispose(bool disposing)
{
if (_window != null)
_window.ShutDown();
base.Dispose(disposing);
}
}
}

View File

@@ -114,8 +114,6 @@
<Reference Include="System.Runtime.Remoting" />
<Reference Include="System.Runtime.Serialization" />
<Reference Include="System.Web" />
<Reference Include="System.Windows.Forms" />
<Reference Include="System.Xaml" />
<Reference Include="System.Xml.Linq" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
@@ -142,16 +140,10 @@
<Compile Include="Kernel\BaseManager.cs" />
<Compile Include="Kernel\BasePeriodicWebSocketListener.cs" />
<Compile Include="Kernel\BaseWebSocketListener.cs" />
<Compile Include="Kernel\IApplicationHost.cs" />
<Compile Include="Kernel\IKernel.cs" />
<Compile Include="Kernel\TcpManager.cs" />
<Compile Include="Localization\LocalizedStringData.cs" />
<Compile Include="Logging\LogHelper.cs" />
<Compile Include="Logging\LogManager.cs" />
<Compile Include="Logging\LogWindow.xaml.cs">
<DependentUpon>LogWindow.xaml</DependentUpon>
</Compile>
<Compile Include="Logging\NLogger.cs" />
<Compile Include="Logging\WindowTraceListener.cs" />
<Compile Include="Mef\MefUtils.cs" />
<Compile Include="Net\AlchemyWebSocket.cs" />
<Compile Include="Net\BaseRestService.cs" />
@@ -201,7 +193,6 @@
<Compile Include="ScheduledTasks\IntervalTrigger.cs" />
<Compile Include="ScheduledTasks\IScheduledTask.cs" />
<Compile Include="ScheduledTasks\WeeklyTrigger.cs" />
<Compile Include="UI\BaseApplication.cs" />
<Compile Include="Updates\ApplicationUpdateCheck.cs" />
<Compile Include="Updates\ApplicationUpdater.cs" />
<Compile Include="Updates\ClickOnceHelper.cs" />
@@ -228,12 +219,6 @@
<ItemGroup>
<Resource Include="Resources\Images\Icon.ico" />
</ItemGroup>
<ItemGroup>
<Page Include="Logging\LogWindow.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
</ItemGroup>
<ItemGroup>
<Resource Include="README.txt" />
<Content Include="swagger-ui\css\screen.css" />
@@ -251,6 +236,7 @@
<Content Include="swagger-ui\swagger-ui.js" />
<Content Include="swagger-ui\swagger-ui.min.js" />
</ItemGroup>
<ItemGroup />
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<Import Project="$(SolutionDir)\.nuget\nuget.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.

View File

@@ -1,5 +1,4 @@
using Alchemy.Classes;
using MediaBrowser.Common.Logging;
using MediaBrowser.Common.Serialization;
using MediaBrowser.Model.Logging;
using System;

View File

@@ -1,7 +1,6 @@
using MediaBrowser.Common.Extensions;
using MediaBrowser.Common.IO;
using MediaBrowser.Common.Kernel;
using MediaBrowser.Common.Logging;
using MediaBrowser.Model.Logging;
using ServiceStack.Common;
using ServiceStack.Common.Web;
@@ -22,17 +21,18 @@ namespace MediaBrowser.Common.Net
/// </summary>
public class BaseRestService : Service, IRestfulService
{
/// <summary>
/// The logger
/// </summary>
protected ILogger Logger = LogManager.GetLogger("RestService");
/// <summary>
/// Gets or sets the kernel.
/// </summary>
/// <value>The kernel.</value>
public IKernel Kernel { get; set; }
/// <summary>
/// Gets or sets the logger.
/// </summary>
/// <value>The logger.</value>
public ILogger Logger { get; set; }
/// <summary>
/// Gets a value indicating whether this instance is range request.
/// </summary>

View File

@@ -1,7 +1,5 @@
using MediaBrowser.Common.Extensions;
using MediaBrowser.Common.Kernel;
using MediaBrowser.Common.Logging;
using MediaBrowser.Model.Logging;
using System;
using System.Collections;
using System.Collections.Generic;
@@ -23,12 +21,6 @@ namespace MediaBrowser.Common.Net.Handlers
public abstract class BaseHandler<TKernelType> : IHttpServerHandler
where TKernelType : IKernel
{
/// <summary>
/// Gets the logger.
/// </summary>
/// <value>The logger.</value>
protected ILogger Logger { get; private set; }
/// <summary>
/// Initializes the specified kernel.
/// </summary>
@@ -36,7 +28,6 @@ namespace MediaBrowser.Common.Net.Handlers
public void Initialize(IKernel kernel)
{
Kernel = (TKernelType)kernel;
Logger = SharedLogger.Logger;
}
/// <summary>
@@ -303,7 +294,7 @@ namespace MediaBrowser.Common.Net.Handlers
response.ContentType = "text/plain";
Logger.ErrorException("Error processing request", ex);
//Logger.ErrorException("Error processing request", ex);
if (!string.IsNullOrEmpty(ex.Message))
{
@@ -321,7 +312,7 @@ namespace MediaBrowser.Common.Net.Handlers
}
catch (Exception ex1)
{
Logger.ErrorException("Error dumping stack trace", ex1);
//Logger.ErrorException("Error dumping stack trace", ex1);
}
}
@@ -449,7 +440,7 @@ namespace MediaBrowser.Common.Net.Handlers
if (Kernel.Configuration.EnableHttpLevelLogging)
{
Logger.LogMultiline(msg, LogSeverity.Debug, log);
//Logger.LogMultiline(msg, LogSeverity.Debug, log);
}
}
@@ -604,7 +595,7 @@ namespace MediaBrowser.Common.Net.Handlers
}
catch (Exception ex)
{
Logger.ErrorException("Error disposing compressed stream", ex);
//Logger.ErrorException("Error disposing compressed stream", ex);
}
}
@@ -615,7 +606,7 @@ namespace MediaBrowser.Common.Net.Handlers
}
catch (Exception ex)
{
Logger.ErrorException("Error disposing response", ex);
//Logger.ErrorException("Error disposing response", ex);
}
}
@@ -750,14 +741,6 @@ namespace MediaBrowser.Common.Net.Handlers
}
}
internal static class SharedLogger
{
/// <summary>
/// The logger
/// </summary>
internal static ILogger Logger = LogManager.GetLogger("Http Handler");
}
/// <summary>
/// Class ResponseInfo
/// </summary>

View File

@@ -4,7 +4,6 @@ using MediaBrowser.Common.Kernel;
using MediaBrowser.Model.Logging;
using ServiceStack.Api.Swagger;
using ServiceStack.Common.Web;
using ServiceStack.Logging;
using ServiceStack.Logging.NLogger;
using ServiceStack.ServiceHost;
using ServiceStack.ServiceInterface.Cors;
@@ -144,6 +143,7 @@ namespace MediaBrowser.Common.Net
}
container.Register(Kernel);
container.Register(_logger);
foreach (var service in Kernel.RestServices)
{
@@ -155,7 +155,7 @@ namespace MediaBrowser.Common.Net
Serialization.JsonSerializer.Configure();
LogManager.LogFactory = new NLogFactory();
ServiceStack.Logging.LogManager.LogFactory = new NLogFactory();
}
/// <summary>

View File

@@ -1,5 +1,4 @@
using MediaBrowser.Common.Logging;
using MediaBrowser.Common.Serialization;
using MediaBrowser.Common.Serialization;
using MediaBrowser.Model.Logging;
using System;
using System.Net;

View File

@@ -1,5 +1,4 @@
using MediaBrowser.Common.Kernel;
using MediaBrowser.Common.Logging;
using MediaBrowser.Common.Serialization;
using MediaBrowser.Model.Logging;
using MediaBrowser.Model.Plugins;

View File

@@ -1,6 +1,5 @@
using MediaBrowser.Common.Extensions;
using MediaBrowser.Common.Kernel;
using MediaBrowser.Common.Logging;
using MediaBrowser.Common.Serialization;
using MediaBrowser.Model.Logging;
using MediaBrowser.Model.Tasks;
@@ -301,9 +300,10 @@ namespace MediaBrowser.Common.ScheduledTasks
/// Initializes the specified kernel.
/// </summary>
/// <param name="kernel">The kernel.</param>
public void Initialize(IKernel kernel)
/// <param name="logger">The logger.</param>
public void Initialize(IKernel kernel, ILogger logger)
{
Logger = LogManager.GetLogger(GetType().Name);
Logger = logger;
Kernel = (TKernelType)kernel;
ReloadTriggerEvents();

View File

@@ -1,4 +1,5 @@
using MediaBrowser.Common.Kernel;
using MediaBrowser.Model.Logging;
using MediaBrowser.Model.Tasks;
using System;
using System.Collections.Generic;
@@ -76,7 +77,8 @@ namespace MediaBrowser.Common.ScheduledTasks
/// Initializes the specified kernel.
/// </summary>
/// <param name="kernel">The kernel.</param>
void Initialize(IKernel kernel);
/// <param name="logger">The logger.</param>
void Initialize(IKernel kernel, ILogger logger);
/// <summary>
/// Cancels if running.

View File

@@ -1,5 +1,4 @@
using MediaBrowser.Common.Kernel;
using MediaBrowser.Common.Logging;
using MediaBrowser.Common.Updates;
using MediaBrowser.Model.Tasks;
using System;

View File

@@ -1,9 +1,8 @@
using MediaBrowser.Common.Logging;
using MediaBrowser.Model.Logging;
using System;
using System.IO;
using System.Linq;
using System.Xml;
using MediaBrowser.Model.Logging;
namespace MediaBrowser.Common.Serialization
{

View File

@@ -1,412 +0,0 @@
using MediaBrowser.Common.Kernel;
using MediaBrowser.Common.Updates;
using MediaBrowser.Model.Logging;
using Microsoft.Win32;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Deployment.Application;
using System.Net.Cache;
using System.Threading;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;
using System.Windows.Media.Imaging;
namespace MediaBrowser.Common.UI
{
/// <summary>
/// Serves as a base Application class for both the UI and Server apps.
/// </summary>
public abstract class BaseApplication : Application, INotifyPropertyChanged
{
/// <summary>
/// The single instance mutex
/// </summary>
private Mutex SingleInstanceMutex;
/// <summary>
/// Gets the name of the publisher.
/// </summary>
/// <value>The name of the publisher.</value>
protected abstract string PublisherName { get; }
/// <summary>
/// Gets the name of the suite.
/// </summary>
/// <value>The name of the suite.</value>
protected abstract string SuiteName { get; }
/// <summary>
/// Gets the name of the product.
/// </summary>
/// <value>The name of the product.</value>
protected abstract string ProductName { get; }
/// <summary>
/// Gets the name of the uninstaller file.
/// </summary>
/// <value>The name of the uninstaller file.</value>
protected abstract string UninstallerFileName { get; }
/// <summary>
/// Gets or sets a value indicating whether [last run at startup value].
/// </summary>
/// <value><c>null</c> if [last run at startup value] contains no value, <c>true</c> if [last run at startup value]; otherwise, <c>false</c>.</value>
private bool? LastRunAtStartupValue { get; set; }
/// <summary>
/// Gets or sets the kernel.
/// </summary>
/// <value>The kernel.</value>
protected IKernel Kernel { get; set; }
/// <summary>
/// Instantiates the kernel.
/// </summary>
/// <returns>IKernel.</returns>
protected abstract IKernel InstantiateKernel();
/// <summary>
/// Instantiates the main window.
/// </summary>
/// <returns>Window.</returns>
protected abstract Window InstantiateMainWindow();
/// <summary>
/// Occurs when [property changed].
/// </summary>
public event PropertyChangedEventHandler PropertyChanged;
/// <summary>
/// Gets or sets the logger.
/// </summary>
/// <value>The logger.</value>
protected ILogger Logger { get; set; }
/// <summary>
/// Initializes a new instance of the <see cref="BaseApplication" /> class.
/// </summary>
/// <param name="logger">The logger.</param>
protected BaseApplication(ILogger logger)
{
Logger = logger;
}
/// <summary>
/// Called when [property changed].
/// </summary>
/// <param name="info">The info.</param>
public void OnPropertyChanged(String info)
{
if (PropertyChanged != null)
{
try
{
PropertyChanged(this, new PropertyChangedEventArgs(info));
}
catch (Exception ex)
{
Logger.ErrorException("Error in event handler", ex);
}
}
}
/// <summary>
/// Raises the <see cref="E:System.Windows.Application.Startup" /> event.
/// </summary>
/// <param name="e">A <see cref="T:System.Windows.StartupEventArgs" /> that contains the event data.</param>
protected override void OnStartup(StartupEventArgs e)
{
bool createdNew;
SingleInstanceMutex = new Mutex(true, @"Local\" + GetType().Assembly.GetName().Name, out createdNew);
if (!createdNew)
{
SingleInstanceMutex = null;
Shutdown();
return;
}
AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException;
LoadKernel();
SystemEvents.SessionEnding += SystemEvents_SessionEnding;
}
/// <summary>
/// Handles the UnhandledException event of the CurrentDomain control.
/// </summary>
/// <param name="sender">The source of the event.</param>
/// <param name="e">The <see cref="UnhandledExceptionEventArgs" /> instance containing the event data.</param>
void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e)
{
var exception = (Exception) e.ExceptionObject;
Logger.ErrorException("UnhandledException", exception);
MessageBox.Show("Unhandled exception: " + exception.Message);
}
/// <summary>
/// Handles the SessionEnding event of the SystemEvents control.
/// </summary>
/// <param name="sender">The source of the event.</param>
/// <param name="e">The <see cref="SessionEndingEventArgs" /> instance containing the event data.</param>
void SystemEvents_SessionEnding(object sender, SessionEndingEventArgs e)
{
// Try to shut down gracefully
Shutdown();
}
/// <summary>
/// Loads the kernel.
/// </summary>
protected virtual async void LoadKernel()
{
Kernel = InstantiateKernel();
try
{
InstantiateMainWindow().Show();
var now = DateTime.UtcNow;
await Kernel.Init();
var done = (DateTime.UtcNow - now);
Logger.Info("Kernel.Init completed in {0}{1} minutes and {2} seconds.", done.Hours > 0 ? done.Hours + " Hours " : "", done.Minutes, done.Seconds);
await OnKernelLoaded();
}
catch (Exception ex)
{
Logger.ErrorException("Error launching application", ex);
MessageBox.Show("There was an error launching Media Browser: " + ex.Message);
// Shutdown the app with an error code
Shutdown(1);
}
}
/// <summary>
/// Called when [kernel loaded].
/// </summary>
/// <returns>Task.</returns>
protected virtual Task OnKernelLoaded()
{
return Task.Run(() =>
{
Kernel.ApplicationRestartRequested += Kernel_ApplicationRestartRequested;
Kernel.ConfigurationUpdated += Kernel_ConfigurationUpdated;
ConfigureClickOnceStartup();
});
}
/// <summary>
/// Handles the ConfigurationUpdated event of the Kernel control.
/// </summary>
/// <param name="sender">The source of the event.</param>
/// <param name="e">The <see cref="EventArgs" /> instance containing the event data.</param>
void Kernel_ConfigurationUpdated(object sender, EventArgs e)
{
if (!LastRunAtStartupValue.HasValue || LastRunAtStartupValue.Value != Kernel.Configuration.RunAtStartup)
{
ConfigureClickOnceStartup();
}
}
/// <summary>
/// Configures the click once startup.
/// </summary>
private void ConfigureClickOnceStartup()
{
if (!ApplicationDeployment.IsNetworkDeployed)
{
return;
}
try
{
var clickOnceHelper = new ClickOnceHelper(PublisherName, ProductName, SuiteName);
if (Kernel.Configuration.RunAtStartup)
{
clickOnceHelper.UpdateUninstallParameters(UninstallerFileName);
clickOnceHelper.AddShortcutToStartup();
}
else
{
clickOnceHelper.RemoveShortcutFromStartup();
}
LastRunAtStartupValue = Kernel.Configuration.RunAtStartup;
}
catch (Exception ex)
{
Logger.ErrorException("Error configuring ClickOnce", ex);
}
}
/// <summary>
/// Handles the ApplicationRestartRequested event of the Kernel control.
/// </summary>
/// <param name="sender">The source of the event.</param>
/// <param name="e">The <see cref="EventArgs" /> instance containing the event data.</param>
void Kernel_ApplicationRestartRequested(object sender, EventArgs e)
{
Restart();
}
/// <summary>
/// Restarts this instance.
/// </summary>
public void Restart()
{
Dispatcher.Invoke(ReleaseMutex);
Kernel.Dispose();
System.Windows.Forms.Application.Restart();
Dispatcher.Invoke(Shutdown);
}
/// <summary>
/// Releases the mutex.
/// </summary>
private void ReleaseMutex()
{
if (SingleInstanceMutex == null)
{
return;
}
SingleInstanceMutex.ReleaseMutex();
SingleInstanceMutex.Close();
SingleInstanceMutex.Dispose();
SingleInstanceMutex = null;
}
/// <summary>
/// Raises the <see cref="E:System.Windows.Application.Exit" /> event.
/// </summary>
/// <param name="e">An <see cref="T:System.Windows.ExitEventArgs" /> that contains the event data.</param>
protected override void OnExit(ExitEventArgs e)
{
ReleaseMutex();
base.OnExit(e);
Kernel.Dispose();
}
/// <summary>
/// Signals the external command line args.
/// </summary>
/// <param name="args">The args.</param>
/// <returns><c>true</c> if XXXX, <c>false</c> otherwise</returns>
public bool SignalExternalCommandLineArgs(IList<string> args)
{
OnSecondInstanceLaunched(args);
return true;
}
/// <summary>
/// Called when [second instance launched].
/// </summary>
/// <param name="args">The args.</param>
protected virtual void OnSecondInstanceLaunched(IList<string> args)
{
if (MainWindow.WindowState == WindowState.Minimized)
{
MainWindow.WindowState = WindowState.Maximized;
}
}
/// <summary>
/// Gets the image.
/// </summary>
/// <param name="uri">The URI.</param>
/// <returns>Image.</returns>
/// <exception cref="System.ArgumentNullException">uri</exception>
public Image GetImage(string uri)
{
if (string.IsNullOrEmpty(uri))
{
throw new ArgumentNullException("uri");
}
return GetImage(new Uri(uri));
}
/// <summary>
/// Gets the image.
/// </summary>
/// <param name="uri">The URI.</param>
/// <returns>Image.</returns>
/// <exception cref="System.ArgumentNullException">uri</exception>
public Image GetImage(Uri uri)
{
if (uri == null)
{
throw new ArgumentNullException("uri");
}
return new Image { Source = GetBitmapImage(uri) };
}
/// <summary>
/// Gets the bitmap image.
/// </summary>
/// <param name="uri">The URI.</param>
/// <returns>BitmapImage.</returns>
/// <exception cref="System.ArgumentNullException">uri</exception>
public BitmapImage GetBitmapImage(string uri)
{
if (string.IsNullOrEmpty(uri))
{
throw new ArgumentNullException("uri");
}
return GetBitmapImage(new Uri(uri));
}
/// <summary>
/// Gets the bitmap image.
/// </summary>
/// <param name="uri">The URI.</param>
/// <returns>BitmapImage.</returns>
/// <exception cref="System.ArgumentNullException">uri</exception>
public BitmapImage GetBitmapImage(Uri uri)
{
if (uri == null)
{
throw new ArgumentNullException("uri");
}
var bitmap = new BitmapImage
{
CreateOptions = BitmapCreateOptions.DelayCreation,
CacheOption = BitmapCacheOption.OnDemand,
UriCachePolicy = new RequestCachePolicy(RequestCacheLevel.CacheIfAvailable)
};
bitmap.BeginInit();
bitmap.UriSource = uri;
bitmap.EndInit();
RenderOptions.SetBitmapScalingMode(bitmap, BitmapScalingMode.Fant);
return bitmap;
}
}
/// <summary>
/// Interface IApplication
/// </summary>
public interface IApplication
{
/// <summary>
/// Initializes the component.
/// </summary>
void InitializeComponent();
}
}