From 28ffeb5121247ced3fc7d764242e41b92837f740 Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Thu, 26 Feb 2015 15:06:42 -0500 Subject: [PATCH] sync updates --- .../Sync/ICloudSyncProvider.cs | 17 ++++-- .../Sync/IServerSyncProvider.cs | 37 +++++-------- .../Subtitles/SubtitleEncoder.cs | 6 +-- ...MediaBrowser.Server.Implementations.csproj | 2 +- .../Sync/CloudSyncProvider.cs | 22 ++++---- .../Sync/MediaSync.cs | 54 ++++++++++--------- .../packages.config | 2 +- .../MediaBrowser.ServerApplication.csproj | 2 +- .../packages.config | 2 +- .../Savers/BaseNfoSaver.cs | 2 +- Nuget/MediaBrowser.Common.Internal.nuspec | 4 +- Nuget/MediaBrowser.Common.nuspec | 2 +- Nuget/MediaBrowser.Model.Signed.nuspec | 2 +- Nuget/MediaBrowser.Server.Core.nuspec | 4 +- 14 files changed, 82 insertions(+), 76 deletions(-) diff --git a/MediaBrowser.Controller/Sync/ICloudSyncProvider.cs b/MediaBrowser.Controller/Sync/ICloudSyncProvider.cs index dd7fda2c5..8f03aea0a 100644 --- a/MediaBrowser.Controller/Sync/ICloudSyncProvider.cs +++ b/MediaBrowser.Controller/Sync/ICloudSyncProvider.cs @@ -1,5 +1,7 @@ using MediaBrowser.Model.Sync; +using System; using System.Collections.Generic; +using System.IO; using System.Threading; using System.Threading.Tasks; @@ -23,13 +25,22 @@ namespace MediaBrowser.Controller.Sync /// /// Transfers the item file. /// - /// The server identifier. - /// The item identifier. /// The input file. /// The path parts. /// The target. + /// The progress. /// The cancellation token. /// Task. - Task TransferItemFile(string serverId, string itemId, string inputFile, string[] pathParts, SyncTarget target, CancellationToken cancellationToken); + Task SendFile(string inputFile, string[] pathParts, SyncTarget target, IProgress progress, CancellationToken cancellationToken); + + /// + /// Gets the file. + /// + /// The path parts. + /// The target. + /// The progress. + /// The cancellation token. + /// Task<Stream>. + Task GetFile(string[] pathParts, SyncTarget target, IProgress progress, CancellationToken cancellationToken); } } diff --git a/MediaBrowser.Controller/Sync/IServerSyncProvider.cs b/MediaBrowser.Controller/Sync/IServerSyncProvider.cs index d11dd9d73..b3e74ee7d 100644 --- a/MediaBrowser.Controller/Sync/IServerSyncProvider.cs +++ b/MediaBrowser.Controller/Sync/IServerSyncProvider.cs @@ -1,5 +1,6 @@ using MediaBrowser.Model.Sync; -using System.Collections.Generic; +using System; +using System.IO; using System.Threading; using System.Threading.Tasks; @@ -7,35 +8,25 @@ namespace MediaBrowser.Controller.Sync { public interface IServerSyncProvider : ISyncProvider { - /// - /// Gets the server item ids. - /// - /// The server identifier. - /// The target. - /// The cancellation token. - /// Task<List<System.String>>. - Task> GetServerItemIds(string serverId, SyncTarget target, CancellationToken cancellationToken); - - /// - /// Removes the item. - /// - /// The server identifier. - /// The item identifier. - /// The target. - /// The cancellation token. - /// Task. - Task DeleteItem(string serverId, string itemId, SyncTarget target, CancellationToken cancellationToken); - /// /// Transfers the file. /// - /// The server identifier. - /// The item identifier. /// The input file. /// The path parts. /// The target. + /// The progress. /// The cancellation token. /// Task. - Task TransferItemFile(string serverId, string itemId, string inputFile, string[] pathParts, SyncTarget target, CancellationToken cancellationToken); + Task SendFile(string inputFile, string[] pathParts, SyncTarget target, IProgress progress, CancellationToken cancellationToken); + + /// + /// Gets the file. + /// + /// The path parts. + /// The target. + /// The progress. + /// The cancellation token. + /// Task<Stream>. + Task GetFile(string[] pathParts, SyncTarget target, IProgress progress, CancellationToken cancellationToken); } } diff --git a/MediaBrowser.MediaEncoding/Subtitles/SubtitleEncoder.cs b/MediaBrowser.MediaEncoding/Subtitles/SubtitleEncoder.cs index b9cad27e0..7d74c51ba 100644 --- a/MediaBrowser.MediaEncoding/Subtitles/SubtitleEncoder.cs +++ b/MediaBrowser.MediaEncoding/Subtitles/SubtitleEncoder.cs @@ -773,7 +773,7 @@ namespace MediaBrowser.MediaEncoding.Subtitles { try { - using (var file = new FileStream(path, FileMode.Open)) + using (var file = _fileSystem.GetFileStream(path, FileMode.Open, FileAccess.Read, FileShare.ReadWrite)) { var detector = new CharsetDetector(); detector.Feed(file); @@ -797,12 +797,12 @@ namespace MediaBrowser.MediaEncoding.Subtitles return null; } - private static Encoding GetFileEncoding(string srcFile) + private Encoding GetFileEncoding(string srcFile) { // *** Detect byte order mark if any - otherwise assume default var buffer = new byte[5]; - using (var file = new FileStream(srcFile, FileMode.Open)) + using (var file = _fileSystem.GetFileStream(srcFile, FileMode.Open, FileAccess.Read, FileShare.ReadWrite)) { file.Read(buffer, 0, 5); } diff --git a/MediaBrowser.Server.Implementations/MediaBrowser.Server.Implementations.csproj b/MediaBrowser.Server.Implementations/MediaBrowser.Server.Implementations.csproj index 509a274ee..5ceaa5f5b 100644 --- a/MediaBrowser.Server.Implementations/MediaBrowser.Server.Implementations.csproj +++ b/MediaBrowser.Server.Implementations/MediaBrowser.Server.Implementations.csproj @@ -47,7 +47,7 @@ False - ..\packages\ImageMagickSharp.1.0.0.2\lib\net45\ImageMagickSharp.dll + ..\packages\ImageMagickSharp.1.0.0.3\lib\net45\ImageMagickSharp.dll False diff --git a/MediaBrowser.Server.Implementations/Sync/CloudSyncProvider.cs b/MediaBrowser.Server.Implementations/Sync/CloudSyncProvider.cs index 37caa561e..1ef9d4b15 100644 --- a/MediaBrowser.Server.Implementations/Sync/CloudSyncProvider.cs +++ b/MediaBrowser.Server.Implementations/Sync/CloudSyncProvider.cs @@ -4,6 +4,7 @@ using MediaBrowser.Model.Dlna; using MediaBrowser.Model.Sync; using System; using System.Collections.Generic; +using System.IO; using System.Linq; using System.Threading; using System.Threading.Tasks; @@ -39,21 +40,18 @@ namespace MediaBrowser.Server.Implementations.Sync return null; } - public Task> GetServerItemIds(string serverId, SyncTarget target, CancellationToken cancellationToken) - { - throw new NotImplementedException(); - } - - public Task DeleteItem(string serverId, string itemId, SyncTarget target, CancellationToken cancellationToken) - { - throw new NotImplementedException(); - } - - public Task TransferItemFile(string serverId, string itemId, string inputFile, string[] pathParts, SyncTarget target, CancellationToken cancellationToken) + public Task SendFile(string inputFile, string[] pathParts, SyncTarget target, IProgress progress, CancellationToken cancellationToken) { var provider = GetProvider(target); - return provider.TransferItemFile(serverId, itemId, inputFile, pathParts, target, cancellationToken); + return provider.SendFile(inputFile, pathParts, target, progress, cancellationToken); + } + + public Task GetFile(string[] pathParts, SyncTarget target, IProgress progress, CancellationToken cancellationToken) + { + var provider = GetProvider(target); + + return provider.GetFile(pathParts, target, progress, cancellationToken); } } } diff --git a/MediaBrowser.Server.Implementations/Sync/MediaSync.cs b/MediaBrowser.Server.Implementations/Sync/MediaSync.cs index 349e6aa1d..764652bbf 100644 --- a/MediaBrowser.Server.Implementations/Sync/MediaSync.cs +++ b/MediaBrowser.Server.Implementations/Sync/MediaSync.cs @@ -23,7 +23,7 @@ namespace MediaBrowser.Server.Implementations.Sync _appHost = appHost; } - public async Task Sync(IServerSyncProvider provider, + public async Task Sync(IServerSyncProvider provider, SyncTarget target, IProgress progress, CancellationToken cancellationToken) @@ -53,28 +53,28 @@ namespace MediaBrowser.Server.Implementations.Sync SyncTarget target, CancellationToken cancellationToken) { - var localIds = await provider.GetServerItemIds(serverId, target, cancellationToken).ConfigureAwait(false); + //var localIds = await provider.GetServerItemIds(serverId, target, cancellationToken).ConfigureAwait(false); - var result = await _syncManager.SyncData(new SyncDataRequest - { - TargetId = target.Id, - LocalItemIds = localIds + //var result = await _syncManager.SyncData(new SyncDataRequest + //{ + // TargetId = target.Id, + // LocalItemIds = localIds - }).ConfigureAwait(false); + //}).ConfigureAwait(false); - cancellationToken.ThrowIfCancellationRequested(); + //cancellationToken.ThrowIfCancellationRequested(); - foreach (var itemIdToRemove in result.ItemIdsToRemove) - { - try - { - await RemoveItem(provider, serverId, itemIdToRemove, target, cancellationToken).ConfigureAwait(false); - } - catch (Exception ex) - { - _logger.ErrorException("Error deleting item from sync target. Id: {0}", ex, itemIdToRemove); - } - } + //foreach (var itemIdToRemove in result.ItemIdsToRemove) + //{ + // try + // { + // await RemoveItem(provider, serverId, itemIdToRemove, target, cancellationToken).ConfigureAwait(false); + // } + // catch (Exception ex) + // { + // _logger.ErrorException("Error deleting item from sync target. Id: {0}", ex, itemIdToRemove); + // } + //} } private async Task GetNewMedia(IServerSyncProvider provider, @@ -83,8 +83,8 @@ namespace MediaBrowser.Server.Implementations.Sync IProgress progress, CancellationToken cancellationToken) { - var jobItems = await _syncManager.GetReadySyncItems(target.Id).ConfigureAwait(false); - + var jobItems = await _syncManager.GetReadySyncItems(target.Id).ConfigureAwait(false); + var numComplete = 0; double startingPercent = 0; double percentPerItem = 1; @@ -138,8 +138,7 @@ namespace MediaBrowser.Server.Implementations.Sync { string[] pathParts = GetPathParts(serverId, libraryItem); - await provider.TransferItemFile(serverId, libraryItem.Id, internalSyncJobItem.OutputPath, pathParts, target, cancellationToken) - .ConfigureAwait(false); + await SendFile(provider, internalSyncJobItem.OutputPath, pathParts, target, cancellationToken).ConfigureAwait(false); progress.Report(92); @@ -171,12 +170,19 @@ namespace MediaBrowser.Server.Implementations.Sync SyncTarget target, CancellationToken cancellationToken) { - return provider.DeleteItem(serverId, itemId, target, cancellationToken); + return Task.FromResult(true); + //return provider.DeleteItem(serverId, itemId, target, cancellationToken); } private string[] GetPathParts(string serverId, BaseItemDto item) { return null; } + + private async Task SendFile(IServerSyncProvider provider, string inputPath, string[] path, SyncTarget target, CancellationToken cancellationToken) + { + await provider.SendFile(inputPath, path, target, new Progress(), cancellationToken) + .ConfigureAwait(false); + } } } diff --git a/MediaBrowser.Server.Implementations/packages.config b/MediaBrowser.Server.Implementations/packages.config index 41df1b471..0112d0f75 100644 --- a/MediaBrowser.Server.Implementations/packages.config +++ b/MediaBrowser.Server.Implementations/packages.config @@ -1,6 +1,6 @@  - + diff --git a/MediaBrowser.ServerApplication/MediaBrowser.ServerApplication.csproj b/MediaBrowser.ServerApplication/MediaBrowser.ServerApplication.csproj index 6f569718e..9750a4e45 100644 --- a/MediaBrowser.ServerApplication/MediaBrowser.ServerApplication.csproj +++ b/MediaBrowser.ServerApplication/MediaBrowser.ServerApplication.csproj @@ -62,7 +62,7 @@ False - ..\packages\ImageMagickSharp.1.0.0.2\lib\net45\ImageMagickSharp.dll + ..\packages\ImageMagickSharp.1.0.0.3\lib\net45\ImageMagickSharp.dll ..\packages\MediaBrowser.IsoMounting.3.0.69\lib\net45\MediaBrowser.IsoMounter.dll diff --git a/MediaBrowser.ServerApplication/packages.config b/MediaBrowser.ServerApplication/packages.config index ab51c30cc..cfe7938de 100644 --- a/MediaBrowser.ServerApplication/packages.config +++ b/MediaBrowser.ServerApplication/packages.config @@ -1,6 +1,6 @@  - + \ No newline at end of file diff --git a/MediaBrowser.XbmcMetadata/Savers/BaseNfoSaver.cs b/MediaBrowser.XbmcMetadata/Savers/BaseNfoSaver.cs index 5455709e9..7aa33b053 100644 --- a/MediaBrowser.XbmcMetadata/Savers/BaseNfoSaver.cs +++ b/MediaBrowser.XbmcMetadata/Savers/BaseNfoSaver.cs @@ -214,7 +214,7 @@ namespace MediaBrowser.XbmcMetadata.Savers } } - using (var filestream = new FileStream(path, FileMode.Create, FileAccess.Write, FileShare.Read)) + using (var filestream = FileSystem.GetFileStream(path, FileMode.Create, FileAccess.Write, FileShare.Read)) { stream.CopyTo(filestream); } diff --git a/Nuget/MediaBrowser.Common.Internal.nuspec b/Nuget/MediaBrowser.Common.Internal.nuspec index 6d9ead15a..09da16b55 100644 --- a/Nuget/MediaBrowser.Common.Internal.nuspec +++ b/Nuget/MediaBrowser.Common.Internal.nuspec @@ -2,7 +2,7 @@ MediaBrowser.Common.Internal - 3.0.576 + 3.0.577 MediaBrowser.Common.Internal Luke ebr,Luke,scottisafool @@ -12,7 +12,7 @@ Contains common components shared by Media Browser Theater and Media Browser Server. Not intended for plugin developer consumption. Copyright © Media Browser 2013 - + diff --git a/Nuget/MediaBrowser.Common.nuspec b/Nuget/MediaBrowser.Common.nuspec index 305db5a1f..6841953ad 100644 --- a/Nuget/MediaBrowser.Common.nuspec +++ b/Nuget/MediaBrowser.Common.nuspec @@ -2,7 +2,7 @@ MediaBrowser.Common - 3.0.576 + 3.0.577 MediaBrowser.Common Media Browser Team ebr,Luke,scottisafool diff --git a/Nuget/MediaBrowser.Model.Signed.nuspec b/Nuget/MediaBrowser.Model.Signed.nuspec index 9305fe51c..0e3d483eb 100644 --- a/Nuget/MediaBrowser.Model.Signed.nuspec +++ b/Nuget/MediaBrowser.Model.Signed.nuspec @@ -2,7 +2,7 @@ MediaBrowser.Model.Signed - 3.0.576 + 3.0.577 MediaBrowser.Model - Signed Edition Media Browser Team ebr,Luke,scottisafool diff --git a/Nuget/MediaBrowser.Server.Core.nuspec b/Nuget/MediaBrowser.Server.Core.nuspec index cc7979590..f0883cc17 100644 --- a/Nuget/MediaBrowser.Server.Core.nuspec +++ b/Nuget/MediaBrowser.Server.Core.nuspec @@ -2,7 +2,7 @@ MediaBrowser.Server.Core - 3.0.576 + 3.0.577 Media Browser.Server.Core Media Browser Team ebr,Luke,scottisafool @@ -12,7 +12,7 @@ Contains core components required to build plugins for Media Browser Server. Copyright © Media Browser 2013 - +