public virtual IFtpType CreateFtpFactory(string iTypeOfFtp, string iUpOrDown, string iRam, string iPattern)
        {
            IFtpType ftp = null;

            switch (iTypeOfFtp)
            {
            case "SFTP":
                if (iUpOrDown == "upload")
                {
                    ftp = new UploadBulkSecureSFtpType();
                }

                if (iUpOrDown == "download")
                {
                    if (iRam == iPattern)
                    {
                        ftp = new DownloadSFtpSinglefileType();
                    }
                    else
                    {
                        ftp = new DownloadSFtpType();
                    }
                }
                break;

            case "FTP":
                ftp = new UploadFtpType();
                break;

            default:
                //res = "Unknown FTP type for " + " for HostIp " + p.HostIP + " pharmacy " + p.PharmacyName + "\r\n";
                break;
            }
            return(ftp);
        }
Example #2
0
        public void ProcessAllFtp()
        {
            _ConnectionString = Helper.LoadConfigKeys("ConnectionString");// +";Integrated Security=SSPI; trusted_connection=Yes;";

            try{
                _processes = GetDataFromDb();
            }
            catch (Exception ex)
            {
                LogObj.WriteLog("Failed Accessing DB for windows user identity " + WindowsIdentity.GetCurrent() + " error:" + ex.Message, enMsgType.enMsgType_Error, _LogPrefix, _AppLogDirectory);
            }
            _AppLogDirectory = Helper.GetMyDir(_ConnectionString);

            foreach (Process p in _processes)
            {
                string res = "For Upload ProcessID " + p.ID + " HostIP " + p.HostIP + ": ";
                LogObj.WriteLog(res, enMsgType.enMsgType_Info, _LogPrefix, _AppLogDirectory);

                if (ValidInput(p))
                {
                    _results += res;

                    p.LocalDir = _UploadFolder; //we change it to the user-selected folder !

                    FTPProcess ftp = new FTPProcess(p.RAM, p.HostIP, p.Port, p.Login, p.Password, p.RemoteDir, p.Pattern,
                                                    _UploadFolder, p.PharmacyName, "not used here");
                    ftp.SetExcelTable(_tblExcel);

                    IFtpType requiredTFtp = null;

                    FtpFactory factory = new FtpFactory();
                    requiredTFtp = factory.CreateFtpFactory(p.FtpType, "upload", "", "");

                    res = ftp.ComputeFtp(requiredTFtp);

                    _tblExcel = ftp.GetExcelTbl();
                    LogObj.WriteLog(res, enMsgType.enMsgType_Info, _LogPrefix, _AppLogDirectory);
                    _results += res;
                }
                //  LogObj.WriteLog(res, enMsgType.enMsgType_Info, _LogPrefix, _AppLogDirectory);

                _results += "\r\n";
            }

            LogObj.WriteLog("Completed!", enMsgType.enMsgType_Info, _LogPrefix, _AppLogDirectory);
            /*  Create the Excel report */
            try
            {
                if (_tblExcel == null)
                {
                    throw new Exception("No Excel Report content was generated");
                }

                CreateExcelFile.CreateExcelDocument(_tblExcel, _AppLogDirectory, _LogPrefix);
            }
            catch (Exception ex)
            {
                LogObj.WriteLog("Couldn't create Excel report. nException: " + ex.Message, enMsgType.enMsgType_Info, _LogPrefix, _AppLogDirectory);
            }
        }
        //use to process through all download-processes in the db and then FTP the  files.
        public void ProcessAllFtp(int hrsGoBack)
        {
            _ConnectionString = Helper.LoadConfigKeys("ConnectionString");           // +
            // ";Integrated Security=SSPI; trusted_connection=Yes;";
            _SshHostKeyFingerPrint = Helper.LoadConfigKeys("SshHostKeyFingerPrint"); //not used anymore.
            _processes             = GetDataFromDb();
            _AppLogDirectory       = Helper.GetMyDir(_ConnectionString);

            foreach (Process p in _processes)
            {
                string res = "For Download ProcessID " + p.ID + " HostIP " + p.HostIP + ": ";
                LogObj.WriteLog(res, enMsgType.enMsgType_Info, _LogPrefix, _AppLogDirectory);

                if (ValidInput(p))
                {
                    _results += res;

                    FTPProcess ftp = new FTPProcess(p.RAM, p.HostIP, p.Port, p.Login, p.Password, p.RemoteDir, p.Pattern, p.LocalDir, p.PharmacyName, "");
                    ftp.NumDaysGoback(hrsGoBack);
                    ftp.SetExcelTable(_tblExcel);
                    //ftp.SetFingerPnt(_SshHostKeyFingerPrint); // we not passing the fingerprint, can ascertain it at time of fileDownload.

                    IFtpType requiredTFtp = null;

                    FtpFactory factory = new FtpFactory();
                    requiredTFtp = factory.CreateFtpFactory(p.FtpType, "download", p.RAM, p.Pattern);

                    res = ftp.ComputeFtp(requiredTFtp);

                    _tblExcel = ftp.GetExcelTbl();
                    LogObj.WriteLog(res, enMsgType.enMsgType_Info, _LogPrefix, _AppLogDirectory);
                    _results += res;
                }
            }

            /*  Create the Excel report */
            LogObj.WriteLog("Completed!", enMsgType.enMsgType_Info, _LogPrefix, _AppLogDirectory);
            try
            {
                CreateExcelFile.CreateExcelDocument(_tblExcel, _AppLogDirectory, _LogPrefix);
            }
            catch (Exception ex)
            {
                LogObj.WriteLog("Couldn't create Excel report. nException: " + ex.Message, enMsgType.enMsgType_Info, _LogPrefix, _AppLogDirectory);
            }
        }
Example #4
0
 //abstract the types of Ftp behind the interface:
 public string ComputeFtp(IFtpType ftp)
 {
     return(ftp.RunFtp(hostIP, port, user, pass, remoteDirectory, remoteFilePattern, localFileDirectory, pharmacyName, localFileName, numDaysGoback, ram, ref tblExcel));
 }