예제 #1
0
        private async Task <BuildProject> GenerateBuildProject(string specificationId)
        {
            BuildProject buildproject = new BuildProject
            {
                SpecificationId = specificationId,
                Id   = Guid.NewGuid().ToString(),
                Name = specificationId,
                DatasetRelationships = new List <DatasetRelationshipSummary>(),
                Build = new Build()
            };

            IEnumerable <DatasetSpecificationRelationshipViewModel> datasetRelationshipModels = await _datasetRepositoryPolicy.ExecuteAsync(() => _datasetRepository.GetCurrentRelationshipsBySpecificationId(specificationId));

            if (!datasetRelationshipModels.IsNullOrEmpty())
            {
                ConcurrentBag <DatasetDefinition> datasetDefinitions = new ConcurrentBag <DatasetDefinition>();

                IList <Task> definitionTasks = new List <Task>();

                IEnumerable <string> definitionIds = datasetRelationshipModels.Select(m => m.Definition?.Id);

                foreach (string definitionId in definitionIds)
                {
                    Task task = Task.Run(async() =>
                    {
                        DatasetDefinition datasetDefinition = await _datasetRepositoryPolicy.ExecuteAsync(() => _datasetRepository.GetDatasetDefinitionById(definitionId));

                        if (datasetDefinition != null)
                        {
                            datasetDefinitions.Add(datasetDefinition);
                        }
                    });

                    definitionTasks.Add(task);
                }

                await TaskHelper.WhenAllAndThrow(definitionTasks.ToArray());

                foreach (DatasetSpecificationRelationshipViewModel datasetRelationshipModel in datasetRelationshipModels)
                {
                    buildproject.DatasetRelationships.Add(new DatasetRelationshipSummary
                    {
                        DatasetDefinitionId = datasetRelationshipModel.Definition.Id,
                        DatasetId           = datasetRelationshipModel.DatasetId,
                        Relationship        = new Common.Models.Reference(datasetRelationshipModel.Id, datasetRelationshipModel.Name),
                        DefinesScope        = datasetRelationshipModel.IsProviderData,
                        Id   = datasetRelationshipModel.Id,
                        Name = datasetRelationshipModel.Name,
                        DatasetDefinition = datasetDefinitions.FirstOrDefault(m => m.Id == datasetRelationshipModel.Definition.Id)
                    });
                }
            }

            return(buildproject);
        }