예제 #1
0
        /// <summary>
        /// main method used to process the files every configurable interval
        /// </summary>
        public void ProcessFileControlThread()
        {
            string theFileToGrab = String.Empty;

            // main processing thread

            while (true)
            {
                try
                {
                    using (FtpLib.FtpConnection ftp = new FtpLib.FtpConnection(m_FTPFolder, m_FTPUserName, m_FTPPwd))
                    {
                        try
                        {
                            ftp.Open();                                    /* Open the FTP connection */
                            ftp.Login();                                   /* Login using previously provided credentials */
                            ftp.SetCurrentDirectory(m_FTPServerDirectory); /* change current directory */
                            FtpLib.FtpFileInfo[] flist = ftp.GetFiles();

                            foreach (FtpLib.FtpFileInfo fi in flist)
                            {
                                if (!_dbMgr.CheckDbBeforeDownloadingFile(fi.Name))
                                {
                                    try
                                    {
                                        string fil = m_FTPServerDirectory + fi.Name;
                                        if (ftp.FileExists(fil))  /* check that a file exists */
                                        {
                                            ftp.GetFile(fil, m_FtpFileToLocation + fi.Name, false);
                                            FileWriter.Instance.WriteToLogFile("FtpHandler::ProcessFileControlThread:DownloadedFile" + fi.Name);
                                            // update the db so we do not download again
                                            _dbMgr.UpdateFtpFileNameInDb(fi.Name);
                                        }
                                    }
                                    catch (SystemException se)
                                    {
                                        FileWriter.Instance.WriteToLogFile("FtpHandler::ProcessControlThread:EXCEPTIONCAUGHT(Open/Login/Directory)::" + se.Message);
                                        FileWriter.Instance.WriteToLogFile(se.StackTrace);
                                    }
                                }
                            }
                        }
                        catch (SystemException se)
                        {
                            FileWriter.Instance.WriteToLogFile("FtpHandler::ProcessFileControlThread:EXCEPTIONCAUGHT::" + se.Message);
                        }
                    }
                }

                catch (SystemException se)
                {
                    FileWriter.Instance.WriteToLogFile("FtpHandler::ProcessFileControlThread:EXCEPTIONCAUGHT::TryingToConnect" + se.Message);
                }

                // wait for the next interval to ftp the next file over
                System.Threading.Thread.Sleep(m_runIntervalInSeconds);
            } // while(true)
        }     //ProcessFileControlThread
예제 #2
0
        /// <summary>
        /// main method used to process the files every configurable interval
        /// </summary>
        public void ProcessFileControlThread()
        {
            string theFileToGrab = String.Empty;

            // main processing thread

            while (true)
            {
                try
                {
                    using (FtpLib.FtpConnection ftp = new FtpLib.FtpConnection(m_FTPFolder, m_FTPUserName, m_FTPPwd))
                    {
                        try
                        {
                            ftp.Open(); /* Open the FTP connection */
                            ftp.Login(); /* Login using previously provided credentials */
                            ftp.SetCurrentDirectory(m_FTPServerDirectory); /* change current directory */
                            FtpLib.FtpFileInfo[] flist = ftp.GetFiles();

                            foreach (FtpLib.FtpFileInfo fi in flist)
                            {
                                if (!_dbMgr.CheckDbBeforeDownloadingFile(fi.Name))
                                {
                                    try
                                    {
                                        string fil = m_FTPServerDirectory + fi.Name;
                                        if (ftp.FileExists(fil))  /* check that a file exists */
                                        {
                                            ftp.GetFile(fil, m_FtpFileToLocation + fi.Name, false);
                                            FileWriter.Instance.WriteToLogFile("FtpHandler::ProcessFileControlThread:DownloadedFile" + fi.Name);
                                            // update the db so we do not download again
                                            _dbMgr.UpdateFtpFileNameInDb(fi.Name);
                                        }
                                    }
                                    catch (SystemException se)
                                    {
                                        FileWriter.Instance.WriteToLogFile("FtpHandler::ProcessControlThread:EXCEPTIONCAUGHT(Open/Login/Directory)::" + se.Message);
                                        FileWriter.Instance.WriteToLogFile(se.StackTrace);
                                    }
                                }
                            }
                        }
                        catch (SystemException se)
                        {
                            FileWriter.Instance.WriteToLogFile("FtpHandler::ProcessFileControlThread:EXCEPTIONCAUGHT::" + se.Message);

                        }
                    }
                }

                catch (SystemException se)
                {

                    FileWriter.Instance.WriteToLogFile("FtpHandler::ProcessFileControlThread:EXCEPTIONCAUGHT::TryingToConnect" + se.Message);

                }

                // wait for the next interval to ftp the next file over
                System.Threading.Thread.Sleep(m_runIntervalInSeconds);

            }// while(true)
        }
예제 #3
0
        private static void RemoveDirectoryEvenIfNotEmpty(FtpConnection ftpConnection, string startDirectory)
        {
            if (!startDirectory.EndsWith("/"))
                startDirectory += "/";

            List<string> directories = new List<string>();
            directories.Add(startDirectory);
            int index = 0;
            while (index < directories.Count)
            {
                string currentDirectory = directories[index];
                directories.AddRange(ftpConnection.GetDirectories(currentDirectory).Select(dir => currentDirectory + dir.Name + "/"));
                index++;
            }

            directories.Reverse();
            List<string> fileNames = new List<string>();
            foreach (var directory in directories)
            {
                foreach (var ftpFile in ftpConnection.GetFiles(directory))
                {
                    string fullPath = directory + ftpFile.Name;
                    if (ftpConnection.FileExists(fullPath))
                        ftpConnection.RemoveFile(fullPath);
                }

                foreach (var ftpDir in ftpConnection.GetDirectories(directory))
                {
                    string fullPath = directory + ftpDir.Name;
                    if (ftpConnection.DirectoryExists(fullPath))
                        ftpConnection.RemoveDirectory(fullPath);
                }
            }

            if (startDirectory != "./" && ftpConnection.DirectoryExists(startDirectory))
                ftpConnection.RemoveDirectory(startDirectory);
        }
        private bool IsValidToBeginDiff(string inputEnv, string inputHost, string refEnv, string refHost, string compareScriptLocation, string scriptHost)
        {
            FtpConnection connection;

            #region RefEnvValidation

            connection = new FtpConnection(refHost, "mxftp", "mxftp");
            try {
                try {
                    connection.Open();
                    // bgDoServerWork.ReportProgress(5, "Validating Results...");
                } catch (Exception ex) {
                    CommonUtils.ShowError(ex.Message, ex);
                    return false;
                }
                connection.Login();
                if (!connection.DirectoryExists(refEnv)) {
                    CommonUtils.ShowInformation("The reference environment path is incorrect!",true);
                    return false;
                }
                if (!connection.FileExists(refEnv + "/mxg2000_settings.sh")) {
                    CommonUtils.ShowInformation("The reference environment path is incorrect!", true);
                    return false;
                }
                if (connection.FileExists(refEnv + "/clean.log")) {
                    CommonUtils.ShowInformation("The reference environment is cleaned!", true);
                    return false;
                }
            } finally {
                connection.Close();
                connection.Dispose();
            }

            #endregion

            #region inputEnvValidations

            connection = new FtpConnection(inputHost, "mxftp", "mxftp");
            try {
                try {
                    connection.Open();
                    // bgDoServerWork.ReportProgress(5, "Validating Results...");
                } catch (Exception ex) {
                    CommonUtils.ShowError(ex.Message, ex);
                    return false;
                }
                connection.Login();
                if (!connection.DirectoryExists(inputEnv)) {
                    CommonUtils.ShowInformation("The input environment path is incorrect!",true);
                    return false;
                }
                if (!connection.FileExists(inputEnv + "/mxg2000_settings.sh")) {
                    CommonUtils.ShowInformation("The input environment path is incorrect!", true);
                    return false;
                }
                if (connection.FileExists(inputEnv + "/clean.log")) {
                    CommonUtils.ShowInformation("The input environment is cleaned!", true);
                    return false;
                }
            } finally {
                connection.Close();
                connection.Dispose();
            }

            #endregion

            #region ComparisonHostValidation

            connection = new FtpConnection(scriptHost, "mxftp", "mxftp");
            try {
                try {
                    connection.Open();
                } catch (Exception ex) {
                    CommonUtils.ShowError(ex.Message, ex);
                    return false;
                }
                connection.Login();
                if (!connection.DirectoryExists(compareScriptLocation)) {
                    CommonUtils.ShowInformation("Could not connect to master host!", true);
                    return false;
                }
                if (!connection.FileExists(compareScriptLocation + "/comparison.sh")) {
                    //testing
                }
            } finally {
                connection.Close();
                connection.Dispose();
            }

            #endregion

            return true;
        }