diff --git a/MediaBrowser.Common/Events/GenericEventArgs.cs b/MediaBrowser.Common/Events/GenericEventArgs.cs new file mode 100644 index 000000000..98e072816 --- /dev/null +++ b/MediaBrowser.Common/Events/GenericEventArgs.cs @@ -0,0 +1,12 @@ +using System; + +namespace MediaBrowser.Common.Events +{ + /// + /// Provides a generic EventArgs subclass that can hold any kind of object + /// + public class GenericEventArgs : EventArgs + { + public T Argument { get; set; } + } +} diff --git a/MediaBrowser.Common/Kernel/BaseKernel.cs b/MediaBrowser.Common/Kernel/BaseKernel.cs index 1fdc597ea..0eebc863c 100644 --- a/MediaBrowser.Common/Kernel/BaseKernel.cs +++ b/MediaBrowser.Common/Kernel/BaseKernel.cs @@ -1,4 +1,5 @@ -using MediaBrowser.Common.Logging; +using MediaBrowser.Common.Events; +using MediaBrowser.Common.Logging; using MediaBrowser.Common.Net; using MediaBrowser.Common.Net.Handlers; using MediaBrowser.Common.Plugins; @@ -24,6 +25,34 @@ namespace MediaBrowser.Common.Kernel where TConfigurationType : BaseApplicationConfiguration, new() where TApplicationPathsType : BaseApplicationPaths, new() { + #region ReloadBeginning Event + /// + /// Fires whenever the kernel begins reloading + /// + public event EventHandler>> ReloadBeginning; + private void OnReloadBeginning(IProgress progress) + { + if (ReloadBeginning != null) + { + ReloadBeginning(this, new GenericEventArgs> { Argument = progress }); + } + } + #endregion + + #region ReloadCompleted Event + /// + /// Fires whenever the kernel completes reloading + /// + public event EventHandler>> ReloadCompleted; + private void OnReloadCompleted(IProgress progress) + { + if (ReloadCompleted != null) + { + ReloadCompleted(this, new GenericEventArgs> { Argument = progress }); + } + } + #endregion + /// /// Gets the current configuration /// @@ -78,7 +107,7 @@ namespace MediaBrowser.Common.Kernel // Performs initializations that can be reloaded at anytime await Reload(progress).ConfigureAwait(false); - progress.Report(new TaskProgress { Description = "Loading Complete" }); + ReportProgress(progress, "Loading Complete"); } /// @@ -87,29 +116,41 @@ namespace MediaBrowser.Common.Kernel protected virtual void InitializeInternal(IProgress progress) { ApplicationPaths = new TApplicationPathsType(); - + ReloadLogger(); - progress.Report(new TaskProgress { Description = "Loading configuration" }); + ReportProgress(progress, "Loading Configuration"); ReloadConfiguration(); - progress.Report(new TaskProgress { Description = "Starting Http server" }); + ReportProgress(progress, "Loading Http Server"); ReloadHttpServer(); } /// /// Performs initializations that can be reloaded at anytime /// - public virtual async Task Reload(IProgress progress) + public async Task Reload(IProgress progress) + { + OnReloadBeginning(progress); + + await ReloadInternal(progress).ConfigureAwait(false); + + OnReloadCompleted(progress); + } + + /// + /// Performs initializations that can be reloaded at anytime + /// + protected virtual async Task ReloadInternal(IProgress progress) { await Task.Run(() => { - progress.Report(new TaskProgress { Description = "Loading Plugins" }); + ReportProgress(progress, "Loading Plugins"); ReloadComposableParts(); }).ConfigureAwait(false); } - + /// /// Disposes the current logger and creates a new one /// @@ -233,7 +274,7 @@ namespace MediaBrowser.Common.Kernel public virtual void Dispose() { Logger.LogInfo("Beginning Kernel.Dispose"); - + DisposeComposableParts(); DisposeHttpServer(); @@ -257,7 +298,7 @@ namespace MediaBrowser.Common.Kernel if (Plugins != null) { Logger.LogInfo("Disposing Plugins"); - + foreach (BasePlugin plugin in Plugins) { plugin.Dispose(); @@ -273,7 +314,7 @@ namespace MediaBrowser.Common.Kernel if (HttpServer != null) { Logger.LogInfo("Disposing Http Server"); - + HttpServer.Dispose(); } @@ -293,7 +334,7 @@ namespace MediaBrowser.Common.Kernel if (Logger.LoggerInstance != null) { Logger.LogInfo("Disposing Logger"); - + Logger.LoggerInstance.Dispose(); } } @@ -309,6 +350,16 @@ namespace MediaBrowser.Common.Kernel } } + protected void ReportProgress(IProgress progress, string message) + { + progress.Report(new TaskProgress { Description = message }); + + if (Logger.LoggerInstance != null) + { + Logger.LogInfo(message); + } + } + BaseApplicationPaths IKernel.ApplicationPaths { get { return ApplicationPaths; } diff --git a/MediaBrowser.Common/MediaBrowser.Common.csproj b/MediaBrowser.Common/MediaBrowser.Common.csproj index fb192ec1a..16b4f236c 100644 --- a/MediaBrowser.Common/MediaBrowser.Common.csproj +++ b/MediaBrowser.Common/MediaBrowser.Common.csproj @@ -81,6 +81,7 @@ + @@ -151,6 +152,7 @@ +