Esempio n. 1
0
        /// <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)
        {
            MeridianSystemLibrary.LogTransaction(null, null, "CheckPBSFTPFolder", "01.11", "Success - inside CheckPBSFTPFolder", "Success - inside CheckPBSFTPFolder", null, null, null, null, "Success - inside CheckPBSFTPFolder");
            _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;

                            try
                            {
                                var    isDSNFile               = currentFileName.ToLower().Trim().StartsWith("awc-dsn");
                                var    isResponseFile          = currentFileName.ToLower().Trim().StartsWith("awc-xcblresponse");
                                var    shouldDeleteCurrentFile = false;
                                string currentFileData         = null;

                                using (WebClient ftpClient = new WebClient())
                                {
                                    ftpClient.Credentials = new NetworkCredential(currentUser.FtpUsername, currentUser.FtpPassword);
                                    currentFileData       = ftpClient.DownloadString(path);
                                }

                                if (!string.IsNullOrWhiteSpace(currentFileData))
                                {
                                    if (isResponseFile)
                                    {
                                        shouldDeleteCurrentFile = CommonProcess.SendShippingScheduleResponseRequestFromPBSFTP(currentUser, currentFileName, currentFileData);
                                    }
                                    else if (isDSNFile)
                                    {
                                        CommonProcess.CreateLogFile(String.Format("{0}\\{1}", MeridianGlobalConstants.PBS_TEXT_FILE_LOCATION, currentFileName), currentFileData);
                                        shouldDeleteCurrentFile = MeridianGlobalConstants.SHOULD_DELETE_PBS_TEXT_FILE.Equals(MeridianGlobalConstants.XCBL_YES_FLAG, StringComparison.OrdinalIgnoreCase);
                                    }
                                }

                                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. 2
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;
        }