コード例 #1
0
        private async Task <GetDetailResponseV1> InternalTryGetDetailAsync(string fileDirectory, CancellationToken cancellationToken)
        {
            GWallInfo analysisReport = null;
            var       status         = DetailStatus.FileNotFound;

            foreach (var fileStore in _fileShares)
            {
                if (!await fileStore.ExistsAsync(fileDirectory, cancellationToken))
                {
                    continue;
                }

                var fullPath = $"{fileDirectory}/report.xml";

                var analysisReportStream = await fileStore.DownloadAsync(fullPath, cancellationToken);

                if (analysisReportStream == null)
                {
                    status = DetailStatus.AnalysisReportNotFound;
                    break;
                }

                analysisReport = await _xmlSerialiser.Deserialize <GWallInfo>(analysisReportStream, Encoding.UTF8);

                status = DetailStatus.Success;
                break;
            }

            return(new GetDetailResponseV1
            {
                Status = status,
                AnalysisReport = analysisReport
            });
        }
        public async Task Setup()
        {
            base.SharedSetup();

            Share1.Setup(s => s.ExistsAsync(It.IsAny <string>(), It.IsAny <CancellationToken>()))
            .ReturnsAsync(true);

            Share1.Setup(s => s.DownloadAsync(It.IsAny <string>(), It.IsAny <CancellationToken>()))
            .ReturnsAsync(_memoryStream = new MemoryStream());

            XmlSerialiser.Setup(s => s.Deserialize <GWallInfo>(It.IsAny <Stream>(), It.IsAny <Encoding>()))
            .ReturnsAsync(_analysisReportDeserialised = new GWallInfo());

            _output = await ClassInTest.GetDetailAsync(Input, CancellationToken.None);
        }
コード例 #3
0
        protected async Task <IActionResult> RebuildZipInfoByFileId(AdaptionDescriptor descriptor)
        {
            CloudProxyResponseModel cloudProxyResponseModel = new CloudProxyResponseModel();

            if (descriptor.UUID == Guid.Empty)
            {
                cloudProxyResponseModel.Errors.Add($"The value {descriptor.UUID} should not be empty.");
                return(BadRequest(cloudProxyResponseModel));
            }

            string fileIdString     = descriptor.UUID.ToString();
            string zipFileName      = Path.Combine(Constants.VAR_PATH, $"{fileIdString}{Constants.ZIP_EXTENSION}");
            string fileIdFolderPath = Path.Combine(Constants.VAR_PATH, fileIdString);
            string tempFolderPath   = Path.Combine(fileIdFolderPath, fileIdString);

            try
            {
                _logger.LogInformation($"[{UserAgentInfo.ClientTypeString}]:: Using store locations '{_storeConfiguration.OriginalStorePath}' and '{_storeConfiguration.RebuiltStorePath}' for {fileIdString}");

                string transactionFolderPath = Directory.GetDirectories(Constants.TRANSACTION_STORE_PATH, $"{ fileIdString}", SearchOption.AllDirectories).FirstOrDefault();

                (ReportInformation reportInformation, IActionResult Result) = await GetReportAndMetadataInformation(fileIdString, descriptor.AdaptationServiceResponse.ReportPresignedUrl, descriptor.AdaptationServiceResponse.MetaDataPresignedUrl);

                if (reportInformation.ReportBytes == null)
                {
                    return(Result);
                }

                GWallInfo gwInfo = reportInformation.ReportXmlText.XmlStringToObject <GWallInfo>();

                if (!Directory.Exists(tempFolderPath))
                {
                    Directory.CreateDirectory(tempFolderPath);
                }

                string reportFolderPath = Path.Combine(tempFolderPath, Constants.REPORT_FOLDER_NAME);
                if (!Directory.Exists(reportFolderPath))
                {
                    Directory.CreateDirectory(reportFolderPath);
                }

                string cleanFolderPath = Path.Combine(tempFolderPath, Constants.CLEAN_FOLDER_NAME);
                if (!Directory.Exists(cleanFolderPath))
                {
                    Directory.CreateDirectory(cleanFolderPath);
                }

                string rebuiltStoreFilePath = Path.Combine(_storeConfiguration.RebuiltStorePath, fileIdString);
                if (!System.IO.File.Exists(rebuiltStoreFilePath))
                {
                    _logger.LogWarning($"[{UserAgentInfo.ClientTypeString}]:: Rebuild file not exist for file {fileIdString}");
                    cloudProxyResponseModel.Errors.Add($"Rebuild file not exist for file {fileIdString}");
                    return(NotFound(cloudProxyResponseModel));
                }

                await System.IO.File.WriteAllTextAsync(Path.Combine(reportFolderPath, Constants.REPORT_XML_FILE_NAME), reportInformation.ReportXmlText);

                await System.IO.File.WriteAllTextAsync(Path.Combine(tempFolderPath, Constants.METADATA_JSON_FILE_NAME), reportInformation.MetadaJsonText);

                await System.IO.File.WriteAllBytesAsync(Path.Combine(cleanFolderPath, $"{Path.GetFileName(rebuiltStoreFilePath)}.{gwInfo.DocumentStatistics.DocumentSummary.FileType}"), await System.IO.File.ReadAllBytesAsync(rebuiltStoreFilePath));

                _zipUtility.CreateZipFile(zipFileName, null, fileIdFolderPath);
                AddHeaderToResponse(Constants.Header.FILE_ID, fileIdString);
                return(new FileContentResult(await System.IO.File.ReadAllBytesAsync(zipFileName), Constants.OCTET_STREAM_CONTENT_TYPE)
                {
                    FileDownloadName = Path.GetFileName(zipFileName)
                });
            }
            catch (Exception ex)
            {
                _logger.LogError(ex, $"[{UserAgentInfo.ClientTypeString}]:: Error Processing 'input' {fileIdString} and error detail is {ex.Message}");
                cloudProxyResponseModel.Errors.Add($"Error Processing 'input' {fileIdString} and error detail is {ex.Message}");
                cloudProxyResponseModel.Status = ReturnOutcome.GW_ERROR;
                return(StatusCode(StatusCodes.Status500InternalServerError, cloudProxyResponseModel));
            }
            finally
            {
                if (Directory.Exists(fileIdFolderPath))
                {
                    Directory.Delete(fileIdFolderPath, true);
                }

                if (System.IO.File.Exists(zipFileName))
                {
                    System.IO.File.Delete(zipFileName);
                }
            }
        }