diff options
| -rw-r--r-- | MediaBrowser.Common.Implementations/BaseApplicationPaths.cs | 23 | ||||
| -rw-r--r-- | MediaBrowser.Common/Kernel/BaseKernel.cs | 2 | ||||
| -rw-r--r-- | MediaBrowser.Common/MediaBrowser.Common.csproj | 1 | ||||
| -rw-r--r-- | MediaBrowser.Common/Net/BaseRestService.cs | 9 | ||||
| -rw-r--r-- | MediaBrowser.Common/Net/MimeTypes.cs | 2 | ||||
| -rw-r--r-- | MediaBrowser.Common/Net/StreamWriter.cs | 48 | ||||
| -rw-r--r-- | MediaBrowser.Server.Implementations/ServerApplicationPaths.cs | 14 | ||||
| -rw-r--r-- | MediaBrowser.ServerApplication/ApplicationHost.cs | 3 |
8 files changed, 90 insertions, 12 deletions
diff --git a/MediaBrowser.Common.Implementations/BaseApplicationPaths.cs b/MediaBrowser.Common.Implementations/BaseApplicationPaths.cs index f38013d00..e7abad1a4 100644 --- a/MediaBrowser.Common.Implementations/BaseApplicationPaths.cs +++ b/MediaBrowser.Common.Implementations/BaseApplicationPaths.cs @@ -13,6 +13,20 @@ namespace MediaBrowser.Common.Implementations public abstract class BaseApplicationPaths : IApplicationPaths { /// <summary> + /// The _use debug path + /// </summary> + private bool _useDebugPath; + + /// <summary> + /// Initializes a new instance of the <see cref="BaseApplicationPaths" /> class. + /// </summary> + /// <param name="useDebugPath">if set to <c>true</c> [use debug paths].</param> + protected BaseApplicationPaths(bool useDebugPath) + { + _useDebugPath = useDebugPath; + } + + /// <summary> /// The _program data path /// </summary> private string _programDataPath; @@ -272,14 +286,9 @@ namespace MediaBrowser.Common.Implementations /// Gets the path to the application's ProgramDataFolder /// </summary> /// <returns>System.String.</returns> - public static string GetProgramDataPath() + private string GetProgramDataPath() { -#if DEBUG - string programDataPath = ConfigurationManager.AppSettings["DebugProgramDataPath"]; - -#else - string programDataPath = Path.Combine(ConfigurationManager.AppSettings["ReleaseProgramDataPath"], ConfigurationManager.AppSettings["ProgramDataFolderName"]); -#endif + var programDataPath = _useDebugPath ? ConfigurationManager.AppSettings["DebugProgramDataPath"] : Path.Combine(ConfigurationManager.AppSettings["ReleaseProgramDataPath"], ConfigurationManager.AppSettings["ProgramDataFolderName"]); programDataPath = programDataPath.Replace("%CommonApplicationData%", Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData)); diff --git a/MediaBrowser.Common/Kernel/BaseKernel.cs b/MediaBrowser.Common/Kernel/BaseKernel.cs index 7a1492359..eb5381e20 100644 --- a/MediaBrowser.Common/Kernel/BaseKernel.cs +++ b/MediaBrowser.Common/Kernel/BaseKernel.cs @@ -312,8 +312,6 @@ namespace MediaBrowser.Common.Kernel // Set these to null so that they can be lazy loaded again Configuration = null; - ReloadLogger(); - Logger.Info("Version {0} initializing", ApplicationVersion); await OnConfigurationLoaded().ConfigureAwait(false); diff --git a/MediaBrowser.Common/MediaBrowser.Common.csproj b/MediaBrowser.Common/MediaBrowser.Common.csproj index dd73e8877..bc3678a5e 100644 --- a/MediaBrowser.Common/MediaBrowser.Common.csproj +++ b/MediaBrowser.Common/MediaBrowser.Common.csproj @@ -107,6 +107,7 @@ <Compile Include="Net\IWebSocket.cs" /> <Compile Include="Net\IWebSocketServer.cs" /> <Compile Include="Net\MimeTypes.cs" /> + <Compile Include="Net\StreamWriter.cs" /> <Compile Include="Net\UdpMessageReceivedEventArgs.cs" /> <Compile Include="Net\WebSocketConnectEventArgs.cs" /> <Compile Include="Net\WebSocketConnection.cs" /> diff --git a/MediaBrowser.Common/Net/BaseRestService.cs b/MediaBrowser.Common/Net/BaseRestService.cs index 59818a932..a7e95fca2 100644 --- a/MediaBrowser.Common/Net/BaseRestService.cs +++ b/MediaBrowser.Common/Net/BaseRestService.cs @@ -241,6 +241,10 @@ namespace MediaBrowser.Common.Net { return false; } + if (contentType.StartsWith("application/", StringComparison.OrdinalIgnoreCase)) + { + return false; + } return true; } @@ -257,7 +261,10 @@ namespace MediaBrowser.Common.Net if (!compress || string.IsNullOrEmpty(RequestContext.CompressionType)) { Response.ContentType = contentType; - return await factoryFn().ConfigureAwait(false); + + var stream = await factoryFn().ConfigureAwait(false); + + return new StreamWriter(stream); } string content; diff --git a/MediaBrowser.Common/Net/MimeTypes.cs b/MediaBrowser.Common/Net/MimeTypes.cs index b9d0347d7..7bd01bf6d 100644 --- a/MediaBrowser.Common/Net/MimeTypes.cs +++ b/MediaBrowser.Common/Net/MimeTypes.cs @@ -173,7 +173,7 @@ namespace MediaBrowser.Common.Net // Misc if (ext.Equals(".dll", StringComparison.OrdinalIgnoreCase)) { - return "application/x-msdownload"; + return "application/octet-stream"; } // Web diff --git a/MediaBrowser.Common/Net/StreamWriter.cs b/MediaBrowser.Common/Net/StreamWriter.cs new file mode 100644 index 000000000..220c52578 --- /dev/null +++ b/MediaBrowser.Common/Net/StreamWriter.cs @@ -0,0 +1,48 @@ +using ServiceStack.Service; +using System.IO; +using System.Threading.Tasks; + +namespace MediaBrowser.Common.Net +{ + /// <summary> + /// Class StreamWriter + /// </summary> + public class StreamWriter : IStreamWriter + { + /// <summary> + /// Gets or sets the source stream. + /// </summary> + /// <value>The source stream.</value> + public Stream SourceStream { get; set; } + + /// <summary> + /// Initializes a new instance of the <see cref="StreamWriter" /> class. + /// </summary> + /// <param name="source">The source.</param> + public StreamWriter(Stream source) + { + SourceStream = source; + } + + /// <summary> + /// Writes to. + /// </summary> + /// <param name="responseStream">The response stream.</param> + public void WriteTo(Stream responseStream) + { + var task = WriteToAsync(responseStream); + + Task.WaitAll(task); + } + + /// <summary> + /// Writes to async. + /// </summary> + /// <param name="responseStream">The response stream.</param> + /// <returns>Task.</returns> + private Task WriteToAsync(Stream responseStream) + { + return SourceStream.CopyToAsync(responseStream); + } + } +} diff --git a/MediaBrowser.Server.Implementations/ServerApplicationPaths.cs b/MediaBrowser.Server.Implementations/ServerApplicationPaths.cs index e473808f5..a5e5b39c4 100644 --- a/MediaBrowser.Server.Implementations/ServerApplicationPaths.cs +++ b/MediaBrowser.Server.Implementations/ServerApplicationPaths.cs @@ -9,6 +9,20 @@ namespace MediaBrowser.Server.Implementations /// </summary> public class ServerApplicationPaths : BaseApplicationPaths, IServerApplicationPaths { +#if (DEBUG) + /// <summary> + /// Initializes a new instance of the <see cref="ServerApplicationPaths" /> class. + /// </summary> + public ServerApplicationPaths() + : base(true) + { + } +#elif (RELEASE) + public ServerApplicationPaths() + : base(false) + { + } +#endif /// <summary> /// The _root folder path /// </summary> diff --git a/MediaBrowser.ServerApplication/ApplicationHost.cs b/MediaBrowser.ServerApplication/ApplicationHost.cs index 88eb1c7e1..5a98e7d93 100644 --- a/MediaBrowser.ServerApplication/ApplicationHost.cs +++ b/MediaBrowser.ServerApplication/ApplicationHost.cs @@ -119,6 +119,7 @@ namespace MediaBrowser.ServerApplication _taskManager = new TaskManager(_applicationPaths, _jsonSerializer, Logger); Kernel = new Kernel(this, _applicationPaths, _xmlSerializer, _taskManager, Logger); + ReloadLogger(); RegisterResources(); @@ -333,7 +334,7 @@ namespace MediaBrowser.ServerApplication /// <exception cref="System.NotImplementedException"></exception> public void ReloadLogger() { - LogFilePath = Path.Combine(Kernel.ApplicationPaths.LogDirectoryPath, "Server-" + DateTime.Now.Ticks + ".log"); + LogFilePath = Path.Combine(_applicationPaths.LogDirectoryPath, "Server-" + DateTime.Now.Ticks + ".log"); NlogManager.AddFileTarget(LogFilePath, Kernel.Configuration.EnableDebugLevelLogging); } |
