From 364fbb9e0c7586afa296ddd7d739df086f4c3533 Mon Sep 17 00:00:00 2001 From: LukePulverenti Date: Mon, 25 Feb 2013 00:17:59 -0500 Subject: [PATCH] fixed plugin assembly downloads as well as debug/release detection with nuget assemblies --- .../BaseApplicationPaths.cs | 23 ++++++--- MediaBrowser.Common/Kernel/BaseKernel.cs | 2 - .../MediaBrowser.Common.csproj | 1 + MediaBrowser.Common/Net/BaseRestService.cs | 9 +++- MediaBrowser.Common/Net/MimeTypes.cs | 2 +- MediaBrowser.Common/Net/StreamWriter.cs | 48 +++++++++++++++++++ .../ServerApplicationPaths.cs | 14 ++++++ .../ApplicationHost.cs | 3 +- 8 files changed, 90 insertions(+), 12 deletions(-) create mode 100644 MediaBrowser.Common/Net/StreamWriter.cs 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 @@ -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 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 @@ + 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 +{ + /// + /// 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 e473808f5..a5e5b39c4 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 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 /// 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); }