コード例 #1
0
        /// <summary>
        /// calculates the latency to insert b/w each call to rt-local
        /// </summary>
        /// <returns></returns>
        private int calculateSleepMS()
        {
            double reqPerMS       = 1000 / maxReqPerSecond;
            int    sleepFrequency = (int)Math.Ceiling(reqPerMS);

            if (sleepFrequency < 0)
            {
                sleepFrequency = 0;
            }

//skip this in debug mode if want to test target rate code
#if !DEBUG
            //occasionally (not every call!) check Auditor for # of running threads in REACT stage
            if ((DateTime.Now - lastAuditorCheck).TotalMinutes >= 5)
            {
                lastAuditorCheck = DateTime.Now;
                DB        ITS     = FreshAddressDatabase.getDB("", "");
                DataTable running = ITS.dataQuery("select count(*) as Total from auditor_log where outcomecomment like '%through REACT%' and outcome is null");
                try
                {
                    runningThreads = Convert.ToInt32(running.Rows[0]["Total"].ToString());
                }
                catch { }
                ITS.disconnect();
            }

            //don't multiply (next step) by 0, there is at least 1 running!
            if (runningThreads == 0)
            {
                runningThreads = 1;
            }

            //multiply out by # so as to make sure each thread averages out to target runtime
            sleepFrequency = sleepFrequency * runningThreads;
#endif

            return(sleepFrequency);
        }
コード例 #2
0
        public FTPConnection(string FTPID)
        {
            //look it up
            DB        ITS     = FreshAddressDatabase.getDB("", "");
            DataTable conInfo = ITS.dataQuery("SELECT * FROM FTPs WHERE FTPID = '" + FTPID + "'");

            if (conInfo.Rows.Count > 0)
            {
                creds = new Credentials(conInfo.Rows[0]["address"].ToString(), conInfo.Rows[0]["username"].ToString(), conInfo.Rows[0]["password"].ToString());

                //if has port
                if (conInfo.Rows[0]["port"].ToString().Trim() != "")
                {
                    creds.setPort(conInfo.Rows[0]["port"].ToString());
                }

                //protocol to use
                string proto = conInfo.Rows[0]["method"].ToString().Trim().ToLower();
                //SFTP
                if (proto == "sftp")
                {
                    ftpProtocol = Protocol.Sftp;
                    creds.setSFTPfingerprint(conInfo.Rows[0]["key"].ToString());
                    connOptions = new SessionOptions
                    {
                        Protocol = ftpProtocol,
                        HostName = creds.address,
                        UserName = creds.username,
                        Password = creds.password,
                        SshHostKeyFingerprint = creds.fingerprint
                    };
                }
                else
                {
                    ftpProtocol = Protocol.Ftp;
                    //FTPS
                    if (proto == "ftps")
                    {
                        creds.setFTPSfingerprint(conInfo.Rows[0]["key"].ToString());
                        connOptions = new SessionOptions
                        {
                            Protocol  = ftpProtocol,
                            HostName  = creds.address,
                            UserName  = creds.username,
                            Password  = creds.password,
                            FtpSecure = WinSCP.FtpSecure.ExplicitTls,
                            SslHostCertificateFingerprint = creds.FTPSfingerP
                        };
                    }
                    //normal FTP
                    else
                    {
                        connOptions = new SessionOptions
                        {
                            Protocol = ftpProtocol,
                            HostName = creds.address,
                            UserName = creds.username,
                            Password = creds.password
                        };
                    }
                }
            }
            ITS.disconnect();
        }