Browse Source

Added IProgress to Kernel.Init

LukePulverenti Luke Pulverenti luke pulverenti 13 years ago
parent
commit
882e20e9a5

+ 16 - 5
MediaBrowser.Common/Kernel/BaseKernel.cs

@@ -11,13 +11,14 @@ using MediaBrowser.Common.Json;
 using MediaBrowser.Common.Logging;
 using MediaBrowser.Common.Net;
 using MediaBrowser.Common.Plugins;
+using MediaBrowser.Common.Progress;
 
 namespace MediaBrowser.Common.Kernel
 {
     /// <summary>
     /// Represents a shared base kernel for both the UI and server apps
     /// </summary>
-    public abstract class BaseKernel<TConfigurationType>
+    public abstract class BaseKernel<TConfigurationType> : IDisposable
         where TConfigurationType : BaseApplicationConfiguration, new()
     {
         /// <summary>
@@ -76,12 +77,12 @@ namespace MediaBrowser.Common.Kernel
             Logger.LoggerInstance = new FileLogger(Path.Combine(ProgramDataPath, "Logs"));
         }
 
-        public virtual void Init()
+        public virtual void Init(IProgress<TaskProgress> progress)
         {
             ReloadConfiguration();
 
             ReloadHttpServer();
-
+            
             ReloadComposableParts();
         }
 
@@ -206,13 +207,18 @@ namespace MediaBrowser.Common.Kernel
         /// Restarts the Http Server, or starts it if not currently running
         /// </summary>
         private void ReloadHttpServer()
+        {
+            DisposeHttpServer();
+
+            HttpServer = new HttpServer("http://+:" + Configuration.HttpServerPortNumber + "/mediabrowser/");
+        }
+
+        private void DisposeHttpServer()
         {
             if (HttpServer != null)
             {
                 HttpServer.Dispose();
             }
-
-            HttpServer = new HttpServer("http://+:" + Configuration.HttpServerPortNumber + "/mediabrowser/");
         }
 
         /// <summary>
@@ -234,5 +240,10 @@ namespace MediaBrowser.Common.Kernel
 
             return null;
         }
+
+        public void Dispose()
+        {
+            DisposeHttpServer();
+        }
     }
 }

+ 1 - 0
MediaBrowser.Common/MediaBrowser.Common.csproj

@@ -67,6 +67,7 @@
     <Compile Include="Logging\Logger.cs" />
     <Compile Include="Logging\LogRow.cs" />
     <Compile Include="Plugins\BasePlugin.cs" />
+    <Compile Include="Progress\TaskProgress.cs" />
     <Compile Include="Properties\AssemblyInfo.cs" />
   </ItemGroup>
   <ItemGroup>

+ 19 - 0
MediaBrowser.Common/Progress/TaskProgress.cs

@@ -0,0 +1,19 @@
+
+namespace MediaBrowser.Common.Progress
+{
+    /// <summary>
+    /// Represents a generic progress class that can be used with IProgress
+    /// </summary>
+    public class TaskProgress
+    {
+        /// <summary>
+        /// Gets or sets the current completion percentage
+        /// </summary>
+        public decimal PercentComplete { get; set; }
+
+        /// <summary>
+        /// Gets or sets a description of the actions currently executing
+        /// </summary>
+        public string Description { get; set; }
+    }
+}

+ 4 - 1
MediaBrowser.Program/Program.cs

@@ -1,5 +1,6 @@
 using System;
 using MediaBrowser.Controller;
+using MediaBrowser.Common.Progress;
 
 namespace MediaBrowser.Program
 {
@@ -18,7 +19,9 @@ namespace MediaBrowser.Program
 
             Kernel kernel = new Kernel();
 
-            kernel.Init();
+            Progress<TaskProgress> progress = new Progress<TaskProgress>();
+
+            kernel.Init(progress);
 
             var time = DateTime.Now - now;
             Console.WriteLine("Done in " + time.TotalSeconds + " seconds");