private void LoadList(string filename, bool suppressError = false) { int i = 0; ObservableCollection <JobDownloadViewModel> batchJob = null; if (filename.ToLower().EndsWith("txt")) { batchJob = new ObservableCollection <JobDownloadViewModel>(); LoadTxt(filename, batchJob); } else if (filename.ToLower().EndsWith("xml")) { batchJob = LoadXml(filename, batchJob); } if (batchJob != null) { foreach (var item in batchJob) { if (!ViewData.Contains(item, new JobDownloadViewModelComparer())) { ViewData.Add(item); ++i; } } } if (i == 0 && !suppressError) { ModernDialog.ShowMessage(string.Format("No job loaded from {0}{1}Either the jobs already loaded or no job in the file.", filename, Environment.NewLine), "Batch Job Loading", MessageBoxButton.OK); } }
private void AddJob(JobDownloadViewModel newJob) { var ok = true; if (newJob.JobType == JobType.Tags) { if (String.IsNullOrWhiteSpace(newJob.SearchTag)) { ModernDialog.ShowMessage("Query String cannot be empty!", "Error", MessageBoxButton.OK); ok = false; } } else if (newJob.JobType == JobType.Image) { if (newJob.ImageId <= 0) { ModernDialog.ShowMessage("Image ID must be larger than 0!", "Error", MessageBoxButton.OK); ok = false; } } else if (newJob.JobType == JobType.Member) { if (newJob.MemberId <= 0) { ModernDialog.ShowMessage("Member ID must be larger than 0!", "Error", MessageBoxButton.OK); ok = false; } } if (ok) { if (ViewData.Contains(newJob, new JobDownloadViewModelComparer())) { MessageBox.Show("Job already exists", "Add Job Warning", MessageBoxButton.OK); } else { ViewData.Add(newJob); if (_jobRunner.BatchStatus == JobStatus.Running) { _jobRunner.DoJob(newJob, cancelToken); newJob.PauseEvent.Set(); MainWindow.Log.Debug(String.Format("Add job {0} in running state.", newJob.Name)); } else if (_jobRunner.BatchStatus == JobStatus.Paused) { newJob.Pause(); _jobRunner.DoJob(newJob, cancelToken); MainWindow.Log.Debug(String.Format("Add job {0} in paused state.", newJob.Name)); } } } }