public SQLFieldMapping(string field, string propertyname, Delegates.ReadValue reader) { this.Table = string.Empty; this.Field = field; this.PropertyName = propertyname; this.Reader = reader; }
public ExternalSiteReaderParameters(Delegates.ReadValue reader, string site) : this() { this.Reader = reader; this.Site = site; }
public SQLFieldMapping(string table, string field, string propertyname, Delegates.ReadValue reader) : this(field, propertyname, reader) { this.Table = table; }
private LazyQuery <T> GetAllTVShows <T>() where T : WebTVShowBasic, new() { // pre-read watched information var watchedCount = new Dictionary <string, WatchedCount>(); string watchQuery = "SELECT e.SeriesID, e.Watched, COUNT(*) AS cnt " + "FROM online_episodes e " + "INNER JOIN local_episodes l ON e.CompositeID = l.CompositeID " + "WHERE e.Hidden = 0 " + "GROUP BY e.Watched, e.SeriesID"; ReadList <bool>(watchQuery, delegate(SQLiteDataReader reader) { var seriesId = reader.GetInt32(0).ToString(); if (!watchedCount.ContainsKey(seriesId)) { watchedCount[seriesId] = new WatchedCount(); } var watched = reader.GetInt32(1); var count = reader.GetInt32(2); if (watched == 0) { watchedCount[seriesId].UnwatchedEpisodes = count; } else { watchedCount[seriesId].WatchedEpisodes = count; } return(true); }); Delegates.ReadValue fixNameReader = delegate(SQLiteDataReader reader, int index) { // MPTvSeries does some magic with the name: if it's empty in the online series, use the Parsed_Name from the local series. I prefer // a complete database, but we can't fix that easily. See DB Classes/DBSeries.cs:359 in MPTvSeries source string data = reader.ReadString(index); if (data.Length > 0) { return(data); } return(reader.ReadString(index - 1)); }; string sql = "SELECT DISTINCT s.ID, l.Parsed_Name, s.Pretty_Name, s.Genre, s.BannerFileNames, STRFTIME('%Y', s.FirstAired) AS year, " + "s.PosterFileNames, s.fanart, s.Actors, s.Summary, s.Network, s.AirsDay, s.AirsTime, s.Runtime, s.Rating, s.ContentRating, s.Status, " + "s.IMDB_ID, s.added " + "FROM online_series AS s " + "INNER JOIN local_series AS l ON s.ID = l.ID AND l.Hidden = 0 " + "WHERE s.ID != 0 AND s.HasLocalFiles = 1 AND %where " + "%order"; return(new LazyQuery <T>(this, sql, new List <SQLFieldMapping>() { new SQLFieldMapping("s", "ID", "Id", DataReaders.ReadIntAsString), new SQLFieldMapping("s", "ID", "ExternalId", CustomReaders.ExternalIdReader, new ExternalSiteReaderParameters(DataReaders.ReadIntAsString, "TVDB")), new SQLFieldMapping("s", "Pretty_Name", "Title", fixNameReader), new SQLFieldMapping("s", "Genre", "Genres", DataReaders.ReadPipeList), new SQLFieldMapping("s", "BannerFileNames", "Artwork", CustomReaders.ArtworkReader, new ArtworkReaderParameters(WebFileType.Banner, configuration["banner"])), new SQLFieldMapping("", "year", "Year", DataReaders.ReadStringAsInt), new SQLFieldMapping("s", "PosterFileNames", "Artwork", CustomReaders.ArtworkReader, new ArtworkReaderParameters(WebFileType.Poster, configuration["banner"])), new SQLFieldMapping("s", "fanart", "Artwork", CustomReaders.ArtworkReader, new ArtworkReaderParameters(WebFileType.Backdrop, configuration["fanart"])), new SQLFieldMapping("s", "Actors", "Actors", CustomReaders.ActorReader), new SQLFieldMapping("s", "Rating", "Rating", DataReaders.ReadFloat), new SQLFieldMapping("s", "ContentRating", "ContentRating", DataReaders.ReadString), new SQLFieldMapping("s", "Summary", "Summary", DataReaders.ReadString), new SQLFieldMapping("s", "Status", "Status", DataReaders.ReadString), new SQLFieldMapping("s", "Network", "Network", DataReaders.ReadString), new SQLFieldMapping("s", "AirsDay", "AirsDay", DataReaders.ReadString), new SQLFieldMapping("s", "AirsTime", "AirsTime", DataReaders.ReadString), new SQLFieldMapping("s", "Runtime", "Runtime", DataReaders.ReadInt32), new SQLFieldMapping("s", "IMDB_ID", "ExternalId", CustomReaders.ExternalIdReader, new ExternalSiteReaderParameters(DataReaders.ReadString, "IMDB")), new SQLFieldMapping("s", "added", "DateAdded", DataReaders.ReadDateTime) }, delegate(T obj) { // cannot rely on information provided by MPTVSeries here because they count different var eps = (LazyQuery <WebTVEpisodeBasic>)(GetAllEpisodes <WebTVEpisodeBasic>().Where(x => x.ShowId == obj.Id)); // and the nice way is... ? obj.EpisodeCount = watchedCount[obj.Id].WatchedEpisodes + watchedCount[obj.Id].UnwatchedEpisodes; obj.UnwatchedEpisodeCount = watchedCount[obj.Id].UnwatchedEpisodes; return obj; })); }