コード例 #1
0
ファイル: FrmFillDownload.cs プロジェクト: xlgwr/TT_Samples
        private void btnStart_Click(object sender, EventArgs e)
        {
            // Validate our inputs

            int interval = 0;

            if (!int.TryParse(txtFrequency.Text, out interval))
            {
                MessageBox.Show("Error parsing frequency \"" + txtFrequency.Text + "\".");
                return;
            }

            if (interval <= 0)
            {
                MessageBox.Show("Frequency must be greater than zero.");
                return;
            }

            TimeSpan start_time = dtpStartTime.Value.TimeOfDay;
            TimeSpan end_time   = dtpEndTime.Value.TimeOfDay;

            if (start_time > end_time)
            {
                MessageBox.Show("Error: Start time must come before end time");
                return;
            }


            // Try to log in to the REST API
            string app_key    = txtSecret.Text.Split(':')[0];
            string app_secret = txtSecret.Text;

            RestManager.Init(app_key, app_secret, txtEnvironment.Text, txtURL.Text);
            if (!RestManager.IsAuthorized())
            {
                MessageBox.Show("Rest API was not able to log in with provided App Key and Secret");
                return;
            }
            else
            {
                FDLog.LogMessage("Successfully logged in with app key and secret");
                RestManager.OnTokenError += RestManager_OnTokenError;
            }

            DateTime start_date = default(DateTime);

            if (dtpStartDate.CustomFormat != " ")
            {
                // TimeStamp correction so it properly reflects midnight of
                // this day in local time
                start_date = dtpStartDate.Value.Date - TimeZoneInfo.Local.BaseUtcOffset;
            }
            else
            {
                start_date = DateTime.Today - TimeZoneInfo.Local.BaseUtcOffset;
            }

            if (!chkSunday.Checked && !chkMonday.Checked && !chkTuesday.Checked && !chkWednesday.Checked && !chkThursday.Checked && !chkFriday.Checked && !chkSaturday.Checked)
            {
                MessageBox.Show("Must select at least one day to run downloader.");
                return;
            }

            bool[] days_to_run = new bool[7];
            days_to_run[0] = chkSunday.Checked;
            days_to_run[1] = chkMonday.Checked;
            days_to_run[2] = chkTuesday.Checked;
            days_to_run[3] = chkWednesday.Checked;
            days_to_run[4] = chkThursday.Checked;
            days_to_run[5] = chkFriday.Checked;
            days_to_run[6] = chkSaturday.Checked;

            try
            {
                FileMode mode = (FileMode)cbFileMode.SelectedItem;
                m_outputFile = FillFile.GetFillFile(mode, txtOutput.Text, GetReportItems());
            }
            catch (Exception ex)
            {
                MessageBox.Show("Error creating output file: " + ex.Message);
                return;
            }

            clbColumns.Enabled = false;
            btnStart.Text      = "Stop Downloading";
            btnStart.Click    -= btnStart_Click;
            btnStart.Click    += btnStart_Close;
            btnBrowse.Enabled  = false;

            FDLog.LogMessage("Beginning downloads...");


            m_fillThread = new FillDownloadThread(start_time, end_time, new TimeSpan(0, interval, 0), days_to_run, start_date);
            m_fillThread.FillDownload += fillThread_OnFillDownload;
            m_fillThread.OnError      += OnError;
            m_fillThread.Start();
        }
コード例 #2
0
        private void btnStart_Click(object sender, EventArgs e)
        {
            // Validate our inputs

            int interval = 0;

            if (!int.TryParse(txtFrequency.Text, out interval))
            {
                MessageBox.Show("Error parsing frequency \"" + txtFrequency.Text + "\".");
                return;
            }

            if (interval <= 0)
            {
                MessageBox.Show("Frequency must be greater than zero.");
                return;
            }

            TimeSpan start_time = dtpStartTime.Value.TimeOfDay;
            TimeSpan end_time   = dtpEndTime.Value.TimeOfDay;

            if (start_time > end_time)
            {
                MessageBox.Show("Error: Start time must come before end time");
                return;
            }

            // Try to log in to the REST API
            RestManager.Init(txtKey.Text, txtSecret.Text, txtEnvironment.Text);
            if (!RestManager.IsAuthorized())
            {
                MessageBox.Show("Rest API was not able to log in with provided App Key and Secret");
                return;
            }
            else
            {
                RestManager.OnTokenError += RestManager_OnTokenError;
            }

            DateTime start_date = default(DateTime);

            if (dtpStartDate.CustomFormat != " ")
            {
                // TimeStamp correction so it properly reflects midnight of
                // this day in local time
                start_date = dtpStartDate.Value.Date - TimeZoneInfo.Local.BaseUtcOffset;
            }
            else
            {
                start_date = DateTime.Today - TimeZoneInfo.Local.BaseUtcOffset;
            }

            if (!chkSunday.Checked && !chkMonday.Checked && !chkTuesday.Checked && !chkWednesday.Checked && !chkThursday.Checked && !chkFriday.Checked && !chkSaturday.Checked)
            {
                MessageBox.Show("Must select at least one day to run downloader.");
                return;
            }

            bool[] days_to_run = new bool[7];
            days_to_run[0] = chkSunday.Checked;
            days_to_run[1] = chkMonday.Checked;
            days_to_run[2] = chkTuesday.Checked;
            days_to_run[3] = chkWednesday.Checked;
            days_to_run[4] = chkThursday.Checked;
            days_to_run[5] = chkFriday.Checked;
            days_to_run[6] = chkSaturday.Checked;

            try
            {
                FileStream fs = File.Create(txtOutput.Text);
                fs.Close();
                m_outputFile           = new StreamWriter(txtOutput.Text, true, Encoding.ASCII);
                m_outputFile.AutoFlush = true;
                m_outputFile.Write(GetCSVHeader());
            }
            catch (Exception ex)
            {
                MessageBox.Show("Error creating output file: " + ex.Message);
                return;
            }

            clbColumns.Enabled = false;
            btnStart.Text      = "Stop Downloading";
            btnStart.Click    -= btnStart_Click;
            btnStart.Click    += btnStart_Close;
            btnBrowse.Enabled  = false;

            m_fillThread = new FillDownloadThread(start_time, end_time, new TimeSpan(0, interval, 0), days_to_run, start_date);
            m_fillThread.FillDownload += fillThread_OnFillDownload;
            m_fillThread.OnError      += OnError;
            m_fillThread.Start();
        }