private void AddImportJobMenuItem_Click(object sender, EventArgs e) { try { using (ImportJob form = new ImportJob()) { form.ShowDialog(); if (form.Cancelled || (form.ImportJobDetail == null) || (form.ImportTrigger == null)) { return; } var scheduler = Scheduler.Instance.GetScheduler(); if (scheduler == null) { MessageBox.Show(Resources.No_active_scheduler, Resources.Missing_scheduler); return; } scheduler.ScheduleJob( form.ImportJobDetail, new HashSet <ITrigger> { form.ImportTrigger }, true); if ((form.ExecutionJobDetail != null) && (form.ExecutionTrigger != null)) { scheduler.ScheduleJob( form.ExecutionJobDetail, new HashSet <ITrigger> { form.ExecutionTrigger }, 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); 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); } }
private void AddImportJobMenuItem_Click(object sender, EventArgs e) { try { IJobDetail importJob; ITrigger importTrigger; IJobDetail monitorJob; ITrigger monitorTrigger; if (Properties.Settings.Default.V3Forms) { using ImportJobV3 form = new ImportJobV3(); form.ShowDialog(); if (form.Cancelled || (form.ImportJobDetail == null) || (form.ImportTrigger == null)) { return; } importJob = form.ImportJobDetail; importTrigger = form.ImportTrigger; monitorJob = form.ExecutionJobDetail; monitorTrigger = form.ExecutionTrigger; } else { using ImportJob form = new ImportJob(); form.ShowDialog(); if (form.Cancelled || (form.ImportJobDetail == null) || (form.ImportTrigger == null)) { return; } importJob = form.ImportJobDetail; importTrigger = form.ImportTrigger; monitorJob = form.ExecutionJobDetail; monitorTrigger = form.ExecutionTrigger; } var scheduler = Scheduler.Instance.GetScheduler(); if (scheduler == null) { MessageBox.Show(Resources.No_active_scheduler, Resources.Missing_scheduler); return; } scheduler.ScheduleJob(importJob, new HashSet <ITrigger> { importTrigger }, true); if ((monitorJob != null) && (monitorTrigger != null)) { scheduler.ScheduleJob(monitorJob, new HashSet <ITrigger> { monitorTrigger }, true); } _scheduleChanged = true; RefreshGrid(); } catch (Exception ex) { MessageBox.Show(ex.Message, Resources.Unexpected_error); } }