public void RemoveIf(Func <Subscription, bool> pred) { foreach (var sub in Subs.Where(x => pred(x)).ToList()) { Remove(sub); } }
public void StopAll() { Debug.Assert(Misc.AssertMainThread()); foreach (var sub in Subs.Where(x => x.State == Subscription.EState.Running)) { sub.Stop(); } }
/// <summary>Start all subscriptions that are not already running</summary> public void StartAll() { Debug.Assert(Misc.AssertMainThread()); foreach (var sub in Subs.Where(x => x.State == Subscription.EState.Initial)) { sub.Start(); } }
/// <summary>Add a subscription instance</summary> public async Task Add(Subscription sub) { Debug.Assert(Misc.AssertMainThread()); Debug.Assert(sub.Api == null); sub.Api = Api; // If there are existing subscriptions equal to 'sub' stop and remove them var tasks = Subs.Where(x => Equals(x, sub)).Select(x => Remove(x)); await Task.WhenAll(tasks); // Add 'sub' to the collection Subs.Add(sub); await sub.Start(); }
/// <summary>Add a subscription instance</summary> public void Add(Subscription sub) { Debug.Assert(Misc.AssertMainThread()); Debug.Assert(sub.Api == null); sub.Api = Api; // If there are existing subscriptions equal to 'sub' stop and remove them var existing = Subs.Where(x => Equals(x, sub)).ToList(); foreach (var s in existing) { Remove(s); } // Add 'sub' to the collection Subs.Add(sub); sub.Start(); }
public async Task SetSubtitles() { if (Status != SubSetStatus.Idle) { throw new Exception(); } await Task.Run(() => { Status = SubSetStatus.Analize; StatusMessage = "Analizing"; var allFiles = Directory.GetFiles("*.*", SearchOption.AllDirectories); RunStatic(); foreach (var file in allFiles) { if (MovieExtensions.Any(e => e == file.Extension)) { Movies.Add(new FileMovie(file)); } if (SubExtensions.Any(e => e == file.Extension)) { Subs.Add(new FileSubtitle(file)); } if (FontExtensions.Any(e => e == file.Extension)) { Fonts.Add(new FileFont(file)); } } if (!Setting.SearchMovieInSubdir) { Movies = Movies.Where(movie => movie.DirectoryPath == Directory.FullName).ToList(); } if (!Setting.SearchSubInSubdir) { Subs = Subs.Where(sub => sub.DirectoryPath == Directory.FullName).ToList(); } StatusPercent = 10; foreach (var fontFile in Fonts) { fontFile.Install(); } StatusPercent = 20; SetEpizodes(Subs); StatusPercent = 50; SetEpizodes(Movies); StatusPercent = 80; foreach (var sub in Subs) { sub.Movie = Movies.FirstOrDefault(m => m.Epizode == sub.Epizode && sub.Path.Contains(m.DirectoryPath)); } StatusPercent = 90; StatusPercent = 0; Status = SubSetStatus.SettingSub; StatusMessage = "RenamingSubs"; for (int i = 0; i < Subs.Count; i++) { var sub = Subs[i]; if (sub.Movie == null) { continue; } var subPath = Path.Combine(sub.Movie.DirectoryPath, sub.Movie.PureName + sub.Extension); if (File.Exists(subPath)) { continue; } sub.Info.MoveTo(subPath); StatusPercent = (byte)(i * 100 / Subs.Count); } Status = SubSetStatus.Completed; StatusPercent = 100; StatusMessage = "Completed"; }); }
public async Task RemoveIf(Func <Subscription, bool> pred) { var tasks = Subs.Where(x => pred(x)).Select(x => Remove(x)); await Task.WhenAll(tasks); }
public async Task StopAll() { Debug.Assert(Misc.AssertMainThread()); var tasks = Subs.Where(x => x.State == Subscription.EState.Running).Select(x => x.Stop()); await Task.WhenAll(tasks); }