public async Task <ReferenceDataViewModel> GetSubmissionsPerCollectionAsync(
            string containerName,
            string collectionName,
            string reportName,
            int maxRows = Constants.MaxFilesToDisplay,
            CancellationToken cancellationToken = default(CancellationToken))
        {
            var model = new ReferenceDataViewModel();

            // get job info from db
            var files = (await _referenceDataServiceClient.GetSubmittedFilesPerCollectionAsync(Api, collectionName, cancellationToken))
                        .OrderByDescending(f => f.SubmissionDate)
                        .Take(maxRows)
                        .ToList();

            var container = _cloudStorageService.GetStorageContainer(containerName);

            // get file info from result report
            await Task.WhenAll(
                files
                .Select(file => _fileUploadJobMetaDataModelBuilderService
                        .PopulateFileUploadJobMetaDataModelForReferenceDataUpload(
                            file,
                            reportName,
                            SummaryFileName,
                            container,
                            collectionName,
                            cancellationToken)));

            model.Files = files;
            model.ReferenceDataCollectionName = collectionName;
            return(model);
        }
        public async Task <ReferenceDataViewModel> GetProcessOutputsForCollectionAsync(
            string containerName,
            string collectionName,
            string reportName,
            string reportExtension,
            string fileNameFormat,
            string fileNameExtension,
            int submissionCount = Constants.DefaultSubmissionCount,
            CancellationToken cancellationToken = default(CancellationToken))
        {
            var model = new ReferenceDataViewModel();

            // get job info from db
            var files = (await _referenceDataServiceClient.GetSubmittedFilesPerCollectionAsync(Api, collectionName, cancellationToken))
                        .OrderByDescending(f => f.SubmissionDate)
                        .Take(submissionCount)
                        .ToList();

            var outputFiles = await _fileUploadJobMetaDataModelBuilderService
                              .BuildFileUploadJobMetaDataModelForReferenceDataProcess(
                files,
                collectionName,
                containerName,
                reportName,
                reportExtension,
                fileNameFormat,
                fileNameExtension,
                cancellationToken);

            model.Files = outputFiles;
            model.ReferenceDataCollectionName = collectionName;

            return(model);
        }
Exemple #3
0
        public async Task SendMessage(CancellationToken cancellationToken)
        {
            if (!ReferenceDataHubUserHandler.AnyConnectionIds(ReferenceDataTypes.DevolvedPostcodes))
            {
                return;
            }

            var collection = (await _referenceDataService.GetSubmissionsPerCollectionAsync(
                                  Constants.ReferenceDataStorageContainerName,
                                  CollectionNames.DevolvedPostcodesFullName,
                                  ReportTypes.DevolvedPostcodesFullNameReportName,
                                  cancellationToken: cancellationToken)).Files.ToList();

            collection.AddRange((await _referenceDataService.GetSubmissionsPerCollectionAsync(
                                     Constants.ReferenceDataStorageContainerName,
                                     CollectionNames.DevolvedPostcodesSof,
                                     ReportTypes.DevolvedPostcodesSofReportName,
                                     cancellationToken: cancellationToken)).Files.ToList());

            collection.AddRange((await _referenceDataService.GetSubmissionsPerCollectionAsync(
                                     Constants.ReferenceDataStorageContainerName,
                                     CollectionNames.DevolvedPostcodesLocalAuthority,
                                     ReportTypes.DevolvedPostcodesLocalAuthorityReportName,
                                     cancellationToken: cancellationToken)).Files.ToList());

            collection.AddRange((await _referenceDataService.GetSubmissionsPerCollectionAsync(
                                     Constants.ReferenceDataStorageContainerName,
                                     CollectionNames.DevolvedPostcodesOnsOverride,
                                     ReportTypes.DevolvedPostcodesOnsOverride,
                                     cancellationToken: cancellationToken)).Files.ToList());

            var model = new ReferenceDataViewModel()
            {
                Files = collection
            };

            var state = _serialisationHelperService.SerialiseToCamelCase(model);

            await _hubContext.Clients.All.SendAsync("ReceiveMessage", state, cancellationToken);
        }
        public async Task <IActionResult> Index(CancellationToken cancellationToken)
        {
            var fileUploadJobs = new List <FileUploadJobMetaDataModel>();

            foreach (var collection in _devolvedPostCodesCollections)
            {
                var col = _collections.Single(s => string.Equals(collection, s.CollectionName, StringComparison.CurrentCultureIgnoreCase));

                fileUploadJobs.AddRange((await _referenceDataService.GetSubmissionsPerCollectionAsync(
                                             Utils.Constants.ReferenceDataStorageContainerName,
                                             col.CollectionName,
                                             col.ReportName,
                                             cancellationToken: cancellationToken)).Files);
            }

            var model = new ReferenceDataViewModel()
            {
                Files = fileUploadJobs
            };

            return(View("Index", model));
        }
        public async Task <IActionResult> Post([FromForm] IFormFile file, ReferenceDataViewModel model, CancellationToken cancellationToken)
        {
            if (file == null)
            {
                return(RedirectToAction("Index", "ReferenceData", new { collectionName = model.ReferenceDataCollectionName }));
            }

            var collection = _collectionsService.GetReferenceDataCollection(model.ReferenceDataCollectionName);

            var validationResult = await ValidateFileName(
                collection,
                file.FileName,
                file.Length,
                cancellationToken);

            if (validationResult.ValidationResult != FileNameValidationResult.Valid)
            {
                return(View("FileUpload", model));
            }

            await _referenceDataService.SubmitJobAsync(Period, model.ReferenceDataCollectionName, User.Name(), User.Email(), file, cancellationToken);

            return(RedirectToAction("Index", "ReferenceData", new { collectionName = model.ReferenceDataCollectionName }));
        }
 public void OnNavigatedFrom(NavigationContext navigationContext)
 {
     this.eventAggregator.Unsubscribe<SaveEvent>(this.Save);
     this.ReferenceData = new ReferenceDataViewModel(null, null, this.eventAggregator);
 }
        private void Save(SaveEvent saveEvent)
        {
            try
            {
                var rds = this.referenceData.Values.Split('\n');
                List<ReferenceData> listReferenceData = new List<ReferenceData>();

                foreach (var rd in rds)
                {
                    listReferenceData.Add(
                        new ReferenceData { ReferenceKey = this.ReferenceData.ReferenceKey, Value = rd });
                }

                this.entityService.ExecuteAsyncRD(
                    () => this.entityService.Create(this.ReferenceData.ReferenceKey, listReferenceData),
                    () => this.ReferenceData = new ReferenceDataViewModel(this.eventAggregator),
                    string.Format(Message.EntityUpdatedFormatString, "ReferenceData"),
                    this.eventAggregator);
            }
            catch (Exception)
            {
                MessageBox.Show("No values supplied", Application.Current.MainWindow.Title);
            }
        }
Exemple #8
0
        public async Task GetProcessOutputsForCollectionAsync()
        {
            var cancellationToken = CancellationToken.None;
            var submissionDateUtc = new DateTime(2020, 8, 1, 9, 0, 0);
            var clockDate         = new DateTime(2020, 8, 1, 8, 0, 0);

            var collectionName    = "CollectionName";
            var containerName     = "Container";
            var reportFormat      = "ReportPreFix";
            var reportExtension   = ".csv";
            var fileNameFormat    = "FileNamePreFix";
            var fileNameExtension = ".zip";

            var file1 = new FileUploadJobMetaDataModel
            {
                JobId          = 1,
                JobStatus      = 4,
                SubmissionDate = submissionDateUtc
            };

            var file2 = new FileUploadJobMetaDataModel
            {
                JobId          = 2,
                JobStatus      = 1,
                SubmissionDate = submissionDateUtc
            };

            var fileModels = new List <FileUploadJobMetaDataModel> {
                file1, file2
            };

            var builtFileModels = new List <FileUploadJobMetaDataModel>
            {
                new FileUploadJobMetaDataModel
                {
                    JobId          = 1,
                    JobStatus      = 4,
                    SubmissionDate = submissionDateUtc,
                    DisplayDate    = "1 August 2020 at 8:00 am",
                    CollectionName = collectionName,
                    FileName       = "FileNamePreFix.1.2.202008010800.zip",
                    ReportName     = "ReportPreFix-202008010800.csv",
                    DisplayStatus  = "Completed"
                },
                new FileUploadJobMetaDataModel
                {
                    JobId          = 2,
                    JobStatus      = 1,
                    SubmissionDate = submissionDateUtc,
                    DisplayDate    = "1 August 2020 at 8:00 am",
                    CollectionName = collectionName,
                    DisplayStatus  = "Processing"
                }
            };

            var refDataServiceClient = new Mock <IReferenceDataServiceClient>();

            refDataServiceClient.Setup(x => x.GetSubmittedFilesPerCollectionAsync(It.IsAny <string>(), collectionName, cancellationToken)).ReturnsAsync(fileModels);

            var modelBuilderService = new Mock <IFileUploadJobMetaDataModelBuilderService>();

            modelBuilderService.Setup(x => x.BuildFileUploadJobMetaDataModelForReferenceDataProcess(
                                          fileModels,
                                          collectionName,
                                          containerName,
                                          reportFormat,
                                          reportExtension,
                                          fileNameFormat,
                                          fileNameExtension,
                                          cancellationToken)).ReturnsAsync(builtFileModels);


            var viewModel = await NewService(modelBuilderService.Object, refDataServiceClient.Object)
                            .GetProcessOutputsForCollectionAsync(
                containerName,
                collectionName,
                reportFormat,
                reportExtension,
                fileNameFormat,
                fileNameExtension);

            var expectedModel = new ReferenceDataViewModel
            {
                ReferenceDataCollectionName = collectionName,
                Files = builtFileModels
            };

            viewModel.Should().BeEquivalentTo(expectedModel);
        }
 public void Sorting()
 {
     this.SelectedReferenceData = null;
 }
        public async Task <IActionResult> Post(ReferenceDataViewModel model, CancellationToken cancellationToken)
        {
            await _referenceDataService.SubmitJobAsync(Period, model.ReferenceDataCollectionName, User.Name(), User.Email(), cancellationToken);

            return(RedirectToAction("Index", "ReferenceDataProcess", new { collectionName = model.ReferenceDataCollectionName }));
        }