public static QuincusTranslatedAddressResponse GetTranslatedAddressResponse(IQuincusAddressTranslationRequest quincusAddressTranslationRequest) { string response = string.Empty; QuincusTranslatedAddressResponse quincusTranslatedAddressResponse = new QuincusTranslatedAddressResponse(); try { string content = GetRequestContextForAddress.GetAddressStringFromRequest(quincusAddressTranslationRequest.shipmentWorkFlowRequests); if (!string.IsNullOrWhiteSpace(content)) { var httpWebRequest = (HttpWebRequest)WebRequest.Create( quincusAddressTranslationRequest.endpoint); if (string.Equals(MapProxy.WebProxyEnable, true.ToString(), StringComparison.OrdinalIgnoreCase)) { WebProxy myProxy = new WebProxy(MapProxy.webProxyURI, false, null, new NetworkCredential(MapProxy.webProxyUsername, MapProxy.webProxyPassword)); httpWebRequest.Proxy = myProxy; } httpWebRequest.ContentType = "application/json"; httpWebRequest.Headers.Add("AUTHORIZATION", "JWT " + quincusAddressTranslationRequest.token); httpWebRequest.Method = "POST"; using (var streamWriter = new StreamWriter(httpWebRequest.GetRequestStream())) { var input = content; streamWriter.Write(input); streamWriter.Flush(); streamWriter.Close(); } var httpResponse = (HttpWebResponse)httpWebRequest.GetResponse(); using (var streamReader = new StreamReader(httpResponse.GetResponseStream())) { response = streamReader.ReadToEnd(); streamReader.Close(); } httpResponse.Close(); quincusTranslatedAddressResponse.ResponseData = JsonConvert.DeserializeObject <GetBatchResponseForAddressTranslation>(response); quincusTranslatedAddressResponse.Response = true; } else { } } catch (Exception exception) { quincusTranslatedAddressResponse.exception = exception; } return(quincusTranslatedAddressResponse); }
public static QuincusTranslatedAddressResponse GetTranslatedAddressResponse(IQuincusAddressTranslationRequest quincusAddressTranslationRequest, QuincusParams quincusParams) { string response = string.Empty; var input = string.Empty; QuincusTranslatedAddressResponse quincusTranslatedAddressResponse = new QuincusTranslatedAddressResponse(); quincusTranslatedAddressResponse.ResponseData = new List <GetBatchResponseForAddressTranslation>(); try { quincusTranslatedAddressResponse.RequestDataCount = quincusAddressTranslationRequest.shipmentWorkFlowRequests.Count; List <string> content = GetRequestContextForAddress.GetAddressStringFromRequest(quincusAddressTranslationRequest.shipmentWorkFlowRequests, quincusParams); quincusTranslatedAddressResponse.QuincusContentRequest = JsonConvert.SerializeObject(content); content.ForEach(requestdata => { var httpWebRequest = (HttpWebRequest)WebRequest.Create( quincusAddressTranslationRequest.endpoint); if (string.Equals(MapProxy.WebProxyEnable, true.ToString(), StringComparison.OrdinalIgnoreCase)) { WebProxy myProxy = new WebProxy(MapProxy.webProxyURI, false, null, new NetworkCredential(MapProxy.webProxyUsername, MapProxy.webProxyPassword)); httpWebRequest.Proxy = myProxy; } httpWebRequest.ContentType = "application/json"; httpWebRequest.Headers.Add("AUTHORIZATION", "JWT " + quincusAddressTranslationRequest.token); httpWebRequest.Method = "POST"; using (var streamWriter = new StreamWriter(httpWebRequest.GetRequestStream())) { input = requestdata; streamWriter.Write(input); streamWriter.Flush(); streamWriter.Close(); } var httpResponse = (HttpWebResponse)httpWebRequest.GetResponse(); using (var streamReader = new StreamReader(httpResponse.GetResponseStream())) { response = streamReader.ReadToEnd(); streamReader.Close(); } httpResponse.Close(); quincusTranslatedAddressResponse.ResponseData.Add(JsonConvert.DeserializeObject <GetBatchResponseForAddressTranslation>(response)); quincusTranslatedAddressResponse.Response = true; quincusTranslatedAddressResponse.ResponseData.ForEach(record => { record.addresses.ForEach(address => { address.rcV_CPY_TE = Convert.ToString( quincusAddressTranslationRequest.shipmentWorkFlowRequests .FirstOrDefault(_ => Convert.ToString(_.pkG_NR_TE) == address.id) .rcV_CPY_TE); }); }); Task.Run(() => AuditEventEntry.LogEntry(new DataObjects.LogData.LogDataModel() { dateTime = DateTime.Now, apiTypes = DataObjects.LogData.APITypes.QuincusAPI_Translation, apiType = Enum.GetName(typeof(UPS.DataObjects.LogData.APITypes), 4), LogInformation = new DataObjects.LogData.LogInformation() { LogResponse = response, LogRequest = JsonConvert.SerializeObject(quincusAddressTranslationRequest.shipmentWorkFlowRequests), LogException = null } })); }); } catch (Exception exception) { quincusTranslatedAddressResponse.exception = exception; Task.Run(() => AuditEventEntry.LogEntry(new DataObjects.LogData.LogDataModel() { dateTime = DateTime.Now, apiTypes = DataObjects.LogData.APITypes.QuincusAPI_Translation, apiType = Enum.GetName(typeof(UPS.DataObjects.LogData.APITypes), 4), LogInformation = new DataObjects.LogData.LogInformation() { LogResponse = null, LogRequest = JsonConvert.SerializeObject(quincusAddressTranslationRequest.shipmentWorkFlowRequests), LogException = exception.InnerException.ToString() } })); } return(quincusTranslatedAddressResponse); }