예제 #1
0
        /// <summary>
        /// This method is called when the cbJobType's SelectedIndexChanged event has been fired.
        /// </summary>
        /// <param name="sender">The <see cref="object"/> that fired the event.</param>
        /// <param name="e">The <see cref="EventArgs"/> of the event.</param>
        private void cbJobType_SelectedIndexChanged(object sender, EventArgs e)
        {
            PlugWrapper pw = cbJobType.SelectedItem as PlugWrapper;

            pnlJobConfig.Controls.Clear();
            if (pw == null || pw.job == null)
            {
                return;
            }
            Job.JobType        = pw.job.GetType().FullName;
            tbDescription.Text = pw.job.Description;
            pw.job.InitiateConfiguration(pnlJobConfig, Job.JobConfiguration);
        }
예제 #2
0
        /// <summary>
        /// This method is called when the ScheduleForm's FormClosing event has been fired.
        /// </summary>
        /// <param name="sender">The <see cref="object"/> that fired the event.</param>
        /// <param name="e">The <see cref="FormClosingEventArgs"/> of the event.</param>
        private void ScheduleForm_FormClosing(object sender, FormClosingEventArgs e)
        {
            if (DialogResult != DialogResult.OK)
            {
                timer.Stop();
                timer.Dispose();
                return;
            }
            string cronString;

            try {
                cronString = cronControl.CRONString;
                CronExpression ce   = new CronExpression(cronString);
                DateTime?      next = ce.GetNextValidTimeAfter(DateTime.Now);
                if (!next.HasValue)
                {
                    MessageBox.Show("You have to select repetitions for the job");
                }
            } catch (Exception ex) {
                MessageBox.Show("Repetition error{0}{1}".FillBlanks(Environment.NewLine, ex.Message), "Repetition error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                e.Cancel = true;
                return;
            }
            if (DialogResult != DialogResult.OK)
            {
                return;
            }
            if (string.IsNullOrEmpty(tbName.Text))
            {
                MessageBox.Show("You have to specify a name", "Specify name", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                e.Cancel = true;
                return;
            }
            if (cbJobType.SelectedIndex < 0)
            {
                MessageBox.Show("You have to specify a job type", "Specify job type", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                e.Cancel = true;
                return;
            }
            if (cbTargetType.SelectedIndex < 0)
            {
                MessageBox.Show("You have to specify a target type", "Specify target type", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                e.Cancel = true;
                return;
            }
            string config;
            string targetConfig;

            try {
                config       = Job.Job.SaveConfiguration();
                targetConfig = target.SaveConfiguration();
            } catch (Exception ex) {
                MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                e.Cancel = true;
                return;
            }
            _job     = Job.Clone();
            Job.Name = tbName.Text;
            PlugWrapper pw = (PlugWrapper)cbJobType.SelectedItem;

            Job.JobType             = pw.job.GetType().FullName;
            Job.JobConfiguration    = config;
            Job.TargetConfiguration = targetConfig;
            Job.CronConfig          = cronString;
            Job.PreCommands         = null;
            if (lvPreCommands.Items.Count > 0)
            {
                List <string> list = new List <string>();
                foreach (ListViewItem li in lvPreCommands.Items)
                {
                    list.Add("{0}\t{1}".FillBlanks(li.Text, li.SubItems[1].Text));
                }
                Job.PreCommands = list.ToString(Environment.NewLine);
            }
            Job.PostCommands = null;
            if (lvPostCommands.Items.Count > 0)
            {
                List <string> list = new List <string>();
                foreach (ListViewItem li in lvPostCommands.Items)
                {
                    list.Add("{0}\t{1}".FillBlanks(li.Text, li.SubItems[1].Text));
                }
                Job.PostCommands = list.ToString(Environment.NewLine);
            }
            timer.Stop();
            timer.Dispose();
        }