示例#1
0
        /// <summary>
        /// This function will authenticate the User with Username and Password
        /// </summary>
        /// <param name="messageHeaders">SOAP MessageHeaders </param>
        /// <param name="messageHeaderInfo">MessageHeaderInfo - Contains the Soap Credential Header</param>
        /// <param name="objXCBLUser">Object - Holds the user related information</param>
        /// <returns></returns>
        private static XCBL_User Meridian_AuthenticateUser(MessageHeaders messageHeaders, MessageHeaderInfo messageHeaderInfo, int index)
        {
            try
            {
                string username = string.Empty;
                string password = string.Empty;
                string hashkey  = string.Empty;

                // Retrieve the Credential header information
                // If a separate namespace is needed for the Credentials tag use the global const CREDENTIAL_NAMESPACE that is commented below
                if (messageHeaderInfo.Name == MeridianGlobalConstants.CREDENTIAL_HEADER)// && h.Namespace == MeridianGlobalConstants.CREDENTIAL_NAMESPACE)
                {
                    // read the value of that header
                    XmlReader xr = messageHeaders.GetReaderAtHeader(index);
                    while (xr.Read())
                    {
                        if (xr.IsStartElement())
                        {
                            if (xr.Name == MeridianGlobalConstants.CREDENTIAL_USERNAME)
                            {
                                if (xr.Read())
                                {
                                    username = xr.Value;
                                }
                            }
                            else if (xr.Name == MeridianGlobalConstants.CREDENTIAL_PASSWORD)
                            {
                                if (xr.Read())
                                {
                                    password = xr.Value;
                                }
                            }
                            else if (xr.Name == MeridianGlobalConstants.CREDENTIAL_HASHKEY)
                            {
                                if (xr.Read())
                                {
                                    hashkey = xr.Value;
                                }
                            }
                        }
                    }
                }

                if (!string.IsNullOrEmpty(username) && !string.IsNullOrEmpty(password) && !string.IsNullOrEmpty(hashkey))
                {
                    username = Encryption.Decrypt(username, hashkey);
                    password = Encryption.Decrypt(password, hashkey);
                    return(MeridianSystemLibrary.sysGetAuthenticationByUsernameAndPassword(username, password));
                }
                return(null);
            }
            catch (Exception ex)
            {
                return(null);
            }
        }
        /// <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();
            }
        }