Beispiel #1
0
        private void AddDownloadJobMenuItem_Click(object sender, EventArgs e)
        {
            try
            {
                IJobDetail downloadJob;
                ITrigger   downloadTrigger;

                if (Properties.Settings.Default.V3Forms)
                {
                    using DownloadJobV3 form = new DownloadJobV3();
                    form.ShowDialog();
                    if (form.Cancelled && (form.JobDetail == null) && (form.Trigger == null))
                    {
                        return;
                    }
                    downloadJob     = form.JobDetail;
                    downloadTrigger = form.Trigger;
                }
                else
                {
                    using DownloadJob form = new DownloadJob();
                    form.ShowDialog();
                    if (form.Cancelled && (form.JobDetail == null) && (form.Trigger == null))
                    {
                        return;
                    }
                    downloadJob     = form.JobDetail;
                    downloadTrigger = form.Trigger;
                }
                var scheduler = Scheduler.Instance.GetScheduler();
                if (scheduler == null)
                {
                    MessageBox.Show(Resources.No_active_scheduler, Resources.Missing_scheduler);
                    return;
                }

                scheduler.ScheduleJob(downloadJob, new HashSet <ITrigger> {
                    downloadTrigger
                }, true);

                _scheduleChanged = true;

                RefreshGrid();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, Resources.Unexpected_error);
            }
        }
        private void EditJob()
        {
            try
            {
                var jobName  = jobsDataGridView.SelectedRows[0].Cells["JobName"].Value.ToString();
                var jobGroup = jobsDataGridView.SelectedRows[0].Cells["JobGroup"].Value.ToString();
                var jobKey   = new JobKey(jobName, jobGroup);

                var scheduler = Scheduler.Instance.GetScheduler();
                if (scheduler == null)
                {
                    MessageBox.Show(Resources.No_active_scheduler, Resources.Missing_scheduler);
                    return;
                }

                var jobDetail  = scheduler.GetJobDetail(jobKey).Result;
                var jobTrigger = scheduler.GetTriggersOfJob(jobKey).Result.First();
                switch (jobDetail.JobType.FullName)
                {
                case SettingsConstants.DownloadJob:
                {
                    using DownloadJobV3 downloadForm = new DownloadJobV3
                          {
                              JobDetail = jobDetail,
                              Trigger   = jobTrigger
                          };

                    downloadForm.ShowDialog();

                    if (downloadForm.Cancelled && downloadForm.JobDetail == null && downloadForm.Trigger == null)
                    {
                        return;
                    }

                    scheduler.ScheduleJob(downloadForm.JobDetail, new HashSet <ITrigger> {
                            downloadForm.Trigger
                        }, true);

                    RefreshGrid();
                }
                break;

                case SettingsConstants.ExportJob:
                {
                    using ExportJobV3 exportForm = new ExportJobV3
                          {
                              JobDetail = jobDetail,
                              Trigger   = jobTrigger
                          };

                    exportForm.ShowDialog();

                    if (exportForm.Cancelled && exportForm.JobDetail == null && exportForm.Trigger == null)
                    {
                        return;
                    }

                    scheduler.ScheduleJob(exportForm.JobDetail, new HashSet <ITrigger> {
                            exportForm.Trigger
                        }, true);

                    RefreshGrid();
                }
                break;

                case SettingsConstants.UploadJob:
                    //find related processing job
                    var      processingJobName    = jobDetail.Key.Name + "-Processing monitor";
                    var      processingJobKey     = new JobKey(processingJobName, jobDetail.Key.Group);
                    var      processingJobDetail  = scheduler.GetJobDetail(processingJobKey).Result;
                    ITrigger processingJobTrigger = null;

                    if (processingJobDetail != null)
                    {
                        processingJobTrigger = scheduler.GetTriggersOfJob(processingJobKey).Result.First();
                    }
                    {
                        using UploadJobV3 uploadForm = new UploadJobV3
                              {
                                  UploadJobDetail = jobDetail,
                                  UploadTrigger   = jobTrigger
                              };
                        if ((processingJobDetail != null) && (processingJobTrigger != null))
                        {
                            uploadForm.ProcessingJobDetail = processingJobDetail;
                            uploadForm.ProcessingTrigger   = processingJobTrigger;
                        }

                        uploadForm.ShowDialog();

                        if (uploadForm.Cancelled && uploadForm.UploadJobDetail == null && uploadForm.UploadTrigger == null)
                        {
                            return;
                        }

                        scheduler.ScheduleJob(uploadForm.UploadJobDetail, new HashSet <ITrigger> {
                            uploadForm.UploadTrigger
                        }, true);

                        if ((uploadForm.ProcessingJobDetail != null) && (uploadForm.ProcessingTrigger != null))
                        {
                            scheduler.ScheduleJob(uploadForm.ProcessingJobDetail, new HashSet <ITrigger> {
                                uploadForm.ProcessingTrigger
                            }, true);
                        }

                        RefreshGrid();
                    }
                    break;

                case SettingsConstants.ImportJob:
                    //find related execution job
                    var      executionJobName    = jobDetail.Key.Name + "-Execution monitor";
                    var      executionJobKey     = new JobKey(executionJobName, jobDetail.Key.Group);
                    var      executionJobDetail  = scheduler.GetJobDetail(executionJobKey).Result;
                    ITrigger executionJobTrigger = null;

                    if (executionJobDetail != null)
                    {
                        executionJobTrigger = scheduler.GetTriggersOfJob(executionJobKey).Result.First();
                    }
                    {
                        using ImportJobV3 importForm = new ImportJobV3
                              {
                                  ImportJobDetail = jobDetail,
                                  ImportTrigger   = jobTrigger
                              };

                        if ((executionJobDetail != null) && (executionJobTrigger != null))
                        {
                            importForm.ExecutionJobDetail = executionJobDetail;
                            importForm.ExecutionTrigger   = executionJobTrigger;
                        }
                        importForm.ShowDialog();

                        if (importForm.Cancelled && importForm.ImportJobDetail == null && importForm.ImportTrigger == null)
                        {
                            return;
                        }

                        scheduler.ScheduleJob(importForm.ImportJobDetail, new HashSet <ITrigger> {
                            importForm.ImportTrigger
                        }, true);

                        if (importForm.ExecutionJobDetail != null && importForm.ExecutionTrigger != null)
                        {
                            scheduler.ScheduleJob(importForm.ExecutionJobDetail, new HashSet <ITrigger> {
                                importForm.ExecutionTrigger
                            }, true);
                        }
                        RefreshGrid();
                    }
                    break;

                default:
                    MessageBox.Show(Resources.This_type_of_job_is_not_supported_for_direct_editing);
                    return;
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, Resources.Unexpected_error);
            }
        }