コード例 #1
0
        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);
                var jobTrigger = scheduler.GetTriggersOfJob(jobKey)[0];

                switch (jobDetail.JobType.FullName)
                {
                case SettingsConstants.DownloadJob:
                    using (DownloadJob downloadForm = new DownloadJob
                    {
                        JobDetail = jobDetail,
                        Trigger = jobTrigger
                    })
                    {
                        downloadForm.ShowDialog();

                        if (!downloadForm.Cancelled && (downloadForm.JobDetail != null) &&
                            (downloadForm.Trigger != null))
                        {
                            scheduler.ScheduleJob(
                                downloadForm.JobDetail, new HashSet <ITrigger> {
                                downloadForm.Trigger
                            }, true);

                            RefreshGrid();
                        }
                    }
                    break;

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

                        if (!exportForm.Cancelled && (exportForm.JobDetail != null) &&
                            (exportForm.Trigger != null))
                        {
                            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);
                    ITrigger processingJobTrigger = null;

                    if (processingJobDetail != null)
                    {
                        processingJobTrigger = scheduler.GetTriggersOfJob(processingJobKey)[0];
                    }

                    using (UploadJob uploadForm = new UploadJob
                    {
                        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))
                        {
                            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);
                    ITrigger executionJobTrigger = null;

                    if (executionJobDetail != null)
                    {
                        executionJobTrigger = scheduler.GetTriggersOfJob(executionJobKey)[0];
                    }

                    using (ImportJob importForm = new ImportJob
                    {
                        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))
                        {
                            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;

                case SettingsConstants.ProcessingJob:
                    MessageBox.Show(Resources.Processing_monitoring_job_is_not_supported);
                    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);
            }
        }