Explorar el Código

fixes #224 - Exception trying to start server after a reboot

Luke Pulverenti hace 12 años
padre
commit
de6acec504
Se han modificado 1 ficheros con 27 adiciones y 1 borrados
  1. 27 1
      MediaBrowser.ServerApplication/ApplicationHost.cs

+ 27 - 1
MediaBrowser.ServerApplication/ApplicationHost.cs

@@ -382,7 +382,8 @@ namespace MediaBrowser.ServerApplication
                     HttpServer.Init(GetExports<IRestfulService>(false));
                     HttpServer.Init(GetExports<IRestfulService>(false));
 
 
                     ServerManager.AddWebSocketListeners(GetExports<IWebSocketListener>(false));
                     ServerManager.AddWebSocketListeners(GetExports<IWebSocketListener>(false));
-                    ServerManager.Start();
+
+                    StartServer(true);
                 },
                 },
 
 
                 () => LibraryManager.AddParts(GetExports<IResolverIgnoreRule>(), GetExports<IVirtualFolderCreator>(), GetExports<IItemResolver>(), GetExports<IIntroProvider>(), GetExports<IBaseItemComparer>()),
                 () => LibraryManager.AddParts(GetExports<IResolverIgnoreRule>(), GetExports<IVirtualFolderCreator>(), GetExports<IItemResolver>(), GetExports<IIntroProvider>(), GetExports<IBaseItemComparer>()),
@@ -405,6 +406,31 @@ namespace MediaBrowser.ServerApplication
                 );
                 );
         }
         }
 
 
+        /// <summary>
+        /// Starts the server.
+        /// </summary>
+        /// <param name="retryOnFailure">if set to <c>true</c> [retry on failure].</param>
+        private void StartServer(bool retryOnFailure)
+        {
+            try
+            {
+                ServerManager.Start();
+            }
+            catch
+            {
+                if (retryOnFailure)
+                {
+                    RegisterServerWithAdministratorAccess();
+
+                    StartServer(false);
+                }
+                else
+                {
+                    throw;
+                }
+            }
+        }
+
         /// <summary>
         /// <summary>
         /// Restarts this instance.
         /// Restarts this instance.
         /// </summary>
         /// </summary>