//Get Details from WCF service private static async Task <SystemPriceModel> GetPriceFromConfigService(string orderCode) { SystemPriceModel priceModel; ProcessRequestRequest PRR = new ProcessRequestRequest(); PRR.request = new ConfigRequest(); PRR.request.ShipToCountry = LightweightProfileData.Country; PRR.request.CountryId = LightweightProfileData.Country; PRR.request.LanguageId = LightweightProfileData.Language; PRR.request.OrderCode = orderCode; PRR.request.CustomerSetId = LightweightProfileData.CustomerSet; ProcessRequestResponse response = await wcfClient.ProcessRequestAsync(PRR); priceModel = response?.ProcessRequestResult?.ConfigPrice; if (priceModel != null) { var systemPriceModel = new SystemPriceModel { RetailPrice = (double)priceModel.RetailPrice, SalePrice = (double)priceModel.SalePrice, TotalDiscount = (double)priceModel.TotalDiscount }; return(systemPriceModel); } return(null); }
private static decimal GetConfigData(string languageCode, string countryCode, string customerSet, string orderCode, int quantity) { try { var service = new ConfigServiceClient("ConfigService.V3.BasicHttpService"); ProcessRequestRequest input = new ProcessRequestRequest { request = new ConfigRequest { LanguageId = languageCode, CountryId = countryCode, CustomerSetId = customerSet, PostType = PostType.NoPost, ConfigRequestFlag = // IncludeItem - return ConfigItem ConfigRequestFlag._262144 // SkipLeadTime - GCM will recalculate for us | ConfigRequestFlag._8192 // SelectedOptionsOnly - Tells Config to skip extra processing (they always return only selected items) | ConfigRequestFlag._4, OrderCode = "CAI135NW10PH5008", //mocking ItemQuantity = quantity } }; var response = service.ProcessRequest(input); decimal price = response.ProcessRequestResult.ConfigItem.OriginalPrice; string str = string.Empty; return(price); } catch (Exception ex) { string str = string.Empty; } return(0); }
public async Task <string> GetOrderCodeDetails(string orderCode, string customerSet, string country, string language) { //_logger.LogInformation("Call to 'GetOrderCodeDetails'"); ConfigServiceClient sc = new ConfigServiceClient(ConfigServiceClient.EndpointConfiguration.BasicHttpService, _IConfigurationSection.GetSection("ServiceURL").Value); ProcessRequestRequest request = new ProcessRequestRequest { request = new ConfigRequest() }; request.request.OrderCode = orderCode; request.request.CustomerSetId = customerSet; request.request.LanguageId = language; request.request.CountryId = country; request.request.Version = 7.1; request.request.AllowChanges = false; //request.request.CartId = System.Guid.NewGuid(); request.request.CatalogId = 0; request.request.PostType = PostType.PartialPost; request.request.ResponseType = ResponseType.Default; request.request.RetrieveCorrectionMode = false; request.request.TrackSelectionUpdates = true; request.request.CfiOptionalModuleId = -2147483648; request.request.CfiRequiredModuleId = -2147483648; //TODO : generate KEY var jsonRequest = JsonConvert.SerializeObject(request); string hashKeyForRequest = HashGenerator.GenerateHashKey(jsonRequest.ToLower()); request.request.CartId = Guid.NewGuid(); //TODO : Write to CallLog // 1. check if already exists or in progress also check for ExpiryDate // 2. Decide if you need to call service or wait (sleep) var callLogRow = _context.CallLog .Where(b => b.Key == hashKeyForRequest) .FirstOrDefault(); if (callLogRow != null) { ProcessRequestResponse processRequestResponse = null; int responseSnapshoptDurationInMinutes = (DateTime.UtcNow - callLogRow.FinishTime).Minutes; int serviceRequestThresholdInSeconds = (DateTime.UtcNow - callLogRow.RequestStartTime).Seconds; if (responseSnapshoptDurationInMinutes >= Convert.ToInt16(_IConfigurationSection.GetSection("ResponseSnapshoptDurationInMinutes").Value)) { if (callLogRow.Status == CallLogStatus.InProgress.ToString() && serviceRequestThresholdInSeconds < Convert.ToInt16(_IConfigurationSection.GetSection("serviceRequestThresholdInSeconds").Value)) { //Open questions are there.. Thread.Sleep(5001); callLogRow = _context.CallLog .Where(b => b.Key == hashKeyForRequest) .FirstOrDefault(); if (callLogRow.Status == CallLogStatus.InProgress.ToString() && serviceRequestThresholdInSeconds < Convert.ToInt16(_IConfigurationSection.GetSection("serviceRequestThresholdInSeconds").Value)) { Thread.Sleep(5001); } } //var task = new[] //{ // Task.Factory.StartNew(() => { }), // Task.Factory.StartNew(() => { }) //}; //Task.WaitAll(task); //new Thread(delegate () //{ // _ICallLogRepository.UpdateCallLog(callLogRow, hashKeyForRequest, // CallLogStatus.InProgress); //}).Start(); _ICallLogRepository.UpdateCallLog(callLogRow, hashKeyForRequest, CallLogStatus.InProgress); try { processRequestResponse = await sc.ProcessRequestAsync(request); } catch (Exception ex) { _ICallLogRepository.DeleteCallLog(callLogRow, hashKeyForRequest); _IOrderCodeRepository.DeleteOrderCode(hashKeyForRequest); _logger.LogError(ex.StackTrace); return(Error.FromConfigService.ToString() + " | " + hashKeyForRequest + "_" + DateTime.UtcNow); } string jsonResponse = JsonConvert.SerializeObject(processRequestResponse); string compressedJsonResponse = Utility.CompressString(jsonResponse); //new Thread(delegate () //{ // _IOrderCodeRepository.UpdateOrderCode(compressedJsonResponse, hashKeyForRequest, // jsonRequest); //}).Start(); _IOrderCodeRepository.UpdateOrderCode(compressedJsonResponse, hashKeyForRequest, jsonRequest); _ICallLogRepository.UpdateCallLog(callLogRow, hashKeyForRequest, CallLogStatus.Completed); return(jsonResponse); } else { var orderCodeRow = _context.OrderCode .Where(b => b.Key == hashKeyForRequest) .FirstOrDefault(); string deCompressedJsonResponse = Utility.DecompressString(orderCodeRow.Response); return(deCompressedJsonResponse); } } else { ProcessRequestResponse processRequestResponse = null; _ICallLogRepository.CreateCallLog(hashKeyForRequest, CallLogStatus.InProgress); //TODO : if first call, make async call to Config Service try { processRequestResponse = await sc.ProcessRequestAsync(request); } catch (Exception ex) { // TODO: update call log _ICallLogRepository.DeleteCallLog(null, hashKeyForRequest); _logger.LogError(ex.StackTrace); return(Error.FromConfigService.ToString() + " | " + hashKeyForRequest + "_" + DateTime.UtcNow); } string jsonResponse = JsonConvert.SerializeObject(processRequestResponse); string compressedJsonResponse = Utility.CompressString(jsonResponse); // 1. Exception Handling (do not store in case of failure) // 2. Zip the output . // 3. Store output in DB (order code model repository) _IOrderCodeRepository.CreateOrderCode(compressedJsonResponse, hashKeyForRequest, jsonRequest); //TODO : UPdate call log with finish time and status. _ICallLogRepository.UpdateCallLog(null, hashKeyForRequest, CallLogStatus.Completed); //TODO : convert the output to required format and return return(jsonResponse); } }