/// <summary> /// Gets season/episode information from database. /// </summary> /// <param name="show">Show to load episode information into</param> public void FullUpdate(TvShow show) { // Check for invalid ID if (show.Id <= 0) return; // Try multiple times - databases requests tend to fail randomly for (int i = 0; i < 5; i++) if (Update(show)) { // Remove episodes that are no longer in the TvDb for (int k = show.Episodes.Count - 1; k >= 0; k--) { TvEpisode ep = show.Episodes[k]; if (!ep.InDatabase && !ep.UserDefined && !ep.PreventDatabaseUpdates) show.Episodes.Remove(ep); } // Update missing episodes for show show.UpdateMissing(); show.LastUpdated = DateTime.Now; break; } }
/// <summary> /// Gets season/episode information from database. /// </summary> /// <param name="show">Show to load episode information into</param> public void FullUpdate(TvShow show) { // Check for invalid ID if (show.Id <= 0) { return; } // Try multiple times - databases requests tend to fail randomly for (int i = 0; i < 5; i++) { if (Update(show)) { // Remove episodes that are no longer in the TvDb for (int k = show.Episodes.Count - 1; k >= 0; k--) { TvEpisode ep = show.Episodes[k]; if (!ep.InDatabase && !ep.UserDefined && !ep.PreventDatabaseUpdates) { show.Episodes.Remove(ep); } } // Update missing episodes for show show.UpdateMissing(); show.LastUpdated = DateTime.Now; break; } } }
/// <summary> /// Load collection from saved XML file /// </summary> public void Load(bool doUpdating) { XmlTextReader reader = null; XmlDocument xmlDoc = new XmlDocument(); try { string path = Path.Combine(Organization.GetBasePath(false), XML_ROOT + ".xml"); if (File.Exists(path)) { // Use dummy collection to load into so that loading doesn't hog use of object ContentCollection loadContent = new ContentCollection(this.ContentType, "Loading Shows"); lock (XmlLock) { // Load XML reader = new XmlTextReader(path); xmlDoc.Load(reader); // Extract data XmlNodeList contentNodes = xmlDoc.DocumentElement.ChildNodes; for (int i = 0; i < contentNodes.Count; i++) { // Update loading progress OnLoadProgressChange((int)(((double)i / contentNodes.Count) * 100)); // All elements will be content items or last update time if (contentNodes[i].Name == "LastUpdate") { loadContent.LastUpdate = contentNodes[i].InnerText; } else { // Load content from element based on type switch (this.ContentType) { case ContentType.TvShow: TvShow show = new TvShow(); if (show.Load(contentNodes[i])) { bool rootFolderExists = false; foreach (ContentRootFolder folder in Settings.GetAllRootFolders(this.ContentType, true)) { if (folder.FullPath == show.RootFolder) { rootFolderExists = true; } } if (!rootFolderExists || !Directory.Exists(show.Path)) { continue; } loadContent.Add(show); if (doUpdating) { show.UpdateMissing(); } } break; case ContentType.Movie: Movie movie = new Movie(); if (movie.Load(contentNodes[i])) { loadContent.Add(movie); } break; default: throw new Exception("Unknown content type"); } } } } // Update progress OnLoadProgressChange(100); this.LastUpdate = loadContent.LastUpdate; this.Clear(); AddMultiple(loadContent); } } catch (Exception e) { MessageBox.Show(e.ToString(), "Error loading " + this.ContentType + "s from saved data!"); } finally { if (reader != null) { reader.Close(); } } // Start updating of TV episode in scan dirs. if (this.ContentType == ContentType.TvShow && doUpdating) { TvItemInScanDirHelper.DoUpdate(false); TvItemInScanDirHelper.StartUpdateTimer(); } // Trigger load complete event OnLoadComplete(); }