protected override async Task <ContractExecutionResult> ProcessAsyncEx <T>(T item) { var request = CastRequestObjectTo <CoordinateSystemFile>(item); var dcFileContentString = System.Text.Encoding.UTF8.GetString(request.CSFileContent, 0, request.CSFileContent.Length); var coreXWrapper = DIContext.Obtain <ICoreXWrapper>(); var coordinateSystem = coreXWrapper.GetCSDFromDCFileContent(dcFileContentString); if (coordinateSystem == null || coordinateSystem.ZoneInfo == null || coordinateSystem.DatumInfo == null) { throw new ServiceException(HttpStatusCode.BadRequest, new ContractExecutionResult(ContractExecutionStatesEnum.FailedToGetResults, $"Failed to convert DC File {request.CSFileName} content to Coordinate System definition data.")); } var projectUid = request.ProjectUid ?? Guid.Empty; var csib = coreXWrapper.GetCSIBFromDCFileContent(dcFileContentString); var addCoordinateSystemRequest = new AddCoordinateSystemRequest(); var addCoordSystemResponse = await addCoordinateSystemRequest.ExecuteAsync(new AddCoordinateSystemArgument() { ProjectID = projectUid, CSIB = csib }); if (addCoordSystemResponse?.Succeeded ?? false) { return(ConvertResult(request.CSFileName, coordinateSystem)); } throw new ServiceException(HttpStatusCode.BadRequest, new ContractExecutionResult(ContractExecutionStatesEnum.FailedToGetResults, $"Failed to post Coordinate System definition data. Project UID: {projectUid}")); }
public async Task <JsonResult> PostCoordinateSystem([FromBody] CoordinateSystemFile request) { string resultToReturn = null; var dcFileContentString = System.Text.Encoding.UTF8.GetString(request.CSFileContent, 0, request.CSFileContent.Length); var coreXWrapper = DIContext.Obtain <ICoreXWrapper>(); var csd = coreXWrapper.GetCSDFromDCFileContent(dcFileContentString); if (csd == null || csd.ZoneInfo == null || csd.DatumInfo == null) { resultToReturn = $"<b>Failed to convert DC File {request.CSFileName} content to Coordinate System definition data.</b>"; } else { var sw = new Stopwatch(); sw.Start(); var projectUid = request.ProjectUid ?? Guid.Empty; var addCoordinateSystemRequest = new AddCoordinateSystemRequest(); var csib = coreXWrapper.GetCSIBFromDCFileContent(dcFileContentString); var addCoordSystemResponse = await addCoordinateSystemRequest.ExecuteAsync(new AddCoordinateSystemArgument() { ProjectID = projectUid, CSIB = csib }); if (addCoordSystemResponse?.Succeeded ?? false) { resultToReturn = $"<b>Coordinate System Settings (in {sw.Elapsed}) :</b><br/>"; resultToReturn += "<b>================================================</b><br/>"; resultToReturn += ConvertCSResult(request.CSFileName, csd); } } return(new JsonResult(resultToReturn)); }