add ApplicationPath to app paths interface to hide implementation

pull/702/head
Luke Pulverenti 11 years ago
parent 40959a816f
commit 4e79eaf65e

@ -33,7 +33,7 @@ namespace MediaBrowser.Common.Implementations
/// </summary> /// </summary>
/// <typeparam name="TApplicationPathsType">The type of the T application paths type.</typeparam> /// <typeparam name="TApplicationPathsType">The type of the T application paths type.</typeparam>
public abstract class BaseApplicationHost<TApplicationPathsType> : IApplicationHost public abstract class BaseApplicationHost<TApplicationPathsType> : IApplicationHost
where TApplicationPathsType : class, IApplicationPaths, new() where TApplicationPathsType : class, IApplicationPaths
{ {
/// <summary> /// <summary>
/// Occurs when [has pending restart changed]. /// Occurs when [has pending restart changed].
@ -83,7 +83,7 @@ namespace MediaBrowser.Common.Implementations
/// <summary> /// <summary>
/// The json serializer /// The json serializer
/// </summary> /// </summary>
public readonly IJsonSerializer JsonSerializer = new JsonSerializer(); public IJsonSerializer JsonSerializer { get; private set; }
/// <summary> /// <summary>
/// The _XML serializer /// The _XML serializer
@ -181,6 +181,8 @@ namespace MediaBrowser.Common.Implementations
/// <returns>Task.</returns> /// <returns>Task.</returns>
public virtual async Task Init() public virtual async Task Init()
{ {
JsonSerializer = CreateJsonSerializer();
IsFirstRun = !ConfigurationManager.CommonConfiguration.IsStartupWizardCompleted; IsFirstRun = !ConfigurationManager.CommonConfiguration.IsStartupWizardCompleted;
Logger = LogManager.GetLogger("App"); Logger = LogManager.GetLogger("App");
@ -212,6 +214,11 @@ namespace MediaBrowser.Common.Implementations
} }
protected virtual IJsonSerializer CreateJsonSerializer()
{
return new JsonSerializer();
}
private void SetHttpLimit() private void SetHttpLimit()
{ {
try try

@ -20,21 +20,23 @@ namespace MediaBrowser.Common.Implementations
/// <summary> /// <summary>
/// Initializes a new instance of the <see cref="BaseApplicationPaths" /> class. /// Initializes a new instance of the <see cref="BaseApplicationPaths" /> class.
/// </summary> /// </summary>
/// <param name="useDebugPath">if set to <c>true</c> [use debug paths].</param> protected BaseApplicationPaths(bool useDebugPath, string applicationPath)
protected BaseApplicationPaths(bool useDebugPath)
{ {
_useDebugPath = useDebugPath; _useDebugPath = useDebugPath;
ApplicationPath = applicationPath;
} }
/// <summary> /// <summary>
/// Initializes a new instance of the <see cref="BaseApplicationPaths"/> class. /// Initializes a new instance of the <see cref="BaseApplicationPaths"/> class.
/// </summary> /// </summary>
/// <param name="programDataPath">The program data path.</param> protected BaseApplicationPaths(string programDataPath, string applicationPath)
protected BaseApplicationPaths(string programDataPath)
{ {
_programDataPath = programDataPath; _programDataPath = programDataPath;
ApplicationPath = applicationPath;
} }
public string ApplicationPath { get; private set; }
/// <summary> /// <summary>
/// The _program data path /// The _program data path
/// </summary> /// </summary>

@ -80,7 +80,7 @@ namespace MediaBrowser.Common.Implementations.Serialization
using (Stream stream = File.OpenRead(file)) using (Stream stream = File.OpenRead(file))
{ {
return ServiceStack.Text.JsonSerializer.DeserializeFromStream(type, stream); return DeserializeFromStream(stream, type);
} }
} }
@ -101,7 +101,7 @@ namespace MediaBrowser.Common.Implementations.Serialization
using (Stream stream = File.OpenRead(file)) using (Stream stream = File.OpenRead(file))
{ {
return ServiceStack.Text.JsonSerializer.DeserializeFromStream<T>(stream); return DeserializeFromStream<T>(stream);
} }
} }

@ -6,6 +6,12 @@ namespace MediaBrowser.Common.Configuration
/// </summary> /// </summary>
public interface IApplicationPaths public interface IApplicationPaths
{ {
/// <summary>
/// Gets the application path.
/// </summary>
/// <value>The application path.</value>
string ApplicationPath { get; }
/// <summary> /// <summary>
/// Gets the path to the program data folder /// Gets the path to the program data folder
/// </summary> /// </summary>

@ -94,6 +94,22 @@ namespace MediaBrowser.Controller.Entities.TV
get { return _series ?? (_series = FindParent<Series>()); } get { return _series ?? (_series = FindParent<Series>()); }
} }
[IgnoreDataMember]
public string SeriesPath
{
get
{
var series = Series;
if (series != null)
{
return series.Path;
}
return System.IO.Path.GetDirectoryName(Path);
}
}
/// <summary> /// <summary>
/// Our rating comes from our series /// Our rating comes from our series
/// </summary> /// </summary>

@ -99,6 +99,14 @@ namespace MediaBrowser.Server.Implementations.HttpServer
return result; return result;
} }
private bool SupportsCompression
{
get
{
return true;
}
}
/// <summary> /// <summary>
/// Gets the optimized result. /// Gets the optimized result.
/// </summary> /// </summary>
@ -116,7 +124,7 @@ namespace MediaBrowser.Server.Implementations.HttpServer
throw new ArgumentNullException("result"); throw new ArgumentNullException("result");
} }
var optimizedResult = requestContext.ToOptimizedResult(result); var optimizedResult = SupportsCompression ? requestContext.ToOptimizedResult(result) : result;
if (responseHeaders != null) if (responseHeaders != null)
{ {
@ -458,6 +466,11 @@ namespace MediaBrowser.Server.Implementations.HttpServer
} }
} }
if (!SupportsCompression)
{
return new HttpResult(content, contentType);
}
var contents = content.Compress(requestContext.CompressionType); var contents = content.Compress(requestContext.CompressionType);
return new CompressedResult(contents, requestContext.CompressionType, contentType); return new CompressedResult(contents, requestContext.CompressionType, contentType);

@ -1,6 +1,6 @@
using MediaBrowser.Common.Net; using MediaBrowser.Common.Configuration;
using MediaBrowser.Common.Net;
using ServiceStack.ServiceHost; using ServiceStack.ServiceHost;
using System.Diagnostics;
using System.IO; using System.IO;
namespace MediaBrowser.Server.Implementations.HttpServer namespace MediaBrowser.Server.Implementations.HttpServer
@ -20,6 +20,13 @@ namespace MediaBrowser.Server.Implementations.HttpServer
public class SwaggerService : IHasResultFactory, IRestfulService public class SwaggerService : IHasResultFactory, IRestfulService
{ {
private readonly IApplicationPaths _appPaths;
public SwaggerService(IApplicationPaths appPaths)
{
_appPaths = appPaths;
}
/// <summary> /// <summary>
/// Gets the specified request. /// Gets the specified request.
/// </summary> /// </summary>
@ -27,7 +34,7 @@ namespace MediaBrowser.Server.Implementations.HttpServer
/// <returns>System.Object.</returns> /// <returns>System.Object.</returns>
public object Get(GetSwaggerResource request) public object Get(GetSwaggerResource request)
{ {
var runningDirectory = Path.GetDirectoryName(Process.GetCurrentProcess().MainModule.FileName); var runningDirectory = Path.GetDirectoryName(_appPaths.ApplicationPath);
var swaggerDirectory = Path.Combine(runningDirectory, "swagger-ui"); var swaggerDirectory = Path.Combine(runningDirectory, "swagger-ui");

@ -6,6 +6,7 @@ using MediaBrowser.Controller.Entities.TV;
using MediaBrowser.Controller.IO; using MediaBrowser.Controller.IO;
using MediaBrowser.Model.Configuration; using MediaBrowser.Model.Configuration;
using MediaBrowser.Model.Entities; using MediaBrowser.Model.Entities;
using MediaBrowser.Model.Logging;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Globalization; using System.Globalization;
@ -13,7 +14,6 @@ using System.IO;
using System.Linq; using System.Linq;
using System.Threading; using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
using MediaBrowser.Model.Logging;
namespace MediaBrowser.Server.Implementations.Providers namespace MediaBrowser.Server.Implementations.Providers
{ {
@ -89,6 +89,23 @@ namespace MediaBrowser.Server.Implementations.Providers
if (locationType == LocationType.Remote || locationType == LocationType.Virtual) if (locationType == LocationType.Remote || locationType == LocationType.Virtual)
{ {
saveLocally = false; saveLocally = false;
var season = item as Season;
// If season is virtual under a physical series, save locally if using compatible convention
if (season != null && _config.Configuration.ImageSavingConvention == ImageSavingConvention.Compatible)
{
var series = season.Series;
if (series != null)
{
var seriesLocationType = series.LocationType;
if (seriesLocationType == LocationType.FileSystem || seriesLocationType == LocationType.Offline)
{
saveLocally = true;
}
}
}
} }
if (type == ImageType.Backdrop && imageIndex == null) if (type == ImageType.Backdrop && imageIndex == null)
@ -402,7 +419,7 @@ namespace MediaBrowser.Server.Implementations.Providers
return path; return path;
} }
private string GetBackdropSaveFilename(List<string> images, string zeroIndexFilename, string numberedIndexPrefix, int index) private string GetBackdropSaveFilename(IEnumerable<string> images, string zeroIndexFilename, string numberedIndexPrefix, int index)
{ {
if (index == 0) if (index == 0)
{ {
@ -431,6 +448,8 @@ namespace MediaBrowser.Server.Implementations.Providers
/// <exception cref="System.ArgumentNullException">imageIndex</exception> /// <exception cref="System.ArgumentNullException">imageIndex</exception>
private string[] GetCompatibleSavePaths(BaseItem item, ImageType type, int? imageIndex, string mimeType) private string[] GetCompatibleSavePaths(BaseItem item, ImageType type, int? imageIndex, string mimeType)
{ {
var season = item as Season;
var extension = mimeType.Split('/').Last(); var extension = mimeType.Split('/').Last();
if (string.Equals(extension, "jpeg", StringComparison.OrdinalIgnoreCase)) if (string.Equals(extension, "jpeg", StringComparison.OrdinalIgnoreCase))
@ -449,9 +468,9 @@ namespace MediaBrowser.Server.Implementations.Providers
if (imageIndex.Value == 0) if (imageIndex.Value == 0)
{ {
if (item is Season && item.IndexNumber.HasValue) if (season != null && item.IndexNumber.HasValue)
{ {
var seriesFolder = Path.GetDirectoryName(item.Path); var seriesFolder = season.SeriesPath;
var seasonMarker = item.IndexNumber.Value == 0 var seasonMarker = item.IndexNumber.Value == 0
? "-specials" ? "-specials"
@ -481,9 +500,9 @@ namespace MediaBrowser.Server.Implementations.Providers
if (type == ImageType.Primary) if (type == ImageType.Primary)
{ {
if (item is Season && item.IndexNumber.HasValue) if (season != null && item.IndexNumber.HasValue)
{ {
var seriesFolder = Path.GetDirectoryName(item.Path); var seriesFolder = season.SeriesPath;
var seasonMarker = item.IndexNumber.Value == 0 var seasonMarker = item.IndexNumber.Value == 0
? "-specials" ? "-specials"
@ -518,9 +537,9 @@ namespace MediaBrowser.Server.Implementations.Providers
if (type == ImageType.Banner) if (type == ImageType.Banner)
{ {
if (item is Season && item.IndexNumber.HasValue) if (season != null && item.IndexNumber.HasValue)
{ {
var seriesFolder = Path.GetDirectoryName(item.Path); var seriesFolder = season.SeriesPath;
var seasonMarker = item.IndexNumber.Value == 0 var seasonMarker = item.IndexNumber.Value == 0
? "-specials" ? "-specials"
@ -534,9 +553,9 @@ namespace MediaBrowser.Server.Implementations.Providers
if (type == ImageType.Thumb) if (type == ImageType.Thumb)
{ {
if (item is Season && item.IndexNumber.HasValue) if (season != null && item.IndexNumber.HasValue)
{ {
var seriesFolder = Path.GetDirectoryName(item.Path); var seriesFolder = season.SeriesPath;
var seasonMarker = item.IndexNumber.Value == 0 var seasonMarker = item.IndexNumber.Value == 0
? "-specials" ? "-specials"

@ -13,16 +13,16 @@ namespace MediaBrowser.Server.Implementations
/// <summary> /// <summary>
/// Initializes a new instance of the <see cref="ServerApplicationPaths" /> class. /// Initializes a new instance of the <see cref="ServerApplicationPaths" /> class.
/// </summary> /// </summary>
public ServerApplicationPaths() public ServerApplicationPaths(string applicationPath)
: base(true) : base(true, applicationPath)
{ {
} }
#else #else
/// <summary> /// <summary>
/// Initializes a new instance of the <see cref="ServerApplicationPaths"/> class. /// Initializes a new instance of the <see cref="ServerApplicationPaths"/> class.
/// </summary> /// </summary>
public ServerApplicationPaths() public ServerApplicationPaths(string applicationPath)
: base(false) : base(false, applicationPath)
{ {
} }
#endif #endif
@ -30,9 +30,8 @@ namespace MediaBrowser.Server.Implementations
/// <summary> /// <summary>
/// Initializes a new instance of the <see cref="BaseApplicationPaths" /> class. /// Initializes a new instance of the <see cref="BaseApplicationPaths" /> class.
/// </summary> /// </summary>
/// <param name="programDataPath">The program data path.</param> public ServerApplicationPaths(string programDataPath, string applicationPath)
public ServerApplicationPaths(string programDataPath) : base(programDataPath, applicationPath)
: base(programDataPath)
{ {
} }

@ -36,7 +36,9 @@ namespace MediaBrowser.Server.Mono
{ {
Application.Init (); Application.Init ();
var appPaths = CreateApplicationPaths(); var applicationPath = Assembly.GetEntryAssembly ().Location;
var appPaths = CreateApplicationPaths(applicationPath);
var logManager = new NlogManager(appPaths.LogDirectoryPath, "server"); var logManager = new NlogManager(appPaths.LogDirectoryPath, "server");
logManager.ReloadLogger(LogSeverity.Info); logManager.ReloadLogger(LogSeverity.Info);
@ -65,9 +67,9 @@ namespace MediaBrowser.Server.Mono
} }
} }
private static ServerApplicationPaths CreateApplicationPaths() private static ServerApplicationPaths CreateApplicationPaths(string applicationPath)
{ {
return new ServerApplicationPaths(); return new ServerApplicationPaths(applicationPath);
} }
/// <summary> /// <summary>

@ -27,6 +27,7 @@ using MediaBrowser.Controller.Session;
using MediaBrowser.Controller.Sorting; using MediaBrowser.Controller.Sorting;
using MediaBrowser.Model.Logging; using MediaBrowser.Model.Logging;
using MediaBrowser.Model.MediaInfo; using MediaBrowser.Model.MediaInfo;
using MediaBrowser.Model.Serialization;
using MediaBrowser.Model.System; using MediaBrowser.Model.System;
using MediaBrowser.Model.Updates; using MediaBrowser.Model.Updates;
using MediaBrowser.Providers; using MediaBrowser.Providers;

@ -158,7 +158,9 @@ namespace MediaBrowser.ServerApplication
return new ServerApplicationPaths(programDataPath); return new ServerApplicationPaths(programDataPath);
} }
return new ServerApplicationPaths(); var applicationPath = Process.GetCurrentProcess().MainModule.FileName;
return new ServerApplicationPaths(applicationPath);
} }
/// <summary> /// <summary>

@ -5,7 +5,6 @@ using MediaBrowser.Common.ScheduledTasks;
using MediaBrowser.Controller; using MediaBrowser.Controller;
using MediaBrowser.Controller.Configuration; using MediaBrowser.Controller.Configuration;
using MediaBrowser.Controller.Dto; using MediaBrowser.Controller.Dto;
using MediaBrowser.Controller.IO;
using MediaBrowser.Controller.Plugins; using MediaBrowser.Controller.Plugins;
using MediaBrowser.Controller.Session; using MediaBrowser.Controller.Session;
using MediaBrowser.Model.Logging; using MediaBrowser.Model.Logging;
@ -13,7 +12,6 @@ using MediaBrowser.Model.Tasks;
using ServiceStack.ServiceHost; using ServiceStack.ServiceHost;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Diagnostics;
using System.IO; using System.IO;
using System.Linq; using System.Linq;
using System.Reflection; using System.Reflection;
@ -151,7 +149,7 @@ namespace MediaBrowser.WebDashboard.Api
return _serverConfigurationManager.Configuration.DashboardSourcePath; return _serverConfigurationManager.Configuration.DashboardSourcePath;
} }
var runningDirectory = Path.GetDirectoryName(Process.GetCurrentProcess().MainModule.FileName); var runningDirectory = Path.GetDirectoryName(_serverConfigurationManager.ApplicationPaths.ApplicationPath);
return Path.Combine(runningDirectory, "dashboard-ui"); return Path.Combine(runningDirectory, "dashboard-ui");
} }

Loading…
Cancel
Save