예제 #1
0
        internal MeridianResult ProcessElectroluxDocument(OperationContext currentOperationContext)
        {
            _meridianResult            = new MeridianResult();
            _meridianResult.IsSchedule = false;
            _meridianResult.Status     = MeridianGlobalConstants.MESSAGE_ACKNOWLEDGEMENT_SUCCESS;
            XCBL_User xCblServiceUser = new XCBL_User();

            if (CommonProcess.IsAuthenticatedRequest(currentOperationContext, ref xCblServiceUser))
            {
                MeridianSystemLibrary.LogTransaction(xCblServiceUser.WebUsername, xCblServiceUser.FtpUsername, "Electrolux:IsAuthenticatedRequest", "03.01", "Success - Authenticated request", "Electrolux Process", "No FileName", "No Electrolux ID", "No Order Number", null, "Success");

                var         requestContext = currentOperationContext.RequestContext;
                var         requestMessage = requestContext.RequestMessage.ToString();        //.ReplaceSpecialCharsWithSpace();
                XmlDocument xmlDoc         = new XmlDocument();
                xmlDoc.LoadXml(requestMessage);

                MeridianSystemLibrary.LogTransaction(xCblServiceUser.WebUsername, xCblServiceUser.FtpUsername, "Electrolux:ElectroluxRequest", "03.02", "Electrolux request logging", "Electrolux Process", "No FileName", "No Electrolux ID", "No Order Number", xmlDoc, "Success");

                XmlNodeList requisitionNode_xml = xmlDoc.GetElementsByTagName("fxEnvelope");                //Http Request creating this tag

                string outerXml             = requisitionNode_xml[0].OuterXml;
                string xmlwithouotNameSpace = RemoveAllNamespaces(outerXml);

                ElectroluxOrderDetails electroluxOrderDetails = null;
                XmlSerializer          serializer             = new XmlSerializer(typeof(ElectroluxOrderDetails));
                using (var stringReader = new StringReader(xmlwithouotNameSpace))
                {
                    electroluxOrderDetails = (ElectroluxOrderDetails)serializer.Deserialize(stringReader);
                }

                if (electroluxOrderDetails != null)
                {
                    if (Convert.ToBoolean(ConfigurationManager.AppSettings["EnableXCBLForElectroluxToSyncWithM4PL"]))
                    {
                        var         response = new List <OrderResponseResult>();
                        List <Task> tasks    = new List <Task>();

                        string ClientId   = ConfigurationManager.AppSettings["ClientId"];
                        string Password   = ConfigurationManager.AppSettings["Electrolux_xCBL_Password"];
                        string Username   = ConfigurationManager.AppSettings["Electrolux_xCBL_Username"];
                        string prodUrl    = ConfigurationManager.AppSettings["M4PLProdAPI"];
                        string devUrl     = ConfigurationManager.AppSettings["M4PLDevUrl"];
                        string scannerUrl = ConfigurationManager.AppSettings["M4PLScannerAPI"];

                        if (!string.IsNullOrEmpty(prodUrl))
                        {
                            tasks.Add(
                                Task.Factory.StartNew(() =>
                            {
                                try
                                {
                                    response = M4PL.M4PLService.CallM4PLAPI <List <OrderResponseResult> >(electroluxOrderDetails, "XCBL/Electrolux/OrderRequest", isElectrolux: true, baseUrl: ConfigurationManager.AppSettings["M4PLProdAPI"], clientId: ClientId, userName: Username, Password: Password);
                                }
                                catch { }
                            }));
                        }
                        if (!string.IsNullOrEmpty(devUrl))
                        {
                            tasks.Add(
                                Task.Factory.StartNew(() =>
                            {
                                try
                                {
                                    M4PL.M4PLService.CallM4PLAPI <List <OrderResponseResult> >(electroluxOrderDetails, "XCBL/Electrolux/OrderRequest", isElectrolux: true, baseUrl: ConfigurationManager.AppSettings["M4PLDevUrl"], clientId: ClientId, userName: Username, Password: Password);
                                }
                                catch { }
                            }));
                        }

                        if (!string.IsNullOrEmpty(scannerUrl))
                        {
                            tasks.Add(
                                Task.Factory.StartNew(() =>
                            {
                                try
                                {
                                    M4PL.M4PLService.CallM4PLAPI <List <OrderResponseResult> >(electroluxOrderDetails, "XCBL/Electrolux/OrderRequest", isElectrolux: true, baseUrl: ConfigurationManager.AppSettings["M4PLScannerAPI"], clientId: ClientId, userName: Username, Password: Password);
                                }
                                catch { }
                            }));
                        }
                        Task.WaitAll(tasks.ToArray());
                        if (response != null)
                        {
                            string      responseString = GetXMLFromObject(response);
                            XmlDocument responsexmlDoc = new XmlDocument();
                            responsexmlDoc.LoadXml(responseString);

                            MeridianSystemLibrary.LogTransaction(xCblServiceUser.WebUsername, xCblServiceUser.FtpUsername, "Electrolux:ElectroluxResponse", "03.03", "Electrolux response logging", "Electrolux Process", "No FileName", "No Electrolux ID", "No Order Number", responsexmlDoc, "Success");
                            _meridianResult.Status = MeridianGlobalConstants.MESSAGE_ACKNOWLEDGEMENT_SUCCESS;
                            if (response.Any() && response.Count > 0)
                            {
                                _meridianResult.ResultObject = response[0];
                            }
                        }
                    }
                }
                else
                {
                    _meridianResult.Status = MeridianGlobalConstants.MESSAGE_ACKNOWLEDGEMENT_FAILURE;
                }
            }
            else
            {
                _meridianResult.Status = MeridianGlobalConstants.MESSAGE_ACKNOWLEDGEMENT_FAILURE;
                MeridianSystemLibrary.LogTransaction("No WebUser", "No FTPUser", "IsAuthenticatedRequest", "03.04", "Error - New SOAP Request not authenticated", "UnAuthenticated Request", "No FileName", "No Requisition ID", "No Order Number", null, "Error 03.01 - Invalid Credentials");
            }
            return(_meridianResult);
        }