diff --git a/MediaBrowser.Common.Implementations/BaseApplicationPaths.cs b/MediaBrowser.Common.Implementations/BaseApplicationPaths.cs index f38013d00c..e7abad1a43 100644 --- a/MediaBrowser.Common.Implementations/BaseApplicationPaths.cs +++ b/MediaBrowser.Common.Implementations/BaseApplicationPaths.cs @@ -12,6 +12,20 @@ namespace MediaBrowser.Common.Implementations /// public abstract class BaseApplicationPaths : IApplicationPaths { + /// + /// The _use debug path + /// + private bool _useDebugPath; + + /// + /// Initializes a new instance of the class. + /// + /// if set to true [use debug paths]. + protected BaseApplicationPaths(bool useDebugPath) + { + _useDebugPath = useDebugPath; + } + /// /// The _program data path /// @@ -272,14 +286,9 @@ namespace MediaBrowser.Common.Implementations /// Gets the path to the application's ProgramDataFolder /// /// System.String. - 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 7a14923593..eb5381e206 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 dd73e8877e..bc3678a5e2 100644 --- a/MediaBrowser.Common/MediaBrowser.Common.csproj +++ b/MediaBrowser.Common/MediaBrowser.Common.csproj @@ -107,6 +107,7 @@ + diff --git a/MediaBrowser.Common/Net/BaseRestService.cs b/MediaBrowser.Common/Net/BaseRestService.cs index 59818a9325..a7e95fca2f 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 b9d0347d7e..7bd01bf6d7 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 0000000000..220c52578e --- /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 +{ + /// + /// Class StreamWriter + /// + public class StreamWriter : IStreamWriter + { + /// + /// Gets or sets the source stream. + /// + /// The source stream. + public Stream SourceStream { get; set; } + + /// + /// Initializes a new instance of the class. + /// + /// The source. + public StreamWriter(Stream source) + { + SourceStream = source; + } + + /// + /// Writes to. + /// + /// The response stream. + public void WriteTo(Stream responseStream) + { + var task = WriteToAsync(responseStream); + + Task.WaitAll(task); + } + + /// + /// Writes to async. + /// + /// The response stream. + /// Task. + private Task WriteToAsync(Stream responseStream) + { + return SourceStream.CopyToAsync(responseStream); + } + } +} diff --git a/MediaBrowser.Server.Implementations/ServerApplicationPaths.cs b/MediaBrowser.Server.Implementations/ServerApplicationPaths.cs index e473808f5c..a5e5b39c44 100644 --- a/MediaBrowser.Server.Implementations/ServerApplicationPaths.cs +++ b/MediaBrowser.Server.Implementations/ServerApplicationPaths.cs @@ -9,6 +9,20 @@ namespace MediaBrowser.Server.Implementations /// public class ServerApplicationPaths : BaseApplicationPaths, IServerApplicationPaths { +#if (DEBUG) + /// + /// Initializes a new instance of the class. + /// + public ServerApplicationPaths() + : base(true) + { + } +#elif (RELEASE) + public ServerApplicationPaths() + : base(false) + { + } +#endif /// /// The _root folder path /// diff --git a/MediaBrowser.ServerApplication/ApplicationHost.cs b/MediaBrowser.ServerApplication/ApplicationHost.cs index 88eb1c7e11..5a98e7d93d 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 /// 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); }