private void Start(int pThreads)
 {
     Task.Run(() => {
         Parallel.For(0, pThreads, (i) => {
             while (true)
             {
                 MeltJob objJob = Queue.Take();
                 if (
                     objJob.Status == JobStatus.Scheduled ||
                     objJob.Status == JobStatus.Paused
                     )
                 {
                     if (Running.TryAdd(objJob.Project.ID.ToString(), objJob))
                     {
                         StartJob(objJob);
                     }
                     else
                     {
                         Queue.Add(objJob);
                     }
                 }
             }
         });
     });
 }
 public bool Equals(MeltJob pJob)
 {
     return
         (pJob != null &&
          Percentage.Equals(pJob.Percentage) &&
          Status.Equals(pJob.Status) &&
          TimeTaken.Equals(pJob.TimeTaken));
 }
 public void Schedule(MeltJob pJob)
 {
     if (Paused.ContainsKey(pJob.Project.ID.ToString()))
     {
         if (Paused.TryRemove(pJob.Project.ID.ToString(), out MeltJob objJob))
         {
             objJob.Scheduled();
             Queue.Add(objJob);
         }
     }
     else
     {
         pJob.Scheduled();
         Queue.Add(pJob);
     }
 }
Beispiel #4
0
        public MLTProject(string pFullPath, VideoInfoProvider pVideoInfoCache)
        {
            VideoInfoProvider = pVideoInfoCache;
            ID = Guid.NewGuid();
            Directory.CreateDirectory(Path.Combine(Settings.TempDirectory, ID.ToString()));

            _objProjectFile = new FileInfo(pFullPath);

            Config = new MeltConfig(this, VideoInfoProvider);
            if (TargetExists)
            {
                _objTargetInfo = VideoInfoProvider.Get(TargetPath);
            }
            if (SourceExists)
            {
                _objSourceInfo = VideoInfoProvider.Get(SourcePath);
            }

            Job = new MeltJob(this); // -- ToDo: pass null or the config for the job, not the project itself
            Job.ProgressChanged += (object sender, System.EventArgs e) => {
                ProjectChanged?.Invoke(sender, this);
            };
            Job.StatusChanged += (object sender, JobStatus e) => {
                Log.Info("Project was changed - notify everyone");
                switch (e)
                {
                case JobStatus.Failed:
                case JobStatus.Success:
                    Reload();
                    break;

                case JobStatus.Paused:
                case JobStatus.Running:
                case JobStatus.Scheduled:
                case JobStatus.UnScheduled:
                    break;
                }
                ProjectChanged?.Invoke(sender, this);
            };
        }
        private void StartJob(MeltJob pJob)
        {
            pJob.StatusChanged += (sender, e) => {
                switch (e)
                {
                case JobStatus.Failed:
                case JobStatus.Success:
                    if (Running.ContainsKey(pJob.Project.ID.ToString()))
                    {
                        Running.TryRemove(pJob.Project.ID.ToString(), out _);
                    }
                    break;

                case JobStatus.Paused:
                    if (Running.ContainsKey(pJob.Project.ID.ToString()))
                    {
                        Running.TryRemove(pJob.Project.ID.ToString(), out _);
                    }
                    Paused.TryAdd(pJob.Project.ID.ToString(), pJob);
                    break;

                case JobStatus.UnScheduled:
                    if (Paused.ContainsKey(pJob.Project.ID.ToString()))
                    {
                        Paused.TryRemove(pJob.Project.ID.ToString(), out _);
                    }
                    if (Running.ContainsKey(pJob.Project.ID.ToString()))
                    {
                        Running.TryRemove(pJob.Project.ID.ToString(), out _);
                    }
                    break;

                case JobStatus.Running:
                case JobStatus.Scheduled:
                    break;
                }
            };
            pJob.Start().Wait();
        }
 public static bool Equals(MeltJob obj1, MeltJob obj2)
 {
     return(obj1 == obj2 || obj1 != null && obj1.Equals(obj2)); // compare reference/value(null)
 }