public void DeleteEpisode(Episode deleted, bool cascade = false) { //Updated references and cache deleted.Season.Episodes.Remove(deleted); cacheByComposite.Remove(deleted.Composite); cacheByID.Remove(deleted.ID); //Remove from XML and persist FindElementByID(deleted.ID).Remove(); factory.Persist(); }
public void UpdateEpisode(Episode updated, bool persist = true) { Pack(updated); //Flush the file if (persist) { factory.Persist(); } }
private Episode create(Season season, string episodeNo = null, long id = 0) { Episode _episode = new Episode(season); if (id > 0) { _episode.ID = id; } else { lock (this) { //Create new based on next ID _episode.ID = nextID; nextID++; factory.ConfigurationRepository.SetValue("NextEpisodeID", Convert.ToString(nextID), false); } } if (episodeNo != null) { //Store in cache _episode.EpisodeNo = episodeNo; cacheByComposite.Add(_episode.Composite, _episode); } //Add to dictionaries and persist cacheByID.Add(_episode.ID, _episode); //Listen to changes of title and ID, to keep cache synced _episode.PropertyChanged += EpisodePropertyChanged; return _episode; }
internal void Pack(Episode _item) { XElement element = FindElementByID(_item.ID); if(element == null) { element = new XElement("Episode", new XAttribute("ID", _item.ID)); (factory.SeasonRepository as XMLSeasonRepository).FindElement(_item.Season.ID).Add(element); } //EpisodeNo XAttribute _episodeNo = element.Attribute("EpisodeNo"); if (_item.EpisodeNo != null && !_item.EpisodeNo.Equals("")) { if (_episodeNo != null) { _episodeNo.Value = _item.EpisodeNo; } else { element.Add(new XAttribute("EpisodeNo", _item.EpisodeNo)); } } else { if (_episodeNo != null) { _episodeNo.Remove(); } } //Title XAttribute _title = element.Attribute("Title"); if (_item.Title != null && !_item.Title.Equals("")) { if (_title != null) { _title.Value = _item.Title; } else { element.Add(new XAttribute("Title", _item.Title)); } } else { if (_title != null) { _title.Remove(); } } //Code XAttribute _code = element.Attribute("Code"); if (_item.Code != null && !_item.Code.Equals("")) { if (_code != null) { _code.Value = _item.Code; } else { element.Add(new XAttribute("Code", _item.Code)); } } else { if (_code != null) { _code.Remove(); } } //Airdate XAttribute _airdate = element.Attribute("Airdate"); if (_item.Airdate != null && !_item.Airdate.Equals("")) { if (_airdate != null) { _airdate.Value = _item.Airdate; } else { element.Add(new XAttribute("Airdate", _item.Airdate)); } } else { if (_airdate != null) { _airdate.Remove(); } } //Rating XAttribute _rating = element.Attribute("Rating"); if (_item.Rating >= 0) { if (_rating != null) { _rating.Value = Convert.ToString(_item.Rating); } else { element.Add(new XAttribute("Rating", Convert.ToString(_item.Rating))); } } else { if (_rating != null) { _rating.Remove(); } } //Watched XAttribute _watched = element.Attribute("Watched"); if (_item.Watched) { if (_watched != null) { _watched.Value = "Yes"; } else { element.Add(new XAttribute("Watched", "Yes")); } } else { if (_watched != null) { _watched.Remove(); } } }