private void GivenNoMatchingLibrary(bool isArchived) { _plexServer = new PlexServerRowBuilder().WithLibraries().Build(); _plexServer.PlexLibraries.ElementAt(0).IsArchived = isArchived; if (isArchived) { _plexServer.PlexLibraries.ElementAt(0).LibraryKey = _command.Key; } _plexService.GetServer().Returns(_plexServer); }
public async Task <ValidationContext> Handle(UpdatePlexServerLibraryCommand request, CancellationToken cancellationToken) { var resultContext = new ValidationContext(); var server = await _plexService.GetServer(); if (server == null) { resultContext.AddError("No admin server found", "Cannot update plex library as no admin server has been found"); return(resultContext); } var libraryToUpdate = server.PlexLibraries.FirstOrDefault(x => x.LibraryKey == request.Key && !x.IsArchived); resultContext.AddErrorIf(() => libraryToUpdate == null, "Invalid library key", "No library was found for the given key"); if (!resultContext.IsSuccessful) { return(resultContext); } // ReSharper disable once PossibleNullReferenceException libraryToUpdate.IsEnabled = request.IsEnabled; await _unitOfWork.CommitAsync(); return(resultContext); }
public async Task Synchronise(bool fullRefresh) { var refreshType = fullRefresh ? "full" : "partial"; _logger.LogInformation($"Starting a {refreshType} sync with Plex."); var plexServer = await _plexService.GetServer(); if (plexServer == null) { _logger.LogInformation("Unable to sync plex content as no admin server was found"); } var librariesToSync = plexServer?.PlexLibraries.Where(x => x.IsEnabled).ToList(); if (librariesToSync == null || !librariesToSync.Any()) { _logger.LogDebug("No Plex libraries have been enabled for synchronisation"); return; } if (fullRefresh) { //TODO Why are we doing this? It should be a soft delete //What about issues/requests that use this as a FK? _plexService.DeleteAllMediaItems(); } var plexUrl = plexServer.GetPlexUri(_plexSettings.ConnectLocally); var plexLibraryContainer = await _plexApi.GetLibraries(plexServer.AccessToken, plexUrl); foreach (var libraryToSync in librariesToSync) { var existsAsRemoteLibrary = plexLibraryContainer.MediaContainer.Directory.Any(x => x.Key == libraryToSync.LibraryKey); if (!existsAsRemoteLibrary) { _logger.LogInformation($"Attempted to sync the local library '{libraryToSync.Type}|{libraryToSync.LibraryKey}' but it no longer exists remotely"); continue; } var syncProcessor = _processorProvider.GetProcessor(libraryToSync.Type); if (syncProcessor == null) { _logger.LogInformation($"Attempted to sync the local library '{libraryToSync.Type}|{libraryToSync.LibraryKey}' but the type is not supported"); return; } await SynchroniseLibrary(fullRefresh, libraryToSync, plexServer, plexUrl, syncProcessor); } }
public async Task <GetPlexServerQueryResult> Handle(GetServerQuery request, CancellationToken cancellationToken) { var server = await _plexService.GetServer(); if (server == null) { return(null); } var serverModel = _mapper.Map <PlexServerDetailModel>(server); return(new GetPlexServerQueryResult { Server = serverModel }); }
public async Task <ValidationContext <GetManyPlexServerLibraryQueryResult> > Handle(GetManyPlexServerLibraryQuery request, CancellationToken cancellationToken) { var result = new ValidationContext <GetManyPlexServerLibraryQueryResult>(); var server = await _plexService.GetServer(); if (server == null) { result.AddError("No admin server found", "Cannot sync libraries as no admin server has been found"); return(result); } result.Data = new GetManyPlexServerLibraryQueryResult { Libraries = _mapper.Map <List <PlexServerLibraryDetailModel> >(server.PlexLibraries) }; return(result); }
public async Task <ValidationContext> Handle(SyncLibrariesCommand request, CancellationToken cancellationToken) { var result = new ValidationContext(); var server = await _plexService.GetServer(); if (server == null) { result.AddError("No admin server found", "Cannot sync libraries as no admin server has been found"); return(result); } var libraryContainer = await _plexApi.GetLibraries(server.AccessToken, server.GetPlexUri(_plexSettings.ConnectLocally)); CheckForDeletedLibraries(server, libraryContainer); SetNewLibraries(libraryContainer, server); await _unitOfWork.CommitAsync(); return(result); }
public async Task <ValidationContext> Handle(SyncUsersCommand request, CancellationToken cancellationToken) { var result = new ValidationContext(); var server = await _plexService.GetServer(); if (server == null) { result.AddError("No admin server found", "Cannot sync users as no admin server has been found"); return(result); } var remoteFriends = await _plexApi.GetFriends(server.AccessToken); var existingFriends = await _userService.GetAllUsers(); DisableDeletedUsers(existingFriends, remoteFriends); await CreateNewUsers(remoteFriends); await _unitOfWork.CommitAsync(); return(result); }
private void GivenAPlexServer() { _plexServer = new PlexServerRowBuilder().Build(); _plexService.GetServer().Returns(_plexServer); }
private void GivenAServer() { _plexService.GetServer().Returns(new PlexServerRowBuilder().Build()); }