/// <summary> /// Updates database if it hasnt been updated in the last day and autodownloads every Series that has autodownload enabled /// </summary> /// <returns></returns> public async static Task Update() { if (Settings.LastCheck.AddDays(1).Date <= DateTime.Now.Date) { await Task.Run(async() => { List <int> ids = Series.GetUpdates(Settings.LastCheck); List <Series> series = Database.GetSeries(); ids = ids.Where(x => series.Any(y => y.id == x)).ToList(); foreach (int id in ids) { await UpdateFullSeries(id); } }); await DownloadLastWeek(); Settings.LastCheck = DateTime.Now; } await Renamer.ScanAndRename(Database.GetSeries()); }
/// <summary> /// Creates database from ids provided USAGE: await CreateDatabase(...) /// </summary> /// <param name="ids">List of TVDb ids</param> /// <returns></returns> private async Task GetFullShows(List <Tuple <int, string> > ids) { ProgressBarPage pbar = new ProgressBarPage(ids.Count); int total = 0; AddPage(pbar); //Wait for this task to complete without blocking main thread await Task.Run(() => { List <Task> tasks = new List <Task>(); foreach (Tuple <int, string> combination in ids) { tasks.Add(Task.Run(() => { int id = combination.Item1; //Create 4 tasks, wait for them to complete and then set value of ProgressBar Task[] secondTasks = new Task[4]; secondTasks[0] = Task.Run(() => { Series s = Series.GetSeries(id); s.libraryPath = combination.Item2; Database.AddSeries(s); }); secondTasks[1] = Task.Run(() => { List <Actor> list = Actor.GetActors(id); if (list != null) { Database.AddActor(id, list); } }); secondTasks[2] = Task.Run(() => { List <Episode> list = Episode.GetEpisodes(id); if (list != null) { Database.AddEpisode(id, list); } }); secondTasks[3] = Task.Run(() => { List <Poster> list = Poster.GetPosters(id); if (list != null) { Database.AddPoster(id, list); } }); Task.WaitAll(secondTasks); Dispatcher.Invoke(new Action(() => { total++; pbar.SetValue(total); }), DispatcherPriority.Send); })); } //Wait for all tasks created in foreach to complete tasks.WaitAll(); Thread.Sleep(500); }); //This code runs after all API calls are done and stuff is saved PleaseWait pleaseWait = new PleaseWait(); AddPage(pleaseWait); var seriesList = Database.GetSeries().Where(x => ids.Any(y => y.Item1 == x.id)).ToList(); await Renamer.ScanAndRename(seriesList); RemoveAllPages(); SetPage(new Library()); }