private void reallyDeleteJob(TaggedJob job) { if (job.Status == JobStatus.PROCESSING) { return; } if (job.OwningWorker != null) { workers[job.OwningWorker].RemoveJobFromQueue(job); } if (jobQueue.HasJob(job)) { jobQueue.removeJobFromQueue(job); } foreach (TaggedJob j in job.EnabledJobs) { j.RequiredJobs.Remove(job); } string fileName = mainForm.MeGUIPath + "\\jobs\\" + job.Name + ".xml"; if (File.Exists(fileName)) { File.Delete(fileName); } allJobs.Remove(job.Name); }
private void deleteAllJobsButton_Click(object sender, EventArgs e) { int incompleteJobs = 0; DialogResult dr = DialogResult.No; TaggedJob[] jobList = new TaggedJob[allJobs.Count]; allJobs.Values.CopyTo(jobList, 0); foreach (TaggedJob j in jobList) { if (j.Status != JobStatus.DONE) { ++incompleteJobs; } } if (incompleteJobs != 0) { dr = MessageBox.Show("Delete incomplete jobs as well?\n\nYes for All, No for completed or Cancel to abort:", "Are you sure you want to clear the queue?", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question); if (dr == DialogResult.Cancel) { return; } } foreach (TaggedJob j in jobList) { if (dr == DialogResult.Yes || j.Status == JobStatus.DONE) { reallyDeleteJob(j); } } }
/// <summary> /// saves a job to programdirectory\jobs\jobname.xml /// using the XML Serializer we get a humanly readable file /// </summary> /// <param name="job">the Job object to be saved</param> /// <param name="path">The path where the program was launched from</param> internal void saveJob(TaggedJob job, string path) { string fileName = Path.Combine(path, "jobs"); fileName = Path.Combine(fileName, job.Name + ".xml"); Util.XmlSerialize(job, fileName); }
public void AddDependency(TaggedJob other) { // we can't have each job depending on the other Debug.Assert(!other.RequiredJobs.Contains(this)); RequiredJobs.Add(other); other.EnabledJobs.Add(this); }
private void addJob(TaggedJob job) { mainForm.Jobs.ResourceLock.WaitOne(10000, false); job.Name = getFreeJobName(); allJobs[job.Name] = job; jobQueue.queueJob(job); mainForm.Jobs.ResourceLock.Release(); }
private void deleteAllDependantJobs(TaggedJob job) { reallyDeleteJob(job); foreach (TaggedJob j in job.EnabledJobs) { deleteAllDependantJobs(j); } }
/// <summary> /// Returns whether all the jobs that j depends on have been successfully completed /// </summary> /// <param name="j"></param> /// <returns></returns> internal bool areDependenciesMet(TaggedJob j) { foreach (TaggedJob job in j.RequiredJobs) { if (job.Status != JobStatus.DONE && job.Status != JobStatus.SKIP) { return(false); } } return(true); }
/// <summary> /// force deletion of the selected job without dependencies /// </summary> /// <param name="job">job to delete</param> private void ReallyDeleteJob(TaggedJob job) { if (job.Status == JobStatus.PROCESSING || job.Status == JobStatus.PAUSED || job.Status == JobStatus.ABORTING) { return; } if (job.Status != JobStatus.DONE && MainForm.Instance.Settings.DeleteIntermediateFiles) { List <string> filesToDelete = new List <string>(); if (job.Job.FilesToDelete.Count > 0) { filesToDelete.AddRange(job.Job.FilesToDelete); } if (filesToDelete.Count > 0) { LogItem oLog = FileUtil.DeleteIntermediateFiles(filesToDelete, false, true); if (oLog != null) { LogItem log = mainForm.Log.Info(string.Format("Log for {0} ({1}, {2} -> {3})", job.Name, job.Job.EncodingMode, job.InputFileName, job.OutputFileName)); log.Add(oLog); } } } lock (mainForm.Jobs.ResourceLock) { if (globalJobQueue.HasJob(job)) { globalJobQueue.RemoveJobFromQueue(job); } foreach (TaggedJob p in job.RequiredJobs) { p.EnabledJobs.Remove(job); } foreach (TaggedJob j in job.EnabledJobs) { j.RequiredJobs.Remove(job); } string fileName = Path.Combine(mainForm.MeGUIPath, "jobs"); fileName = Path.Combine(fileName, job.Name + ".xml"); if (File.Exists(fileName)) { File.Delete(fileName); } allJobs.Remove(job.Name); } }
/// <summary> /// loads all the jobs from the harddisk /// upon loading, the jobs are ordered according to their position field /// so that the order in which the jobs were previously shown in the GUI is preserved /// </summary> public void LoadJobs() { string jobsPath = Path.Combine(mainForm.MeGUIPath, "jobs"); DirectoryInfo di = FileUtil.ensureDirectoryExists(jobsPath); FileInfo[] files = di.GetFiles("*.xml"); foreach (FileInfo fi in files) { string fileName = fi.FullName; TaggedJob job = LoadJob(fileName); if (job != null && job.Name != null) { if (allJobs.ContainsKey(job.Name)) { MessageBox.Show("A job named " + job.Name + " is already in the queue.\nThe job defined in " + fileName + "\nwill be discarded", "Duplicate job name detected", MessageBoxButtons.OK, MessageBoxIcon.Warning); } else { allJobs.Add(job.Name, job); } } } foreach (TaggedJob job in allJobs.Values) { if (job.Status == JobStatus.PROCESSING || job.Status == JobStatus.PAUSED || job.Status == JobStatus.ABORTING) { job.Status = JobStatus.ABORTED; } job.RequiredJobs = ToJobList(job.RequiredJobNames); job.EnabledJobs = ToJobList(job.EnabledJobNames); } string path = Path.Combine(mainForm.MeGUIPath, "joblists.xml"); JobListSerializer s = Util.XmlDeserializeOrDefault <JobListSerializer>(path); globalJobQueue.JobList = ToJobList(s.mainJobList); foreach (TaggedJob job in allJobs.Values) { if (globalJobQueue.HasJob(job)) { continue; } globalJobQueue.QueueJob(job); } AdjustWorkerCount(false); }
/// <summary> /// delete also all dependent jobs /// </summary> /// <param name="job">job to delete</param> private void DeleteAllDependantJobs(TaggedJob job) { ReallyDeleteJob(job); foreach (TaggedJob j in job.EnabledJobs) { DeleteAllDependantJobs(j); } foreach (TaggedJob j in job.RequiredJobs) { DeleteAllDependantJobs(j); } }
private void deleteAllJobsButton_Click(object sender, EventArgs e) { DialogResult dr = MessageBox.Show("Are you sure you want to clear the queue? This will delete all jobs in all workers.", "Are you sure?", MessageBoxButtons.YesNo, MessageBoxIcon.Question); if (dr == DialogResult.Yes) { TaggedJob[] jobList = new TaggedJob[allJobs.Count]; allJobs.Values.CopyTo(jobList, 0); foreach (TaggedJob j in jobList) { reallyDeleteJob(j); } } }
internal void ReleaseJob(TaggedJob j) { if (j.OwningWorker == null) { return; } workers[j.OwningWorker].RemoveJobFromQueue(j); j.OwningWorker = null; if (!jobQueue.HasJob(j)) { jobQueue.enqueueJob(j); } refresh(); }
private void AddJob(TaggedJob job) { lock (mainForm.Jobs.ResourceLock) { int jobNr = 1; string name = ""; while (true) { name = "job" + jobNr; if (!allJobs.ContainsKey(name)) { job.Name = name; break; } jobNr++; } allJobs[job.Name] = job; globalJobQueue.QueueJob(job); } }
/// <summary> /// loads all the jobs from the harddisk /// upon loading, the jobs are ordered according to their position field /// so that the order in which the jobs were previously shown in the GUI is preserved /// </summary> public void loadJobs() { string jobsPath = mainForm.MeGUIPath + "\\jobs\\"; if (!Directory.Exists(jobsPath)) { Directory.CreateDirectory(jobsPath); } DirectoryInfo di = new DirectoryInfo(mainForm.MeGUIPath + "\\jobs\\"); FileInfo[] files = di.GetFiles("*.xml"); foreach (FileInfo fi in files) { string fileName = fi.FullName; TaggedJob job = loadJob(fileName); if (job != null) { if (allJobs.ContainsKey(job.Name)) { MessageBox.Show("A job named " + job.Name + " is already in the queue.\nThe job defined in " + fileName + "\nwill be discarded", "Duplicate job name detected", MessageBoxButtons.OK, MessageBoxIcon.Warning); } else { allJobs.Add(job.Name, job); } } } foreach (TaggedJob job in allJobs.Values) { if (job.Status == JobStatus.PROCESSING) { job.Status = JobStatus.ABORTED; } job.RequiredJobs = toJobList(job.RequiredJobNames); job.EnabledJobs = toJobList(job.EnabledJobNames); } loadJobLists(); }
internal void DeleteJob(TaggedJob job) { if (job.Status == JobStatus.PROCESSING) { MessageBox.Show("You cannot delete a job while it is being processed.", "Deleting job failed", MessageBoxButtons.OK); return; } if (job.EnabledJobs.Count == 0) { reallyDeleteJob(job); return; } DialogResult dr = MessageBox.Show("Some jobs depend on the job, '" + job.Name + "' being completed for them to run. Do you want to delete all dependant jobs? " + "Press Yes to delete all dependant jobs, No to delete this job and " + "remove the dependencies, or Cancel to abort", "Job dependency detected", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Warning); switch (dr) { case DialogResult.Yes: // Delete all dependent jobs deleteAllDependantJobs(job); break; case DialogResult.No: // Just delete the single job reallyDeleteJob(job); break; case DialogResult.Cancel: // do nothing break; } }
internal void DeleteJob(TaggedJob job) { if (job.Status == JobStatus.PROCESSING || job.Status == JobStatus.ABORTING) { MessageBox.Show("You cannot delete a job while it is being processed.", "Deleting " + job.Name + " failed", MessageBoxButtons.OK, MessageBoxIcon.Stop); return; } if (job.EnabledJobs.Count == 0 && job.RequiredJobs.Count == 0) { reallyDeleteJob(job); return; } DialogResult dr = MessageBox.Show("'" + job.Name + "' is related to a job series. Do you want to delete all related jobs?\r\n" + "Press Yes to delete all related jobs, No to delete this job and " + "remove the dependencies, or Cancel to abort", "Job dependency detected", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Warning); switch (dr) { case DialogResult.Yes: // Delete all dependent jobs deleteAllDependantJobs(job); break; case DialogResult.No: // Just delete the single job reallyDeleteJob(job); break; case DialogResult.Cancel: // do nothing break; } }
/// <summary> /// Unassigns a Job /// </summary> /// <param name="j"></param> public void UnassignJob(TaggedJob j) { j.OwningWorker = null; }
internal void removeJobFromQueue(TaggedJob job) { if (InvokeRequired) { Invoke(new MethodInvoker(delegate { removeJobFromQueue(job); })); return; } queueListView.Items[indexOf(job)].Remove(); jobs.Remove(job.Name); queueListView.Refresh(); }
private int indexOf(TaggedJob j) { Debug.Assert(jobs.ContainsKey(j.Name), "Looking for a job which isn't in the jobs dictionary"); foreach (ListViewItem i in queueListView.Items) { if (i.Text == j.Name) { int index = i.Index; Debug.Assert(index >= 0); return index; } } Debug.Assert(false, "Couldn't find job in the GUI queue"); throw new Exception(); }
/// <summary> /// Assigns a Job /// </summary> /// <param name="j">the job to assign</param> /// <param name="WorkerName">the worker to assign the job to</param> public void AssignJob(TaggedJob j, string WorkerName) { j.OwningWorker = WorkerName; }
internal bool HasJob(TaggedJob job) { return jobs.ContainsKey(job.Name); }
internal override void MakeJobDependOnChain(TaggedJob allowedEnd) { allowedEnd.AddDependency(j); }
internal override void MakeJobDependOnChain(TaggedJob allowedEnd) { }
internal JobDependencyChain(Job j) { this.j = new TaggedJob(j); jobs = new TaggedJob[] { this.j }; }
/// <summary> /// removes this job, and any previous jobs that belong to a series of jobs from the /// queue, then update the queue positions /// </summary> /// <param name="job">the job to be removed</param> internal void RemoveCompletedJob(TaggedJob job) { reallyDeleteJob(job); }
private List<TaggedJob> removeAllDependantJobsFromQueue(TaggedJob job) { removeJobFromQueue(job); List<TaggedJob> list = new List<TaggedJob>(); foreach (TaggedJob j in job.EnabledJobs) { if (jobs.ContainsKey(j.Name)) list.AddRange(removeAllDependantJobsFromQueue(j)); else list.Add(j); } return list; }
/// <summary> /// saves a job to programdirectory\jobs\jobname.xml /// using the XML Serializer we get a humanly readable file /// </summary> /// <param name="job">the Job object to be saved</param> /// <param name="path">The path where the program was launched from</param> internal void saveJob(TaggedJob job, string path) { string fileName = path + "\\jobs\\" + job.Name + ".xml"; Util.XmlSerialize(job, fileName); }
private void addJob(TaggedJob job) { job.Name = getFreeJobName(); allJobs[job.Name] = job; jobQueue.enqueueJob(job); }
private void reallyDeleteJob(TaggedJob job) { if (job.Status == JobStatus.PROCESSING || job.Status == JobStatus.ABORTING) { return; } if (job.Status != JobStatus.DONE && MainForm.Instance.Settings.DeleteIntermediateFiles) { List <string> filesToDelete = new List <string>(); if (job.Job.FilesToDelete.Count > 0) { filesToDelete.AddRange(job.Job.FilesToDelete); } if (job.Job is CleanupJob && ((CleanupJob)job.Job).files.Count > 0) { filesToDelete.AddRange(((CleanupJob)job.Job).files); } if (filesToDelete.Count > 0) { LogItem oLog = FileUtil.DeleteIntermediateFiles(filesToDelete, false, true); if (oLog != null) { LogItem log = mainForm.Log.Info(string.Format("Log for {0} ({1}, {2} -> {3})", job.Name, job.Job.EncodingMode, job.InputFileName, job.OutputFileName)); log.Add(oLog); } } } mainForm.Jobs.ResourceLock.WaitOne(10000, false); if (job.OwningWorker != null && workers.ContainsKey(job.OwningWorker)) { workers[job.OwningWorker].RemoveJobFromQueue(job); } if (jobQueue.HasJob(job)) { jobQueue.removeJobFromQueue(job); } foreach (TaggedJob p in job.RequiredJobs) { p.EnabledJobs.Remove(job); } foreach (TaggedJob j in job.EnabledJobs) { j.RequiredJobs.Remove(job); } string fileName = Path.Combine(mainForm.MeGUIPath, "jobs"); fileName = Path.Combine(fileName, job.Name + ".xml"); if (File.Exists(fileName)) { File.Delete(fileName); } allJobs.Remove(job.Name); mainForm.Jobs.ResourceLock.Release(); }
/// <summary> /// saves a job to programdirectory\jobs\jobname.xml /// using the XML Serializer we get a humanly readable file /// </summary> /// <param name="job">the Job object to be saved</param> /// <param name="path">The path where the program was launched from</param> public void SaveJob(TaggedJob job, string path) { string fileName = Path.Combine(Path.Combine(path, "jobs"), job.Name + ".xml"); Util.XmlSerialize(job, fileName); }
internal void enqueueJob(TaggedJob j) { if (InvokeRequired) { Invoke(new MethodInvoker(delegate { enqueueJob(j); })); return; } queueListView.Items.Add(new ListViewItem(new string[] { j.Name, "", "", "", "", "", "", "", "", "" })); jobs[j.Name] = j; refreshQueue(); }