diff --git a/MediaBrowser.Common.Implementations/Logging/NlogManager.cs b/MediaBrowser.Common.Implementations/Logging/NlogManager.cs
index e20f9bc13..56f2b5e29 100644
--- a/MediaBrowser.Common.Implementations/Logging/NlogManager.cs
+++ b/MediaBrowser.Common.Implementations/Logging/NlogManager.cs
@@ -202,5 +202,13 @@ namespace MediaBrowser.Common.Implementations.Logging
}
}
}
+
+ ///
+ /// Flushes this instance.
+ ///
+ public void Flush()
+ {
+ LogManager.Flush();
+ }
}
}
diff --git a/MediaBrowser.Model/Logging/ILogManager.cs b/MediaBrowser.Model/Logging/ILogManager.cs
index 2207ddc75..fabca4459 100644
--- a/MediaBrowser.Model/Logging/ILogManager.cs
+++ b/MediaBrowser.Model/Logging/ILogManager.cs
@@ -35,5 +35,10 @@ namespace MediaBrowser.Model.Logging
/// Occurs when [logger loaded].
///
event EventHandler LoggerLoaded;
+
+ ///
+ /// Flushes this instance.
+ ///
+ void Flush();
}
}
diff --git a/MediaBrowser.Server.Implementations/Session/WebSocketController.cs b/MediaBrowser.Server.Implementations/Session/WebSocketController.cs
index 6bbebf156..70d7ac071 100644
--- a/MediaBrowser.Server.Implementations/Session/WebSocketController.cs
+++ b/MediaBrowser.Server.Implementations/Session/WebSocketController.cs
@@ -123,7 +123,7 @@ namespace MediaBrowser.Server.Implementations.Session
return socket.SendAsync(new WebSocketMessage
{
- MessageType = "Playstate",
+ MessageType = "LibraryChanged",
Data = info
}, cancellationToken);
diff --git a/MediaBrowser.Server.Implementations/WebSocket/AlchemyServer.cs b/MediaBrowser.Server.Implementations/WebSocket/AlchemyServer.cs
index 14d468a8e..251083dc2 100644
--- a/MediaBrowser.Server.Implementations/WebSocket/AlchemyServer.cs
+++ b/MediaBrowser.Server.Implementations/WebSocket/AlchemyServer.cs
@@ -4,7 +4,6 @@ using MediaBrowser.Common.Net;
using MediaBrowser.Model.Logging;
using System;
using System.Net;
-using System.Net.Sockets;
namespace MediaBrowser.Server.Implementations.WebSocket
{
@@ -29,6 +28,8 @@ namespace MediaBrowser.Server.Implementations.WebSocket
///
private readonly ILogger _logger;
+ private bool _hasStopped;
+
///
/// Initializes a new instance of the class.
///
@@ -57,6 +58,8 @@ namespace MediaBrowser.Server.Implementations.WebSocket
/// The port number.
public void Start(int portNumber)
{
+ _logger.Info("Starting Alchemy web socket server on port {0}", portNumber);
+
try
{
WebSocketServer = new WebSocketServer(portNumber, IPAddress.Any)
@@ -87,6 +90,11 @@ namespace MediaBrowser.Server.Implementations.WebSocket
/// The context.
private void OnAlchemyWebSocketClientConnected(UserContext context)
{
+ if (_hasStopped)
+ {
+ return;
+ }
+
if (WebSocketConnected != null)
{
var socket = new AlchemyWebSocket(context, _logger);
@@ -127,6 +135,8 @@ namespace MediaBrowser.Server.Implementations.WebSocket
/// true to release both managed and unmanaged resources; false to release only unmanaged resources.
protected virtual void Dispose(bool dispose)
{
+ _hasStopped = true;
+
lock (_syncLock)
{
if (WebSocketServer != null)
diff --git a/MediaBrowser.ServerApplication/MainStartup.cs b/MediaBrowser.ServerApplication/MainStartup.cs
index 7e19e5f95..577f5ea38 100644
--- a/MediaBrowser.ServerApplication/MainStartup.cs
+++ b/MediaBrowser.ServerApplication/MainStartup.cs
@@ -1,5 +1,4 @@
-using System.Runtime.InteropServices;
-using MediaBrowser.Common.Constants;
+using MediaBrowser.Common.Constants;
using MediaBrowser.Common.Implementations.Logging;
using MediaBrowser.Common.Implementations.Updates;
using MediaBrowser.Controller.IO;
@@ -13,6 +12,7 @@ using System.Configuration.Install;
using System.Diagnostics;
using System.IO;
using System.Linq;
+using System.Runtime.InteropServices;
using System.ServiceProcess;
using System.Windows;
@@ -251,9 +251,7 @@ namespace MediaBrowser.ServerApplication
if (_isRestarting)
{
- using (var process = Process.Start("cmd", "/c net start " + BackgroundService.Name))
- {
- }
+ Process.Start("cmd", "/c net start " + BackgroundService.Name);
_logger.Info("New service process started");
}
@@ -383,6 +381,8 @@ namespace MediaBrowser.ServerApplication
_logger.ErrorException("UnhandledException", exception);
+ _appHost.LogManager.Flush();
+
if (!_isRunningAsService)
{
_app.OnUnhandledException(exception);
@@ -390,7 +390,7 @@ namespace MediaBrowser.ServerApplication
if (!Debugger.IsAttached)
{
- Environment.Exit(System.Runtime.InteropServices.Marshal.GetHRForException(exception));
+ Environment.Exit(Marshal.GetHRForException(exception));
}
}
@@ -411,13 +411,16 @@ namespace MediaBrowser.ServerApplication
// Update is there - execute update
try
{
- new ApplicationUpdater().UpdateApplication(MBApplication.MBServer, appPaths, updateArchive);
+ var serviceName = _isRunningAsService ? BackgroundService.Name : string.Empty;
+ new ApplicationUpdater().UpdateApplication(MBApplication.MBServer, appPaths, updateArchive, logger, serviceName);
// And just let the app exit so it can update
return true;
}
catch (Exception e)
{
+ logger.ErrorException("Error starting updater.", e);
+
MessageBox.Show(string.Format("Error attempting to update application.\n\n{0}\n\n{1}", e.GetType().Name, e.Message));
}
}