private void GivenASyncProcessor() { _syncProcessor = Substitute.For <ISyncProcessor>(); _syncProcessor .Synchronise(Arg.Any <PlexMediaContainer>(), Arg.Any <bool>(), Arg.Any <string>(), Arg.Any <string>(), Arg.Any <string>()) .Returns(_syncProcessorResult); _processorProvider.GetProcessor(Arg.Any <string>()).Returns(_syncProcessor); }
public static ISyncProcessorBuilder UseMiddleware(this ISyncProcessorBuilder processorBuilder, ISyncProcessor processor, StageConfiguration stageConfiguration) { if ((object)processorBuilder == null) { throw new ArgumentNullException(nameof(processorBuilder)); } if ((object)processor == null) { throw new ArgumentNullException(nameof(processor)); } if ((object)stageConfiguration == null) { throw new ArgumentNullException(nameof(stageConfiguration)); } return(processorBuilder.Use(next => { return (context, configuration, channel) => { ISyncProcessor _processor = processor; // prevent closure bug ISyncChannel newChannel; using (_processor) { _processor.Configuration = stageConfiguration; _processor.Create(); _processor.PreExecute(context, configuration); newChannel = _processor.Process(context, configuration, channel, next); _processor.PostExecute(context, configuration); return newChannel; } }; })); }
private async Task SynchroniseLibrary(bool fullRefresh, PlexLibraryRow libraryToSync, PlexServerRow plexServer, string plexUrl, ISyncProcessor syncProcessor) { _logger.LogInformation($"Sync processing library type: {libraryToSync.Type}|{libraryToSync.LibraryKey}"); var libraryContainer = await GetLibraryContainer(libraryToSync, fullRefresh, plexServer.AccessToken, plexUrl); var syncResult = await syncProcessor.Synchronise(libraryContainer, fullRefresh, plexServer.AccessToken, plexUrl, plexServer.MachineIdentifier); _logger.LogInformation($"Sync finished processing library type: {libraryToSync.Type}|{libraryToSync.LibraryKey}"); _logger.LogInformation($"Sync Results. Create: {syncResult.NewItems.Count} Update: {syncResult.ExistingItems.Count}"); foreach (var newItem in syncResult.NewItems) { libraryToSync.PlexMediaItems.Add(newItem); } await _unitOfWork.CommitAsync(); await AutoCompleteRequests(syncResult, syncProcessor.Type); }