Skip to content

Commit

Permalink
Merge pull request #956 from MediaBrowser/dev
Browse files Browse the repository at this point in the history
3.0.5464.40000
  • Loading branch information
LukePulverenti committed Dec 17, 2014
2 parents 7376169 + ebdf0cf commit 1616e34
Show file tree
Hide file tree
Showing 73 changed files with 655 additions and 290 deletions.
2 changes: 1 addition & 1 deletion MediaBrowser.Api/PackageReviewService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ public class PackageReviewService : BaseApiService
private readonly IHttpClient _httpClient;
private readonly INetworkManager _netManager;
private readonly IJsonSerializer _serializer;
private const string MbAdminUrl = "https://www.mb3admin.com/admin/";
private const string MbAdminUrl = "http://www.mb3admin.com/admin/";

public PackageReviewService(IHttpClient client, INetworkManager net, IJsonSerializer serializer)
{
Expand Down
113 changes: 92 additions & 21 deletions MediaBrowser.Api/Sync/SyncService.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
using MediaBrowser.Controller.Net;
using MediaBrowser.Controller.Dto;
using MediaBrowser.Controller.Library;
using MediaBrowser.Controller.Net;
using MediaBrowser.Controller.Sync;
using MediaBrowser.Model.Dto;
using MediaBrowser.Model.Querying;
using MediaBrowser.Model.Sync;
using ServiceStack;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace MediaBrowser.Api.Sync
Expand All @@ -22,22 +27,14 @@ public class GetSyncJob : IReturn<SyncJob>
public string Id { get; set; }
}

[Route("/Sync/JobItems", "GET", Summary = "Gets sync job items.")]
public class GetSyncJobItems : SyncJobItemQuery, IReturn<QueryResult<SyncJobItem>>
{
}

[Route("/Sync/Jobs", "GET", Summary = "Gets sync jobs.")]
public class GetSyncJobs : IReturn<QueryResult<SyncJob>>
public class GetSyncJobs : SyncJobQuery, IReturn<QueryResult<SyncJob>>
{
/// <summary>
/// Skips over a given number of items within the results. Use for paging.
/// </summary>
/// <value>The start index.</value>
[ApiMember(Name = "StartIndex", Description = "Optional. The record index to start at. All items with a lower index will be dropped from the results.", IsRequired = false, DataType = "int", ParameterType = "query", Verb = "GET")]
public int? StartIndex { get; set; }

/// <summary>
/// The maximum number of items to return
/// </summary>
/// <value>The limit.</value>
[ApiMember(Name = "Limit", Description = "Optional. The maximum number of records to return", IsRequired = false, DataType = "int", ParameterType = "query", Verb = "GET")]
public int? Limit { get; set; }
}

[Route("/Sync/Jobs", "POST", Summary = "Gets sync jobs.")]
Expand All @@ -52,14 +49,42 @@ public class GetSyncTargets : IReturn<List<SyncTarget>>
public string UserId { get; set; }
}

[Route("/Sync/Options", "GET", Summary = "Gets a list of available sync targets.")]
public class GetSyncDialogOptions : IReturn<SyncDialogOptions>
{
[ApiMember(Name = "UserId", Description = "UserId", IsRequired = true, DataType = "string", ParameterType = "query", Verb = "GET")]
public string UserId { get; set; }

[ApiMember(Name = "ItemIds", Description = "ItemIds", IsRequired = true, DataType = "string", ParameterType = "query", Verb = "GET")]
public string ItemIds { get; set; }
}

[Route("/Sync/JobItems/{Id}/Transferred", "POST", Summary = "Reports that a sync job item has successfully been transferred.")]
public class ReportSyncJobItemTransferred : IReturnVoid
{
[ApiMember(Name = "Id", Description = "Id", IsRequired = true, DataType = "string", ParameterType = "path", Verb = "POST")]
public string Id { get; set; }
}

[Route("/Sync/JobItems/{Id}/File", "GET", Summary = "Gets a sync job item file")]
public class GetSyncJobItemFile
{
[ApiMember(Name = "Id", Description = "Id", IsRequired = true, DataType = "string", ParameterType = "path", Verb = "GET")]
public string Id { get; set; }
}

[Authenticated]
public class SyncService : BaseApiService
{
private readonly ISyncManager _syncManager;
private readonly IDtoService _dtoService;
private readonly ILibraryManager _libraryManager;

public SyncService(ISyncManager syncManager)
public SyncService(ISyncManager syncManager, IDtoService dtoService, ILibraryManager libraryManager)
{
_syncManager = syncManager;
_dtoService = dtoService;
_libraryManager = libraryManager;
}

public object Get(GetSyncTargets request)
Expand All @@ -71,11 +96,14 @@ public object Get(GetSyncTargets request)

public object Get(GetSyncJobs request)
{
var result = _syncManager.GetJobs(new SyncJobQuery
{
StartIndex = request.StartIndex,
Limit = request.Limit
});
var result = _syncManager.GetJobs(request);

return ToOptimizedResult(result);
}

public object Get(GetSyncJobItems request)
{
var result = _syncManager.GetJobItems(request);

return ToOptimizedResult(result);
}
Expand All @@ -100,5 +128,48 @@ public async Task<object> Post(CreateSyncJob request)

return ToOptimizedResult(result);
}

public void Post(ReportSyncJobItemTransferred request)
{
var task = _syncManager.ReportSyncJobItemTransferred(request.Id);

Task.WaitAll(task);
}

public object Get(GetSyncJobItemFile request)
{
var jobItem = _syncManager.GetJobItem(request.Id);

if (jobItem.Status != SyncJobItemStatus.Transferring)
{
throw new ArgumentException("The job item is not yet ready for transfer.");
}

return ToStaticFileResult(jobItem.OutputPath);
}

public object Get(GetSyncDialogOptions request)
{
var result = new SyncDialogOptions();

result.Targets = _syncManager.GetSyncTargets(request.UserId)
.ToList();

var dtos = request.ItemIds.Split(',')
.Select(_libraryManager.GetItemById)
.Where(i => i != null)
.Select(i => _dtoService.GetBaseItemDto(i, new DtoOptions
{
Fields = new List<ItemFields>
{
ItemFields.SyncInfo
}
}))
.ToList();

result.Options = SyncHelper.GetSyncOptions(dtos);

return ToOptimizedResult(result);
}
}
}
33 changes: 17 additions & 16 deletions MediaBrowser.Common.Implementations/BaseApplicationHost.cs
Original file line number Diff line number Diff line change
Expand Up @@ -294,33 +294,34 @@ protected virtual void OnLoggerLoaded(bool isFirstLoad)

public static void LogEnvironmentInfo(ILogger logger, IApplicationPaths appPaths, bool isStartup)
{
if (isStartup)
{
logger.Info("Media Browser Server started");
}
logger.LogMultiline("Media Browser", LogSeverity.Info, GetBaseExceptionMessage(appPaths));
}

logger.Info("Command line: {0}", string.Join(" ", Environment.GetCommandLineArgs()));
protected static StringBuilder GetBaseExceptionMessage(IApplicationPaths appPaths)
{
var builder = new StringBuilder();

logger.Info("Server: {0}", Environment.MachineName);
logger.Info("Operating system: {0}", Environment.OSVersion.ToString());
logger.Info("Processor count: {0}", Environment.ProcessorCount);
logger.Info("64-Bit OS: {0}", Environment.Is64BitOperatingSystem);
logger.Info("64-Bit Process: {0}", Environment.Is64BitProcess);
logger.Info("Program data path: {0}", appPaths.ProgramDataPath);
builder.AppendLine(string.Format("Command line: {0}", string.Join(" ", Environment.GetCommandLineArgs())));

builder.AppendLine(string.Format("Operating system: {0}", Environment.OSVersion));
builder.AppendLine(string.Format("Processor count: {0}", Environment.ProcessorCount));
builder.AppendLine(string.Format("64-Bit OS: {0}", Environment.Is64BitOperatingSystem));
builder.AppendLine(string.Format("64-Bit Process: {0}", Environment.Is64BitProcess));
builder.AppendLine(string.Format("Program data path: {0}", appPaths.ProgramDataPath));

Type type = Type.GetType("Mono.Runtime");
if (type != null)
{
MethodInfo displayName = type.GetMethod("GetDisplayName", BindingFlags.NonPublic | BindingFlags.Static);
if (displayName != null)
{
logger.Info("Mono: " + displayName.Invoke(null, null));
builder.AppendLine("Mono: " + displayName.Invoke(null, null));
}
}
logger.Info("Application Path: {0}", appPaths.ApplicationPath);
}

builder.AppendLine(string.Format("Application Path: {0}", appPaths.ApplicationPath));

logger.Info("*** When reporting issues please include the entire log file. ***".ToUpper());
return builder;
}

protected virtual IJsonSerializer CreateJsonSerializer()
Expand Down
13 changes: 12 additions & 1 deletion MediaBrowser.Common.Implementations/Logging/NLogger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ public class NLogger : ILogger
/// </summary>
private readonly NLog.Logger _logger;

private readonly ILogManager _logManager;

/// <summary>
/// The _lock object
/// </summary>
Expand All @@ -23,8 +25,10 @@ public class NLogger : ILogger
/// Initializes a new instance of the <see cref="NLogger" /> class.
/// </summary>
/// <param name="name">The name.</param>
public NLogger(string name)
/// <param name="logManager">The log manager.</param>
public NLogger(string name, ILogManager logManager)
{
_logManager = logManager;
lock (LockObject)
{
_logger = NLog.LogManager.GetLogger(name);
Expand Down Expand Up @@ -96,6 +100,13 @@ private void LogException(LogSeverity level, string message, Exception exception

var messageText = LogHelper.GetLogMessage(exception);

var prefix = _logManager.ExceptionMessagePrefix;

if (!string.IsNullOrWhiteSpace(prefix))
{
messageText.Insert(0, prefix);
}

LogMultiline(message, level, messageText);
}

Expand Down
8 changes: 7 additions & 1 deletion MediaBrowser.Common.Implementations/Logging/NlogManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,12 @@ public class NlogManager : ILogManager
/// <value>The log file path.</value>
public string LogFilePath { get; private set; }

/// <summary>
/// Gets or sets the exception message prefix.
/// </summary>
/// <value>The exception message prefix.</value>
public string ExceptionMessagePrefix { get; set; }

/// <summary>
/// Initializes a new instance of the <see cref="NlogManager" /> class.
/// </summary>
Expand Down Expand Up @@ -159,7 +165,7 @@ public void RemoveTarget(string name)
/// <returns>ILogger.</returns>
public ILogger GetLogger(string name)
{
return new NLogger(name);
return new NLogger(name, this);
}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@
<Compile Include="ScheduledTasks\Tasks\DeleteCacheFileTask.cs" />
<Compile Include="ScheduledTasks\Tasks\DeleteLogFileTask.cs" />
<Compile Include="ScheduledTasks\Tasks\ReloadLoggerFileTask.cs" />
<Compile Include="Security\MbAdmin.cs" />
<Compile Include="Security\MBLicenseFile.cs" />
<Compile Include="Security\PluginSecurityManager.cs" />
<Compile Include="Security\RegRecord.cs" />
Expand Down
13 changes: 13 additions & 0 deletions MediaBrowser.Common.Implementations/Security/MbAdmin.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@

namespace MediaBrowser.Common.Implementations.Security
{
public class MbAdmin
{
public const string HttpUrl = "http://www.mb3admin.com/admin/";

/// <summary>
/// Leaving as http for now until we get it squared away
/// </summary>
public const string HttpsUrl = "http://www.mb3admin.com/admin/";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,7 @@ namespace MediaBrowser.Common.Implementations.Security
/// </summary>
public class PluginSecurityManager : ISecurityManager
{
private const string MbAdminUrl = "https://www.mb3admin.com/admin/";

private const string MBValidateUrl = MbAdminUrl + "service/registration/validate";
private const string MBValidateUrl = MbAdmin.HttpsUrl + "service/registration/validate";

/// <summary>
/// The _is MB supporter
Expand Down Expand Up @@ -162,7 +160,7 @@ public async Task<SupporterInfo> GetSupporterInfo()
return new SupporterInfo();
}

var url = MbAdminUrl + "/service/supporter/retrieve?key=" + key;
var url = MbAdmin.HttpsUrl + "/service/supporter/retrieve?key=" + key;

using (var stream = await _httpClient.Get(url, CancellationToken.None).ConfigureAwait(false))
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using MediaBrowser.Common.Configuration;
using MediaBrowser.Common.Events;
using MediaBrowser.Common.Implementations.Security;
using MediaBrowser.Common.Net;
using MediaBrowser.Common.Plugins;
using MediaBrowser.Common.Progress;
Expand Down Expand Up @@ -161,7 +162,7 @@ public async Task<IEnumerable<PackageInfo>> GetAvailablePackages(CancellationTok
{ "systemid", _applicationHost.SystemId }
};

using (var json = await _httpClient.Post(MbAdminUrlHttps + "service/package/retrieveall", data, cancellationToken).ConfigureAwait(false))
using (var json = await _httpClient.Post(MbAdmin.HttpsUrl + "service/package/retrieveall", data, cancellationToken).ConfigureAwait(false))
{
cancellationToken.ThrowIfCancellationRequested();

Expand All @@ -172,8 +173,6 @@ public async Task<IEnumerable<PackageInfo>> GetAvailablePackages(CancellationTok
}

private Tuple<List<PackageInfo>, DateTime> _lastPackageListResult;
private const string MbAdminUrlHttp = "http://www.mb3admin.com/admin/";
private const string MbAdminUrlHttps = "https://www.mb3admin.com/admin/";

/// <summary>
/// Gets all available packages.
Expand Down Expand Up @@ -205,7 +204,7 @@ public async Task<IEnumerable<PackageInfo>> GetAvailablePackagesWithoutRegistrat
}
}

using (var json = await _httpClient.Get(MbAdminUrlHttp + "service/MB3Packages.json", cancellationToken).ConfigureAwait(false))
using (var json = await _httpClient.Get(MbAdmin.HttpUrl + "service/MB3Packages.json", cancellationToken).ConfigureAwait(false))
{
cancellationToken.ThrowIfCancellationRequested();

Expand Down
15 changes: 0 additions & 15 deletions MediaBrowser.Controller/Entities/BaseItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -899,21 +899,6 @@ internal virtual bool IsValidFromResolver(BaseItem newItem)
{
var current = this;

var currentAsPlaceHolder = current as ISupportsPlaceHolders;

if (currentAsPlaceHolder != null)
{
var newHasPlaceHolder = newItem as ISupportsPlaceHolders;

if (newHasPlaceHolder != null)
{
if (currentAsPlaceHolder.IsPlaceHolder != newHasPlaceHolder.IsPlaceHolder)
{
return false;
}
}
}

return current.IsInMixedFolder == newItem.IsInMixedFolder;
}

Expand Down
6 changes: 5 additions & 1 deletion MediaBrowser.Controller/Entities/Video.cs
Original file line number Diff line number Diff line change
Expand Up @@ -363,7 +363,11 @@ public override async Task UpdateToRepository(ItemUpdateType updateReason, Cance
{
await base.UpdateToRepository(updateReason, cancellationToken).ConfigureAwait(false);

foreach (var item in GetLocalAlternateVersionIds().Select(i => LibraryManager.GetItemById(i)))
var localAlternates = GetLocalAlternateVersionIds()
.Select(i => LibraryManager.GetItemById(i))
.Where(i => i != null);

foreach (var item in localAlternates)
{
item.ImageInfos = ImageInfos;
item.Overview = Overview;
Expand Down
Loading

0 comments on commit 1616e34

Please sign in to comment.