public override void TryDeleteResult(IParallelTask _task)
        {
            FileEncodeTask task = (FileEncodeTask)_task;

            Utility.TryDeleteFile(task.TargetFilename);
            Utility.TryDeleteEmptyFoldersToTheRoot(Path.GetDirectoryName(task.TargetFilename));
        }
        public IEncoder CreateEncoder(int threadNumber, IParallelTask _task)
        {
            if (_task is ReplayGainTask)
            {
                ReplayGainTask task = (ReplayGainTask)_task;
                return new ReplayGainTagEncoder(task);
            }
            else if (_task is FileEncodeTask)
            {
                FileEncodeTask task = (FileEncodeTask)_task;
                IAudioSource audioSource = task.AudioSourceLazy();
                if (audioSource == null)
                {
                    throw new SkipEncodingItemException("Unsupported audio format.");
                }
                if (this.CalculateReplayGain)
                {
                    task.TrackGain = DspHelper.CreateTrackGain(audioSource);
                }
                if (this.CalculateDynamicRange)
                {
                    task.DrMeter = DspHelper.CreateDrMeter(audioSource);
                }
                return new DspCalculatorEncoder(audioSource, task.TrackGain, task.DrMeter);
            }

            throw new NotSupportedException();
        }
Example #3
0
        public IEncoder CreateEncoder(int threadNumber, IParallelTask _task)
        {
            if (_task is ReplayGainTask)
            {
                ReplayGainTask task = (ReplayGainTask)_task;
                return(new ReplayGainTagEncoder(task));
            }
            else if (_task is FileEncodeTask)
            {
                FileEncodeTask task        = (FileEncodeTask)_task;
                IAudioSource   audioSource = task.AudioSourceLazy();
                if (audioSource == null)
                {
                    throw new SkipEncodingItemException("Unsupported audio format.");
                }
                if (this.CalculateReplayGain)
                {
                    task.TrackGain = DspHelper.CreateTrackGain(audioSource);
                }
                if (this.CalculateDynamicRange)
                {
                    task.DrMeter = DspHelper.CreateDrMeter(audioSource);
                }
                return(new DspCalculatorEncoder(audioSource, task.TrackGain, task.DrMeter));
            }

            throw new NotSupportedException();
        }
Example #4
0
        private void ExecuteTasks()
        {
            while (_isRunning)
            {
                try
                {
                    if (TaskQueue.Count == 0)
                    {
                        TaskQueue.LoadTasks();
                        Thread.Sleep(_sleepInterval);
                    }
                    else
                    {
                        if (_runningTaskCount < Setting.MaxTaskCount)
                        {
                            Interlocked.Increment(ref _runningTaskCount);

                            Task.Factory.StartNew <ParallelTaskResult>(() =>
                            {
                                IParallelTask _task = null;
                                if (TaskQueue.TryDequeue(out _task))
                                {
                                    return(_task.Execute());
                                }
                                else
                                {
                                    return(null);
                                }
                            })
                            .ContinueWith <ParallelTaskResult>(t =>
                            {
                                if (t.IsFaulted)
                                {
                                    t.Result.Task.OnException(t.Result, t.Exception);
                                }

                                Interlocked.Decrement(ref _runningTaskCount);
                                return(t.Result);
                            });
                        }
                        else
                        {
                            Thread.Sleep(_sleepInterval);
                        }
                    }
                }
                catch
                {
                    //keep thread was not aborted.
                }
            }

            while (_runningTaskCount > 0)
            {
                Thread.Sleep(_sleepInterval);
            }
        }
Example #5
0
        public static void Enqueue(IParallelTask task)
        {
            string taskType = task.GetType().FullName;

            if (!_pool.ContainsKey(taskType))
            {
                throw new IndexOutOfRangeException(string.Format("The Task Queue to {0} no exists.", taskType));
            }
            if (!_pool[taskType].Contains(task))
            {
                _pool[taskType].TryAdd(task);
            }
        }
 public IEncoder CreateEncoder(int threadNumber, IParallelTask _task)
 {
     FileEncodeTask task = (FileEncodeTask)_task;
     IAudioSource audioSource = this.SetupTask(task);
     try
     {
         return this.CreateEncoderInternal(threadNumber, task, audioSource);
     }
     catch
     {
         if (audioSource != null)
         {
             audioSource.Close();
         }
         throw;
     }
 }
        public IEncoder CreateEncoder(int threadNumber, IParallelTask _task)
        {
            FileEncodeTask task        = (FileEncodeTask)_task;
            IAudioSource   audioSource = this.SetupTask(task);

            try
            {
                return(this.CreateEncoderInternal(threadNumber, task, audioSource));
            }
            catch
            {
                if (audioSource != null)
                {
                    audioSource.Close();
                }
                throw;
            }
        }
        public EncoderController(IParallelTask[] tasks, int concurrency)
        {
            this.DeleteSuccessfullyEncodedItemsIfFailure = true;
            this.Tasks = tasks;

            this.tasksRemaining = new BlockingCollection<IParallelTask>();
            foreach (IParallelTask task in this.Tasks)
            {
                this.tasksRemaining.Add(task);
            }

            this.workerTasks = new Task[concurrency];
            for (int i = 0; i < this.workerTasks.Length; ++i)
            {
                this.workerTasks[i] = new Task(WorkerTask, i, TaskCreationOptions.LongRunning);
            }
            this.workersCompletedTask = Task.Factory.ContinueWhenAll(workerTasks, WorkersCompleted);

            this.Status = EncoderControllerStatus.NotStarted;
        }
Example #9
0
        private void UpdateUI()
        {
            this.textStatus.Text   = "Encoding";
            this.progressBar.Value = this.controller.Tasks.Select(t => t.Progress).Average();

            for (int i = 0; i < this.controller.Tasks.Length; ++i)
            {
                EncodingItemView view = this.viewItems[i];
                IParallelTask    task = this.controller.Tasks[i];

                string statusString = task.Status == EncodeTaskStatus.Processing ? "" : task.Status.ToString();
                if (checkScrollLock.IsChecked != true && view.Status != statusString)
                {
                    this.listTasks.ScrollIntoView(view);
                }

                view.Progress           = this.controller.Tasks[i].Progress;
                view.ProgressVisibility = this.controller.Tasks[i].Status == EncodeTaskStatus.Processing ? Visibility.Visible : Visibility.Collapsed;
                view.Status             = statusString;
            }
        }
 public override void TryDeleteResult(IParallelTask _task)
 {
     FileEncodeTask task = (FileEncodeTask)_task;
     Utility.TryDeleteFile(task.TargetFilename);
     Utility.TryDeleteEmptyFoldersToTheRoot(Path.GetDirectoryName(task.TargetFilename));
 }
 public void TryDeleteResult(IParallelTask _task)
 {
 }
Example #12
0
 public void TryDeleteResult(IParallelTask _task)
 {
 }
Example #13
0
 /// <summary>
 /// 任务事件参数构造方法
 /// </summary>
 /// <param name="t"></param>
 public TaskArgs(IParallelTask t, IParallelTaskContext context, object state)
 {
     this.Task    = t;
     this.Context = context;
     this.State   = state;
 }
 public abstract void TryDeleteResult(IParallelTask task);
 public abstract void TryDeleteResult(IParallelTask task);