Exemple #1
0
        public void Add (Job job)
        {
            lock (jobs) {
                lock (job) {
                    if (jobs.Contains (job) || job.HasScheduler) {
                        throw new ArgumentException ("Job not schedulable", "job");
                    }

                    job.HasScheduler = true;
                }

                jobs.Add (job);
                job.State = JobState.Scheduled;
                job.Finished += OnJobFinished;

                if (CanStart (job)) {
                    StartJob (job);
                }
            }

            Action<Job> handler = JobAdded;
            if (handler != null) {
                handler (job);
            }
        }
Exemple #2
0
        public UserJobTile (Job job) : base (3, 2, false)
        {
            this.job = job;
            this.job.Updated += OnJobUpdated;

            BuildWidget ();
            UpdateFromJob ();
        }
Exemple #3
0
        private void RefreshVideos ()
        {
            CancelTasks ();

            if (show_when_ready && !String.IsNullOrEmpty (Query)) {
                refreshing = true;
                yt_context_page.SetState (Banshee.ContextPane.ContextState.Loading);
                refresh_videos_jobs = new RefreshVideosJob (this, Query);
                scheduler.Add (refresh_videos_jobs);
            }
        }
        private void RemoveJob(Job job)
        {
            if (!scheduler.HasAnyDataLossJobs) {
                Respond (Gtk.ResponseType.Ok);
                return;
            }

            if (ListView == null || ListView.Model == null) {
                return;
            }

            for (int i = 0, n = ListView.Model.IterNChildren (); i < n; i++) {
                TreeIter iter;
                if (!ListView.Model.IterNthChild (out iter, i)) {
                    break;
                }

                if (ListView.Model.GetValue (iter, 1) == job) {
                    ThreadAssist.ProxyToMain (delegate {
                        (ListView.Model as ListStore).Remove (ref iter);
                    });
                    break;
                }
            }
        }
 private void AddJob(Job job)
 {
     if (job.Has (PriorityHints.DataLossIfStopped)) {
         ThreadAssist.ProxyToMain (delegate {
             TreeIter iter = (ListView.Model as ListStore).Prepend ();
             (ListView.Model as ListStore).SetValue (iter, 0, job.Title);
             (ListView.Model as ListStore).SetValue (iter, 1, job);
         });
     }
 }
 private void RemoveJob(Job job)
 {
     lock (this) {
         if (job_tiles.ContainsKey (job)) {
             ThreadAssist.AssertInMainThread ();
             UserJobTile tile = job_tiles[job];
             box.Remove (tile);
             job_tiles.Remove (job);
             job_start_times.Remove (job);
         }
     }
 }
        private void AddJob(Job job)
        {
            lock (this) {
                if (job == null || job.IsFinished) {
                    return;
                }

                if ((job.DelayShow && job.Progress < 0.33) || !job.DelayShow) {
                    ThreadAssist.AssertInMainThread ();
                    UserJobTile tile = new UserJobTile (job);
                    job_tiles.Add (job, tile);
                    job_start_times.Add (job, DateTime.Now);
                    box.PackEnd (tile, Easing.QuadraticOut);
                    tile.Show ();
                }
            }
        }
Exemple #8
0
 public void Pause (Job job)
 {
     lock (jobs) {
         if (jobs.Contains (job)) {
             if (job.Pause ()) {
                 // See if any scheduled jobs can now be started
                 Schedule ();
             }
         }
     }
 }
        private void OnJobRemoved(Job job)
        {
            ThreadAssist.ProxyToMain (delegate {
                lock (this) {
                    if (job_start_times.ContainsKey (job)) {
                        double ms_since_added = (DateTime.Now - job_start_times[job]).TotalMilliseconds;
                        if (ms_since_added < 1000) {
                            // To avoid user jobs flasing up and out, don't let any job be visible for less than 1 second
                            Banshee.ServiceStack.Application.RunTimeout ((uint) (1000 - ms_since_added), delegate {
                                RemoveJob (job);
                                return false;
                            });
                            return;
                        }
                    }

                    RemoveJob (job);
                }
            });
        }
Exemple #10
0
        private void AddJob (Job job)
        {
            lock (jobs) {
                if (job == null || (ShowOnlyBackgroundTasks && !job.IsBackground) || job.IsFinished) {
                    return;
                }

                jobs.Add (job);
                job.Updated += OnJobUpdated;
            }

            ThreadAssist.ProxyToMain (Update);
        }
Exemple #11
0
        private void RemoveJob (Job job)
        {
            lock (jobs) {
                if (jobs.Contains (job)) {
                    job.Updated -= OnJobUpdated;
                    jobs.Remove (job);
                }
            }

            ThreadAssist.ProxyToMain (Update);
        }
Exemple #12
0
 private void PreemptJob (Job job)
 {
     job.Preempt ();
 }
Exemple #13
0
        private IEnumerable<Job> ConflictingJobs (Job job)
        {
            if (job.Has (PriorityHints.SpeedSensitive)) {
                // Preempt non-SpeedSensitive jobs that use the same Resource(s)
                return jobs.Where (IsRunning)
                           .Without (PriorityHints.SpeedSensitive)
                           .SharingResourceWith (job);
            } else if (!job.Has (PriorityHints.LongRunning)) {
                // Preempt any LongRunning jobs that use the same Resource(s)
                return jobs.Where (IsRunning)
                           .With (PriorityHints.LongRunning)
                           .SharingResourceWith (job);
            }

            return Enumerable.Empty<Job> ();
        }
Exemple #14
0
 private void StartJob (Job job)
 {
     ConflictingJobs (job).ForEach (PreemptJob);
     job.Start ();
 }
Exemple #15
0
        private bool CanStartJob (Job job, bool pausedJob)
        {
            if (!job.IsScheduled && !(pausedJob && job.IsPaused))
                return false;

            if (job.Has (PriorityHints.SpeedSensitive))
                return true;

            // Run only one non-SpeedSensitive job that uses a given Resource
            if (job.Has (PriorityHints.LongRunning))
                return jobs.Where (IsRunning)
                           .SharingResourceWith (job)
                           .Any () == false;

            // With the exception that non-LongRunning jobs will preempt LongRunning ones
            return jobs.Where (IsRunning)
                       .Without (PriorityHints.LongRunning)
                       .SharingResourceWith (job)
                       .Any () == false;
        }
Exemple #16
0
 private bool CanStart (Job job)
 {
     return CanStartJob (job, false);
 }
Exemple #17
0
 private bool IsRunning (Job job)
 {
     return job.IsRunning;
 }
Exemple #18
0
 public void Resume (Job job)
 {
     lock (jobs) {
         if (jobs.Contains (job) && CanStartJob (job, true)) {
             StartJob (job);
         }
     }
 }
Exemple #19
0
 private void OnJobAdded (Job job)
 {
     AddJob (job);
 }
Exemple #20
0
 public void Cancel (Job job)
 {
     lock (jobs) {
         if (jobs.Contains (job)) {
             // Cancel will call OnJobFinished which will call Schedule
             job.Cancel ();
         }
     }
 }
Exemple #21
0
 private void OnJobRemoved (Job job)
 {
     RemoveJob (job);
 }
        private void OnJobAdded(Job job)
        {
            if (job.IsBackground) {
                return;
            }

            ThreadAssist.ProxyToMain (delegate {
                if (job.DelayShow) {
                    // Give the Job 1 second to become more than 33% complete
                    Banshee.ServiceStack.Application.RunTimeout (1000, delegate {
                        AddJob (job);
                        return false;
                    });
                } else {
                    AddJob (job);
                }
            });
        }