public CalculationsMigration(IServiceProvider sourceServices, IServiceProvider destinationServices, bool preventWrites) { Guard.ArgumentNotNull(sourceServices, nameof(sourceServices)); Guard.ArgumentNotNull(destinationServices, nameof(destinationServices)); _sourceClients = new MigrationClients(sourceServices); _destinationClients = new MigrationClients(destinationServices); _preventWrites = preventWrites; }
private Task <ApiResponse <SpecificationSummary> > GetSpecificationTask(string specificationId, MigrationClients migrationClients) { return(migrationClients.MakeSpecificationsCall(_ => _.GetSpecificationSummaryById(specificationId))); }
private Task <ApiResponse <IEnumerable <DatasetSpecificationRelationshipViewModel> > > GetSpecificationCurrentRelationshipsTask( MigrationClients clients, string specificationId) { return(clients.MakeDataSetsCall(_ => _.GetCurrentRelationshipsBySpecificationId(specificationId))); }
private async Task <IEnumerable <TemplateMappingItem> > GetTemplateMappingItemsInSpecification(SpecificationSummary specification, MigrationClients clients) { SemaphoreSlim throttle = new SemaphoreSlim(5, 5); ConcurrentBag <Task <TemplateMapping> > templateMappingQueryTasks = new ConcurrentBag <Task <TemplateMapping> >(); string specificationId = specification.Id; foreach (Reference fundingStream in specification.FundingStreams) { templateMappingQueryTasks.Add(Task.Run(() => { try { throttle.Wait(); string fundingStreamId = fundingStream.Id; ApiResponse <TemplateMapping> templateMappingResponse = clients.MakeCalculationsCall(_ => _.GetTemplateMapping(specificationId, fundingStreamId)) .GetAwaiter() .GetResult(); CheckApiResponse(templateMappingResponse, $"Unable to fetch template mapping for specification id {specificationId} and funding stream id {fundingStreamId}"); return(templateMappingResponse.Content); } finally { throttle.Release(); } })); } await TaskHelper.WhenAllAndThrow(templateMappingQueryTasks.ToArray()); return(templateMappingQueryTasks.SelectMany(_ => _.Result.TemplateMappingItems).ToArray()); }