public void WhenIsCancellationRequestedinExchangeSet_ThenThrowCancelledException() { SalesCatalogueServiceResponseQueueMessage scsResponseQueueMessage = GetScsResponseQueueMessage(); SalesCatalogueProductResponse salesCatalogueProductResponse = GetSalesCatalogueResponse(); string storageAccountConnectionString = "DefaultEndpointsProtocol = https; AccountName = testessdevstorage2; AccountKey =testaccountkey; EndpointSuffix = core.windows.net"; fakeConfiguration["HOME"] = @"D:\\Downloads"; A.CallTo(() => fakeScsStorageService.GetStorageAccountConnectionString(null, null)) .Returns(storageAccountConnectionString); var productList = new List <Products> { new Products { ProductName = "DE5NOBRK", EditionNumber = 0, UpdateNumbers = new List <int?> { 0, 1 }, FileSize = 400 } }; CancellationTokenSource cancellationTokenSource = new CancellationTokenSource(); cancellationTokenSource.Cancel(); CancellationToken cancellationToken = cancellationTokenSource.Token; A.CallTo(() => fakeAzureBlobStorageService.DownloadSalesCatalogueResponse(A <string> .Ignored, A <string> .Ignored, A <string> .Ignored)).Returns(salesCatalogueProductResponse); Assert.ThrowsAsync <TaskCanceledException>(async() => await fulfilmentDataService.QueryFileShareServiceFiles(scsResponseQueueMessage, productList, null, cancellationTokenSource, cancellationToken)); }
public async Task CreateAndUploadErrorFileToFileShareService(SalesCatalogueServiceResponseQueueMessage fulfilmentServiceQueueMessage, EventId eventId, string errorMessage, string batchFolderPath) { fileSystemHelper.CheckAndCreateFolder(batchFolderPath); var errorFileFullPath = Path.Combine(batchFolderPath, fileShareServiceConfig.Value.ErrorFileName); fileSystemHelper.CreateFileContent(errorFileFullPath, errorMessage); if (fileSystemHelper.CheckFileExists(errorFileFullPath)) { var isUploaded = await fileShareService.UploadFileToFileShareService(fulfilmentServiceQueueMessage.BatchId, batchFolderPath, fulfilmentServiceQueueMessage.CorrelationId, fileShareServiceConfig.Value.ErrorFileName); if (isUploaded) { logger.LogError(EventIds.ErrorTxtIsUploaded.ToEventId(), "Error while processing Exchange Set creation and error.txt file is created and uploaded in file share service with ErrorCode-EventId:{EventId} and EventName:{EventName} for BatchId:{BatchId} and _X-Correlation-ID:{CorrelationId}", eventId.Id, eventId.Name, fulfilmentServiceQueueMessage.BatchId, fulfilmentServiceQueueMessage.CorrelationId); logger.LogError(EventIds.ExchangeSetCreatedWithError.ToEventId(), "Exchange set is created with error for BatchId:{BatchId} and _X-Correlation-ID:{CorrelationId}", fulfilmentServiceQueueMessage.BatchId, fulfilmentServiceQueueMessage.CorrelationId); } else { logger.LogError(EventIds.ErrorTxtNotUploaded.ToEventId(), "Error while uploading error.txt file to file share service for BatchId:{BatchId} and _X-Correlation-ID:{CorrelationId}", fulfilmentServiceQueueMessage.BatchId, fulfilmentServiceQueueMessage.CorrelationId); } } else { logger.LogError(EventIds.ErrorTxtNotCreated.ToEventId(), "Error while creating error.txt for BatchId:{BatchId} and _X-Correlation-ID:{CorrelationId}", fulfilmentServiceQueueMessage.BatchId, fulfilmentServiceQueueMessage.CorrelationId); } await SendErrorCallBackResponse(fulfilmentServiceQueueMessage); }
public void WhenScsStorageAccountAccessKeyValueNotfound_ThenGetStorageAccountConnectionStringReturnsKeyNotFoundException() { SalesCatalogueServiceResponseQueueMessage scsResponseQueueMessage = GetScsResponseQueueMessage(); A.CallTo(() => fakeScsStorageService.GetStorageAccountConnectionString(null, null)) .Throws(new KeyNotFoundException("Storage account accesskey not found")); Assert.ThrowsAsync(Is.TypeOf <KeyNotFoundException>().And.Message.EqualTo("Storage account accesskey not found"), async delegate { await fulfilmentDataService.CreateExchangeSet(scsResponseQueueMessage, currentUtcDate); }); }
private SalesCatalogueServiceResponseQueueMessage GetSalesCatalogueServiceResponseQueueMessage(string batchId, SalesCatalogueProductResponse salesCatalogueResponse, string callBackUri, string correlationId, CloudBlockBlob cloudBlockBlob, string expiryDate) { long fileSize = CommonHelper.GetFileSize(salesCatalogueResponse); var scsResponseQueueMessage = new SalesCatalogueServiceResponseQueueMessage() { BatchId = batchId, ScsResponseUri = cloudBlockBlob.Uri.AbsoluteUri, FileSize = fileSize, CallbackUri = callBackUri == null ? string.Empty : callBackUri, CorrelationId = correlationId, ExchangeSetUrlExpiryDate = expiryDate }; return(scsResponseQueueMessage); }
public void Setup() { postBodyParam = "This should be replace by actual value when param passed to api call"; uriParam = null; httpMethodParam = null; salesCatalogueProductResponse = GetSalesCatalogueServiceResponse(); scsResponseQueueMessage = GetScsResponseQueueMessage(); fakeEssCallBackConfiguration = Options.Create(new EssCallBackConfiguration() { }); fakeCallBackClient = A.Fake <ICallBackClient>(); fakeFileShareServiceConfig = Options.Create(new FileShareServiceConfiguration() { }); fakeLogger = A.Fake <ILogger <FulfilmentCallBackService> >(); fulfilmentCallBackService = new FulfilmentCallBackService(fakeEssCallBackConfiguration, fakeCallBackClient, fakeFileShareServiceConfig, fakeLogger); }
public async Task WhenValidMessageQueueTrigger_ThenReturnsExchangeSetCreatedSuccessfully() { SalesCatalogueServiceResponseQueueMessage scsResponseQueueMessage = GetScsResponseQueueMessage(); SalesCatalogueProductResponse salesCatalogueProductResponse = GetSalesCatalogueResponse(); var fulfilmentDataResponse = new List <FulfilmentDataResponse>() { new FulfilmentDataResponse { BatchId = "63d38bde-5191-4a59-82d5-aa22ca1cc6dc", EditionNumber = 10, ProductName = "Demo", UpdateNumber = 3, FileUri = new List <string> { "http://ffs-demo.azurewebsites.net" } } }; string storageAccountConnectionString = "DefaultEndpointsProtocol = https; AccountName = testessdevstorage2; AccountKey =testaccountkey; EndpointSuffix = core.windows.net"; fakeConfiguration["HOME"] = @"D:\\Downloads"; fakeFileShareServiceConfig.Value.ExchangeSetFileFolder = "V01X01"; fakeFileShareServiceConfig.Value.EncRoot = "ENC_ROOT"; SalesCatalogueDataResponse salesCatalogueDataResponse = GetSalesCatalogueDataResponse(); A.CallTo(() => fakeScsStorageService.GetStorageAccountConnectionString(null, null)) .Returns(storageAccountConnectionString); string filePath = @"D:\\Downloads"; A.CallTo(() => fakeAzureBlobStorageService.DownloadSalesCatalogueResponse(A <string> .Ignored, A <string> .Ignored, A <string> .Ignored)).Returns(salesCatalogueProductResponse); A.CallTo(() => fakeQueryFssService.SearchReadMeFilePath(A <string> .Ignored, A <string> .Ignored)).Returns(filePath); A.CallTo(() => fakeQueryFssService.DownloadReadMeFile(A <string> .Ignored, A <string> .Ignored, A <string> .Ignored, A <string> .Ignored)).Returns(true); A.CallTo(() => fakeQueryFssService.CreateZipFileForExchangeSet(A <string> .Ignored, A <string> .Ignored, A <string> .Ignored)).Returns(true); A.CallTo(() => fakeQueryFssService.UploadZipFileForExchangeSetToFileShareService(A <string> .Ignored, A <string> .Ignored, A <string> .Ignored)).Returns(true); A.CallTo(() => fakeFulfilmentAncillaryFiles.CreateCatalogFile(A <string> .Ignored, A <string> .Ignored, A <string> .Ignored, fulfilmentDataResponse, salesCatalogueDataResponse, salesCatalogueProductResponse)).Returns(true); A.CallTo(() => fakeFulfilmentSalesCatalogueService.GetSalesCatalogueDataResponse(A <string> .Ignored, A <string> .Ignored)).Returns(salesCatalogueDataResponse); A.CallTo(() => fakeFulfilmentAncillaryFiles.CreateProductFile(A <string> .Ignored, A <string> .Ignored, A <string> .Ignored, salesCatalogueDataResponse)).Returns(true); A.CallTo(() => fakeFulfilmentCallBackService.SendCallBackResponse(A <SalesCatalogueProductResponse> .Ignored, A <SalesCatalogueServiceResponseQueueMessage> .Ignored)).Returns(true); string salesCatalogueResponseFile = await fulfilmentDataService.CreateExchangeSet(scsResponseQueueMessage, currentUtcDate); Assert.AreEqual("Exchange Set Created Successfully", salesCatalogueResponseFile); }
public async Task WhenInvalidMessageQueueTrigger_ThenReturnsExchangeSetIsNotCreated() { SalesCatalogueServiceResponseQueueMessage scsResponseQueueMessage = GetScsResponseQueueMessage(); SalesCatalogueProductResponse salesCatalogueProductResponse = GetSalesCatalogueResponse(); string storageAccountConnectionString = "DefaultEndpointsProtocol = https; AccountName = testessdevstorage2; AccountKey =testaccountkey; EndpointSuffix = core.windows.net"; fakeConfiguration["HOME"] = @"D:\\Downloads"; fakeFileShareServiceConfig.Value.ExchangeSetFileFolder = "V01X01"; fakeFileShareServiceConfig.Value.EncRoot = "ENC_ROOT"; A.CallTo(() => fakeScsStorageService.GetStorageAccountConnectionString(null, null)) .Returns(storageAccountConnectionString); string filePath = @"D:\\Downloads"; A.CallTo(() => fakeAzureBlobStorageService.DownloadSalesCatalogueResponse(A <string> .Ignored, A <string> .Ignored, A <string> .Ignored)).Returns(salesCatalogueProductResponse); A.CallTo(() => fakeQueryFssService.SearchReadMeFilePath(A <string> .Ignored, A <string> .Ignored)).Returns(filePath); A.CallTo(() => fakeQueryFssService.DownloadReadMeFile(A <string> .Ignored, A <string> .Ignored, A <string> .Ignored, A <string> .Ignored)).Returns(true); A.CallTo(() => fakeQueryFssService.CreateZipFileForExchangeSet(A <string> .Ignored, A <string> .Ignored, A <string> .Ignored)).Returns(true); A.CallTo(() => fakeQueryFssService.UploadZipFileForExchangeSetToFileShareService(A <string> .Ignored, A <string> .Ignored, A <string> .Ignored)).Returns(false); string salesCatalogueResponseFile = await fulfilmentDataService.CreateExchangeSet(scsResponseQueueMessage, currentUtcDate); Assert.AreEqual("Exchange Set Is Not Created", salesCatalogueResponseFile); }
public async Task ProcessQueueMessage([QueueTrigger("%ESSFulfilmentStorageConfiguration:QueueName%")] CloudQueueMessage message) { SalesCatalogueServiceResponseQueueMessage fulfilmentServiceQueueMessage = JsonConvert.DeserializeObject <SalesCatalogueServiceResponseQueueMessage>(message.AsString); string homeDirectoryPath = configuration["HOME"]; string currentUtcDate = DateTime.UtcNow.ToString("ddMMMyyyy"); string batchFolderPath = Path.Combine(homeDirectoryPath, currentUtcDate, fulfilmentServiceQueueMessage.BatchId); try { await logger.LogStartEndAndElapsedTimeAsync(EventIds.CreateExchangeSetRequestStart, EventIds.CreateExchangeSetRequestCompleted, "Create Exchange Set web job request for BatchId:{BatchId} and _X-Correlation-ID:{CorrelationId}", async() => { return(await fulFilmentDataService.CreateExchangeSet(fulfilmentServiceQueueMessage, currentUtcDate)); }, fulfilmentServiceQueueMessage.BatchId, fulfilmentServiceQueueMessage.CorrelationId); } catch (Exception ex) { EventId exceptionEventId = EventIds.SystemException.ToEventId(); if (ex.GetType() == typeof(FulfilmentException)) { exceptionEventId = ((FulfilmentException)ex).EventId; } FulfilmentException fulfilmentException = new FulfilmentException(exceptionEventId); string errorMessage = string.Format(fulfilmentException.Message, exceptionEventId.Id, fulfilmentServiceQueueMessage.CorrelationId); await CreateAndUploadErrorFileToFileShareService(fulfilmentServiceQueueMessage, exceptionEventId, errorMessage, batchFolderPath); if (ex.GetType() != typeof(FulfilmentException)) { logger.LogError(exceptionEventId, ex, "Unhandled exception while processing Exchange Set web job for BatchId:{BatchId} and _X-Correlation-ID:{CorrelationId} and Exception:{Message}", fulfilmentServiceQueueMessage.BatchId, fulfilmentServiceQueueMessage.CorrelationId, ex.Message); } } }
public async Task SendErrorCallBackResponse(SalesCatalogueServiceResponseQueueMessage fulfilmentServiceQueueMessage) { SalesCatalogueProductResponse salesCatalogueProductResponse = await azureBlobStorageService.DownloadSalesCatalogueResponse(fulfilmentServiceQueueMessage.ScsResponseUri, fulfilmentServiceQueueMessage.BatchId, fulfilmentServiceQueueMessage.CorrelationId); await fulfilmentCallBackService.SendCallBackErrorResponse(salesCatalogueProductResponse, fulfilmentServiceQueueMessage); }
public async Task <string> CreateExchangeSet(SalesCatalogueServiceResponseQueueMessage message, string currentUtcDate) { DateTime createExchangeSetTaskStartedAt = DateTime.UtcNow; string homeDirectoryPath = configuration["HOME"]; var exchangeSetPath = Path.Combine(homeDirectoryPath, currentUtcDate, message.BatchId, fileShareServiceConfig.Value.ExchangeSetFileFolder); var exchangeSetRootPath = Path.Combine(exchangeSetPath, fileShareServiceConfig.Value.EncRoot); var exchangeSetZipFilePath = Path.Combine(homeDirectoryPath, currentUtcDate, message.BatchId); var listFulfilmentData = new List <FulfilmentDataResponse>(); var response = await DownloadSalesCatalogueResponse(message); if (response.Products != null && response.Products.Any()) { DateTime queryAndDownloadEncFilesFromFileShareServiceTaskStartedAt = DateTime.UtcNow; int parallelSearchTaskCount = fileShareServiceConfig.Value.ParallelSearchTaskCount; int productGroupCount = response.Products.Count % parallelSearchTaskCount == 0 ? response.Products.Count / parallelSearchTaskCount : (response.Products.Count / parallelSearchTaskCount) + 1; var productsList = CommonHelper.SplitList((response.Products), productGroupCount); List <FulfilmentDataResponse> fulfilmentDataResponse = new List <FulfilmentDataResponse>(); object sync = new object(); int fileShareServiceSearchQueryCount = 0; var cancellationTokenSource = new CancellationTokenSource(); CancellationToken cancellationToken = cancellationTokenSource.Token; var tasks = productsList.Select(async item => { fulfilmentDataResponse = await QueryFileShareServiceFiles(message, item, exchangeSetRootPath, cancellationTokenSource, cancellationToken); int queryCount = fulfilmentDataResponse.Count > 0 ? fulfilmentDataResponse.FirstOrDefault().FileShareServiceSearchQueryCount : 0; lock (sync) { fileShareServiceSearchQueryCount += queryCount; } if (cancellationToken.IsCancellationRequested) { cancellationTokenSource.Cancel(); logger.LogError(EventIds.CancellationTokenEvent.ToEventId(), "Operation is cancelled as IsCancellationRequested flag is true in QueryFileShareServiceFiles with {cancellationTokenSource.Token} and batchId:{message.BatchId} and CorrelationId:{message.CorrelationId}", JsonConvert.SerializeObject(cancellationTokenSource.Token), message.BatchId, message.CorrelationId); throw new OperationCanceledException(); } listFulfilmentData.AddRange(fulfilmentDataResponse); }); await Task.WhenAll(tasks); DateTime queryAndDownloadEncFilesFromFileShareServiceTaskCompletedAt = DateTime.UtcNow; int downloadedENCFileCount = 0; foreach (var item in listFulfilmentData) { downloadedENCFileCount += item.Files.Count(); } monitorHelper.MonitorRequest("Query and Download ENC Files Task", queryAndDownloadEncFilesFromFileShareServiceTaskStartedAt, queryAndDownloadEncFilesFromFileShareServiceTaskCompletedAt, message.CorrelationId, fileShareServiceSearchQueryCount, downloadedENCFileCount, null, message.BatchId); } await CreateAncillaryFiles(message.BatchId, exchangeSetPath, message.CorrelationId, listFulfilmentData, response); bool isZipFileUploaded = await PackageAndUploadExchangeSetZipFileToFileShareService(message.BatchId, exchangeSetPath, exchangeSetZipFilePath, message.CorrelationId); DateTime createExchangeSetTaskCompletedAt = DateTime.UtcNow; if (isZipFileUploaded) { logger.LogInformation(EventIds.ExchangeSetCreated.ToEventId(), "Exchange set is created for BatchId:{BatchId} and _X-Correlation-ID:{CorrelationId}", message.BatchId, message.CorrelationId); await fulfilmentCallBackService.SendCallBackResponse(response, message); monitorHelper.MonitorRequest("Create Exchange Set Task", createExchangeSetTaskStartedAt, createExchangeSetTaskCompletedAt, message.CorrelationId, null, null, null, message.BatchId); return("Exchange Set Created Successfully"); } monitorHelper.MonitorRequest("Create Exchange Set Task", createExchangeSetTaskStartedAt, createExchangeSetTaskCompletedAt, message.CorrelationId, null, null, null, message.BatchId); return("Exchange Set Is Not Created"); }
public async Task <List <FulfilmentDataResponse> > QueryFileShareServiceFiles(SalesCatalogueServiceResponseQueueMessage message, List <Products> products, string exchangeSetRootPath, CancellationTokenSource cancellationTokenSource, CancellationToken cancellationToken) { return(await logger.LogStartEndAndElapsedTimeAsync(EventIds.QueryFileShareServiceENCFilesRequestStart, EventIds.QueryFileShareServiceENCFilesRequestCompleted, "File share service search query and download request for ENC files for BatchId:{BatchId} and _X-Correlation-ID:{CorrelationId}", async() => { return await fulfilmentFileShareService.QueryFileShareServiceData(products, message, cancellationTokenSource, cancellationToken, exchangeSetRootPath); }, message.BatchId, message.CorrelationId)); }
public async Task <SalesCatalogueProductResponse> DownloadSalesCatalogueResponse(SalesCatalogueServiceResponseQueueMessage message) { return(await azureBlobStorageService.DownloadSalesCatalogueResponse(message.ScsResponseUri, message.BatchId, message.CorrelationId)); }
public async Task AddQueueMessage(string batchId, SalesCatalogueProductResponse salesCatalogueResponse, string callBackUri, string correlationId, CloudBlockBlob cloudBlockBlob, int instanceNumber, string storageAccountConnectionString, string expiryDate) { SalesCatalogueServiceResponseQueueMessage scsResponseQueueMessage = GetSalesCatalogueServiceResponseQueueMessage(batchId, salesCatalogueResponse, callBackUri, correlationId, cloudBlockBlob, expiryDate); var scsResponseQueueMessageJSON = JsonConvert.SerializeObject(scsResponseQueueMessage); await azureMessageQueueHelper.AddMessage(batchId, instanceNumber, storageAccountConnectionString, scsResponseQueueMessageJSON, correlationId); }
public async Task <bool> SendCallBackErrorResponse(SalesCatalogueProductResponse salesCatalogueProductResponse, SalesCatalogueServiceResponseQueueMessage scsResponseQueueMessage) { salesCatalogueProductResponse.ProductCounts.ReturnedProductCount = 0; salesCatalogueProductResponse.ProductCounts.RequestedProductsNotReturned = new List <RequestedProductsNotReturned> { new RequestedProductsNotReturned { ProductName = null, Reason = essCallBackConfiguration.Value.Reason } }; if (!string.IsNullOrWhiteSpace(scsResponseQueueMessage.CallbackUri)) { try { ExchangeSetResponse exchangeSetResponse = SetExchangeSetResponse(salesCatalogueProductResponse, scsResponseQueueMessage); exchangeSetResponse.Links.ExchangeSetFileUri = null; exchangeSetResponse.Links.ExchangeSetErrorFileUri = new LinkSetErrorFileUri { Href = $"{fileShareServiceConfig.Value.PublicBaseUrl}/batch/{scsResponseQueueMessage.BatchId}/files/{fileShareServiceConfig.Value.ErrorFileName}" }; CallBackResponse callBackResponse = SetCallBackResponse(exchangeSetResponse); callBackResponse.Subject = essCallBackConfiguration.Value.ErrorSubject; if (ValidateCallbackErrorRequestPayload(callBackResponse)) { string payloadJson = JsonConvert.SerializeObject(callBackResponse); return(await SendResponseToCallBackApi(true, payloadJson, scsResponseQueueMessage)); } else { logger.LogError(EventIds.ExchangeSetCreatedWithErrorPostCallbackUriNotCalled.ToEventId(), "Post Callback uri is not called after exchange set is created with error for BatchId:{BatchId} and _X-Correlation-ID:{CorrelationId} as payload data is incorrect.", scsResponseQueueMessage.BatchId, scsResponseQueueMessage.CorrelationId); return(false); } } catch (Exception ex) { logger.LogError(EventIds.ExchangeSetCreatedWithErrorPostCallbackUriNotCalled.ToEventId(), "Post Callback uri is not called after exchange set is created with error for BatchId:{BatchId} and _X-Correlation-ID:{CorrelationId} and Exception:{Message}", scsResponseQueueMessage.BatchId, scsResponseQueueMessage.CorrelationId, ex.Message); return(false); } } else { logger.LogInformation(EventIds.ExchangeSetCreatedWithErrorPostCallbackUriNotProvided.ToEventId(), "Post callback uri was not provided by requestor for exchange set creation with error for BatchId:{BatchId} and _X-Correlation-ID:{CorrelationId}", scsResponseQueueMessage.BatchId, scsResponseQueueMessage.CorrelationId); return(false); } }
public ExchangeSetResponse SetExchangeSetResponse(SalesCatalogueProductResponse salesCatalogueProductResponse, SalesCatalogueServiceResponseQueueMessage scsResponseQueueMessage) { return(new ExchangeSetResponse() { Links = new Links() { ExchangeSetBatchStatusUri = new LinkSetBatchStatusUri { Href = $"{fileShareServiceConfig.Value.PublicBaseUrl}/batch/{scsResponseQueueMessage.BatchId}/status" }, ExchangeSetBatchDetailsUri = new LinkSetBatchDetailsUri { Href = $"{fileShareServiceConfig.Value.PublicBaseUrl}/batch/{scsResponseQueueMessage.BatchId}" }, ExchangeSetFileUri = new LinkSetFileUri { Href = $"{fileShareServiceConfig.Value.PublicBaseUrl}/batch/{scsResponseQueueMessage.BatchId}/files/{fileShareServiceConfig.Value.ExchangeSetFileName}" } }, ExchangeSetUrlExpiryDateTime = Convert.ToDateTime(scsResponseQueueMessage.ExchangeSetUrlExpiryDate).ToUniversalTime(), RequestedProductCount = salesCatalogueProductResponse.ProductCounts.RequestedProductCount.Value, ExchangeSetCellCount = salesCatalogueProductResponse.ProductCounts.ReturnedProductCount.Value, RequestedProductsAlreadyUpToDateCount = salesCatalogueProductResponse.ProductCounts.RequestedProductsAlreadyUpToDateCount.Value, RequestedProductsNotInExchangeSet = GetRequestedProductsNotInExchangeSet(salesCatalogueProductResponse) }); }
public async Task <List <FulfilmentDataResponse> > QueryFileShareServiceData(List <Products> products, SalesCatalogueServiceResponseQueueMessage message, CancellationTokenSource cancellationTokenSource, CancellationToken cancellationToken, string exchangeSetRootPath) { if (products != null && products.Any()) { var batchProducts = SliceFileShareServiceProducts(products); var listBatchDetails = new List <BatchDetail>(); int fileShareServiceSearchQueryCount = 0; foreach (var item in batchProducts) { if (cancellationToken.IsCancellationRequested) { var productDetail = new StringBuilder(); foreach (var productitem in item) { productDetail.AppendFormat("\n Product/CellName:{0}, EditionNumber:{1} and UpdateNumbers:[{2}]", productitem.ProductName, productitem.EditionNumber.ToString(), string.Join(",", productitem?.UpdateNumbers.Select(a => a.Value.ToString()))); } logger.LogError(EventIds.CancellationTokenEvent.ToEventId(), "Operation cancelled as IsCancellationRequested flag is true while searching ENC files from File Share Service with cancellationToken:{cancellationTokenSource.Token} at time:{DateTime.UtcNow} and productdetails:{productDetail.ToString()} and BatchId:{batchId} and _X-Correlation-ID:{correlationId}", JsonConvert.SerializeObject(cancellationTokenSource.Token), DateTime.UtcNow, productDetail.ToString(), message.BatchId, message.CorrelationId); throw new OperationCanceledException(); } var result = await fileShareService.GetBatchInfoBasedOnProducts(item, message, cancellationTokenSource, cancellationToken, exchangeSetRootPath); listBatchDetails.AddRange(result.Entries); fileShareServiceSearchQueryCount += result.QueryCount; } var fulFilmentDataResponse = SetFulfilmentDataResponse(new SearchBatchResponse() { Entries = listBatchDetails }); if (fulFilmentDataResponse.Count > 0) { fulFilmentDataResponse.FirstOrDefault().FileShareServiceSearchQueryCount = fileShareServiceSearchQueryCount; } return(fulFilmentDataResponse); } return(null); }
private Task <BatchDetail> CheckIfCacheProductsExistsInBlob(string exchangeSetRootPath, SalesCatalogueServiceResponseQueueMessage queueMessage, Products item, List <int?> updateNumbers, int?itemUpdateNumber, string storageConnectionString, FssSearchResponseCache cacheInfo) { logger.LogInformation(EventIds.FileShareServiceSearchENCFilesFromCacheStart.ToEventId(), "File share service search request from cache started for Product/CellName:{ProductName}, EditionNumber:{EditionNumber} and UpdateNumber:{UpdateNumber}. BatchId:{batchId} and _X-Correlation-ID:{CorrelationId}", item.ProductName, item.EditionNumber, itemUpdateNumber, queueMessage.BatchId, queueMessage.CorrelationId); var internalBatchDetail = JsonConvert.DeserializeObject <BatchDetail>(cacheInfo.Response); logger.LogInformation(EventIds.FileShareServiceSearchENCFilesFromCacheCompleted.ToEventId(), "File share service search request from cache completed for Product/CellName:{ProductName}, EditionNumber:{EditionNumber} and UpdateNumber:{UpdateNumber}. BatchId:{batchId} and _X-Correlation-ID:{CorrelationId}", item.ProductName, item.EditionNumber, itemUpdateNumber, queueMessage.BatchId, queueMessage.CorrelationId); var downloadPath = Path.Combine(exchangeSetRootPath, item.ProductName.Substring(0, 2), item.ProductName, item.EditionNumber.Value.ToString(), itemUpdateNumber.Value.ToString()); return(logger.LogStartEndAndElapsedTimeAsync(EventIds.FileShareServiceDownloadENCFilesFromCacheStart, EventIds.FileShareServiceDownloadENCFilesFromCacheCompleted, "File share service download request from cache container for Product/CellName:{ProductName}, EditionNumber:{EditionNumber} and UpdateNumber:{UpdateNumber} with \n Href: [{FileUri}]. ESS BatchId:{batchId} and _X-Correlation-ID:{CorrelationId}", async() => { foreach (var fileItem in internalBatchDetail.Files?.Select(a => a.Links.Get.Href)) { var uriArray = fileItem.Split("/"); var fileName = uriArray[^ 1];
public async Task <List <Products> > GetNonCachedProductDataForFss(List <Products> products, SearchBatchResponse internalSearchBatchResponse, string exchangeSetRootPath, SalesCatalogueServiceResponseQueueMessage queueMessage, CancellationTokenSource cancellationTokenSource, CancellationToken cancellationToken) { var internalProductsNotFound = new List <Products>(); foreach (var item in products) { if (cancellationToken.IsCancellationRequested) { logger.LogError(EventIds.CancellationTokenEvent.ToEventId(), "Operation cancelled as IsCancellationRequested flag is true while searching ENC files from cache for Product/CellName:{ProductName}, EditionNumber:{EditionNumber} and UpdateNumbers:[{UpdateNumbers}]. BatchId:{batchId} and _X-Correlation-ID:{CorrelationId}", item.ProductName, item.EditionNumber, string.Join(",", item.UpdateNumbers.Select(a => a.Value.ToString())), queueMessage.BatchId, queueMessage.CorrelationId); throw new OperationCanceledException(); } var internalProductItemNotFound = new Products { Cancellation = item.Cancellation, Dates = item.Dates, EditionNumber = item.EditionNumber, FileSize = item.FileSize, ProductName = item.ProductName, UpdateNumbers = new List <int?>() }; List <int?> updateNumbers = new List <int?>(); foreach (var itemUpdateNumber in item.UpdateNumbers) { var compareProducts = $"{item.ProductName}|{item.EditionNumber.Value}|{itemUpdateNumber.Value}"; var productList = new List <string>(); if (!productList.Contains(compareProducts)) { var storageConnectionString = azureStorageService.GetStorageAccountConnectionString(fssCacheConfiguration.Value.CacheStorageAccountName, fssCacheConfiguration.Value.CacheStorageAccountKey); var cacheInfo = (FssSearchResponseCache)await azureTableStorageClient.RetrieveFromTableStorageAsync <FssSearchResponseCache>(item.ProductName, item.EditionNumber + "|" + itemUpdateNumber.Value, fssCacheConfiguration.Value.FssSearchCacheTableName, storageConnectionString); if (cacheInfo != null && !string.IsNullOrEmpty(cacheInfo.Response)) { var internalBatchDetail = await CheckIfCacheProductsExistsInBlob(exchangeSetRootPath, queueMessage, item, updateNumbers, itemUpdateNumber, storageConnectionString, cacheInfo); internalSearchBatchResponse.Entries.Add(internalBatchDetail); productList.Add(compareProducts); } else { internalProductItemNotFound.UpdateNumbers.Add(itemUpdateNumber); } } } if (internalProductItemNotFound.UpdateNumbers != null && internalProductItemNotFound.UpdateNumbers.Any()) { internalProductsNotFound.Add(internalProductItemNotFound); } } return(internalProductsNotFound); }
public async Task <bool> SendResponseToCallBackApi(bool errorStatus, string payloadJson, SalesCatalogueServiceResponseQueueMessage scsResponseQueueMessage) { await callBackClient.CallBackApi(HttpMethod.Post, payloadJson, scsResponseQueueMessage.CallbackUri); if (!errorStatus) { logger.LogInformation(EventIds.ExchangeSetCreatedPostCallbackUriCalled.ToEventId(), "Post Callback uri is called after exchange set is created for BatchId:{BatchId} and _X-Correlation-ID:{CorrelationId}", scsResponseQueueMessage.BatchId, scsResponseQueueMessage.CorrelationId); } else { logger.LogInformation(EventIds.ExchangeSetCreatedWithErrorPostCallbackUriCalled.ToEventId(), "Post Callback uri is called after exchange set is created with error for BatchId:{BatchId} and _X-Correlation-ID:{CorrelationId}", scsResponseQueueMessage.BatchId, scsResponseQueueMessage.CorrelationId); } return(true); }
public async Task <bool> SendCallBackResponse(SalesCatalogueProductResponse salesCatalogueProductResponse, SalesCatalogueServiceResponseQueueMessage scsResponseQueueMessage) { if (!string.IsNullOrWhiteSpace(scsResponseQueueMessage.CallbackUri)) { try { ExchangeSetResponse exchangeSetResponse = SetExchangeSetResponse(salesCatalogueProductResponse, scsResponseQueueMessage); CallBackResponse callBackResponse = SetCallBackResponse(exchangeSetResponse); callBackResponse.Subject = essCallBackConfiguration.Value.Subject; if (ValidateCallbackRequestPayload(callBackResponse)) { string payloadJson = JsonConvert.SerializeObject(callBackResponse); return(await SendResponseToCallBackApi(false, payloadJson, scsResponseQueueMessage)); } else { logger.LogError(EventIds.ExchangeSetCreatedPostCallbackUriNotCalled.ToEventId(), "Post Callback uri is not called after exchange set is created for BatchId:{BatchId} and _X-Correlation-ID:{CorrelationId} as payload data is incorrect.", scsResponseQueueMessage.BatchId, scsResponseQueueMessage.CorrelationId); return(false); } } catch (Exception ex) { logger.LogError(EventIds.ExchangeSetCreatedPostCallbackUriNotCalled.ToEventId(), ex, "Post Callback uri is not called after exchange set is created for BatchId:{BatchId} and _X-Correlation-ID:{CorrelationId} and Exception:{Message}", scsResponseQueueMessage.BatchId, scsResponseQueueMessage.CorrelationId, ex.Message); return(false); } } else { logger.LogInformation(EventIds.ExchangeSetCreatedPostCallbackUriNotProvided.ToEventId(), "Post callback uri was not provided by requestor for successful exchange set creation for BatchId:{BatchId} and _X-Correlation-ID:{CorrelationId}", scsResponseQueueMessage.BatchId, scsResponseQueueMessage.CorrelationId); return(false); } }