Exemplo n.º 1
0
        /// <summary>
        /// aborts the currently active job
        /// </summary>
        public void Abort()
        {
            Debug.Assert(IsRunning);

            if (currentProcessor != null)
            {
                if (currentJob.Status == JobStatus.ABORTING)
                {
                    return;
                }
                try
                {
                    if (currentJob.Status == JobStatus.PAUSED)
                    {
                        currentProcessor.resume();
                    }
                    currentJob.Status = JobStatus.ABORTING;
                    RefreshAll();
                    currentProcessor.stop();
                }
                catch (JobRunException er)
                {
                    mainForm.Log.LogValue("Error attempting to stop processing", er, ImageType.Error);
                }
                MarkJobAborted();
            }
            status = JobWorkerStatus.Stopped;
            RefreshAll();
        }
Exemplo n.º 2
0
 public void SetRunning()
 {
     if (status == JobWorkerStatus.Stopping)
     {
         status = JobWorkerStatus.Running;
     }
 }
Exemplo n.º 3
0
        private JobStartInfo startNextJobInQueue()
        {
            mainForm.Jobs.ResourceLock.WaitOne(10000, false);

            TaggedJob job = getNextJob();

            if (job == null)
            {
                status = JobWorkerStatus.Idle;
                mainForm.Jobs.ResourceLock.Release();
                return(JobStartInfo.NO_JOBS_WAITING);
            }

            while (job != null)
            {
                if (job.Job.EncodingMode.Equals("audio") && mainForm.Jobs.IsAnyWorkerEncodingAudio)
                {
                    // another audio encoding is already in process. postpone the worker
                    status = JobWorkerStatus.Postponed;
                    mainForm.Jobs.ResourceLock.Release();
                    return(JobStartInfo.NO_JOBS_WAITING);
                }

                if (startEncoding(job)) // successful
                {
                    mainForm.Jobs.ResourceLock.Release();
                    return(JobStartInfo.JOB_STARTED);
                }
                job = getNextJob();
            }
            status = JobWorkerStatus.Idle;
            mainForm.Jobs.ResourceLock.Release();
            return(JobStartInfo.COULDNT_START);
        }
Exemplo n.º 4
0
        /// <summary>
        /// starts the next job in the queue which is available
        /// </summary>
        /// <returns></returns>
        private JobStartInfo StartNextJobInQueue()
        {
            TaggedJob job = GetNextAvailableJob();

            if (job == null)
            {
                status = JobWorkerStatus.Idle;
                RefreshAll();
                return(JobStartInfo.NO_JOBS_WAITING);
            }

            status = JobWorkerStatus.Running;
            RefreshAll();

            if (StartEncoding(job))
            {
                // successfully started
                return(JobStartInfo.JOB_STARTED);
            }
            else
            {
                status = JobWorkerStatus.Idle;
                RefreshAll();
                return(JobStartInfo.COULDNT_START);
            }
        }
Exemplo n.º 5
0
 /// <summary>
 /// aborts the currently active job
 /// </summary>
 public void Abort()
 {
     Debug.Assert(IsEncoding);
     if (currentProcessor == null || currentJob.Status == JobStatus.ABORTING)
     {
         return;
     }
     try
     {
         currentJob.Status = JobStatus.ABORTING;
         refreshAll();
         currentProcessor.stop();
     }
     catch (JobRunException er)
     {
         mainForm.Log.LogValue("Error attempting to stop processing", er, ImageType.Error);
     }
     markJobAborted();
     if (status == JobWorkerStatus.Stopping)
     {
         status = JobWorkerStatus.Stopped;
     }
     else
     {
         status = JobWorkerStatus.Idle;
     }
     refreshAll();
 }
Exemplo n.º 6
0
        public void StartEncoding(bool showMessageBoxes)
        {
            status = JobWorkerStatus.Idle;
            JobStartInfo retval = startNextJobInQueue();

            if (showMessageBoxes)
            {
                if (retval == JobStartInfo.COULDNT_START)
                {
                    MessageBox.Show("Couldn't start processing. Please consult the log for more details", "Processing failed", MessageBoxButtons.OK);
                }
                else if (retval == JobStartInfo.NO_JOBS_WAITING)
                {
                    MessageBox.Show("No jobs are waiting or can be processed at the moment.\r\nOnly one audio job can run at a time and there may be\r\nsome dependencies which have to be fulfilled first.", "No jobs waiting", MessageBoxButtons.OK);
                }
            }
        }
Exemplo n.º 7
0
 /// <summary>
 /// aborts the currently active job
 /// </summary>
 public void Abort()
 {
     Debug.Assert(IsEncoding);
     if (currentProcessor == null)
     {
         return;
     }
     try
     {
         currentProcessor.stop();
     }
     catch (JobRunException er)
     {
         mainForm.addToLog("Error when trying to stop processing: " + er.Message + "\r\n");
     }
     markJobAborted();
     status = JobWorkerStatus.Idle;
     refreshAll();
 }
Exemplo n.º 8
0
        private JobStartInfo startNextJobInQueue()
        {
            TaggedJob job = getNextJob();

            if (job == null)
            {
                status = JobWorkerStatus.Idle;
                return(JobStartInfo.NO_JOBS_WAITING);
            }

            while (job != null)
            {
                if (startEncoding(job)) // successful
                {
                    return(JobStartInfo.JOB_STARTED);
                }
                job = getNextJob();
            }
            status = JobWorkerStatus.Idle;
            return(JobStartInfo.COULDNT_START);
        }
Exemplo n.º 9
0
        public void StartEncoding(bool showMessageBoxes)
        {
            status = JobWorkerStatus.Idle;
            JobStartInfo retval = JobStartInfo.COULDNT_START;

            retval = StartNextJobInQueue();
            if (showMessageBoxes)
            {
                if (retval == JobStartInfo.COULDNT_START)
                {
                    MessageBox.Show("Couldn't start processing. Please consult the log for more details", "Processing failed", MessageBoxButtons.OK);
                }
                else if (retval == JobStartInfo.NO_JOBS_WAITING)
                {
                    MessageBox.Show("No jobs are waiting or can be processed at the moment.", "No jobs waiting", MessageBoxButtons.OK);
                }
            }

            // check if a temporary worker has to be closed
            if (bIsTemporaryWorker && retval != JobStartInfo.JOB_STARTED)
            {
                ShutDown();
            }
        }
Exemplo n.º 10
0
 public void SetStopping()
 {
     Debug.Assert(status == JobWorkerStatus.Running);
     status = JobWorkerStatus.Stopping;
 }
Exemplo n.º 11
0
        /// <summary>
        /// starts the job provided as parameters
        /// </summary>
        /// <param name="job">the Job object containing all the parameters</param>
        /// <returns>success / failure indicator</returns>
        private bool startEncoding(TaggedJob job)
        {
            try
            {
                log = mainForm.Log.Info(string.Format("Log for {0} ({1}, {2} -> {3})", job.Name, job.Job.EncodingMode, job.InputFileName, job.OutputFileName));
                log.LogEvent("Started handling job");
                log.Expand();

                status = JobWorkerStatus.Running;
                //Check to see if output file already exists before encoding.
                if (File.Exists(job.Job.Output) && !mainForm.DialogManager.overwriteJobOutput(job.Job.Output))
                {
                    throw new JobStartException("File exists and the user doesn't want to overwrite", ExceptionType.UserSkip);
                }

                // Get IJobProcessor
                currentProcessor = getProcessor(job.Job);
                if (currentProcessor == null)
                {
                    throw new JobStartException("No processor could be found", ExceptionType.Error);
                }


                // Preprocess
                preprocessJob(job.Job);

                // Setup
                try
                {
                    currentProcessor.setup(job.Job, new StatusUpdate(job.Name), log);
                }
                catch (JobRunException e)
                {
                    throw new JobStartException("Calling setup of processor failed with error '" + e.Message + "'", ExceptionType.Error);
                }

                // Do JobControl setup
                currentProcessor.StatusUpdate += new JobProcessingStatusUpdateCallback(UpdateGUIStatus);

                // Progress window
                pw.setPriority(mainForm.Settings.DefaultPriority);
                if (mainForm.Settings.OpenProgressWindow && mainForm.Visible)
                {
                    this.ShowProcessWindow();
                }

                job.Status  = JobStatus.PROCESSING;
                job.Start   = DateTime.Now;
                status      = JobWorkerStatus.Running;
                pauseStatus = PauseState.Encoding;
                currentJob  = job;

                // Start
                try
                {
                    currentProcessor.start();
                }
                catch (JobRunException e)
                {
                    throw new JobStartException("starting encoder failed with error '" + e.Message + "'", ExceptionType.Error);
                }

                log.LogEvent("Encoding started");
                refreshAll();
                return(true);
            }
            catch (JobStartException e)
            {
                mainForm.Log.LogValue("Error starting job", e);
                if (e.type == ExceptionType.Error)
                {
                    job.Status = JobStatus.ERROR;
                }
                else // ExceptionType.UserSkip
                {
                    job.Status = JobStatus.SKIP;
                }
                currentProcessor = null;
                currentJob       = null;
                status           = JobWorkerStatus.Idle;
                pauseStatus      = PauseState.NotEncoding;
                refreshAll();
                return(false);
            }
        }
Exemplo n.º 12
0
        /// <summary>
        /// updates the actual GUI with the status information received as parameter
        /// If the StatusUpdate indicates that the job has ended, the Progress window is closed
        /// and the logging messages from the StatusUpdate object are added to the log tab
        /// if the job mentioned in the statusupdate has a next job name defined, the job is looked
        /// up and processing of that job starts - this applies even in queue encoding mode
        /// the linked jobs will always be encoded first, regardless of their position in the queue
        /// If we're in queue encoding mode, the next nob in the queue is also started
        /// </summary>
        /// <param name="su">StatusUpdate object containing the current encoder stats</param>
        private void UpdateGUIStatus(StatusUpdate su)
        {
            if (su.IsComplete)
            {
                // so we don't lock up the GUI, we start a new thread
                Thread t = new Thread(new ThreadStart(delegate
                {
                    TaggedJob job = mainForm.Jobs.ByName(su.JobName);

                    copyInfoIntoJob(job, su);
                    progress = 0;
                    HideProcessWindow();

                    // Postprocessing
                    bool jobFailed = (job.Status != JobStatus.PROCESSING);
                    if (!jobFailed)
                    {
                        postprocessJob(job.Job);
                        job.Status = JobStatus.DONE;
                    }

                    currentProcessor = null;
                    currentJob       = null;

                    // Logging
                    log.LogEvent("Job completed");
                    log.Collapse();

                    if (!jobFailed && mainForm.Settings.DeleteCompletedJobs)
                    {
                        mainForm.Jobs.RemoveCompletedJob(job);
                    }
                    else
                    {
                        mainForm.Jobs.saveJob(job, mainForm.MeGUIPath);     //AAA: save state more often
                    }
                    if (shutdownWorkerIfJobsCompleted())
                    {
                    }
                    else if (job.Status == JobStatus.ABORTED)
                    {
                        log.LogEvent("Current job was aborted");
                        status = JobWorkerStatus.Idle;
                    }
                    else if (status == JobWorkerStatus.Stopping)
                    {
                        log.LogEvent("Queue mode stopped");
                        status = JobWorkerStatus.Idle;
                    }
                    else
                    {
                        switch (startNextJobInQueue())
                        {
                        case JobStartInfo.JOB_STARTED:
                            break;

                        case JobStartInfo.COULDNT_START:
                            status = JobWorkerStatus.Idle;
                            break;

                        case JobStartInfo.NO_JOBS_WAITING:
                            status = JobWorkerStatus.Idle;
                            new Thread(delegate()
                            {
                                WorkerFinishedJobs(this, EventArgs.Empty);
                            }).Start();
                            break;
                        }
                    }

                    refreshAll();
                }));
                t.IsBackground = true;
                t.Start();
            }
            else // job is not complete yet
            {
                try
                {
                    if (pw.IsHandleCreated && pw.Visible) // the window is there, send the update to the window
                    {
                        pw.BeginInvoke(new UpdateStatusCallback(pw.UpdateStatus), su);
                    }
                }
                catch (Exception e)
                {
                    mainForm.Log.LogValue("Error trying to update status while a job is running", e, ImageType.Warning);
                }

                progress = su.PercentageDoneExact ?? 0;
                updateProgress();
            }
        }
Exemplo n.º 13
0
 public void SetRunning()
 {
     Debug.Assert(status == JobWorkerStatus.Stopping);
     status = JobWorkerStatus.Running;
 }
Exemplo n.º 14
0
        /// <summary>
        /// starts the job provided as parameters
        /// </summary>
        /// <param name="job">the Job object containing all the parameters</param>
        /// <returns>success / failure indicator</returns>
        private bool startEncoding(TaggedJob job)
        {
            try
            {
                status = JobWorkerStatus.Running;
                //Check to see if output file already exists before encoding.
                if (File.Exists(job.Job.Output) && !mainForm.DialogManager.overwriteJobOutput(job.Job.Output))
                {
                    throw new JobStartException("File exists and the user doesn't want to overwrite", ExceptionType.UserSkip);
                }

                // Get IJobProcessor
                currentProcessor = getProcessor(job.Job);
                if (currentProcessor == null)
                {
                    throw new JobStartException("No processor could be found", ExceptionType.Error);
                }

                addToLog("\r\n\r\n------------------------------------------------------\r\n\r\n");
                addToLog("Starting job " + job.Name + " at " + DateTime.Now.ToLongTimeString() + "\r\n");

                // Preprocess
                preprocessJob(job.Job);

                // Setup
                try
                {
                    currentProcessor.setup(job.Job, new StatusUpdate(job.Name));
                }
                catch (JobRunException e)
                {
                    throw new JobStartException("Calling setup of processor failed with error '" + e.Message + "'", ExceptionType.Error);
                }

                // Do JobControl setup
                //addToLog("encoder commandline:\r\n" + job.Commandline + "\r\n");
                currentProcessor.StatusUpdate += new JobProcessingStatusUpdateCallback(UpdateGUIStatus);

                // Progress window
                pw.setPriority(mainForm.Settings.DefaultPriority);
                if (mainForm.Settings.OpenProgressWindow && mainForm.Visible)
                {
                    this.ShowProcessWindow();
                }

                job.Status  = JobStatus.PROCESSING;
                job.Start   = DateTime.Now;
                status      = JobWorkerStatus.Running;
                pauseStatus = PauseState.Encoding;
                currentJob  = job;

                // Start
                try
                {
                    currentProcessor.start();
                }
                catch (JobRunException e)
                {
                    throw new JobStartException("starting encoder failed with error '" + e.Message + "'", ExceptionType.Error);
                }

                addToLog("successfully started encoding\r\n");
                refreshAll();
                return(true);
            }
            catch (JobStartException e)
            {
                addToLog("Job not started. Reason: " + e.Message + "\r\n");
                if (e.type == ExceptionType.Error)
                {
                    job.Status = JobStatus.ERROR;
                }
                else // ExceptionType.UserSkip
                {
                    job.Status = JobStatus.SKIP;
                }
                currentProcessor = null;
                currentJob       = null;
                status           = JobWorkerStatus.Idle;
                pauseStatus      = PauseState.NotEncoding;
                refreshAll();
                return(false);
            }
        }
Exemplo n.º 15
0
        /// <summary>
        /// updates the actual GUI with the status information received as parameter
        /// If the StatusUpdate indicates that the job has ended, the Progress window is closed
        /// and the logging messages from the StatusUpdate object are added to the log tab
        /// if the job mentioned in the statusupdate has a next job name defined, the job is looked
        /// up and processing of that job starts - this applies even in queue encoding mode
        /// the linked jobs will always be encoded first, regardless of their position in the queue
        /// If we're in queue encoding mode, the next nob in the queue is also started
        /// </summary>
        /// <param name="su">StatusUpdate object containing the current encoder stats</param>
        private void UpdateGUIStatus(StatusUpdate su)
        {
            if (su.IsComplete)
            {
                // so we don't lock up the GUI, we start a new thread
                Thread t = new Thread(new ThreadStart(delegate
                {
                    TaggedJob job = mainForm.Jobs.ByName(su.JobName);

                    copyInfoIntoJob(job, su);
                    progress = 0;
                    //ensureProgressWindowClosed();
                    HideProcessWindow();
                    currentProcessor = null;
                    currentJob       = null;

                    // Logging
                    addToLog("Processing ended at " + DateTime.Now.ToLongTimeString() + "\r\n");
                    addToLog("------------------------------------------------------" +
                             "\r\n\r\nLog for job " + su.JobName + "\r\n\r\n" + su.Log +
                             "\r\n------------------------------------------------------\r\n");

                    // Postprocessing
                    bool jobCompletedSuccessfully = (job.Status == JobStatus.DONE);
                    if (jobCompletedSuccessfully)
                    {
                        postprocessJob(job.Job);
                    }

                    if (jobCompletedSuccessfully && mainForm.Settings.DeleteCompletedJobs)
                    {
                        mainForm.Jobs.RemoveCompletedJob(job);
                    }

                    addToLog("End of log for " + job.Name + "\r\n" +
                             "------------------------------------------------------\r\n\r\n");

                    if (shutdownWorkerIfJobsCompleted())
                    {
                    }
                    else if (job.Status == JobStatus.ABORTED)
                    {
                        addToLog("The current job was aborted. Stopping queue mode\r\n");
                        status = JobWorkerStatus.Idle;
                    }
                    else if (status == JobWorkerStatus.Stopping)
                    {
                        addToLog("Told to stop. Stopping queue mode.\r\n");
                        status = JobWorkerStatus.Idle;
                    }
                    else
                    {
                        switch (startNextJobInQueue())
                        {
                        case JobStartInfo.JOB_STARTED:
                            break;

                        case JobStartInfo.COULDNT_START:
                            status = JobWorkerStatus.Idle;
                            break;

                        case JobStartInfo.NO_JOBS_WAITING:
                            status = JobWorkerStatus.Idle;
                            new Thread(delegate()
                            {
                                WorkerFinishedJobs(this, EventArgs.Empty);
                            }).Start();
                            break;
                        }
                    }

                    refreshAll();
                }));
                t.IsBackground = true;
                t.Start();
            }
            else // job is not complete yet
            {
                try
                {
                    if (pw.IsHandleCreated && pw.Visible) // the window is there, send the update to the window
                    {
                        pw.BeginInvoke(new UpdateStatusCallback(pw.UpdateStatus), su);
                    }
                }
                catch (Exception e)
                {
                    mainForm.addToLog("Exception when trying to update status while a job is running. Text: " + e.Message + " stacktrace: " + e.StackTrace);
                }

                progress = su.PercentageDoneExact ?? 0;
                updateProgress();

                /*
                 * string percentage = (su.PercentageDoneExact ?? 0M).ToString("##.##");
                 * if (percentage.IndexOf(".") != -1 && percentage.Substring(percentage.IndexOf(".")).Length == 1)
                 *  percentage += "0";
                 * mainForm.TitleText = "MeGUI " + su.JobName + " " + percentage + "% ";
                 * if (mainForm.Settings.AfterEncoding == AfterEncoding.Shutdown)
                 *  mainForm.TitleText += "- SHUTDOWN after encode";
                 * this.jobProgress.Value = su.PercentageDone;*/
            }
        }
Exemplo n.º 16
0
        /// <summary>
        /// updates the actual GUI with the status information received as parameter
        /// If the StatusUpdate indicates that the job has ended, the Progress window is closed
        /// and the logging messages from the StatusUpdate object are added to the log tab
        /// if the job mentioned in the statusupdate has a next job name defined, the job is looked
        /// up and processing of that job starts - this applies even in queue encoding mode
        /// the linked jobs will always be encoded first, regardless of their position in the queue
        /// If we're in queue encoding mode, the next nob in the queue is also started
        /// </summary>
        /// <param name="su">StatusUpdate object containing the current encoder stats</param>
        private void UpdateGUIStatus(StatusUpdate su)
        {
            if (su.IsComplete)
            {
                // so we don't lock up the GUI, we start a new thread
                new Thread(new ThreadStart(delegate
                {
                    Job job = mainForm.Jobs.ByName(su.JobName);

                    copyInfoIntoJob(job, su);
                    progress = 0;
                    ensureProgressWindowClosed();
                    currentProcessor = null;
                    currentJob = null;

                    // Logging
                    addToLog("Processing ended at " + DateTime.Now.ToLongTimeString() + "\r\n");
                    addToLog("----------------------" +
                        "\r\n\r\nLog for job " + su.JobName + "\r\n\r\n" + su.Log +
                        "\r\n----------------------\r\n");

                    // Postprocessing
                    bool jobCompletedSuccessfully = (job.Status == JobStatus.DONE);
                    if (jobCompletedSuccessfully)
                        postprocessJob(job);

                    if (jobCompletedSuccessfully && mainForm.Settings.DeleteCompletedJobs)
                        mainForm.Jobs.removeCompletedJob(job);

                    addToLog("End of log for " + job.Name + "\r\n" +
                        "-------------------------------------------------------\r\n\r\n");

                    if (job.Status == JobStatus.ABORTED)
                    {
                        addToLog("The current job was aborted. Stopping queue mode\r\n");
                        status = JobWorkerStatus.Idle;
                    }
                    else if (status == JobWorkerStatus.Stopping)
                    {
                        addToLog("Told to stop. Stopping queue mode.\r\n");
                        status = JobWorkerStatus.Idle;
                    }
                    else
                        startNextJobInQueue();

                    refreshAll();
                })).Start();
            }
            else // job is not complete yet
            {
                try
                {
                    if (pw.IsHandleCreated) // the window is there, send the update to the window
                    {
                        pw.Invoke(new UpdateStatusCallback(pw.UpdateStatus), new object[] { su });
                    }
                }
                catch (Exception e)
                {
                    mainForm.addToLog("Exception when trying to update status while a job is running. Text: " + e.Message + " stacktrace: " + e.StackTrace);
                }

                progress = su.PercentageDone;
                /*
                string percentage = (su.PercentageDoneExact ?? 0M).ToString("##.##");
                if (percentage.IndexOf(".") != -1 && percentage.Substring(percentage.IndexOf(".")).Length == 1)
                    percentage += "0";
                mainForm.TitleText = "MeGUI " + su.JobName + " " + percentage + "% ";
                if (mainForm.Settings.AfterEncoding == AfterEncoding.Shutdown)
                    mainForm.TitleText += "- SHUTDOWN after encode";
                this.jobProgress.Value = su.PercentageDone;*/
            }
        }
Exemplo n.º 17
0
        /// <summary>
        /// starts the job provided as parameters
        /// </summary>
        /// <param name="job">the Job object containing all the parameters</param>
        /// <returns>success / failure indicator</returns>
        private bool startEncoding(Job job)
        {
            Debug.Assert(status == JobWorkerStatus.Idle);

            try
            {
                //Check to see if output file already exists before encoding.
                if (File.Exists(job.Output) && !mainForm.DialogManager.overwriteJobOutput(job.Output))
                    throw new JobStartException("File exists and the user doesn't want to overwrite", ExceptionType.UserSkip);

                // Get IJobProcessor
                currentProcessor = getProcessor(job);
                if (currentProcessor == null)
                    throw new JobStartException("No processor could be found", ExceptionType.Error);

                addToLog("\r\n\r\n------------------------------------------------------\r\n\r\n");
                addToLog("Starting job " + job.Name + " at " + DateTime.Now.ToLongTimeString() + "\r\n");

                // Preprocess
                preprocessJob(job);

                // Setup
                try
                {
                    currentProcessor.setup(job);
                }
                catch (JobRunException e)
                {
                    throw new JobStartException("Calling setup of processor failed with error '" + e.Message + "'", ExceptionType.Error);
                }

                // Do JobControl setup
                addToLog("encoder commandline:\r\n" + job.Commandline + "\r\n");
                currentProcessor.StatusUpdate += new JobProcessingStatusUpdateCallback(UpdateGUIStatus);

                // Progress window
                pw = new ProgressWindow(job.JobType);
                pw.WindowClosed += new WindowClosedCallback(pw_WindowClosed);
                pw.Abort += new AbortCallback(pw_Abort);
                pw.setPriority(job.Priority);
                pw.PriorityChanged += new PriorityChangedCallback(pw_PriorityChanged);
                if (mainForm.Settings.OpenProgressWindow && mainForm.Visible)
                    pw.Show();

                job.Status = JobStatus.PROCESSING;
                job.Start = DateTime.Now;
                status = JobWorkerStatus.Running;
                pauseStatus = PauseState.Encoding;
                currentJob = job;

                // Start
                try
                {
                    currentProcessor.start();
                }
                catch (JobRunException e)
                {
                    throw new JobStartException("starting encoder failed with error '" + e.Message +"'", ExceptionType.Error);
                }

                addToLog("successfully started encoding\r\n");

                refreshAll();
                return true;
            }
            catch (JobStartException e)
            {
                addToLog("Job not started. Reason: " + e.Message + "\r\n");
                if (e.type == ExceptionType.Error)
                    job.Status = JobStatus.ERROR;
                else // ExceptionType.UserSkip
                    job.Status = JobStatus.SKIP;
                currentProcessor = null;
                currentJob = null;
                status = JobWorkerStatus.Idle;
                pauseStatus = PauseState.NotEncoding;
                refreshAll();
                return false;
            }
        }
Exemplo n.º 18
0
        private void JobFinished(StatusUpdate su)
        {
            // so we don't lock up the GUI, we start a new thread
            Thread t = new Thread(new ThreadStart(delegate
            {
                TaggedJob job        = mainForm.Jobs.ByName(su.JobName);
                JobStartInfo JobInfo = JobStartInfo.JOB_STARTED;

                copyInfoIntoJob(job, su);
                progress = 0;
                HideProcessWindow();

                // Postprocessing
                bool jobFailed = (job.Status != JobStatus.PROCESSING);
                if (!jobFailed)
                {
                    PostprocessJob(job.Job);
                    job.Status = JobStatus.DONE;
                }

                currentProcessor = null;
                currentJob       = null;

                // Logging
                if (job.Status == JobStatus.ABORTED)
                {
                    log.LogEvent("Job aborted");
                }
                else
                {
                    log.LogEvent("Job completed");
                }
                log.Collapse();

                if (!jobFailed && mainForm.Settings.WorkerRemoveJob)
                {
                    mainForm.Jobs.RemoveCompletedJob(job);
                }
                else
                {
                    mainForm.Jobs.SaveJob(job, mainForm.MeGUIPath);
                }

                if (job.Status == JobStatus.ABORTED)
                {
                    status  = JobWorkerStatus.Stopped;
                    JobInfo = JobStartInfo.COULDNT_START;
                    if (bIsTemporaryWorker)
                    {
                        ShutDown();
                    }
                }
                else if (status == JobWorkerStatus.Stopping)
                {
                    log.LogEvent("Queue mode stopped");
                    status  = JobWorkerStatus.Stopped;
                    JobInfo = JobStartInfo.COULDNT_START;
                }
                else if (mainForm.Jobs.WorkersCount <= MainForm.Instance.Settings.WorkerMaximumCount || bIsTemporaryWorker)
                {
                    JobInfo = StartNextJobInQueue();
                    switch (JobInfo)
                    {
                    case JobStartInfo.COULDNT_START:
                        if (status != JobWorkerStatus.Postponed)
                        {
                            status = JobWorkerStatus.Idle;
                        }
                        break;

                    case JobStartInfo.NO_JOBS_WAITING:
                        if (status != JobWorkerStatus.Postponed)
                        {
                            status = JobWorkerStatus.Idle;
                        }
                        if (mode == JobWorkerMode.CloseOnLocalListCompleted)
                        {
                            ShutDown();
                        }
                        WorkerFinishedJobs(this, EventArgs.Empty);
                        break;
                    }
                }
                else
                {
                    status = JobWorkerStatus.Idle;
                }

                mainForm.Jobs.AdjustWorkerCount(true);

                if (!mainForm.Jobs.IsAnyJobRunning)
                {
                    MeGUI.core.util.WindowUtil.AllowSystemPowerdown();
                }

                RefreshAll();
            }));

            t.IsBackground = true;
            t.Start();
        }
Exemplo n.º 19
0
 /// <summary>
 /// aborts the currently active job
 /// </summary>
 public void Abort()
 {
     Debug.Assert(IsEncoding);
     if (currentProcessor == null) return;
     try
     {
         currentProcessor.stop();
     }
     catch (JobRunException er)
     {
         mainForm.addToLog("Error when trying to stop processing: " + er.Message + "\r\n");
     }
     markJobAborted();
     status = JobWorkerStatus.Idle;
     refreshAll();
 }