public Episode GetEpisode(Season season, string episodeNo) { //See if the show contains the given season return (from Episode episode in season.Episodes where episode.EpisodeNo == episodeNo select episode).FirstOrDefault(); //The building of the show would have loaded any seasons and episodes for it, so if it wasn't found it didn't exist. }
internal Episode(Season _season) { rating = -1; season = _season; if (season != null) { season.PropertyChanged += Season_PropertyChanged; season.Episodes.Add(this); } }
public Episode CreateOrGetEpisode(Season season, string episode, bool persist = true) { //Check if we already have it Episode _episode = GetEpisode(season, episode); if (_episode == null) { //Create a new season _episode = create(season: season, episodeNo: episode); //Store as XML Pack(_episode); if (persist) { factory.Persist(); } } return _episode; }
public void DeleteSeason(Season deleted, bool cascade = false) { //Cascade to children if called for if (cascade) { foreach (Episode episode in deleted.Episodes) { factory.EpisodeRepository.DeleteEpisode(episode); } } //If no children are remaining, delete if (deleted.Episodes.Count == 0) { //Updated references and cache deleted.Show.Seasons.Remove(deleted); cacheByComposite.Remove(deleted.Composite); cacheByID.Remove(deleted.ID); //Remove from XML and persist FindElement(deleted.ID).Remove(); factory.Persist(); } }
public void UpdateSeason(Season updated, bool persist = true) { Pack(updated); //Flush the file if (persist) { factory.Persist(); } }
private Season create(Show show, int seasonNo = 0, long id = 0) { Season _season = new Season(show); if (id > 0) { _season.ID = id; } else { lock (this) { //Create new based on next ID _season.ID = nextID; nextID++; factory.ConfigurationRepository.SetValue("NextSeasonID", Convert.ToString(nextID), false); } } if (seasonNo > 0) { //Store in cache _season.SeasonNo = seasonNo; cacheByComposite.Add(_season.Composite, _season); } //Add to dictionaries and persist cacheByID.Add(_season.ID, _season); //Listen to changes of title and ID, to keep cache synced _season.PropertyChanged += SeasonPropertyChanged; return _season; }
internal void Pack(Season _item) { XElement element = FindElement(_item.ID); if (element == null) { element = new XElement("Season", new XAttribute("ID", _item.ID)); (factory.ShowRepository as XMLShowRepository).FindElement(_item.Show.ID).Add(element); } //SeasonNo XAttribute _seasonNo = element.Attribute("SeasonNo"); if (_item.SeasonNo >= 0) { if (_seasonNo != null) { _seasonNo.Value = Convert.ToString(_item.SeasonNo); } else { element.Add(new XAttribute("SeasonNo", _item.SeasonNo)); } } else { if (_seasonNo != null) { _seasonNo.Remove(); } } //Quality XAttribute _quality = element.Attribute("Quality"); if (_item.Quality != null && !_item.Quality.Equals("")) { if (_quality != null) { _quality.Value = _item.Quality; } else { element.Add(new XAttribute("Quality", _item.Quality)); } } else { if (_quality != null) { _quality.Remove(); } } }
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; }