internal Season(Show _show) { seasonNo = -1; episodes = new ObservableEpisodeCollection(); show = _show; if (show != null) { show.Seasons.Add(this); } }
internal ExternalShow(ExternalSource _source, Show _show) { externalSource = _source; show = _show; if (externalSource != null) { externalSource.ExternalShows.Add(this); } if (show != null) { show.ExternalShows.Add(this); } }
public Season GetSeason(Show show, int seasonNo) { //See if the show contains the given season return (from Season season in show.Seasons where season.SeasonNo == seasonNo select season).FirstOrDefault(); //The building of the show would have loaded any seasons for it, so if it wasn't found it didn't exist. }
public Season CreateOrGetSeason(Show show, int season, bool persist = true) { //Check if we already have it Season _season = GetSeason(show, season); if (_season == null) { //Create a new season _season = create(show: show, seasonNo: season); //Store as XML Pack(_season); if (persist) { factory.Persist(); } } return _season; }
public void DeleteShow(Show deleted, bool cascade = false) { //Cascade to children if called for if (cascade) { foreach (Season season in deleted.Seasons) { factory.SeasonRepository.DeleteSeason(season, cascade); } foreach (ExternalShow ext in deleted.ExternalShows) { factory.ExternalShowRepository.DeleteExternalShow(ext, cascade); } } //If no children are remaining, delete if (deleted.ExternalShows.Count == 0 && deleted.Seasons.Count == 0) { //Updated references and cache cacheByTitle.Remove(deleted.Title); cacheByID.Remove(deleted.ID); //Remove from tree & persist FindElement(deleted.ID).Remove(); factory.Persist(); } }
public ExternalShow CreateOrGetExternalShow(Show show, ExternalSource source, bool persist = true) { if (show == null || source == null) { //We can't really do this, so return null return null; } ExternalShow _ext; if (externalsByComposite.TryGetValue(BuildComposite(show, source.Title), out _ext)) { return _ext; } //Create a new as needed _ext = new ExternalShow(source, show); //ID _ext.ID = nextID++; //Store in cache externalsByComposite.Add(BuildComposite(_ext.Show, source.Title), _ext); externalsByID.Add(_ext.ID, _ext); //Add to document XElement element = new XElement("External", new XAttribute("Source", source.Title)); (factory.ShowRepository as XMLShowRepository).FindElement(show.ID).Add(element); if (persist) { factory.Persist(); } return _ext; }
private Show create(long id = 0, string title = null) { Show _show = new Show(); if (id > 0) { _show.ID = id; } else { //Create a new Show based on the next available ID. This needs to be thread safe. lock (this) { _show.ID = nextID; nextID++; factory.ConfigurationRepository.SetValue("NextShowID", Convert.ToString(nextID), false); } } //Store in cache cacheByID.Add(_show.ID, _show); if (title != null) { _show.Title = title; cacheByTitle.Add(_show.Title, _show); } //Listen to changes of title and ID, to keep cache synced _show.PropertyChanged += ShowPropertyChanged; return _show; }
internal void Pack(Show _item) { XElement element = FindElement(_item.ID); if (element == null) { element = new XElement("Show", new XAttribute("ID", _item.ID)); document.Root.Element("Shows").Add(element); } //Title attribute XAttribute _title = element.Attribute("Title"); if (_item.Title != null) { if (_title != null) { _title.Value = _item.Title; } else { element.Add(new XAttribute("Title", _item.Title)); } } else { if (_title != null) { _title.Remove(); } } //Year attribute XAttribute _year = element.Attribute("Year"); if (_item.Year != null && _item.Year > 0) { if (_year != null) { _year.Value = Convert.ToString(_item.Year); } else { element.Add(new XAttribute("Year", _item.Year)); } } else { if (_year != null) { _year.Remove(); } } }
public void UpdateShow(Show updated, bool persist = true) { //Pack the item into the XML document Pack(updated); //Flush the file if called for if (persist) { factory.Persist(); } }
public ExternalShow GetExternalShow(Show show, ExternalSource source) { ExternalShow _ext; if (externalsByComposite.TryGetValue(BuildComposite(show, source.Title), out _ext)) { return _ext; } return null; }
private string BuildComposite(Show show, string source) { return string.Format("{0}#{1}", show.Title, source); }
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; }