Esempio n. 1
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);
        }
Esempio n. 2
0
        /// <summary>
        /// This function will call the ProcessDocument Method internally and will make async result compelted
        /// </summary>
        /// <param name="state">current MeridianAsyncResult </param>
        /// <returns></returns>
        private void CompleteProcess(object state)
        {
            var meridianAsyncResult = state as MeridianAsyncResult;

            if (CommonProcess.IsShippingScheduleRequest(meridianAsyncResult.CurrentOperationContext))
            {
                ProcessShippingSchedule objProcessShippingSchedule = new ProcessShippingSchedule();
                meridianAsyncResult.Result = objProcessShippingSchedule.ProcessDocument(meridianAsyncResult.CurrentOperationContext);
            }
            else
            {
                ProcessRequisition objProcessRequisition = new ProcessRequisition();
                meridianAsyncResult.Result = objProcessRequisition.ProcessRequisitionDocument(meridianAsyncResult.CurrentOperationContext);
            }
            meridianAsyncResult.Completed();
        }
        /// <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);
        }
        /// <summary>
        /// To create CSV file
        /// </summary>
        /// <param name="processData">Process data</param>
        /// <returns></returns>
        private bool CreateLocalCsvFile(ProcessData processData)
        {
            bool result = false;

            try
            {
                if (processData != null && !string.IsNullOrEmpty(processData.ScheduleResponseID) &&
                    !string.IsNullOrEmpty(processData.OrderNumber) &&
                    !string.IsNullOrEmpty(processData.CsvFileName))
                {
                    var record = string.Format(MeridianGlobalConstants.SHIPPING_SCHEDULE_RESPONSE_CSV_HEADER_NAMES_FORMAT,
                                               processData.ShippingScheduleResponse.ScheduleResponseID, processData.ShippingScheduleResponse.ScheduleResponseIssueDate, processData.ShippingScheduleResponse.ScheduleResponseOrderNumber,
                                               processData.ShippingScheduleResponse.ScheduleResponsePurposeCoded, processData.ShippingScheduleResponse.ScheduleResponseTypeCoded, "",
                                               processData.ShippingScheduleResponse.ScheduleID, processData.ShippingScheduleResponse.ScheduleIssuedDate, processData.ShippingScheduleResponse.OrderNumber, processData.ShippingScheduleResponse.SequenceNumber,
                                               processData.ShippingScheduleResponse.Other_FirstStop, processData.ShippingScheduleResponse.Other_Before7, processData.ShippingScheduleResponse.Other_Before9, processData.ShippingScheduleResponse.Other_Before12, processData.ShippingScheduleResponse.Other_SameDay, processData.ShippingScheduleResponse.Other_OwnerOccupied, processData.ShippingScheduleResponse.Other_7, processData.ShippingScheduleResponse.Other_8, processData.ShippingScheduleResponse.Other_9, processData.ShippingScheduleResponse.Other_10,
                                               processData.ShippingScheduleResponse.PurposeCoded, processData.ShippingScheduleResponse.ScheduleType, processData.ShippingScheduleResponse.AgencyCoded, processData.ShippingScheduleResponse.Name1, processData.ShippingScheduleResponse.Street, processData.ShippingScheduleResponse.StreetSupplement1, processData.ShippingScheduleResponse.PostalCode, processData.ShippingScheduleResponse.City, processData.ShippingScheduleResponse.RegionCoded,
                                               processData.ShippingScheduleResponse.ContactName, processData.ShippingScheduleResponse.ContactNumber_1, processData.ShippingScheduleResponse.ContactNumber_2, processData.ShippingScheduleResponse.ContactNumber_3, processData.ShippingScheduleResponse.ContactNumber_4, processData.ShippingScheduleResponse.ContactNumber_5, processData.ShippingScheduleResponse.ContactNumber_6,
                                               processData.ShippingScheduleResponse.ShippingInstruction, processData.ShippingScheduleResponse.GPSSystem, processData.ShippingScheduleResponse.Latitude.ToString(), processData.ShippingScheduleResponse.Longitude.ToString(), processData.ShippingScheduleResponse.LocationID, processData.ShippingScheduleResponse.EstimatedArrivalDate, processData.ShippingScheduleResponse.OrderType,
                                               processData.ShippingScheduleResponse.ScheduleResponseOrderNumber.ExtractNumericOrderNumber());
                    StringBuilder strBuilder = new StringBuilder(MeridianGlobalConstants.SHIPPING_SCHEDULE_RESPONSE_CSV_HEADER_NAMES);
                    strBuilder.AppendLine();
                    strBuilder.AppendLine(record);
                    string csvContent = strBuilder.ToString();

                    _meridianResult.FtpUserName            = processData.FtpUserName;
                    _meridianResult.FtpPassword            = processData.FtpPassword;
                    _meridianResult.FtpServerInFolderPath  = processData.FtpServerInFolderPath;
                    _meridianResult.FtpServerOutFolderPath = processData.FtpServerOutFolderPath;
                    _meridianResult.LocalFilePath          = processData.LocalFilePath;
                    _meridianResult.WebUserName            = processData.WebUserName;
                    _meridianResult.UniqueID    = processData.ScheduleResponseID;
                    _meridianResult.OrderNumber = processData.OrderNumber;
                    _meridianResult.FileName    = processData.CsvFileName;

                    if (MeridianGlobalConstants.CONFIG_CREATE_LOCAL_CSV == MeridianGlobalConstants.SHOULD_CREATE_LOCAL_FILE)
                    {
                        _meridianResult.UploadFromLocalPath = true;
                        return(CommonProcess.CreateFile(csvContent, _meridianResult));
                    }
                    else
                    {
                        byte[] content = Encoding.UTF8.GetBytes(csvContent);
                        int    length  = content.Length;

                        if (!string.IsNullOrEmpty(processData.CsvFileName) && length > 40)
                        {
                            _meridianResult.Content = content;
                            result = true;
                        }
                        else
                        {
                            MeridianSystemLibrary.LogTransaction(processData.WebUserName, processData.FtpUserName, "CreateLocalCsvFile", "03.06", ("Error - Creating CSV File because of Stream " + length), string.Format("Error - Creating CSV File {0} with error of Stream", processData.CsvFileName), processData.CsvFileName, processData.ScheduleResponseID, processData.OrderNumber, processData.XmlDocument, "Error 03.06 - Create CSV File");
                        }
                    }
                }
                else
                {
                    MeridianSystemLibrary.LogTransaction(processData.WebUserName, processData.FtpUserName, "CreateLocalCsvFile", "03.06", "Error - Creating CSV File because of Process DATA", string.Format("Error - Creating CSV File {0} with error of Process DATA", processData.CsvFileName), processData.CsvFileName, processData.ScheduleResponseID, processData.OrderNumber, processData.XmlDocument, "Error 03.06 - Create CSV File");
                }
            }
            catch (Exception ex)
            {
                MeridianSystemLibrary.LogTransaction(processData.WebUserName, processData.FtpUserName, "CreateLocalCsvFile", "03.06", "Error - Creating CSV File", string.Format("Error - Creating CSV File {0} with error {1}", processData.CsvFileName, ex.Message), processData.CsvFileName, processData.ScheduleResponseID, processData.OrderNumber, processData.XmlDocument, "Error 03.06 - Create CSV File");
            }

            return(result);
        }
        /// <summary>
        /// To Check the PBS FTP folder and if any file available then Process it and send Shipping Schedule Response Request to AWC.
        /// </summary>
        /// <param name="sender">timer</param>
        /// <param name="e">elasped event args</param>
        private static void CheckPBSFTPFolder(object sender, ElapsedEventArgs e)
        {
            _pbsFtpTimer.Stop();
            try
            {
                var currentUser = MeridianSystemLibrary.sysGetAuthenticationByUsernameAndPassword(MeridianGlobalConstants.CONFIG_USER_NAME, MeridianGlobalConstants.CONFIG_PASSWORD);
                if (currentUser != null)
                {
                    WebRequest request = WebRequest.Create(currentUser.FtpServerOutFolderPath);
                    request.Method      = WebRequestMethods.Ftp.ListDirectory;
                    request.Credentials = new NetworkCredential(currentUser.FtpUsername, currentUser.FtpPassword);
                    request.Timeout     = Timeout.Infinite;
                    List <string> directories = new List <string>();
                    using (var response = (FtpWebResponse)request.GetResponse())
                    {
                        StreamReader streamReader = new StreamReader(response.GetResponseStream());
                        string       line         = streamReader.ReadLine();
                        while (!string.IsNullOrEmpty(line))
                        {
                            directories.Add(line);
                            line = streamReader.ReadLine();
                        }
                        streamReader.Close();
                    }

                    for (int i = 0; i <= (directories.Count - 1); i++)
                    {
                        if (directories[i].Contains("."))
                        {
                            var    currentFileName = directories[i].ToString();
                            string path            = currentUser.FtpServerOutFolderPath + currentFileName;

                            var shouldDeleteCurrentFile = false;
                            try
                            {
                                using (WebClient ftpClient = new WebClient())
                                {
                                    ftpClient.Credentials = new NetworkCredential(currentUser.FtpUsername, currentUser.FtpPassword);
                                    byte[] currentFileData = ftpClient.DownloadData(path);
                                    shouldDeleteCurrentFile = CommonProcess.SendShippingScheduleResponseRequestFromPBSFTP(currentUser, currentFileName, currentFileData);
                                }

                                if (shouldDeleteCurrentFile)
                                {
                                    /*After process completion delete the file so that will not process that particular file*/
                                    FtpWebRequest ftpRequest = (FtpWebRequest)FtpWebRequest.Create(path);
                                    ftpRequest.Credentials = new NetworkCredential(currentUser.FtpUsername, currentUser.FtpPassword);
                                    ftpRequest.Method      = WebRequestMethods.Ftp.DeleteFile;
                                    ftpRequest.UseBinary   = true;
                                    ftpRequest.KeepAlive   = false;
                                    ftpRequest.Timeout     = Timeout.Infinite;
                                    FtpWebResponse ftpResponse = (FtpWebResponse)ftpRequest.GetResponse();
                                    ftpResponse.Close();
                                    ftpRequest = null;
                                }
                            }
                            catch (Exception ex)
                            {
                                MeridianSystemLibrary.LogTransaction(MeridianGlobalConstants.CONFIG_USER_NAME, string.Empty, "CheckPBSFTPFolder", "06.08", "Error - While reading FTP file - Inside CATCH block", string.Format("Error - While reading FTP file: {0} with error - Inside Catch Block", ex.Message), currentFileName, string.Empty, string.Empty, null, "Error 06.08 - Read PBS FTP folder");
                            }
                        }
                    }
                    _pbsFtpTimer.Start();
                }
            }
            catch (Exception ex)
            {
                MeridianSystemLibrary.LogTransaction(MeridianGlobalConstants.CONFIG_USER_NAME, string.Empty, "CheckPBSFTPFolder", "06.04", "Error - While checking FTP folder - Inside CATCH block", string.Format("Error - While checking FTP folder: {0} with error - Inside Catch Block", ex.Message), string.Empty, string.Empty, string.Empty, null, "Error 06.04 - Check PBS FTP folder");
                _pbsFtpTimer.Start();
            }
        }
Esempio n. 6
0
        private void GetAllOrder()
        {
            IsProcessing = true;
            MeridianSystemLibrary.LogTransaction(null, null, "GetAllOrder", "01.10", "Success - inside GetAllOrder", "Success - inside GetAllOrder", null, null, null, null, "Success - inside GetAllOrder");
            var allLatestPBSOrders = new Dictionary <string, PBSData>();

            pbsFrequencyTimer.Stop();
            pbsFrequencyTimer.Interval = TimeSpan.FromMinutes(MeridianGlobalConstants.PBS_QUERY_FREQUENCY).TotalMilliseconds;
            pbsFrequencyTimer.Start();
            string fileNameFormat = DateTime.Now.ToString(MeridianGlobalConstants.XCBL_FILE_DATETIME_FORMAT);

            using (HttpClient client = new HttpClient())
            {
                var sqlQuery = string.Format(MeridianGlobalConstants.PBS_WEB_SERVICE, MeridianGlobalConstants.PBS_WEB_SERVICE_QUERY, MeridianGlobalConstants.CONFIG_PBS_WEB_SERVICE_USER_NAME,
                                             MeridianGlobalConstants.CONFIG_PBS_WEB_SERVICE_PASSWORD);
                var res          = client.GetAsync(sqlQuery).Result;
                var resultString = client.GetStringAsync(MeridianGlobalConstants.PBS_OUTPUT_FILE).Result;

                if (MeridianGlobalConstants.PBS_ENABLE_CACHE_LOG == MeridianGlobalConstants.XCBL_YES_FLAG)
                {
                    CommonProcess.CreateLogFile(string.Format("{0}\\PBS{1}voc.txt", MeridianGlobalConstants.PBS_CACHE_LOG_LOCATION, fileNameFormat), resultString);
                }

                if (!string.IsNullOrWhiteSpace(resultString))
                {
                    var lines = resultString.Split(new[] { "\r\n", "\r", "\n" }, StringSplitOptions.None);
                    if (lines.Count() > 1)
                    {
                        for (int i = 1; i < lines.Length; i++)
                        {
                            if (!string.IsNullOrWhiteSpace(lines[i]))
                            {
                                var values = lines[i].Split(',');
                                if (values.Length > 29)
                                {
                                    DateTimeOffset orderDate;
                                    if (DateTimeOffset.TryParse(values[4], out orderDate))
                                    {
                                        PBSData pbsData = new PBSData();
                                        pbsData.DeliveryDate                 = values[1];
                                        pbsData.ShipmentDate                 = values[2];
                                        pbsData.IsScheduled                  = values[3];
                                        pbsData.OrderNumber                  = values[10].Trim();
                                        pbsData.DestinationName              = values[25];
                                        pbsData.DestinationStreet            = values[26];
                                        pbsData.DestinationStreetSupplyment1 = values[27];
                                        pbsData.DestinationCity              = values[28];
                                        pbsData.DestinationRegionCoded       = string.Format(MeridianGlobalConstants.XCBL_US_CODE + values[29]);
                                        pbsData.DestinationPostalCode        = values[30];

                                        if (!allLatestPBSOrders.ContainsKey(pbsData.OrderNumber))
                                        {
                                            allLatestPBSOrders.Add(pbsData.OrderNumber.Trim(), pbsData);
                                        }
                                    }
                                }
                                else
                                {
                                    MeridianSystemLibrary.LogTransaction(null, null, "GetAllOrder", "02.25", "Warning - Values lenght less then 29", "Warning - Values lenght less then 29 from PBS WebService",
                                                                         null, null, null, null, "Warning 02.25 : Values lenght less then 29");
                                }
                            }
                        }
                    }
                    else
                    {
                        MeridianSystemLibrary.LogTransaction(null, null, "GetAllOrder", "02.26", "Warning - PBS File Lines Count < 2", "Warning - PBS File Lines Count < 2 from PBS WebService", null,
                                                             null, null, null, "Warning 02.26 : PBS File Lines Count < 2");
                    }
                }
                else
                {
                    MeridianSystemLibrary.LogTransaction(null, null, "GetAllOrder", "02.27", "Warning - Empty PBS text file", "Warning - Empty PBS text file from PBS WebService",
                                                         null, null, null, null, "Warning 02.27 : Empty Text File");
                }
            }

            if (MeridianGlobalConstants.PBS_ENABLE_CACHE_LOG == MeridianGlobalConstants.XCBL_YES_FLAG)
            {
                StringBuilder strBuilder = new StringBuilder(MeridianGlobalConstants.PBS_CSV_HEADERS);
                strBuilder.AppendLine();
                foreach (var item in allLatestPBSOrders)
                {
                    strBuilder.AppendLine(string.Format(MeridianGlobalConstants.PBS_CSV_HEADER_NAME_FORMAT,
                                                        item.Value.DeliveryDate, item.Value.ShipmentDate, item.Value.IsScheduled,
                                                        item.Value.OrderNumber, item.Value.DestinationName, item.Value.DestinationStreet,
                                                        item.Value.DestinationStreetSupplyment1, item.Value.DestinationCity, item.Value.DestinationRegionCoded,
                                                        item.Value.DestinationPostalCode));
                }
                CommonProcess.CreateLogFile(string.Format("{0}\\XCBL{1}PBSCachedOrders.csv", MeridianGlobalConstants.PBS_CACHE_LOG_LOCATION, fileNameFormat), strBuilder.ToString());
            }

            AllPBSOrder  = allLatestPBSOrders;
            IsProcessing = false;
        }