/// <summary> /// Validate the Create request e.g that the file has been uploaded and parameters are as expected. /// </summary> public static void ValidateUpsertImportedFileRequest(FlowFile file, Guid projectUid, ImportedFileType importedFileType, DxfUnitsType dxfUnitsType, DateTime fileCreatedUtc, DateTime fileUpdatedUtc, string importedBy, DateTime?surveyedUtc, Guid?parentUid, double?offset) { if (file == null) { throw new ServiceException(HttpStatusCode.BadRequest, new ContractExecutionResult(ProjectErrorCodesProvider.GetErrorNumberwithOffset(27), ProjectErrorCodesProvider.FirstNameWithOffset(27))); } if (file.flowFilename.Length > MAX_FILE_NAME_LENGTH || string.IsNullOrEmpty(file.flowFilename) || file.flowFilename.IndexOfAny(Path.GetInvalidPathChars()) > 0) { throw new ServiceException(HttpStatusCode.BadRequest, new ContractExecutionResult(ProjectErrorCodesProvider.GetErrorNumberwithOffset(28), ProjectErrorCodesProvider.FirstNameWithOffset(28))); } if (string.IsNullOrEmpty(file.path) || file.path.IndexOfAny(Path.GetInvalidPathChars()) > 0) { throw new ServiceException(HttpStatusCode.BadRequest, new ContractExecutionResult(ProjectErrorCodesProvider.GetErrorNumberwithOffset(29), ProjectErrorCodesProvider.FirstNameWithOffset(29))); } ValidateUpsertImportedFileRequest(projectUid, importedFileType, dxfUnitsType, fileCreatedUtc, fileUpdatedUtc, importedBy, surveyedUtc, file.flowFilename, parentUid, offset); }
public FileDataSingleResult CreateMockImportedFile( FlowFile file, [FromQuery] Guid projectUid, [FromQuery] ImportedFileType importedFileType, [FromQuery] DxfUnitsType dxfUnitsType, [FromQuery] DateTime fileCreatedUtc, [FromQuery] DateTime fileUpdatedUtc, [FromQuery] DateTime?surveyedUtc = null) { Logger.LogInformation( $"CreateMockImportedFile. file: {file.flowFilename} path {file.path} projectUid {projectUid} ImportedFileType: {importedFileType} " + $"DxfUnitsType: {dxfUnitsType} surveyedUtc {(surveyedUtc == null ? "N/A" : surveyedUtc.ToString())}"); if (projectUid.ToString() == ConstantsUtil.DIMENSIONS_PROJECT_UID) { var result = new FileDataSingleResult(); result.ImportedFileDescriptor = ImportedFilesService.ImportedFiles[ConstantsUtil.DIMENSIONS_PROJECT_UID] .SingleOrDefault(f => f.Name.Equals(file.flowFilename, StringComparison.OrdinalIgnoreCase)); return(result); } return(new FileDataSingleResult { Code = ContractExecutionStatesEnum.InternalProcessingError, Message = "Failed to create imported file" }); }
//[ActionName("UploadImage")] public IHttpActionResult UploadFile([FromUri] FlowFile file) { //if (ClaimArchiveFlowFile != null) // System.IO.File.Delete(ClaimArchiveFlowFile.path); // return Ok(); AddAttachment(file); return(Json(new { derp = file.flowFilename })); }
public void ValidateImportFile_AlignmentHappyPath() { var file = new FlowFile { path = "\\*", flowFilename = "deblah.svl" }; FlowJsFileImportDataValidator.ValidateUpsertImportedFileRequest(file, projectUid, ImportedFileType.Alignment, DxfUnitsType.ImperialFeet, fileCreatedUtc, fileUpdatedUtc, IMPORTED_BY, null, null, 0); }
public void ValidateImportFile_SurveyedSurfaceHappyPath() { var file = new FlowFile { path = "\\*", flowFilename = "deblah.ttm" }; FlowJsFileImportDataValidator.ValidateUpsertImportedFileRequest(file, projectUid, ImportedFileType.DesignSurface, DxfUnitsType.ImperialFeet, fileCreatedUtc, fileUpdatedUtc, IMPORTED_BY, surfaceUtc, null, 0); }
public void ValidateImportFile_ReferenceSurfaceHappyPath() { var file = new FlowFile { path = "\\*", flowFilename = "deblah" }; FileImportDataValidator.ValidateUpsertImportedFileRequest(projectUid, ImportedFileType.ReferenceSurface, DxfUnitsType.ImperialFeet, fileCreatedUtc, fileUpdatedUtc, IMPORTED_BY, null, "deblah", parentUid, offset); }
public void ValidateImportFile_LineworkHappyPath() { var file = new FlowFile { path = "\\*", flowFilename = "deblah.dxf" }; FlowJsFileImportDataValidator.ValidateUpsertImportedFileRequest(file, projectUid, ImportedFileType.Linework, DxfUnitsType.Meters, fileCreatedUtc, fileUpdatedUtc, IMPORTED_BY, null, parentUid, offset); }
public async Task <ScheduleJobResult> BackgroundUpload( FlowFile file, [FromQuery] Guid projectUid, [FromQuery] ImportedFileType importedFileType, [FromQuery] DxfUnitsType dxfUnitsType, [FromQuery] DateTime fileCreatedUtc, [FromQuery] DateTime fileUpdatedUtc, [FromQuery] DateTime?surveyedUtc, [FromServices] ISchedulerProxy scheduler, [FromServices] ITransferProxyFactory transferProxyFactory) { if (importedFileType == ImportedFileType.ReferenceSurface) { ServiceExceptionHandler.ThrowServiceException(HttpStatusCode.BadRequest, 122); } FlowJsFileImportDataValidator.ValidateUpsertImportedFileRequest( file, projectUid, importedFileType, dxfUnitsType, fileCreatedUtc, fileUpdatedUtc, UserEmailAddress, surveyedUtc, null, null); Logger.LogInformation( $"{nameof(BackgroundUpload)}: file: {file.flowFilename} path {file.path} projectUid {projectUid} ImportedFileType: {importedFileType} " + $"DxfUnitsType: {dxfUnitsType} surveyedUtc {(surveyedUtc == null ? "N/A" : surveyedUtc.ToString())}"); if (string.Equals(Request.Method, HttpMethod.Post.ToString(), StringComparison.OrdinalIgnoreCase)) { await ValidateFileDoesNotExist(projectUid.ToString(), file.flowFilename, importedFileType, surveyedUtc, null, null); } var s3Path = $"project/importedfile/{Guid.NewGuid()}.dat"; var fileStream = System.IO.File.Open(file.path, FileMode.Open, FileAccess.Read); var transferProxy = transferProxyFactory.NewProxy(TransferProxyType.Temporary); transferProxy.Upload(fileStream, s3Path); var baseUrl = Request.Host.ToUriComponent(); // The QueryString will have values in it, so it's safe to add extra queries with the & as opposed to ?, then & var callbackUrl = $"http://{baseUrl}/internal/v6/importedfile{Request.QueryString}"; callbackUrl += $"&filename={WebUtility.UrlEncode(file.flowFilename)}&awsFilePath={WebUtility.UrlEncode(s3Path)}"; Logger.LogInformation($"{nameof(BackgroundUpload)}: baseUrl {callbackUrl}"); var executionTimeout = ConfigStore.GetValueInt("PEGASUS_EXECUTION_TIMEOUT_MINS", 5) * 60000;//minutes converted to millisecs var request = new ScheduleJobRequest { Filename = file.flowFilename, Method = "GET", // match the internal upload Method Url = callbackUrl, Timeout = executionTimeout }; request.SetStringPayload(string.Empty); var headers = Request.Headers.GetCustomHeaders(); return(await scheduler.ScheduleBackgroundJob(request, headers)); }
public void ValidateImportFile_UnsupportedImportedFileType() { var file = new FlowFile { path = "blahblah", flowFilename = "deblah" }; var ex = Assert.Throws <ServiceException>( () => FlowJsFileImportDataValidator.ValidateUpsertImportedFileRequest(file, projectUid, ImportedFileType.MassHaulPlan, DxfUnitsType.ImperialFeet, fileCreatedUtc, fileUpdatedUtc, IMPORTED_BY, surfaceUtc, parentUid, offset)); Assert.NotEqual(-1, ex.GetContent.IndexOf(projectErrorCodesProvider.FirstNameWithOffset(31))); }
public void ValidateImportFile_AlignmentWrongFileExtension() { var file = new FlowFile { path = "\\*", flowFilename = "deblah.ttm" }; var ex = Assert.Throws <ServiceException>( () => FlowJsFileImportDataValidator.ValidateUpsertImportedFileRequest(file, projectUid, ImportedFileType.Alignment, DxfUnitsType.ImperialFeet, fileCreatedUtc, fileUpdatedUtc, IMPORTED_BY, null, null, 0)); Assert.NotEqual(-1, ex.GetContent.IndexOf(projectErrorCodesProvider.FirstNameWithOffset(32))); }
public void AddAttachment(FlowFile file) { List <FlowFile> lst = ApplicationContext.AttachmentContext.AttachmentsCache; if (lst == null) { lst = new List <FlowFile>(); lst.Add(file); } else { lst.Add(file); } ApplicationContext.AttachmentContext.AttachmentsCache = lst; }
public async Task <ImportedFileDescriptorSingleResult> SyncUpload( [FromServices] ISchedulerProxy schedulerProxy, FlowFile file, [FromQuery] Guid projectUid, [FromQuery] ImportedFileType importedFileType, [FromQuery] DxfUnitsType dxfUnitsType, [FromQuery] DateTime fileCreatedUtc, [FromQuery] DateTime fileUpdatedUtc, [FromQuery] DateTime?surveyedUtc) { if (importedFileType == ImportedFileType.ReferenceSurface) { ServiceExceptionHandler.ThrowServiceException(HttpStatusCode.BadRequest, 122); } // Validate the file FlowJsFileImportDataValidator.ValidateUpsertImportedFileRequest( file, projectUid, importedFileType, dxfUnitsType, fileCreatedUtc, fileUpdatedUtc, UserEmailAddress, surveyedUtc, null, null); Logger.LogInformation( $"{nameof(SyncUpload)}: file: {file.flowFilename} path {file.path} projectUid {projectUid} ImportedFileType: {importedFileType} " + $"DxfUnitsType: {dxfUnitsType} surveyedUtc {(surveyedUtc == null ? "N/A" : surveyedUtc.ToString())}"); await ValidateFileDoesNotExist(projectUid.ToString(), file.flowFilename, importedFileType, surveyedUtc, null, null); ContractExecutionResult importedFileResult; using (var fileStream = System.IO.File.Open(file.path, FileMode.Open, FileAccess.Read)) { importedFileResult = await UpsertFileInternal(file.flowFilename, fileStream, projectUid, importedFileType, dxfUnitsType, fileCreatedUtc, fileUpdatedUtc, surveyedUtc, schedulerProxy); } Logger.LogInformation( $"{nameof(SyncUpload)}: Completed successfully. Response: {JsonConvert.SerializeObject(importedFileResult)}"); return(importedFileResult as ImportedFileDescriptorSingleResult); }
public Task <ImportedFileDescriptorSingleResult> UpsertImportedFileV6( [FromServices] ISchedulerProxy schedulerProxy, FlowFile file, [FromQuery] Guid projectUid, [FromQuery] ImportedFileType importedFileType, [FromQuery] DxfUnitsType dxfUnitsType, [FromQuery] DateTime fileCreatedUtc, [FromQuery] DateTime fileUpdatedUtc, [FromQuery] DateTime?surveyedUtc = null) { if (importedFileType == ImportedFileType.ReferenceSurface) { ServiceExceptionHandler.ThrowServiceException(HttpStatusCode.BadRequest, 122); } FlowJsFileImportDataValidator.ValidateUpsertImportedFileRequest(file, projectUid, importedFileType, dxfUnitsType, fileCreatedUtc, fileUpdatedUtc, UserEmailAddress, surveyedUtc, null, null); Logger.LogInformation( $"{nameof(UpsertImportedFileV6)}: file: {JsonConvert.SerializeObject(file)} projectUid {projectUid} ImportedFileType: {importedFileType} DxfUnitsType: {dxfUnitsType} surveyedUtc {(surveyedUtc == null ? "N/A" : surveyedUtc.ToString())}"); return(UpsertFile(file.path, file.flowFilename, projectUid.ToString(), importedFileType, dxfUnitsType, fileCreatedUtc, fileUpdatedUtc, surveyedUtc, schedulerProxy)); }
public ActionResult Upload(FlowFile file) { return(Json(new { derp = file.flowFilename })); }