Beispiel #1
0
        public void OrderChange(ChangeOrderRequest changeOrderRequest, Vendor administrativeVendor, List <OrderLine> orderLines)
        {
            StringBuilder     requestString = new StringBuilder();
            XmlWriterSettings settings      = new XmlWriterSettings();

            settings.Encoding = Encoding.UTF8;
            using (XmlWriter xw = XmlWriter.Create(requestString, settings))
            {
                xw.WriteProcessingInstruction("xml", "version=\"1.0\" encoding=\"utf-8\"");
                XmlSerializer           serializer = new XmlSerializer(typeof(ChangeOrderRequest));
                XmlSerializerNamespaces nm         = new XmlSerializerNamespaces();
                nm.Add("xsi", "http://www.w3.org/2001/XMLSchema-instance");
                serializer.Serialize(xw, changeOrderRequest, nm);

                XmlDocument document = new XmlDocument();
                document.LoadXml(requestString.ToString());
                HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(administrativeVendor.VendorSettings.GetValueByKey("EDIUrl", string.Empty));
                request.Method = "POST";

                HttpPurchasePostState state = new HttpPurchasePostState(orderLines, administrativeVendor, request, "OrderChange");

                byte[] byteData = UTF8Encoding.UTF8.GetBytes(document.OuterXml);
                using (Stream s = request.GetRequestStream())
                {
                    s.Write(byteData, 0, byteData.Length);
                }

                IAsyncResult result = request.BeginGetResponse(HttpCallBack, state);
                result.AsyncWaitHandle.WaitOne();
            }
        }
Beispiel #2
0
        public static void HttpCallBack(IAsyncResult result)
        {
            try
            {
                HttpPurchasePostState state = (HttpPurchasePostState)result.AsyncState;

                using (HttpWebResponse httpResponse = (HttpWebResponse)state.Request.EndGetResponse(result))
                {
                    switch (httpResponse.StatusCode)
                    {
                    case HttpStatusCode.OK:
                        //POST OK
                        foreach (var line in state.OrderLines)
                        {
                            line.Response += string.Format(",{0} {1} status OK: {2}", state.Type, state.Vendor.Name, httpResponse.StatusDescription);
                        }
                        break;

                    default:
                        foreach (var line in state.OrderLines)
                        {
                            line.Response += string.Format(",{0} {1} failed: {2}", state.Type, state.Vendor.Name, httpResponse.StatusDescription);
                        }
                        throw new Exception("Error in order response");
                    }
                }
            }
            catch (Exception)
            {
                throw new Exception("Callback failed");
            }
        }
Beispiel #3
0
        public bool PurchaseOrders(Concentrator.Objects.Models.Orders.Order order, List <Concentrator.Objects.Models.Orders.OrderLine> orderLines, Vendor administrativeVendor, Vendor vendor, bool directShipment, IUnitOfWork unit, ILog logger)
    #region IPurchase Members
        {
            try
            {
                if (directShipment)
                {
                    var directShipmentOrder = new BasOrderExporter().GetDirectShipmentOrder(order, orderLines, administrativeVendor, vendor);

                    StringBuilder     requestString = new StringBuilder();
                    XmlWriterSettings settings      = new XmlWriterSettings();
                    settings.Encoding = Encoding.UTF8;
                    using (XmlWriter xw = XmlWriter.Create(requestString, settings))
                    {
                        xw.WriteProcessingInstruction("xml", "version=\"1.0\" encoding=\"utf-8\"");
                        XmlSerializer           serializer = new XmlSerializer(typeof(DirectShipmentRequest));
                        XmlSerializerNamespaces nm         = new XmlSerializerNamespaces();
                        nm.Add("xsi", "http://www.w3.org/2001/XMLSchema-instance");
                        serializer.Serialize(xw, directShipmentOrder, nm);

                        XmlDocument document = new XmlDocument();
                        document.LoadXml(requestString.ToString());
                        HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(administrativeVendor.VendorSettings.GetValueByKey("EDIUrl", string.Empty));
                        request.Method = "POST";

                        HttpPurchasePostState state = new HttpPurchasePostState(orderLines, administrativeVendor, request, "DirectShipmentPost");

                        byte[] byteData = UTF8Encoding.UTF8.GetBytes(document.OuterXml);
                        using (Stream s = request.GetRequestStream())
                        {
                            s.Write(byteData, 0, byteData.Length);
                        }

                        IAsyncResult result = request.BeginGetResponse(HttpCallBack, state);
                        result.AsyncWaitHandle.WaitOne();
                    }
                    return(true);
                }
                else
                {
                    var purchaseOrder = new BasOrderExporter().GetDirectShipmentOrder(order, orderLines, administrativeVendor, vendor);

                    StringBuilder     requestString = new StringBuilder();
                    XmlWriterSettings settings      = new XmlWriterSettings();
                    settings.Encoding = Encoding.UTF8;
                    using (XmlWriter xw = XmlWriter.Create(requestString, settings))
                    {
                        xw.WriteProcessingInstruction("xml", "version=\"1.0\" encoding=\"utf-8\"");
                        XmlSerializer           serializer = new XmlSerializer(typeof(PurchaseRequest));
                        XmlSerializerNamespaces nm         = new XmlSerializerNamespaces();
                        nm.Add("xsi", "http://www.w3.org/2001/XMLSchema-instance");
                        serializer.Serialize(xw, purchaseOrder, nm);

                        XmlDocument document = new XmlDocument();
                        document.LoadXml(requestString.ToString());
                        HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(administrativeVendor.VendorSettings.GetValueByKey("EDIUrl", string.Empty));
                        request.Method = "POST";

                        HttpPurchasePostState state = new HttpPurchasePostState(orderLines, administrativeVendor, request, "PurchasePost");

                        byte[] byteData = UTF8Encoding.UTF8.GetBytes(document.OuterXml);
                        using (Stream s = request.GetRequestStream())
                        {
                            s.Write(byteData, 0, byteData.Length);
                        }

                        IAsyncResult result = request.BeginGetResponse(HttpCallBack, state);
                        result.AsyncWaitHandle.WaitOne();
                    }
                    return(true);
                }
            }
            catch (Exception e)
            {
                throw new Exception("Bas dispatching failed", e);
            }
        }