public static XCBL_User sysGetAuthenticationByUsernameAndPassword(string webUsername, string webPassword) { // If either the username or password are empty then return null for the method if (string.IsNullOrEmpty(webUsername) || string.IsNullOrEmpty(webPassword)) { return(null); } // Try to retrieve the authentication record based on the specified username and password try { DataSet dsRecords = new DataSet(); using (SqlConnection sqlConnection = new SqlConnection(MeridianGlobalConstants.XCBL_DATABASE_SERVER_URL)) { sqlConnection.Open(); using (SqlCommand sqlCommand = new SqlCommand("XCBL_SP_GetXcblAuthenticationUser", sqlConnection)) { sqlCommand.CommandType = CommandType.StoredProcedure; sqlCommand.Parameters.Add("@webUsername", SqlDbType.NVarChar).Value = webUsername; sqlCommand.Parameters.Add("@webPassword", SqlDbType.NVarChar).Value = webPassword; // Fill the data adapter with the sql query results using (SqlDataAdapter sdaAdapter = new SqlDataAdapter(sqlCommand)) { sdaAdapter.Fill(dsRecords); } } } // Parse the authentication record to a XCBL_User class object XCBL_User user = new XCBL_User() { WebUsername = dsRecords.Tables[0].Rows[0]["CALLER"].ToString(), WebPassword = dsRecords.Tables[0].Rows[0]["Password"].ToString(), }; return(user); } catch (Exception ex) { // If there was an error encountered in retrieving the authentication record then try to insert a record in MER010TransactionLog table to record the issue try { // LogTransaction(webUsername, "", "sysGetAuthenticationByUsername", "00.00", "Warning - Cannot retrieve record from MER000Authentication table", ex.InnerException.ToString(), "", "", "", new XmlDocument(), "Warning 26 - DB Connection"); } catch { } return(null); } }
public static ProcessData GetNewProcessData(this XCBL_User xCblServiceUser) { var processData = new ProcessData { ScheduleID = "No Schedule Id", RequisitionID = "No Requisition Id", ScheduleResponseID = "No Schedule Response Id", OrderNumber = "No Order Number", CsvFileName = "No FileName", XmlFileName = "No FileName", ShippingSchedule = new ShippingSchedule(), // Requisition = new Requisition(), ShippingScheduleResponse = new ShippingScheduleResponse() //WebUserName = xCblServiceUser.WebUsername, //FtpUserName = xCblServiceUser.FtpUsername }; return(processData); }
/// <summary> /// Method to pass xCBL XML data to the web serivce /// </summary> /// <param name="currentOperationContext">Operation context inside this XmlElement the xCBL XML data to parse</param> /// <returns>XElement - XML Message Acknowledgement response indicating Success or Failure</returns> internal MeridianResult ProcessShippingScheduleResponseRequest(OperationContext currentOperationContext) { _meridianResult = new MeridianResult(); _meridianResult.Status = MeridianGlobalConstants.MESSAGE_ACKNOWLEDGEMENT_SUCCESS; XCBL_User xCblServiceUser = new XCBL_User(); //MeridianSystemLibrary.LogTransaction("No WebUser", "No FTPUser", "ProcessShippingScheduleResponseDocument", "01.01", "Success - New SOAP Request Received", "Shipping Schedule Response Process", "No FileName", "No Schedule ID", "No Order Number", null, "Success"); if (CommonProcess.IsAuthenticatedRequest(currentOperationContext, ref xCblServiceUser)) { //MeridianSystemLibrary.LogTransaction(xCblServiceUser.WebUsername, xCblServiceUser.FtpUsername, "IsAuthenticatedRequest", "01.02", "Success - Authenticated request", "Shipping Schedule Response Process", "No FileName", "No Schedule ID", "No Order Number", null, "Success"); ProcessData processData = ProcessRequestAndCreateFiles(currentOperationContext, xCblServiceUser); if (processData == null || string.IsNullOrEmpty(processData.ScheduleResponseID) || string.IsNullOrEmpty(processData.OrderNumber)) { _meridianResult.Status = MeridianGlobalConstants.MESSAGE_ACKNOWLEDGEMENT_FAILURE; } else { processData.FtpUserName = xCblServiceUser.FtpUsername; processData.FtpPassword = xCblServiceUser.FtpPassword; processData.FtpServerInFolderPath = xCblServiceUser.FtpServerInFolderPath; processData.FtpServerOutFolderPath = xCblServiceUser.FtpServerOutFolderPath; processData.LocalFilePath = xCblServiceUser.LocalFilePath; _meridianResult.WebUserName = xCblServiceUser.WebUsername; _meridianResult.WebPassword = xCblServiceUser.WebPassword; _meridianResult.WebHashKey = xCblServiceUser.Hashkey; if (!CreateLocalCsvFile(processData)) { _meridianResult.Status = MeridianGlobalConstants.MESSAGE_ACKNOWLEDGEMENT_FAILURE; } _meridianResult.UniqueID = processData.ScheduleResponseID; return(_meridianResult); } } else { _meridianResult.Status = MeridianGlobalConstants.MESSAGE_ACKNOWLEDGEMENT_FAILURE; //MeridianSystemLibrary.LogTransaction("No WebUser", "No FTPUser", "IsAuthenticatedRequest", "03.01", "Error - New SOAP Request not authenticated", "UnAuthenticated Request", "No FileName", "No Schedule ID", "No Order Number", null, "Error 03.01 - Incorrect Credential"); } return(_meridianResult); }
internal MeridianResult ProcessDocument(OperationContext currentOperationContext) { _meridianResult = new MeridianResult(); _meridianResult.Status = MeridianGlobalConstants.MESSAGE_ACKNOWLEDGEMENT_SUCCESS; XCBL_User xCblServiceUser = new XCBL_User(); ProcessData processDatatest = ProcessRequestAndCreateFiles(currentOperationContext, xCblServiceUser); if (processDatatest != null) { WriteScheduleShippingXmlDocument(currentOperationContext.RequestContext); } if (CommonProcess.IsAuthenticatedRequest(currentOperationContext, ref xCblServiceUser)) { ApplicationError.WriteMessage("AuthenticatedRequest Sucess - New SOAP Request authenticated."); ProcessData processData = ProcessRequestAndCreateFiles(currentOperationContext, xCblServiceUser); if (processData == null || string.IsNullOrEmpty(processData.ScheduleID) || string.IsNullOrEmpty(processData.OrderNumber)) { _meridianResult.Status = MeridianGlobalConstants.MESSAGE_ACKNOWLEDGEMENT_FAILURE; } else { if (!UpdateToServer(processData)) { // ApplicationError.WriteMessage("NOT FOUND Order Ref Number For Process Is " + processData.ShippingSchedule.OrderNumber); _meridianResult.Status = MeridianGlobalConstants.MESSAGE_ACKNOWLEDGEMENT_FAILURE; } _meridianResult.UniqueID = processData.ScheduleID; return(_meridianResult); } } else { _meridianResult.Status = MeridianGlobalConstants.MESSAGE_ACKNOWLEDGEMENT_FAILURE; ApplicationError.WriteMessage("Error - New SOAP Request not authenticated. UnAuthenticated Request"); } return(_meridianResult); }
/// <summary> /// To Process request and create csv and xml files. /// </summary> /// <param name="operationContext">Current OperationContext</param> /// <returns></returns> private ProcessData ProcessRequestAndCreateFiles(OperationContext operationContext, XCBL_User xCblServiceUser) { try { ProcessData processData = ValidateScheduleShippingResponseXmlDocument(operationContext.RequestContext, xCblServiceUser); if (processData != null && !string.IsNullOrEmpty(processData.ScheduleResponseID) && !string.IsNullOrEmpty(processData.OrderNumber) && !string.IsNullOrEmpty(processData.CsvFileName)) { //MeridianSystemLibrary.LogTransaction(xCblServiceUser.WebUsername, xCblServiceUser.FtpUsername, "ProcessRequestAndCreateFiles", "01.03", string.Format("Success - Parsed requested xml for CSV file {0}", processData.ScheduleResponseID), "Shipping Schedule Response Process", processData.CsvFileName, processData.ScheduleResponseID, processData.OrderNumber, processData.XmlDocument, "Success"); return(processData); } } catch (Exception ex) { // MeridianSystemLibrary.LogTransaction(xCblServiceUser.WebUsername, xCblServiceUser.FtpUsername, "ValidateScheduleShippingXmlDocument", "03.02", "Error - Incorrect request ", string.Format("Exception - Invalid request xml {0}", ex.Message), "No file Name", "No Schedule Id", "No Order Number", null, "Error 03.02 - Invalid request xml"); } return(new ProcessData()); }
/// <summary> /// To Parse sent SOAP XML and make list of Process data /// </summary> /// <param name="requestContext"> Current OperationContext's RequestContext</param> /// <param name="xCblServiceUser">Service User</param> /// <returns>List of process data</returns> private ProcessData ValidateScheduleShippingResponseXmlDocument(RequestContext requestContext, XCBL_User xCblServiceUser) { var requestMessage = requestContext.RequestMessage.ToString().ReplaceSpecialCharsWithSpace(); XmlDocument xmlDoc = new XmlDocument(); xmlDoc.LoadXml(requestMessage); XmlNamespaceManager xmlNsManager = new XmlNamespaceManager(xmlDoc.NameTable); xmlNsManager.AddNamespace("default", "rrn:org.xcbl:schemas/xcbl/v4_0/materialsmanagement/v1_0/materialsmanagement.xsd"); xmlNsManager.AddNamespace("core", "rrn:org.xcbl:schemas/xcbl/v4_0/core/core.xsd"); XmlNodeList shippingElement = xmlDoc.GetElementsByTagName(MeridianGlobalConstants.XCBL_SHIPPING_SCHEDULE_RESPONSE_HEADER); //Find the Shipping schedule response tag and getting the Inner Xml of its Node XmlNodeList shippingScheduleResponseNode_xml = xmlDoc.GetElementsByTagName(MeridianGlobalConstants.XCBL_ShippingScheuleResponse_XML_Http);//Http Request creating this tag if (shippingScheduleResponseNode_xml.Count == 0) { shippingScheduleResponseNode_xml = xmlDoc.GetElementsByTagName(MeridianGlobalConstants.XCBL_ShippingScheuleResponse_XML_Https);//Https Request creating this tag } if (shippingElement != null) { // There should only be one element in the Shipping Schedule request, but this should handle multiple ones foreach (XmlNode element in shippingElement) { var processData = xCblServiceUser.GetNewProcessData(); processData.XmlDocument = xmlDoc; _meridianResult.XmlDocument = xmlDoc; var scheduleResponseId = element.GetNodeByNameAndLogErrorTrans(xmlNsManager, MeridianGlobalConstants.XCBL_SCHEDULE_RESPONSE_ID, "10", processData, processData.ScheduleResponseID); var scheduleResponseIssuedDate = element.GetNodeByNameAndInnerTextLogWarningTrans(xmlNsManager, MeridianGlobalConstants.XCBL_SCHEDULE_RESPONSE_ISSUE_DATE, "21", processData, processData.ScheduleResponseID); var scheduleResponseReference = element.GetNodeByNameAndInnerTextLogWarningTrans(xmlNsManager, MeridianGlobalConstants.XCBL_SCHEDULE_RESPONSE_REFERENCE, "22", processData, processData.ScheduleResponseID); var scheduleResponsePurposeCoded = element.GetNodeByNameAndInnerTextLogWarningTrans(xmlNsManager, MeridianGlobalConstants.XCBL_SCHEDULE_RESPONSE_PURPOSE_CODED, "03", processData, processData.ScheduleResponseID); var scheduleResponseResponseTypeCoded = element.GetNodeByNameAndInnerTextLogWarningTrans(xmlNsManager, MeridianGlobalConstants.XCBL_SCHEDULE_RESPONSE_RESPONSE_TYPE_CODED, "23", processData, processData.ScheduleResponseID); if (scheduleResponseId != null && !string.IsNullOrEmpty(scheduleResponseId.InnerText)) { processData.ScheduleResponseID = scheduleResponseId.InnerText.ReplaceSpecialCharsWithSpace(); processData.ShippingScheduleResponse.ScheduleResponseID = processData.ScheduleResponseID; if (scheduleResponseIssuedDate != null && !string.IsNullOrEmpty(scheduleResponseIssuedDate.InnerText)) { processData.ShippingScheduleResponse.ScheduleResponseIssueDate = scheduleResponseIssuedDate.InnerText.ReplaceSpecialCharsWithSpace(); } if (scheduleResponseReference != null && !string.IsNullOrEmpty(scheduleResponseReference.InnerText)) { processData.OrderNumber = scheduleResponseReference.InnerText.ReplaceSpecialCharsWithSpace(); processData.ShippingScheduleResponse.ScheduleResponseOrderNumber = processData.OrderNumber; string formattedOrderNumber = processData.OrderNumber.ReplaceSpecialCharsWithSpace().Replace(" ", ""); string fileNameFormat = DateTime.Now.ToString(MeridianGlobalConstants.XCBL_FILE_DATETIME_FORMAT); processData.CsvFileName = string.Concat(MeridianGlobalConstants.XCBL_AWC_FILE_PREFIX, fileNameFormat, formattedOrderNumber, MeridianGlobalConstants.XCBL_FILE_EXTENSION); processData.XmlFileName = string.Concat(MeridianGlobalConstants.XCBL_AWC_FILE_PREFIX, fileNameFormat, formattedOrderNumber, MeridianGlobalConstants.XCBL_XML_EXTENSION); } //else // MeridianSystemLibrary.LogTransaction(processData.WebUserName, processData.FtpUserName, "ValidateScheduleShippingResponseXmlDocument", "03.11", "Error - Schedule Response References XML tag missing or incorrect to get order number", "Exception - Response order number", processData.CsvFileName, processData.ScheduleResponseID, "No Order Number", processData.XmlDocument, "Error 03.14 - Seller OrderNumber not found"); if (scheduleResponsePurposeCoded != null && !string.IsNullOrEmpty(scheduleResponsePurposeCoded.InnerText)) { processData.ShippingScheduleResponse.ScheduleResponsePurposeCoded = scheduleResponsePurposeCoded.InnerText.ReplaceSpecialCharsWithSpace(); } if (scheduleResponseResponseTypeCoded != null && !string.IsNullOrEmpty(scheduleResponseResponseTypeCoded.InnerText)) { processData.ShippingScheduleResponse.ScheduleResponseTypeCoded = scheduleResponseResponseTypeCoded.InnerText.ReplaceSpecialCharsWithSpace(); } if (string.IsNullOrWhiteSpace(processData.ShippingScheduleResponse.ScheduleResponseID) || string.IsNullOrWhiteSpace(processData.ShippingScheduleResponse.ScheduleResponseOrderNumber)) { break; } var scheduleId = element.GetNodeByNameAndLogErrorTrans(xmlNsManager, MeridianGlobalConstants.XCBL_SCHEDULE_ID, "03", processData, processData.ScheduleResponseID); var scheduleIssuedDate = element.GetNodeByNameAndInnerTextLogWarningTrans(xmlNsManager, MeridianGlobalConstants.XCBL_SCHEDULE_ISSUED_DATE, "01", processData, processData.ScheduleResponseID); //Schedule Header Information --start if (scheduleId != null && !string.IsNullOrEmpty(scheduleId.InnerText)) { processData.ShippingScheduleResponse.ScheduleID = scheduleId.InnerText.ReplaceSpecialCharsWithSpace(); if (scheduleIssuedDate != null && !string.IsNullOrEmpty(scheduleIssuedDate.InnerText)) { processData.ShippingScheduleResponse.ScheduleIssuedDate = scheduleIssuedDate.InnerText.ReplaceSpecialCharsWithSpace(); } XmlNode xnScheduleReferences = element.GetNodeByNameAndLogWarningTrans(xmlNsManager, MeridianGlobalConstants.XCBL_SCHEDULE_REFERENCES, "02", processData, processData.ScheduleResponseID); if (xnScheduleReferences != null) { GetPurchaseOrderReference(xmlNsManager, xnScheduleReferences, processData); } //else if (string.IsNullOrEmpty(processData.ShippingScheduleResponse.OrderNumber)) // MeridianSystemLibrary.LogTransaction(processData.WebUserName, processData.FtpUserName, "ValidateScheduleShippingResponseXmlDocument", "03.04", "Error - Schedule References XML tag missing or incorrect to get seller order number", "Exception - Seller order number", processData.CsvFileName, processData.ScheduleResponseID, "No Order Number", processData.XmlDocument, "Error 03.04 - Seller OrderNumber not found"); if (string.IsNullOrEmpty(processData.ShippingScheduleResponse.ScheduleID) || string.IsNullOrEmpty(processData.ShippingScheduleResponse.OrderNumber)) { break; } else { GetOtherScheduleReferences(xmlNsManager, xnScheduleReferences, processData); GetPurposeScheduleTypeCodeAndParty(xmlNsManager, element, processData); GetListOfContactNumber(xmlNsManager, element, processData); GetListOfTransportRouting(xmlNsManager, element, processData); return(processData); } } } } } //else // MeridianSystemLibrary.LogTransaction(xCblServiceUser.WebUsername, xCblServiceUser.FtpUsername, "ValidateScheduleShippingResponseXmlDocument", "03.02", "Error - Shipping Schedule Response Header XML tag missing or incorrect", "Exception - Invalid request xml", "No file Name", "No Schedule Id", "No Order Number", xmlDoc, "Error 03.02 - Invalid request xml"); return(new ProcessData()); }
/// <summary> /// To authenticate request whether it has valid credential to proceed /// </summary> /// <param name="xCblServiceUser">Service User</param> /// <param name="operationContext">Current OperationContext</param> /// <returns></returns> internal static bool IsAuthenticatedRequest(OperationContext operationContext, ref XCBL_User xCblServiceUser) { try { // If a separate namespace is needed for the Credentials tag use the global const CREDENTIAL_NAMESPACE that is commented below int index = operationContext.IncomingMessageHeaders.FindHeader("Credentials", ""); // Retrieve the first soap headers, this should be the Credentials tag MessageHeaderInfo messageHeaderInfo = operationContext.IncomingMessageHeaders[index]; xCblServiceUser = Meridian_AuthenticateUser(operationContext.IncomingMessageHeaders, messageHeaderInfo, index); if (xCblServiceUser == null || string.IsNullOrEmpty(xCblServiceUser.WebUsername)) { ApplicationError.WriteMessage("UnAuthenticated Request Incorrect Credentials"); return(false); } return(true); } catch (Exception ex) { ApplicationError.logErrors(ex, "IsAuthenticatedRequest"); // MeridianSystemLibrary.LogTransaction("No WebUser", "No FTPUser", "IsAuthenticatedRequest", "03.01", "Error - New SOAP Request not authenticated", "UnAuthenticated Request", "No FileName", "No Schedule ID", "No Order Number", null, "Error 03.01 - Incorrect Credentials"); return(false); } }
private ProcessData ValidateScheduleShippingXmlDocument(RequestContext requestContext, XCBL_User xCblServiceUser) { ApplicationError.WriteMessage("ValidateScheduleShippingXmlDocument Starts"); var requestMessage = requestContext.RequestMessage.ToString().ReplaceSpecialCharsWithSpace(); XmlDocument xmlDoc = new XmlDocument(); xmlDoc.LoadXml(requestMessage); try { string path = Path.Combine(System.Configuration.ConfigurationManager.AppSettings["XmlPath"].ToString() + "\\" + DateTime.Now.ToString("yyyyMMdd HHss") + ".XML"); using (XmlTextWriter writer = new XmlTextWriter(path, null)) { writer.Formatting = Formatting.Indented; xmlDoc.Save(writer); } } catch (Exception ex) { ApplicationError.logErrors(ex); ApplicationError.logErrors(ex, "ValidateScheduleShippingXmlDocument"); } XmlNamespaceManager xmlNsManager = new XmlNamespaceManager(xmlDoc.NameTable); xmlNsManager.AddNamespace("default", "rrn:org.xcbl:schemas/xcbl/v4_0/materialsmanagement/v1_0/materialsmanagement.xsd"); xmlNsManager.AddNamespace("core", "rrn:org.xcbl:schemas/xcbl/v4_0/core/core.xsd"); XmlNodeList shippingElement = xmlDoc.GetElementsByTagName(MeridianGlobalConstants.XCBL_SHIPPING_SCHEDULE_HEADER); //Find the Shipping schedule tag and getting the Inner Xml of its Node XmlNodeList shippingScheduleNode_xml = xmlDoc.GetElementsByTagName(MeridianGlobalConstants.XCBL_ShippingScheule_XML_Http);//Http Request creating this tag if (shippingScheduleNode_xml.Count == 0) { shippingScheduleNode_xml = xmlDoc.GetElementsByTagName(MeridianGlobalConstants.XCBL_ShippingScheule_XML_Https);//Https Request creating this tag } if (shippingElement != null) { // There should only be one element in the Shipping Schedule request, but this should handle multiple ones ApplicationError.WriteMessage("Shipping Schedule Header XML tag are correct processing data"); foreach (XmlNode element in shippingElement) { var processData = xCblServiceUser.GetNewProcessData(); processData.XmlDocument = xmlDoc; _meridianResult.XmlDocument = xmlDoc; var scheduleId = element.GetNodeByNameAndLogErrorTrans(xmlNsManager, MeridianGlobalConstants.XCBL_SCHEDULE_ID, "03", processData, processData.ScheduleID); var scheduleIssuedDate = element.GetNodeByNameAndInnerTextLogWarningTrans(xmlNsManager, MeridianGlobalConstants.XCBL_SCHEDULE_ISSUED_DATE, "01", processData, processData.ScheduleID); //Schedule Header Information --start if (scheduleId != null && !string.IsNullOrEmpty(scheduleId.InnerText)) { processData.ScheduleID = scheduleId.InnerText.ReplaceSpecialCharsWithSpace(); processData.ShippingSchedule.ScheduleID = processData.ScheduleID; if (scheduleIssuedDate != null && !string.IsNullOrEmpty(scheduleIssuedDate.InnerText)) { processData.ShippingSchedule.ScheduleIssuedDate = scheduleIssuedDate.InnerText.ReplaceSpecialCharsWithSpace(); } XmlNode xnScheduleReferences = element.GetNodeByNameAndLogWarningTrans(xmlNsManager, MeridianGlobalConstants.XCBL_SCHEDULE_REFERENCES, "02", processData, processData.ScheduleID); if (xnScheduleReferences != null) { GetPurchaseOrderReference(xmlNsManager, xnScheduleReferences, processData); } else if (string.IsNullOrEmpty(processData.ShippingSchedule.OrderNumber)) { ApplicationError.WriteMessage("Error - Schedule References XML tag missing or incorrect to get seller order number No Order Number found"); } if (string.IsNullOrEmpty(processData.ShippingSchedule.ScheduleID) || string.IsNullOrEmpty(processData.ShippingSchedule.OrderNumber)) { break; } else { GetOtherScheduleReferences(xmlNsManager, xnScheduleReferences, processData); GetPurposeScheduleTypeCodeAndParty(xmlNsManager, element, processData); GetListOfContactNumber(xmlNsManager, element, processData); GetListOfTransportRouting(xmlNsManager, element, processData); return(processData); } } } } else { ApplicationError.WriteMessage("Shipping Schedule Header XML tag missing or incorrect Invalid request xml"); } return(new ProcessData()); }
private ProcessData ProcessRequestAndCreateFiles(OperationContext operationContext, XCBL_User xCblServiceUser) { try { ProcessData processData = ValidateScheduleShippingXmlDocument(operationContext.RequestContext, xCblServiceUser); if (processData != null && !string.IsNullOrEmpty(processData.ScheduleID) && !string.IsNullOrEmpty(processData.OrderNumber)) { if (UsePBSServiceDataAndUpdateFlags(processData)) { return(processData); } else { return(null); } } } catch (Exception ex) { ApplicationError.logErrors(ex); ApplicationError.logErrors(ex, "ProcessRequestAndCreateFiles"); } return(new ProcessData()); }