public static XmlDocument GetProductsInfo(string dwProductsXml) { XmlDocument result = null; if (IsWebServiceConnectionAvailable()) { try { Logger.Instance.Log(ErrorLevel.DebugInfo, string.Format("Request GetProductsInfo sent: '{0}'.", dwProductsXml)); string erpProductsResponse = ErpServiceCaller.GetDataFromRequestString(Url, SecurityKey, dwProductsXml); _lastErpCommunication = DateTime.Now; if (!string.IsNullOrEmpty(erpProductsResponse)) { if (!Helpers.ParseResponseToXml(erpProductsResponse, out result)) { result = null; } Logger.Instance.Log(ErrorLevel.DebugInfo, string.Format("Response GetProductsInfo received: '{0}'.", erpProductsResponse)); } else { Logger.Instance.Log(ErrorLevel.ResponseError, "Response GetProductsInfo returned null."); } } catch (Exception ex) { _lastErpCommunication = null; Logger.Instance.Log(ErrorLevel.ConnectionError, string.Format("Error occurred while calling GetProductsInfo from Web Service: '{0}'.", ex.Message)); } } return(result); }
public override void RetrievePDF(HttpRequest request, HttpResponse response) { string id = request["id"]; string type = request["type"]; bool forceDownload = Converter.ToBoolean(request["forceDownload"]); string requestString = string.Format("<GetPDFForItem type=\"{0}\" id=\"{1}\"", type, id); var user = User.GetCurrentExtranetUser(); if (user?.ExternalID != null) { requestString += $" externalUserID=\"{user.ExternalID}\""; } requestString += "></GetPDFForItem>"; string base64EncodedPdf = ErpServiceCaller.GetDataFromRequestString(UrlHandler.Instance.GetWebServiceUrl(), SecurityKey, requestString); var inputStream = new MemoryStream(); var writer = new StreamWriter(inputStream); writer.Write(base64EncodedPdf); writer.Flush(); inputStream.Position = 0; response.ContentType = "application/pdf"; if (forceDownload) { string fileName = string.Format("IntegrationCustomerCenterItem{0}.pdf", id); string filePath = HttpContext.Current.Server.MapPath(string.Format("/{0}/System/Log/LiveIntegration/{1}", Dynamicweb.Content.Files.FilesAndFolders.GetFilesFolderName(), fileName)); using (Stream stream = File.OpenWrite(filePath)) { DecodeStream(inputStream, stream); } response.Clear(); response.AddHeader("content-disposition", string.Format("attachment;filename={0}", fileName)); response.WriteFile(filePath); response.Flush(); File.Delete(filePath); } else { DecodeStream(inputStream, response.OutputStream); response.OutputStream.Flush(); response.OutputStream.Close(); } }
public static XmlDocument RetrieveDataFromRequestString(string request, bool throwException = false) { XmlDocument result = null; if (IsWebServiceConnectionAvailable()) { try { Logger.Instance.Log(ErrorLevel.DebugInfo, string.Format("Request RetrieveDataFromRequestString sent: '{0}'.", request)); string response = ErpServiceCaller.GetDataFromRequestString(Url, SecurityKey, request); _lastErpCommunication = DateTime.Now; if (!string.IsNullOrEmpty(response)) { if (!Helpers.ParseResponseToXml(response, out result)) { result = null; } Logger.Instance.Log(ErrorLevel.DebugInfo, string.Format("Response GetProductsInfo received: '{0}'.", response)); } else { Logger.Instance.Log(ErrorLevel.ResponseError, "Response GetProductsInfo returned null."); } } catch (Exception ex) { _lastErpCommunication = null; Logger.Instance.Log(ErrorLevel.ConnectionError, string.Format("Error in RetrieveDataFromRequestString: '{0}'. Request: '{1}'.", ex.Message, request)); if (throwException) { throw; } } } return(result); }
public static XmlDocument CalculateOrder(string dwOrderXml, string orderId, bool createOrder) { XmlDocument result = null; if (IsWebServiceConnectionAvailable()) { try { Logger.Instance.Log(ErrorLevel.DebugInfo, string.Format("Request CalculateOrder sent. ID: {0}. CreateOrder: {1}. XML:\r\n{2}\r\n", orderId, createOrder, dwOrderXml)); string erpOrderXmlResponse = ErpServiceCaller.GetDataFromRequestString(Url, SecurityKey, dwOrderXml); _lastErpCommunication = DateTime.Now; if (!string.IsNullOrEmpty(erpOrderXmlResponse)) { if (!Helpers.ParseResponseToXml(erpOrderXmlResponse, out result)) { result = null; } Logger.Instance.Log(ErrorLevel.DebugInfo, string.Format("Response CalculateOrder received. ID: {0}. CreateOrder: {1}. XML:\r\n{2}\r\n", orderId, createOrder, erpOrderXmlResponse)); } else { Logger.Instance.Log(ErrorLevel.ResponseError, "Response CalculateOrder returned null."); } } catch (Exception ex) { _lastErpCommunication = null; var errorMessage = string.Format("An error occurred while calling CalculateOrder from Web Service: '{0}'.", ex); throw new LiveIntegrationException(errorMessage, ex); } } return(result); }
public static bool IsWebServiceConnectionAvailable() { if (_lastErpCommunication.HasValue && DateTime.Now.Subtract(_lastErpCommunication.Value).Minutes < 5) { return(_isWebServiceConnectionAvailable); } bool success = false; //check if the connection status was already checked if (HttpContext.Current.Items[Constants.WebServiceConnectionCacheKey] != null) { success = Converter.ToBoolean(HttpContext.Current.Items[Constants.WebServiceConnectionCacheKey]); } else { const string request = "<GetEcomData></GetEcomData>"; //simple request for checking connection try { ErpServiceCaller.GetDataFromRequestString(Url, SecurityKey, request); success = true; } catch (Exception ex) { Logger.Instance.Log(ErrorLevel.ConnectionError, string.Format("Error checking Web Service connection: '{0}'. Request: '{1}'.", ex.Message, request)); } //cache web service connection status to be available during one request HttpContext.Current.Items[Constants.WebServiceConnectionCacheKey] = success; } _isWebServiceConnectionAvailable = success; _lastErpCommunication = DateTime.Now; return(success); }