Exemplo n.º 1
0
        /// <summary>
        /// To Delete created file
        /// </summary>
        /// <param name="filePath">File Path</param>
        /// <param name="processData">Process Data</param>
        /// <returns></returns>
        internal static bool DeleteFile(string filePath, MeridianResult meridianResult = null)
        {
            bool result = false;

            if (meridianResult == null)
            {
                meridianResult = new MeridianResult();
            }
            try
            {
                if (File.Exists(filePath))
                {
                    string fileName = Path.GetFileName(filePath);
                    string ext      = Path.GetExtension(filePath);
                    File.Delete(filePath);
                    result = true;
                    MeridianSystemLibrary.LogTransaction(meridianResult.WebUserName, meridianResult.FtpUserName, "DeleteFile", "01.07", string.Format("Success - Deleted CSV file {0} after ftp upload: {0}", fileName), string.Format("Deleted CSV file: {0}", fileName), fileName, meridianResult.UniqueID, meridianResult.OrderNumber, null, "Success");
                }
                result = true;
            }
            catch (Exception ex)
            {
                MeridianSystemLibrary.LogTransaction(meridianResult.WebUserName, meridianResult.FtpUserName, "DeleteFile", "03.09", "Error - Delete CSV File", string.Format("Error - While deleting local CSV file: {0} with error {1}", meridianResult.FileName, ex.Message), meridianResult.FileName, meridianResult.UniqueID, meridianResult.OrderNumber, null, "Error 03.09 - Delete local CSV");
                result = false;
            }
            return(result);
        }
Exemplo n.º 2
0
        /// <summary>
        /// To send Shipping Schedule Response to AWC.
        /// </summary>
        /// <param name="filePath">File Path </param>
        /// <param name="content">Content want to write</param>
        /// <param name="processData">Process Data</param>
        /// <returns></returns>
        internal async static void SendShippingScheduleResponse1(MeridianResult meridianResult, string responseTypeCoded = null)
        {
            try
            {
                string shippingScheduleRequestId = null;

                responseTypeCoded = !string.IsNullOrWhiteSpace(responseTypeCoded) ? responseTypeCoded : (meridianResult.Approve01.Equals(MeridianGlobalConstants.XCBL_YES_FLAG) ||
                                                                                                         meridianResult.Approve02.Equals(MeridianGlobalConstants.XCBL_YES_FLAG) ||
                                                                                                         meridianResult.Approve03.Equals(MeridianGlobalConstants.XCBL_YES_FLAG) ||
                                                                                                         meridianResult.Approve04.Equals(MeridianGlobalConstants.XCBL_YES_FLAG) ||
                                                                                                         meridianResult.Approve05.Equals(MeridianGlobalConstants.XCBL_YES_FLAG)) ?
                                    MeridianGlobalConstants.XCBL_RESPONSE_TYPE_CODED_SHIPPING_SCHEDULE_RESPONSE_ACCEPTED :
                                    meridianResult.Rejected01.Equals(MeridianGlobalConstants.XCBL_YES_FLAG) ?
                                    MeridianGlobalConstants.XCBL_RESPONSE_TYPE_CODED_SHIPPING_SCHEDULE_RESPONSE_REJECTED :
                                    MeridianGlobalConstants.XCBL_RESPONSE_TYPE_CODED_SHIPPING_SCHEDULE_RESPONSE_PENDING;

                var purposeCoded = MeridianGlobalConstants.XCBL_PURPOSE_CODED_SHIPPING_SCHEDULE_RESPONSE;

                for (int i = 0; i < 3; i++)//Loop through 3 times if got response unsuccessful
                {
                    bool isSuccess = false;
                    /*Below code to send Shipping Schedule Request to AWC*/
                    using (var client = new WebClient())
                    {
                        var data        = CreateShippingScheduleResponse(meridianResult, responseTypeCoded, purposeCoded, ref shippingScheduleRequestId);
                        var requestData = Encoding.ASCII.GetBytes(data);
                        client.Headers.Add("Content-Type", "text/xml;charset=utf-8");
                        client.Headers.Add("SOAPAction", MeridianGlobalConstants.CONFIG_AWC_ACTION);
                        try
                        {
                            var responseData = await client.UploadDataTaskAsync(new Uri(MeridianGlobalConstants.CONFIG_AWC_ENDPOINT), requestData);

                            var response = Encoding.ASCII.GetString(responseData);
                            isSuccess = GetCurrentShippingScheduleRequestResponse(response, data, shippingScheduleRequestId, meridianResult.OrderNumber);
                        }
                        catch (Exception ex)
                        {
                            MeridianSystemLibrary.LogTransaction(meridianResult.WebUserName, meridianResult.FtpUserName, "SendShippingScheduleResponse", "06.07", "Error - Send ShippingScheduleResponse Request", string.Format("Error - While sending SSR Request: {0}", ex.Message), meridianResult.FileName, meridianResult.UniqueID, meridianResult.OrderNumber, meridianResult.XmlDocument, "Error 06.07 - Send AWC SSR Request");
                        }
                        finally
                        {
                            client.Dispose();
                        }
                    }
                    if (isSuccess)
                    {
                        break;
                    }
                }
            }
            catch (Exception ex)
            {
                MeridianSystemLibrary.LogTransaction(meridianResult.WebUserName, meridianResult.FtpUserName, "SendShippingScheduleResponse", "06.07", "Error - Send ShippingScheduleResponse Request", string.Format("Error - While sending SSR Request: {0}", ex.Message), meridianResult.FileName, meridianResult.UniqueID, meridianResult.OrderNumber, meridianResult.XmlDocument, "Error 06.07 - Send AWC SSR Request");
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// To upload file to FTP from MeridianResult.
        /// </summary>
        private async Task <bool> SendFileToFTP(MeridianResult meridianResult)
        {
            if ((meridianResult != null) && !string.IsNullOrWhiteSpace(meridianResult.FileName))
            {
                try
                {
                    FtpWebRequest ftpRequest = (FtpWebRequest)FtpWebRequest.Create(meridianResult.FtpServerInFolderPath + meridianResult.FileName);
                    ftpRequest.Credentials = new NetworkCredential(meridianResult.FtpUserName, meridianResult.FtpPassword);
                    ftpRequest.Method      = WebRequestMethods.Ftp.UploadFile;
                    ftpRequest.UseBinary   = true;
                    ftpRequest.KeepAlive   = false;
                    ftpRequest.Timeout     = Timeout.Infinite;

                    if (meridianResult.UploadFromLocalPath)
                    {
                        using (StreamReader sourceStream = new StreamReader(meridianResult.LocalFilePath + meridianResult.FileName))
                            meridianResult.Content = Encoding.UTF8.GetBytes(sourceStream.ReadToEnd());
                    }

                    using (Stream requestStream = await ftpRequest.GetRequestStreamAsync())
                    {
                        requestStream.Write(meridianResult.Content, 0, meridianResult.Content.Length);
                        requestStream.Flush();
                    }
                    using (FtpWebResponse response = (FtpWebResponse)ftpRequest.GetResponse())
                        if (response.StatusCode == FtpStatusCode.ClosingData)
                        {
                            var prefixToTake = meridianResult.IsSchedule ? MeridianGlobalConstants.XCBL_AWC_FILE_PREFIX : MeridianGlobalConstants.XCBL_AWC_REQUISITION_FILE_PREFIX;
                            MeridianSystemLibrary.LogTransaction(meridianResult.WebUserName, meridianResult.FtpUserName, (prefixToTake + "- Successfully completed request"), "01.06", string.Format("{0} - Successfully completed request for {1}", prefixToTake, meridianResult.UniqueID), string.Format("Uploaded CSV file: {0} on ftp server successfully for {1}", meridianResult.FileName, meridianResult.UniqueID), meridianResult.FileName, meridianResult.UniqueID, meridianResult.OrderNumber, meridianResult.XmlDocument, "Success");
                            if (meridianResult.IsSchedule && MeridianGlobalConstants.CONFIG_AWC_CALL_SSR_REQUEST.Equals(MeridianGlobalConstants.XCBL_YES_FLAG, StringComparison.OrdinalIgnoreCase))
                            {
                                CommonProcess.SendShippingScheduleResponse1(meridianResult);
                            }
                            return(true);
                        }
                        else
                        {
                            MeridianSystemLibrary.LogTransaction(meridianResult.WebUserName, meridianResult.FtpUserName, "UploadFileToFtp", "03.08", "Error - While CSV uploading file - Inside TRY block", string.Format("Error - While uploading CSV file: {0} with error - Inside TRY block - ", meridianResult.FileName), meridianResult.FileName, meridianResult.UniqueID, meridianResult.OrderNumber, null, "Error 03.08 - Upload CSV to PBS");
                            return(false);
                        }
                }
                catch (Exception ex)
                {
                    MeridianSystemLibrary.LogTransaction(meridianResult.WebUserName, meridianResult.FtpUserName, "UploadFileToFtp", "03.08", "Error - While CSV uploading file - Inside CATCH block", string.Format("Error - While uploading CSV file: {0} with error {1} - Inside CATCH block - ", meridianResult.FileName, ex.Message), meridianResult.FileName, meridianResult.UniqueID, meridianResult.OrderNumber, null, "Error 03.08 - Upload CSV to PBS");
                    return(false);
                }
            }
            return(false);
        }
Exemplo n.º 4
0
 /// <summary>
 /// To Create file if not exist and on catch safer side: if first call created file but on write got issue so deleting that file so that for next createfile call it creates again and close.
 /// </summary>
 /// <param name="filePath">File Path </param>
 /// <param name="content">Content want to write</param>
 /// <param name="processData">Process Data</param>
 /// <returns></returns>
 internal static bool CreateFile(string content, MeridianResult meridianResult)
 {
     try
     {
         var    filePath = meridianResult.LocalFilePath + meridianResult.FileName;
         string fileName = Path.GetFileName(filePath);
         string ext      = Path.GetExtension(filePath);
         DeleteFile(filePath, meridianResult);// Safer side
         File.Create(filePath).Close();
         File.WriteAllText(filePath, content);
         MeridianSystemLibrary.LogTransaction(meridianResult.WebUserName, meridianResult.FtpUserName, "CreateFile", "01.04", "Success - Created CSV File", "CSV File Created", meridianResult.FileName, meridianResult.UniqueID, meridianResult.OrderNumber, null, "Success");
         return(true);
     }
     catch (Exception ex)
     {
         MeridianSystemLibrary.LogTransaction(meridianResult.WebUserName, meridianResult.FtpUserName, "CreateFile", "03.12", "Error - Create CSV File", string.Format("Error - While creating local CSV file: {0} with error {1}", meridianResult.FileName, ex.Message), meridianResult.FileName, meridianResult.UniqueID, meridianResult.OrderNumber, null, "Error 03.12 - Create local CSV");
         return(false);
     }
 }
        /// <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);
        }
Exemplo n.º 6
0
        internal static bool SendShippingScheduleResponseRequestFromPBSFTP(XCBL_User currentUser, string fileName, string currentFileData)
        {
            bool shouldDeletePBSOutFile = false;

            try
            {
                List <PBSData> allPBSData = new List <PBSData>();

                var lines = currentFileData.Split(new[] { "\r\n", "\r", "\n" }, StringSplitOptions.None);
                if (lines.Count() > 0)
                {
                    for (int i = 1; i < lines.Length; i++)
                    {
                        if (!string.IsNullOrWhiteSpace(lines[i]))
                        {
                            var values = lines[i].Split(',');
                            if (values.Length > 4)
                            {
                                allPBSData.Add(new PBSData()
                                {
                                    ScheduleId  = values[0],
                                    OrderNumber = values[3],
                                    Status      = values[4],
                                    Comment     = (values.Length == 6) ? values[5] : null
                                });
                            }
                        }
                    }
                }

                if (allPBSData.Count > 0)
                {
                    foreach (var pbsData in allPBSData)
                    {
                        var currentShippingScheduleId = pbsData.ScheduleId ?? string.Empty;
                        var currentOrderNumber        = pbsData.OrderNumber ?? string.Empty;
                        var comment = pbsData.Comment ?? string.Empty;
                        pbsData.Status = pbsData.Status ?? string.Empty;

                        currentShippingScheduleId = currentShippingScheduleId.Replace("'", "");
                        currentOrderNumber        = currentOrderNumber.Replace("'", "");
                        comment        = comment.Replace("'", "");
                        pbsData.Status = pbsData.Status.Replace("'", "");

                        var responseTypeCoded = MeridianGlobalConstants.XCBL_RESPONSE_TYPE_CODED_SHIPPING_SCHEDULE_RESPONSE_ACCEPTED;
                        switch (pbsData.Status.Trim().ToUpper())
                        {
                        case "A":
                            responseTypeCoded = MeridianGlobalConstants.XCBL_RESPONSE_TYPE_CODED_SHIPPING_SCHEDULE_RESPONSE_ACCEPTED;
                            break;

                        case "R":
                            responseTypeCoded = MeridianGlobalConstants.XCBL_RESPONSE_TYPE_CODED_SHIPPING_SCHEDULE_RESPONSE_REJECTED;
                            break;

                        default:
                            responseTypeCoded = MeridianGlobalConstants.XCBL_RESPONSE_TYPE_CODED_SHIPPING_SCHEDULE_RESPONSE_REJECTED;
                            comment           = MeridianGlobalConstants.XCBL_COMMENT_RECEIVED_INVALID_CODE_FROM_PBS;
                            break;
                        }

                        if (!string.IsNullOrWhiteSpace(currentShippingScheduleId) && !string.IsNullOrWhiteSpace(currentOrderNumber) && !string.IsNullOrWhiteSpace(responseTypeCoded))
                        {
                            var currentStringifiedRequest = MeridianSystemLibrary.GetShippingScheduleRequest(currentUser.WebUsername, currentShippingScheduleId, currentOrderNumber);

                            if (!string.IsNullOrWhiteSpace(currentStringifiedRequest))
                            {
                                MeridianSystemLibrary.LogTransaction(currentUser.WebUsername, currentUser.FtpUsername, "SendShippingScheduleResponseRequestFromPBSFTP", "04.03", "Success - Saved PBS File", string.Format("Success - Saved PBS file : {0}", fileName), fileName, currentShippingScheduleId, currentOrderNumber, null, "Success", currentFileData);
                                shouldDeletePBSOutFile = true;

                                var savedShippingScheduleRequest = new XmlDocument();
                                savedShippingScheduleRequest.LoadXml(currentStringifiedRequest);

                                /*Below code commented so that later if client will come back on 'AcceptedWithAmendments' then we can use this*/
                                //if (responseTypeCoded.Trim().Equals(MeridianGlobalConstants.XCBL_RESPONSE_TYPE_CODED_ACCEPTED_WITH_AMENDMENTS, StringComparison.OrdinalIgnoreCase))
                                //    savedShippingScheduleRequest = UpdateShippingScheduleRequest(savedShippingScheduleRequest, values);

                                MeridianResult meridianResult = new MeridianResult();
                                meridianResult.XmlDocument = savedShippingScheduleRequest;
                                meridianResult.OrderNumber = currentOrderNumber;
                                meridianResult.UniqueID    = currentShippingScheduleId;
                                meridianResult.Comments    = comment;
                                meridianResult.WebUserName = currentUser.WebUsername;
                                meridianResult.WebPassword = currentUser.WebPassword;
                                meridianResult.WebHashKey  = currentUser.Hashkey;

                                SendShippingScheduleResponse(meridianResult, responseTypeCoded);
                            }
                            else
                            {
                                MeridianSystemLibrary.LogTransaction(currentUser.WebUsername, currentUser.FtpUsername, "SendShippingScheduleResponseRequestFromPBSFTP", "05.05", "Warning - No Request Found", string.Format("No Request found for '{0}' PBS FTP file and ShippingScheduleId is '{1}' and OrderNumber is '{2}'", fileName, currentShippingScheduleId, currentOrderNumber), fileName, string.Empty, string.Empty, null, "Warning");
                            }
                        }
                        else
                        {
                            MeridianSystemLibrary.LogTransaction(currentUser.WebUsername, currentUser.FtpUsername, "SendShippingScheduleResponseRequestFromPBSFTP", "05.06", "Warning - ShippingScheduleId/OrderNumber/ResponseType/PurposeCoded Empty", string.Format("ShippingScheduleId - {0} /OrderNumber - {1} / ResponseType - {2} Empty for '{3}' PBS FTP file", currentShippingScheduleId, currentOrderNumber, responseTypeCoded, fileName), fileName, string.Empty, string.Empty, null, "Warning");
                        }
                    }
                }
                else
                {
                    MeridianSystemLibrary.LogTransaction(currentUser.WebUsername, currentUser.FtpUsername, "SendShippingScheduleResponseRequestFromPBSFTP", "05.04", "Warning - Empty File", string.Format("Empty File - '{0}' in PBS FTP folder", fileName), fileName, string.Empty, string.Empty, null, "Warning");
                }
            }
            catch (Exception ex)
            {
                MeridianSystemLibrary.LogTransaction(currentUser.WebUsername, currentUser.FtpUsername, "SendShippingScheduleResponseRequestFromPBSFTP", "06.05", "Error - While Parsing PBS File", string.Format("Error - While Parsing PBS FTP File - Inside Catch Block : {0}", ex.Message), fileName, string.Empty, string.Empty, null, "Error 06.05 - PBS File Parsing");
            }
            return(shouldDeletePBSOutFile);
        }
Exemplo n.º 7
0
        internal static string CreateShippingScheduleResponse(MeridianResult meridianResult, string responseTypeCoded, string purposeCoded, ref string shipScheduleRespId)
        {
            try
            {
                var           shippingScheduleResponseGUID = shipScheduleRespId = Guid.NewGuid().ToString();
                StringBuilder request = new StringBuilder();

                var shippingScheduleHeader = meridianResult.XmlDocument.GetElementsByTagName(MeridianGlobalConstants.XCBL_SHIPPING_SCHEDULE_HEADER).Item(0);

                request.Append("<?xml version=\"1.0\" encoding=\"utf-8\"?>");
                request.Append("<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns=\"rrn:org.xcbl:schemas/xcbl/v4_0/materialsmanagement/v1_0/materialsmanagement.xsd\" xmlns:core=\"rrn:org.xcbl:schemas/xcbl/v4_0/core/core.xsd\">");
                request.Append("<soapenv:Header>");
                request.Append("<Credentials>");
                request.Append("<UserName>");
                request.Append(Encryption.Encrypt(meridianResult.WebUserName, meridianResult.WebHashKey));
                request.Append("</UserName>");
                request.Append("<Password>");
                request.Append(Encryption.Encrypt(meridianResult.WebPassword, meridianResult.WebHashKey));
                request.Append("</Password>");
                request.Append("<Hashkey>");
                request.Append(meridianResult.WebHashKey);
                request.Append("</Hashkey>");
                request.Append("</Credentials>");
                request.Append("</soapenv:Header>");
                request.Append("<soapenv:Body>");
                request.Append("<ShippingScheduleResponse>");
                request.Append("<ShippingScheduleResponseHeader>");
                request.Append("<ScheduleResponseID>");
                request.Append(shippingScheduleResponseGUID);
                request.Append("</ScheduleResponseID>");
                request.Append("<ScheduleResponseIssueDate>");
                request.Append(DateTime.Now.ToString("yyyy-MM-ddTHH:mm:ss.fff"));
                request.Append("</ScheduleResponseIssueDate>");
                request.Append("<ShippingScheduleReference>");
                request.Append("<core:RefNum>");
                request.Append(meridianResult.OrderNumber);
                request.Append("</core:RefNum>");
                request.Append("</ShippingScheduleReference>");
                request.Append("<Purpose>");
                request.Append("<core:PurposeCoded>");
                request.Append(purposeCoded);
                request.Append("</core:PurposeCoded>");
                request.Append("</Purpose>");
                request.Append("<ResponseType>");
                request.Append("<core:ResponseTypeCoded>");
                request.Append(responseTypeCoded);
                request.Append("</core:ResponseTypeCoded>");
                request.Append("</ResponseType>");
                request.Append("<ShippingScheduleHeader>");
                request.Append(shippingScheduleHeader.InnerXml);
                request.Append("</ShippingScheduleHeader>");
                if (!string.IsNullOrWhiteSpace(meridianResult.Comments))
                {
                    request.Append("<ShippingScheduleResponseHeaderNote>");
                    request.Append(meridianResult.Comments);
                    request.Append("</ShippingScheduleResponseHeaderNote>");
                }
                request.Append("</ShippingScheduleResponseHeader>");
                request.Append("</ShippingScheduleResponse>");
                request.Append("</soapenv:Body>");
                request.Append("</soapenv:Envelope>");

                var currentXmlDocument = new XmlDocument();
                currentXmlDocument.LoadXml(request.ToString());
                MeridianSystemLibrary.LogTransaction(meridianResult.WebUserName, meridianResult.FtpUserName, "CreateShippingScheduleResponse", "04.01", "Success - Created ShippingScheduleResponse Request", "Shipping Schedule Response Request", "No File Name", shippingScheduleResponseGUID, meridianResult.OrderNumber, currentXmlDocument, "Success");
                return(request.ToString());
            }
            catch (Exception ex)
            {
                MeridianSystemLibrary.LogTransaction(meridianResult.WebUserName, meridianResult.FtpUserName, "CreateShippingScheduleResponse", "06.02", "Error - Create ShippingScheduleResponse Request", string.Format("Error - While creating SSR Request: {0}", ex.Message), meridianResult.FileName, meridianResult.UniqueID, meridianResult.OrderNumber, meridianResult.XmlDocument, "Error 06.02 - Create AWC SSR Request");
                return(string.Empty);
            }
        }