This commit is contained in:
Eric Reed 2013-05-07 15:27:23 -04:00
commit 52a7267864
6 changed files with 92 additions and 30 deletions

View File

@ -201,7 +201,7 @@ namespace MediaBrowser.Common.Implementations
Task.Run(() => ConfigureAutoRunAtStartup()); Task.Run(() => ConfigureAutoRunAtStartup());
ConfigurationManager.ConfigurationUpdated += ConfigurationManager_ConfigurationUpdated; ConfigurationManager.ConfigurationUpdated += OnConfigurationUpdated;
}); });
} }
@ -459,7 +459,7 @@ namespace MediaBrowser.Common.Implementations
/// <param name="sender">The source of the event.</param> /// <param name="sender">The source of the event.</param>
/// <param name="e">The <see cref="EventArgs" /> instance containing the event data.</param> /// <param name="e">The <see cref="EventArgs" /> instance containing the event data.</param>
/// <exception cref="System.NotImplementedException"></exception> /// <exception cref="System.NotImplementedException"></exception>
void ConfigurationManager_ConfigurationUpdated(object sender, EventArgs e) protected virtual void OnConfigurationUpdated(object sender, EventArgs e)
{ {
ConfigureAutoRunAtStartup(); ConfigureAutoRunAtStartup();
} }

View File

@ -410,11 +410,13 @@ namespace MediaBrowser.Server.Implementations.IO
return false; return false;
} }
FileStream stream = null;
try try
{ {
stream = new FileStream(path, FileMode.Open, FileAccess.ReadWrite, FileShare.ReadWrite); using (new FileStream(path, FileMode.Open, FileAccess.ReadWrite, FileShare.ReadWrite))
{
//file is not locked
return false;
}
} }
catch catch
{ {
@ -424,14 +426,6 @@ namespace MediaBrowser.Server.Implementations.IO
//or does not exist (has already been processed) //or does not exist (has already been processed)
return true; return true;
} }
finally
{
if (stream != null)
stream.Close();
}
//file is not locked
return false;
} }
/// <summary> /// <summary>

View File

@ -682,6 +682,7 @@ namespace MediaBrowser.Server.Implementations.MediaEncoder
throw new ApplicationException(msg); throw new ApplicationException(msg);
} }
await SetAssFont(outputPath).ConfigureAwait(false);
} }
/// <summary> /// <summary>
@ -843,6 +844,36 @@ namespace MediaBrowser.Server.Implementations.MediaEncoder
throw new ApplicationException(msg); throw new ApplicationException(msg);
} }
await SetAssFont(outputPath).ConfigureAwait(false);
}
/// <summary>
/// Sets the ass font.
/// </summary>
/// <param name="file">The file.</param>
/// <returns>Task.</returns>
private async Task SetAssFont(string file)
{
string text;
Encoding encoding;
using (var reader = new StreamReader(file, detectEncodingFromByteOrderMarks: true))
{
encoding = reader.CurrentEncoding;
text = await reader.ReadToEndAsync().ConfigureAwait(false);
}
var newText = text.Replace(",Arial,", ",Arial Unicode MS,");
if (!string.Equals(text, newText))
{
using (var writer = new StreamWriter(file, false, encoding))
{
writer.Write(newText);
}
}
} }
/// <summary> /// <summary>

View File

@ -457,9 +457,9 @@ namespace MediaBrowser.Server.Implementations.Providers
{ {
var ms = new MemoryStream(); var ms = new MemoryStream();
using (var input = dataToSave) using (dataToSave)
{ {
await input.CopyToAsync(ms).ConfigureAwait(false); await dataToSave.CopyToAsync(ms).ConfigureAwait(false);
} }
ms.Position = 0; ms.Position = 0;
@ -470,9 +470,9 @@ namespace MediaBrowser.Server.Implementations.Providers
{ {
using (var fs = new FileStream(path, FileMode.Create, FileAccess.Write, FileShare.Read, StreamDefaults.DefaultFileStreamBufferSize, FileOptions.Asynchronous)) using (var fs = new FileStream(path, FileMode.Create, FileAccess.Write, FileShare.Read, StreamDefaults.DefaultFileStreamBufferSize, FileOptions.Asynchronous))
{ {
using (var input = dataToSave) using (dataToSave)
{ {
await input.CopyToAsync(fs, StreamDefaults.DefaultCopyToBufferSize, cancellationToken).ConfigureAwait(false); await dataToSave.CopyToAsync(fs, StreamDefaults.DefaultCopyToBufferSize, cancellationToken).ConfigureAwait(false);
} }
} }

View File

@ -114,6 +114,8 @@ namespace MediaBrowser.Server.Implementations.ServerManager
_applicationHost = applicationHost; _applicationHost = applicationHost;
ConfigurationManager = configurationManager; ConfigurationManager = configurationManager;
_kernel = kernel; _kernel = kernel;
ConfigurationManager.ConfigurationUpdated += ConfigurationUpdated;
} }
/// <summary> /// <summary>
@ -127,8 +129,6 @@ namespace MediaBrowser.Server.Implementations.ServerManager
{ {
ReloadExternalWebSocketServer(); ReloadExternalWebSocketServer();
} }
ConfigurationManager.ConfigurationUpdated += ConfigurationUpdated;
} }
/// <summary> /// <summary>
@ -352,16 +352,6 @@ namespace MediaBrowser.Server.Implementations.ServerManager
void ConfigurationUpdated(object sender, EventArgs e) void ConfigurationUpdated(object sender, EventArgs e)
{ {
HttpServer.EnableHttpRequestLogging = ConfigurationManager.Configuration.EnableHttpLevelLogging; HttpServer.EnableHttpRequestLogging = ConfigurationManager.Configuration.EnableHttpLevelLogging;
if (!string.Equals(HttpServer.UrlPrefix, _kernel.HttpServerUrlPrefix, StringComparison.OrdinalIgnoreCase))
{
ReloadHttpServer();
}
if (!SupportsNativeWebSocket && ExternalWebSocketServer != null && ExternalWebSocketServer.Port != ConfigurationManager.Configuration.LegacyWebSocketPortNumber)
{
ReloadExternalWebSocketServer();
}
} }
/// <summary> /// <summary>

View File

@ -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,52 @@ 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>
/// Called when [configuration updated].
/// </summary>
/// <param name="sender">The sender.</param>
/// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param>
protected override void OnConfigurationUpdated(object sender, EventArgs e)
{
base.OnConfigurationUpdated(sender, e);
if (!string.Equals(HttpServer.UrlPrefix, ServerKernel.HttpServerUrlPrefix, StringComparison.OrdinalIgnoreCase))
{
NotifyPendingRestart();
}
else if (!ServerManager.SupportsNativeWebSocket && ServerManager.WebSocketPortNumber != ServerConfigurationManager.Configuration.LegacyWebSocketPortNumber)
{
NotifyPendingRestart();
}
}
/// <summary> /// <summary>
/// Restarts this instance. /// Restarts this instance.
/// </summary> /// </summary>