public async Task <bool> ExportDrawingViewablesAsync(string projectName, string hash) { _logger.LogInformation($"Generating drawing viewables for hash {hash}"); ProjectStorage storage = await _userResolver.GetProjectStorageAsync(projectName); Project project = storage.Project; var ossNameProvider = project.OssNameProvider(hash); bool generated = false; ApiResponse <dynamic> ossObjectResponse = null; var bucket = await _userResolver.GetBucketAsync(); // check if Drawing viewables file is already generated try { ossObjectResponse = await bucket.GetObjectAsync(ossNameProvider.DrawingViewables); if (ossObjectResponse != null) { using (Stream objectStream = ossObjectResponse.Data) { // zero length means that there is nothing to generate, but processed and do not continue generated = objectStream.Length > 0; } } return(generated); } catch (ApiException e) when(e.ErrorCode == StatusCodes.Status404NotFound) { // the file does not exist, so just swallow } // OK, nothing in cache - generate it now var inputDocUrl = await bucket.CreateSignedUrlAsync(ossNameProvider.GetCurrentModel(storage.IsAssembly)); ProcessingArgs drawingData = await _arranger.ForDrawingViewablesAsync(inputDocUrl, storage.Metadata.TLA); ProcessingResult result = await _fdaClient.ExportDrawingAsync(drawingData); if (!result.Success) { _logger.LogError($"{result.ErrorMessage} for project {project.Name} and hash {hash}"); throw new FdaProcessingException($"{result.ErrorMessage} for project {project.Name} and hash {hash}", result.ReportUrl); } // check if Drawing viewables file is generated try { await bucket.CreateSignedUrlAsync(ossNameProvider.DrawingViewables); generated = true; } catch (ApiException e) when(e.ErrorCode == StatusCodes.Status404NotFound) { // the file does not exist after generating drawing, so just mark with zero length that we already processed it await bucket.UploadObjectAsync(ossNameProvider.DrawingViewables, new MemoryStream(0)); } await _arranger.MoveDrawingViewablesAsync(project, hash); return(generated); }
public async Task <(FdaStatsDTO stats, int drawingIdx, string reportUrl)> ExportDrawingPdfAsync(string projectName, string hash, string drawingKey) { _logger.LogInformation($"Getting drawing pdf for hash {hash}"); ProjectStorage storage = await _userResolver.GetProjectStorageAsync(projectName); Project project = storage.Project; var ossNames = project.OssNameProvider(hash); var ossAttributes = project.OssAttributes; // get drawing index from drawing specified var bucket = await _userResolver.GetBucketAsync(); var localAttributes = project.LocalAttributes; // read cached drawingsList var drawings = Json.DeserializeFile <List <string> >(localAttributes.DrawingsList); int index = drawings.IndexOf(drawingKey); var drawingIdx = index >= 0 ? index : 0; // check if Drawing viewables file is already generated try { bool generated = false; ApiResponse <dynamic> ossObjectResponse = await bucket.GetObjectAsync(ossNames.DrawingPdf(drawingIdx)); if (ossObjectResponse != null) { await using Stream objectStream = ossObjectResponse.Data; // zero length means that there is nothing to generate, but processed and do not continue generated = objectStream.Length > 0; } if (generated) { var nativeStats = await bucket.DeserializeAsync <List <Statistics> >(ossNames.StatsDrawingPDF(drawingIdx)); return(FdaStatsDTO.CreditsOnly(nativeStats), drawingIdx, null); } else { return(null, drawingIdx, null); } } catch (ApiException e) when(e.ErrorCode == StatusCodes.Status404NotFound) { // the file does not exist, so just swallow } _logger.LogInformation($"Drawing PDF for hash {hash}: generating"); // OK, nothing in cache - generate it now var inputDocUrl = await bucket.CreateSignedUrlAsync(ossNames.GetCurrentModel(storage.IsAssembly)); ProcessingArgs drawingData = await _arranger.ForDrawingPdfAsync(inputDocUrl, drawingKey, storage.Metadata.TLA); ProcessingResult result = await _fdaClient.ExportDrawingAsync(drawingData); if (!result.Success) { _logger.LogError($"{result.ErrorMessage} for project {project.Name} and hash {hash}"); throw new FdaProcessingException($"{result.ErrorMessage} for project {project.Name} and hash {hash}", result.ReportUrl); } // move to the right place await _arranger.MoveDrawingPdfAsync(project, drawingIdx, hash); // check if Drawing PDF file is generated try { await bucket.CreateSignedUrlAsync(ossNames.DrawingPdf(drawingIdx)); // handle statistics await bucket.UploadAsJsonAsync(ossNames.StatsDrawingPDF(drawingIdx), result.Stats); _logger.LogInformation($"Drawing PDF for hash {hash} is generated"); return(FdaStatsDTO.All(result.Stats), drawingIdx, result.ReportUrl); } catch (ApiException e) when(e.ErrorCode == StatusCodes.Status404NotFound) { // the file does not exist after generating drawing, so just mark with zero length that we already processed it await bucket.UploadObjectAsync(ossNames.DrawingPdf(drawingIdx), new MemoryStream(0)); _logger.LogError($"Drawing PDF for hash {hash} is NOT generated"); return(null, drawingIdx, result.ReportUrl); } }