public async Task <ReturnLongV5Result> UpsertImportedFileV5TBC( [FromRoute] long projectId, [FromBody] ImportedFileTbc importedFileTbc, [FromServices] ISchedulerProxy schedulerProxy) { // MobileLinework .kml/.kmz files are sent along with linework files // we need to suppress any error and return as if all ok. // however we won't have a LegacyFileId to return - hmmm hope Business centre ignores this if (importedFileTbc.ImportedFileTypeId == ImportedFileType.MobileLinework) { Logger.LogInformation( $"{nameof(UpsertImportedFileV5TBC)}: Ignore MobileLinework from BusinessCentre. projectId {projectId} importedFile: {JsonConvert.SerializeObject(importedFileTbc)}"); return(ReturnLongV5Result.CreateLongV5Result(HttpStatusCode.OK, -1)); } // this also validates that this customer has access to the projectUid var project = await ProjectRequestHelper.GetProjectForCustomer(new Guid(CustomerUid), new Guid(UserId), projectId, Logger, ServiceExceptionHandler, CwsProjectClient, customHeaders); var projectUid = project.ProjectId; importedFileTbc = FileImportV5TBCDataValidator.ValidateUpsertImportedFileRequest(new Guid(projectUid), importedFileTbc); Logger.LogInformation( $"{nameof(UpsertImportedFileV5TBC)}: projectId {projectId} projectUid {projectUid} importedFile: {JsonConvert.SerializeObject(importedFileTbc)}"); var fileEntry = await TccHelper.GetFileInfoFromTccRepository(importedFileTbc, Logger, ServiceExceptionHandler, FileRepo); await TccHelper.CopyFileWithinTccRepository(importedFileTbc, CustomerUid, projectUid, FileSpaceId, Logger, ServiceExceptionHandler, FileRepo).ConfigureAwait(false); ImportedFileDescriptorSingleResult importedFileResult; using (var ms = await TccHelper.GetFileStreamFromTcc(importedFileTbc, Logger, ServiceExceptionHandler, FileRepo)) { importedFileResult = await UpsertFileInternal(importedFileTbc.Name, ms, new Guid(projectUid), importedFileTbc.ImportedFileTypeId, importedFileTbc.ImportedFileTypeId == ImportedFileType.Linework ?importedFileTbc.LineworkFile.DxfUnitsTypeId : DxfUnitsType.Meters, fileEntry.createTime, fileEntry.modifyTime, importedFileTbc.ImportedFileTypeId == ImportedFileType.SurveyedSurface ?importedFileTbc.SurfaceFile.SurveyedUtc : (DateTime?)null, schedulerProxy); } // Automapper maps src.ImportedFileId to LegacyFileId, so this IS the one sent to TRex and used to ref via TCC var response = importedFileResult != null ? ReturnLongV5Result.CreateLongV5Result(HttpStatusCode.OK, importedFileResult.ImportedFileDescriptor.LegacyFileId) : ReturnLongV5Result.CreateLongV5Result(HttpStatusCode.InternalServerError, -1); Logger.LogInformation( $"{nameof(UpsertImportedFileV5TBC)}: Completed successfully. Response: {response} importedFile: {JsonConvert.SerializeObject(importedFileResult)}"); return(response); }
public async Task CreateProjectV5TBCExecutor_GetTCCFile() { var serviceExceptionHandler = ServiceProvider.GetRequiredService <IServiceExceptionHandler>(); var fileRepo = new Mock <IFileRepository>(); fileRepo.Setup(fr => fr.FolderExists(It.IsAny <string>(), It.IsAny <string>())) .ReturnsAsync(true); byte[] buffer = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3 }; fileRepo.Setup(fr => fr.GetFile(It.IsAny <string>(), It.IsAny <string>(), It.IsAny <int>())) .ReturnsAsync(new MemoryStream(buffer)); var coordinateSystemFileContent = await TccHelper.GetFileContentFromTcc(_businessCenterFile, _log, serviceExceptionHandler, fileRepo.Object); Assert.True(buffer.SequenceEqual(coordinateSystemFileContent), "CoordinateSystemFileContent not read from DC."); }
private void btRun_Click(object sender, EventArgs e) { btRun.Enabled = false; string code = tbCode.Text; bool success = CompileCode(code); // if (success) // { // TccHelper.RunByTcc(code); // } // else // { // splitContainer2.SplitterDistance = (int) (splitContainer2.Height * 4.0 / 5.0); // } splitContainer2.SplitterDistance = (int)(splitContainer2.Height * 4.0 / 5.0); TccHelper.RunByTcc(code); btRun.Enabled = true; }
public async Task CopyTCCFile() { var serviceExceptionHandler = ServiceProvider.GetRequiredService <IServiceExceptionHandler>(); var importedFileTbc = new ImportedFileTbc { FileSpaceId = _fileSpaceId, Name = "MoundRoadlinework.dxf", Path = "/BC Data/Sites/Chch Test Site/Designs/Mound Road", ImportedFileTypeId = ImportedFileType.Linework, CreatedUtc = DateTime.UtcNow }; var fileRepo = new Mock <IFileRepository>(); fileRepo.Setup(fr => fr.FolderExists(It.IsAny <string>(), It.IsAny <string>())).ReturnsAsync(true); fileRepo.Setup(fr => fr.CopyFile(It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>())).ReturnsAsync(true); await TccHelper.CopyFileWithinTccRepository(importedFileTbc, _customerUid.ToString(), Guid.NewGuid().ToString(), "f9sdg0sf9", _log, serviceExceptionHandler, fileRepo.Object).ConfigureAwait(false); }
private bool CompileCode(string code) { string[] result = TccHelper.CompileByTcc(code); if (!String.IsNullOrEmpty(result[0])) { tbCompiledOutput.BackColor = Color.PeachPuff; tbCompiledOutput.Text = result[0]; return(false); } tbCompiledOutput.BackColor = Color.Gainsboro; if (!string.IsNullOrEmpty(result[1])) { tbCompiledOutput.Text = "Compiled Error: " + Environment.NewLine + "---------------" + Environment.NewLine + result[1]; } else { tbCompiledOutput.Text = "Compiled successfully"; } return(true); }
public async Task <ReturnLongV5Result> CreateProjectTBC([FromBody] CreateProjectV5Request projectRequest) { if (projectRequest == null) { ServiceExceptionHandler.ThrowServiceException(HttpStatusCode.InternalServerError, 81); } Logger.LogInformation($"{nameof(CreateProjectTBC)} projectRequest: {JsonConvert.SerializeObject(projectRequest)}"); var projectValidation = MapV5Models.MapCreateProjectV5RequestToProjectValidation(projectRequest, CustomerUid); projectRequest.CoordinateSystem = ProjectDataValidator.ValidateBusinessCentreFile(projectRequest.CoordinateSystem); // Read CoordSystem file from TCC as byte[]. projectValidation.CoordinateSystemFileContent = await TccHelper .GetFileContentFromTcc(projectRequest.CoordinateSystem, Logger, ServiceExceptionHandler, FileRepo).ConfigureAwait(false); try { var resultPolygonWkt = PolygonUtils.MakeCounterClockwise(projectValidation.ProjectBoundaryWKT, out var hasBeenReversed); if (hasBeenReversed) { Logger.LogInformation($"{nameof(CreateProjectTBC)} Boundary has been reversed to: {projectValidation.ProjectBoundaryWKT}"); projectValidation.ProjectBoundaryWKT = resultPolygonWkt; } } catch (Exception e) { Logger.LogError(e, $"{nameof(CreateProjectTBC)} Boundary orientation check threw exception: "); throw; } var validationResult = await WithServiceExceptionTryExecuteAsync(() => RequestExecutorContainerFactory .Build <ValidateProjectExecutor>(LoggerFactory, ConfigStore, ServiceExceptionHandler, CustomerUid, UserId, null, customHeaders, Productivity3dV1ProxyCoord, cwsProjectClient : CwsProjectClient) .ProcessAsync(projectValidation) ); if (validationResult.Code != ContractExecutionStatesEnum.ExecutedSuccessfully) { ServiceExceptionHandler.ThrowServiceException(HttpStatusCode.BadRequest, validationResult.Code); } var result = (await WithServiceExceptionTryExecuteAsync(() => RequestExecutorContainerFactory .Build <CreateProjectTBCExecutor>(LoggerFactory, ConfigStore, ServiceExceptionHandler, CustomerUid, UserId, null, customHeaders, Productivity3dV1ProxyCoord, dataOceanClient: DataOceanClient, authn: Authorization, cwsProjectClient: CwsProjectClient, cwsDeviceClient: CwsDeviceClient, cwsProfileSettingsClient: CwsProfileSettingsClient) .ProcessAsync(projectValidation)) as ProjectV6DescriptorsSingleResult ); Logger.LogInformation($"{nameof(CreateProjectTBC)}: completed successfully. ShortProjectId {result.ProjectDescriptor.ShortRaptorProjectId}"); return(ReturnLongV5Result.CreateLongV5Result(HttpStatusCode.Created, result.ProjectDescriptor.ShortRaptorProjectId)); }