sync updates

This commit is contained in:
Luke Pulverenti 2015-02-17 13:39:37 -05:00
parent 053f2fccbf
commit ee632803b3
2 changed files with 22 additions and 3 deletions

View File

@ -47,6 +47,7 @@ namespace MediaBrowser.Server.Implementations.Sync
private readonly IFileSystem _fileSystem;
private readonly Func<ISubtitleEncoder> _subtitleEncoder;
private readonly IConfigurationManager _config;
private IUserDataManager _userDataManager;
private ISyncProvider[] _providers = { };
@ -56,7 +57,7 @@ namespace MediaBrowser.Server.Implementations.Sync
public event EventHandler<GenericEventArgs<SyncJobItem>> SyncJobItemUpdated;
public event EventHandler<GenericEventArgs<SyncJobItem>> SyncJobItemCreated;
public SyncManager(ILibraryManager libraryManager, ISyncRepository repo, IImageProcessor imageProcessor, ILogger logger, IUserManager userManager, Func<IDtoService> dtoService, IApplicationHost appHost, ITVSeriesManager tvSeriesManager, Func<IMediaEncoder> mediaEncoder, IFileSystem fileSystem, Func<ISubtitleEncoder> subtitleEncoder, IConfigurationManager config)
public SyncManager(ILibraryManager libraryManager, ISyncRepository repo, IImageProcessor imageProcessor, ILogger logger, IUserManager userManager, Func<IDtoService> dtoService, IApplicationHost appHost, ITVSeriesManager tvSeriesManager, Func<IMediaEncoder> mediaEncoder, IFileSystem fileSystem, Func<ISubtitleEncoder> subtitleEncoder, IConfigurationManager config, IUserDataManager userDataManager)
{
_libraryManager = libraryManager;
_repo = repo;
@ -70,6 +71,7 @@ namespace MediaBrowser.Server.Implementations.Sync
_fileSystem = fileSystem;
_subtitleEncoder = subtitleEncoder;
_config = config;
_userDataManager = userDataManager;
}
public void AddParts(IEnumerable<ISyncProvider> providers)
@ -666,7 +668,24 @@ namespace MediaBrowser.Server.Implementations.Sync
public Task ReportOfflineAction(UserAction action)
{
return Task.FromResult(true);
switch (action.Type)
{
case UserActionType.PlayedItem:
return ReportOfflinePlayedItem(action);
default:
throw new ArgumentException("Unexpected action type");
}
}
private Task ReportOfflinePlayedItem(UserAction action)
{
var item = _libraryManager.GetItemById(action.ItemId);
var userData = _userDataManager.GetUserData(new Guid(action.UserId), item.GetUserDataKey());
userData.LastPlayedDate = action.Date;
_userDataManager.UpdatePlayState(item, userData, action.PositionTicks ?? item.RunTimeTicks ?? 0);
return _userDataManager.SaveUserData(new Guid(action.UserId), item, userData, UserDataSaveReason.Import, CancellationToken.None);
}
public List<SyncedItem> GetReadySyncItems(string targetId)

View File

@ -445,7 +445,7 @@ namespace MediaBrowser.Server.Startup.Common
TVSeriesManager = new TVSeriesManager(UserManager, UserDataManager, LibraryManager);
RegisterSingleInstance(TVSeriesManager);
SyncManager = new SyncManager(LibraryManager, SyncRepository, ImageProcessor, LogManager.GetLogger("SyncManager"), UserManager, () => DtoService, this, TVSeriesManager, () => MediaEncoder, FileSystemManager, () => SubtitleEncoder, ServerConfigurationManager);
SyncManager = new SyncManager(LibraryManager, SyncRepository, ImageProcessor, LogManager.GetLogger("SyncManager"), UserManager, () => DtoService, this, TVSeriesManager, () => MediaEncoder, FileSystemManager, () => SubtitleEncoder, ServerConfigurationManager, UserDataManager);
RegisterSingleInstance(SyncManager);
DtoService = new DtoService(Logger, LibraryManager, UserDataManager, ItemRepository, ImageProcessor, ServerConfigurationManager, FileSystemManager, ProviderManager, () => ChannelManager, SyncManager, this, () => DeviceManager);