public async Task <Regex> GetFileNameRegexAsync(string collectionName, CancellationToken cancellationToken) { Collection collection; if (!_collectionsDb.TryGetValue(collectionName, out collection)) { _collectionsDb.Add(collectionName, await _collectionService.GetCollectionAsync(collectionName, cancellationToken)); collection = _collectionsDb[collectionName]; } var fileNameRegex = collection.FileNameRegex; return(!string.IsNullOrEmpty(fileNameRegex) ? new Regex(fileNameRegex, RegexOptions.Compiled) : null); }
private async Task <JobSubmission> CreateJobSubmissionAsync(int period, string collectionName, string userName, string email, string fileName, long fileSizeInBytes, CancellationToken cancellationToken) { var collection = await _collectionsService.GetCollectionAsync(collectionName, cancellationToken); return(new JobSubmission { CollectionName = collection.CollectionTitle, FileName = fileName, FileSizeBytes = fileSizeInBytes, SubmittedBy = userName, NotifyEmail = email, StorageReference = collection.StorageReference, Period = period, CollectionYear = collection.CollectionYear }); }
public async Task <IActionResult> BulkUpload(IFormFile file, CancellationToken cancellationToken) { if (file == null) { return(View("AddNewOption")); } var collection = _collections.SingleOrDefault(s => string.Equals(ProvidersUploadCollectionName, s.CollectionName, StringComparison.CurrentCultureIgnoreCase)); var fileName = Path.GetFileName(file.FileName); var collectionDb = await _collectionService.GetCollectionAsync(ProvidersUploadCollectionName); if (collectionDb == null || !collectionDb.IsOpen) { _logger.LogWarning($"collection {ProvidersUploadCollectionName} is not open/available, but file is being uploaded"); ModelState.AddModelError(ErrorMessageKeys.ErrorSummaryKey, $"collection {ProvidersUploadCollectionName} is not open/available."); return(View("AddNewOption")); } var fileNameValidationService = _fileNameValidationServiceProvider.GetFileNameValidationService(collection.CollectionName); var validationResult = await fileNameValidationService.ValidateFileNameAsync(collection.CollectionName, fileName.ToUpper(CultureInfo.CurrentUICulture), collection.FileNameFormat, file.Length, cancellationToken); if (validationResult.ValidationResult != FileNameValidationResult.Valid) { ModelState.AddModelError(ErrorMessageKeys.Submission_FileFieldKey, validationResult.FieldError); ModelState.AddModelError(ErrorMessageKeys.ErrorSummaryKey, validationResult.SummaryError); _logger.LogWarning($"User uploaded invalid file with name :{fileName}"); return(View("AddNewOption")); } await(await _storageService.GetAzureStorageReferenceService(_opsDataLoadServiceConfigSettings.ConnectionString, collectionDb.StorageReference)).SaveAsync(fileName, file?.OpenReadStream()); var jobId = await _jobService.SubmitJob( new JobSubmission { CollectionName = ProvidersUploadCollectionName, FileName = fileName, FileSizeBytes = file.Length, SubmittedBy = User.Name(), NotifyEmail = User.Email(), StorageReference = collectionDb.StorageReference }, cancellationToken); return(RedirectToAction("InProgress", new { jobId })); }
public async Task <IActionResult> UnpublishAsync(CancellationToken cancellationToken, int periodNumber, string collectionName) { try { var collection = await _collectionsService.GetCollectionAsync(collectionName, cancellationToken); await _reportsPublicationService.UnpublishSldAsync(collectionName, periodNumber); await _reportsPublicationService.UnpublishSldDeleteFolderAsync(collection.StorageReference, periodNumber); return(View("UnpublishSuccess")); } catch (Exception ex) { string errorMessage = $"The FRM Reports were not able to be unpublished from SLD"; _logger.LogError(errorMessage, ex); TempData["Error"] = errorMessage; return(View("ErrorView")); } }
public async Task SubmitJob(int period, string collectionName, string userName, string email, IFormFile file, CancellationToken cancellationToken) { if (file == null) { return; } var collection = await _collectionService.GetCollectionAsync(collectionName, cancellationToken); var fileName = Path.GetFileName(file.FileName); await(await _storageService.GetAzureStorageReferenceService(_azureStorageConfig.ConnectionString, collection.StorageReference)) .SaveAsync(fileName, file.OpenReadStream(), cancellationToken); try { var job = new JobSubmission { CollectionName = collection.CollectionTitle, FileName = fileName, FileSizeBytes = file.Length, SubmittedBy = userName, NotifyEmail = email, StorageReference = collection.StorageReference, Period = period, CollectionYear = collection.CollectionYear }; // add to the queue await _jobService.SubmitJob(job, cancellationToken); } catch (Exception ex) { _logger.LogError($"Error trying to submit ALLF file with name : {file.Name}", ex); throw; } }