示例#1
0
        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);
        }
示例#2
0
        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);
                }
            }
        }
示例#3
0
        /// <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);
        }
示例#4
0
 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);
 }
示例#5
0
 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();
 }
示例#6
0
        private void deleteAllDependantJobs(TaggedJob job)
        {
            reallyDeleteJob(job);

            foreach (TaggedJob j in job.EnabledJobs)
            {
                deleteAllDependantJobs(j);
            }
        }
示例#7
0
        /// <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);
        }
示例#8
0
        /// <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);
            }
        }
示例#9
0
        /// <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);
        }
示例#10
0
        /// <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);
            }
        }
示例#11
0
        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);
                }
            }
        }
示例#12
0
        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();
        }
示例#13
0
 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);
     }
 }
示例#14
0
        /// <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();
        }
示例#15
0
        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;
            }
        }
示例#16
0
        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;
            }
        }
示例#17
0
 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);
 }
示例#18
0
 /// <summary>
 /// Unassigns a Job
 /// </summary>
 /// <param name="j"></param>
 public void UnassignJob(TaggedJob j)
 {
     j.OwningWorker = null;
 }
示例#19
0
        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();
        }
示例#20
0
 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();
 }
示例#21
0
 /// <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;
 }
示例#22
0
 internal bool HasJob(TaggedJob job)
 {
     return jobs.ContainsKey(job.Name);
 }
示例#23
0
 internal override void MakeJobDependOnChain(TaggedJob allowedEnd)
 {
     allowedEnd.AddDependency(j);
 }
示例#24
0
 internal override void MakeJobDependOnChain(TaggedJob allowedEnd)
 {
 }
示例#25
0
 internal override void MakeJobDependOnChain(TaggedJob allowedEnd)
 {
     allowedEnd.AddDependency(j);
 }
示例#26
0
 internal JobDependencyChain(Job j)
 {
     this.j = new TaggedJob(j);
     jobs = new TaggedJob[] { this.j };
 }
示例#27
0
 /// <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);
 }
示例#28
0
 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;
 }
示例#29
0
        /// <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);
        }
示例#30
0
 private void addJob(TaggedJob job)
 {
     job.Name          = getFreeJobName();
     allJobs[job.Name] = job;
     jobQueue.enqueueJob(job);
 }
示例#31
0
        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();
        }
示例#32
0
 internal JobDependencyChain(Job j)
 {
     this.j = new TaggedJob(j);
     jobs   = new TaggedJob[] { this.j };
 }
示例#33
0
        /// <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);
        }
示例#34
0
 internal override void MakeJobDependOnChain(TaggedJob allowedEnd)
 {
 }
示例#35
0
        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();
        }