Exemplo n.º 1
0
        public static int?FetchInfo(int progid, string episodeExtId)
        {
            int?epid = null;

            using (SQLiteCommand command = new SQLiteCommand("select epid from episodes where progid=@progid and extid=@extid", FetchDbConn()))
            {
                command.Parameters.Add(new SQLiteParameter("@progid", progid));
                command.Parameters.Add(new SQLiteParameter("@extid", episodeExtId));

                using (SQLiteMonDataReader reader = new SQLiteMonDataReader(command.ExecuteReader()))
                {
                    if (reader.Read())
                    {
                        epid = reader.GetInt32(reader.GetOrdinal("epid"));
                    }
                }
            }

            if (epid == null)
            {
                // Fetch episode information, as it currently doesn't have an ID
                epid = UpdateInfo(progid, episodeExtId);
            }

            return(epid);
        }
Exemplo n.º 2
0
        protected void FetchData(SQLiteMonDataReader reader)
        {
            int descriptionOrdinal = reader.GetOrdinal("description");
            int durationOrdinal    = reader.GetOrdinal("duration");
            int imageOrdinal       = reader.GetOrdinal("image");

            this.Epid   = reader.GetInt32(reader.GetOrdinal("epid"));
            this.Progid = reader.GetInt32(reader.GetOrdinal("progid"));
            this.Date   = reader.GetDateTime(reader.GetOrdinal("date"));
            this.Name   = reader.GetString(reader.GetOrdinal("name"));

            if (!reader.IsDBNull(descriptionOrdinal))
            {
                this.Description = reader.GetString(descriptionOrdinal);
            }

            if (!reader.IsDBNull(durationOrdinal))
            {
                this.Duration = reader.GetInt32(durationOrdinal);
            }

            this.AutoDownload = reader.GetInt32(reader.GetOrdinal("autodownload")) == 1;

            if (!reader.IsDBNull(imageOrdinal))
            {
                this.imgid = reader.GetInt32(imageOrdinal);
            }
        }
Exemplo n.º 3
0
        public static int Compare(int epid1, int epid2)
        {
            lock (sortCacheLock)
            {
                if (sortCache == null || !sortCache.ContainsKey(epid1) || !sortCache.ContainsKey(epid2))
                {
                    // The sort cache is either empty or missing one of the values that are required, so recreate it
                    sortCache = new Dictionary <int, int>();

                    int    sort    = 0;
                    string orderBy = null;

                    switch (sortBy)
                    {
                    case DownloadCols.EpisodeName:
                        orderBy = "name" + (sortAsc ? string.Empty : " desc");
                        break;

                    case DownloadCols.EpisodeDate:
                        orderBy = "date" + (sortAsc ? string.Empty : " desc");
                        break;

                    case DownloadCols.Status:
                        orderBy = "status = 0" + (sortAsc ? " desc" : string.Empty) + ", status" + (sortAsc ? " desc" : string.Empty) + ", playcount > 0" + (sortAsc ? string.Empty : " desc") + ", date" + (sortAsc ? " desc" : string.Empty);
                        break;

                    case DownloadCols.Duration:
                        orderBy = "duration" + (sortAsc ? string.Empty : " desc");
                        break;

                    default:
                        throw new InvalidDataException("Invalid column: " + sortBy.ToString());
                    }

                    using (SQLiteCommand command = new SQLiteCommand("select downloads.epid from downloads, episodes where downloads.epid=episodes.epid order by " + orderBy, FetchDbConn()))
                    {
                        using (SQLiteMonDataReader reader = new SQLiteMonDataReader(command.ExecuteReader()))
                        {
                            int epidOrdinal = reader.GetOrdinal("epid");

                            while (reader.Read())
                            {
                                sortCache.Add(reader.GetInt32(epidOrdinal), sort);
                                sort += 1;
                            }
                        }
                    }
                }

                try
                {
                    return(sortCache[epid1] - sortCache[epid2]);
                }
                catch (KeyNotFoundException)
                {
                    // One of the entries has been removed from the database, but not yet from the list
                    return(0);
                }
            }
        }
Exemplo n.º 4
0
        protected new void FetchData(SQLiteMonDataReader reader)
        {
            base.FetchData(reader);

            int filepathOrdinal = reader.GetOrdinal("filepath");

            this.Status = (DownloadStatus)reader.GetInt32(reader.GetOrdinal("status"));

            if (this.Status == DownloadStatus.Errored)
            {
                this.ErrorType = (ErrorType)reader.GetInt32(reader.GetOrdinal("errortype"));

                if (this.ErrorType != ErrorType.UnknownError)
                {
                    this.ErrorDetails = reader.GetString(reader.GetOrdinal("errordetails"));
                }
            }

            if (!reader.IsDBNull(filepathOrdinal))
            {
                this.DownloadPath = reader.GetString(filepathOrdinal);
            }

            this.PlayCount = reader.GetInt32(reader.GetOrdinal("playcount"));
        }
Exemplo n.º 5
0
        public static int Compare(int progid1, int progid2)
        {
            lock (sortCacheLock)
            {
                if (sortCache == null || !sortCache.ContainsKey(progid1) || !sortCache.ContainsKey(progid2))
                {
                    // The sort cache is either empty or missing one of the values that are required, so recreate it
                    sortCache = new Dictionary <int, int>();

                    int sort = 0;

                    using (SQLiteCommand command = new SQLiteCommand("select subscriptions.progid from subscriptions, programmes where programmes.progid=subscriptions.progid order by name", FetchDbConn()))
                    {
                        using (SQLiteMonDataReader reader = new SQLiteMonDataReader(command.ExecuteReader()))
                        {
                            int progidOrdinal = reader.GetOrdinal("progid");

                            while (reader.Read())
                            {
                                sortCache.Add(reader.GetInt32(progidOrdinal), sort);
                                sort += 1;
                            }
                        }
                    }
                }

                return(sortCache[progid1] - sortCache[progid2]);
            }
        }
Exemplo n.º 6
0
        public static bool Add(int progid)
        {
            Model.Programme progInfo = new Model.Programme(progid);

            if (progInfo.SingleEpisode)
            {
                using (SQLiteCommand command = new SQLiteCommand("select downloads.epid from downloads, episodes where downloads.epid=episodes.epid and progid=@progid", FetchDbConn()))
                {
                    command.Parameters.Add(new SQLiteParameter("progid", progid));

                    using (SQLiteMonDataReader reader = new SQLiteMonDataReader(command.ExecuteReader()))
                    {
                        if (reader.Read())
                        {
                            // The one download for this programme is already in the downloads list
                            return(false);
                        }
                    }
                }
            }

            ThreadPool.QueueUserWorkItem(delegate { AddAsync(progid); });

            return(true);
        }
Exemplo n.º 7
0
        public static System.Drawing.Bitmap GetImage(int progid)
        {
            using (SQLiteCommand command = new SQLiteCommand("select image from programmes where progid=@progid and image not null", FetchDbConn()))
            {
                command.Parameters.Add(new SQLiteParameter("@progid", progid));

                using (SQLiteMonDataReader reader = new SQLiteMonDataReader(command.ExecuteReader()))
                {
                    if (reader.Read())
                    {
                        return(RetrieveImage(reader.GetInt32(reader.GetOrdinal("image"))));
                    }
                    else
                    {
                        // Find the id of the latest episode's image
                        using (SQLiteCommand latestCmd = new SQLiteCommand("select image from episodes where progid=@progid and image not null order by date desc limit 1", FetchDbConn()))
                        {
                            latestCmd.Parameters.Add(new SQLiteParameter("@progid", progid));

                            using (SQLiteMonDataReader latestRdr = new SQLiteMonDataReader(latestCmd.ExecuteReader()))
                            {
                                if (latestRdr.Read())
                                {
                                    return(RetrieveImage(latestRdr.GetInt32(latestRdr.GetOrdinal("image"))));
                                }
                            }
                        }
                    }
                }
            }

            return(null);
        }
Exemplo n.º 8
0
        protected void FetchData(SQLiteMonDataReader reader)
        {
            int descriptionOrdinal    = reader.GetOrdinal("description");
            int latestdownloadOrdinal = reader.GetOrdinal("latestdownload");

            this.Progid = reader.GetInt32(reader.GetOrdinal("progid"));
            this.extId  = reader.GetString(reader.GetOrdinal("extid"));
            this.Name   = reader.GetString(reader.GetOrdinal("name"));

            if (!reader.IsDBNull(descriptionOrdinal))
            {
                this.Description = reader.GetString(descriptionOrdinal);
            }

            this.SingleEpisode = reader.GetBoolean(reader.GetOrdinal("singleepisode"));

            Guid pluginId = new Guid(reader.GetString(reader.GetOrdinal("pluginid")));

            Provider.Handler provider = Provider.Handler.GetFromId(pluginId);

            if (provider != null)
            {
                this.ProviderName    = provider.Name;
                this.moreInfoHandler = provider.ShowMoreProgInfoHandler;
            }
            else
            {
                this.ProviderName = "<missing>";
            }

            if (!reader.IsDBNull(latestdownloadOrdinal))
            {
                this.LatestDownload = reader.GetDateTime(latestdownloadOrdinal);
            }
        }
Exemplo n.º 9
0
        public static bool Add(int progid)
        {
            Model.Programme progInfo = new Model.Programme(progid);

            if (progInfo.SingleEpisode)
            {
                using (SQLiteCommand command = new SQLiteCommand("select downloads.epid from downloads, episodes where downloads.epid=episodes.epid and progid=@progid", FetchDbConn()))
                {
                    command.Parameters.Add(new SQLiteParameter("progid", progid));

                    using (SQLiteMonDataReader reader = new SQLiteMonDataReader(command.ExecuteReader()))
                    {
                        if (reader.Read())
                        {
                            // The one download for this programme is already in the downloads list
                            return false;
                        }
                    }
                }
            }

            ThreadPool.QueueUserWorkItem(delegate { AddAsync(progid); });

            return true;
        }
Exemplo n.º 10
0
        public static int Compare(int progid1, int progid2)
        {
            lock (sortCacheLock)
            {
                if (sortCache == null || !sortCache.ContainsKey(progid1) || !sortCache.ContainsKey(progid2))
                {
                    // The sort cache is either empty or missing one of the values that are required, so recreate it
                    sortCache = new Dictionary<int, int>();

                    int sort = 0;

                    using (SQLiteCommand command = new SQLiteCommand("select favourites.progid from favourites, programmes where programmes.progid=favourites.progid order by name", FetchDbConn()))
                    {
                        using (SQLiteMonDataReader reader = new SQLiteMonDataReader(command.ExecuteReader()))
                        {
                            int progidOrdinal = reader.GetOrdinal("progid");

                            while (reader.Read())
                            {
                                sortCache.Add(reader.GetInt32(progidOrdinal), sort);
                                sort += 1;
                            }
                        }
                    }
                }

                return sortCache[progid1] - sortCache[progid2];
            }
        }
Exemplo n.º 11
0
        public static List <Subscription> FetchAll()
        {
            List <Subscription> items = new List <Subscription>();

            using (SQLiteCommand command = new SQLiteCommand("select " + Columns + " from subscriptions, programmes where subscriptions.progid=programmes.progid", FetchDbConn()))
                using (SQLiteMonDataReader reader = new SQLiteMonDataReader(command.ExecuteReader()))
                {
                    while (reader.Read())
                    {
                        items.Add(new Subscription(reader));
                    }
                }

            return(items);
        }
Exemplo n.º 12
0
        public static List <Programme> FetchAllWithDownloads()
        {
            List <Programme> items = new List <Programme>();

            using (SQLiteCommand command = new SQLiteCommand("select distinct " + Columns + " from programmes, episodes, downloads where downloads.epid=episodes.epid and episodes.progid=programmes.progid", FetchDbConn()))
                using (SQLiteMonDataReader reader = new SQLiteMonDataReader(command.ExecuteReader()))
                {
                    while (reader.Read())
                    {
                        items.Add(new Programme(reader));
                    }
                }

            return(items);
        }
Exemplo n.º 13
0
        public static List <Download> FetchAll()
        {
            List <Download> items = new List <Download>();

            using (SQLiteCommand command = new SQLiteCommand("select " + Columns + " from episodes, downloads where downloads.epid=episodes.epid", FetchDbConn()))
                using (SQLiteMonDataReader reader = new SQLiteMonDataReader(command.ExecuteReader()))
                {
                    while (reader.Read())
                    {
                        items.Add(new Download(reader));
                    }
                }

            return(items);
        }
Exemplo n.º 14
0
        public static int Compare(int progid1, int progid2)
        {
            lock (sortCacheLock)
            {
                if (sortCache == null || !sortCache.ContainsKey(progid1) || !sortCache.ContainsKey(progid2))
                {
                    // The sort cache is either empty or missing one of the values that are required, so recreate it
                    sortCache = new Dictionary <int, int>();

                    int    sort    = 0;
                    string orderBy = null;

                    switch (sortBy)
                    {
                    case SubscriptionCols.ProgrammeName:
                        orderBy = "name" + (sortAsc ? string.Empty : " desc");
                        break;

                    case SubscriptionCols.LastDownload:
                        orderBy = "latestdownload" + (sortAsc ? string.Empty : " desc");
                        break;

                    case SubscriptionCols.Provider:
                        orderBy = "pluginid" + (sortAsc ? " desc" : string.Empty);
                        break;

                    default:
                        throw new InvalidDataException("Invalid column: " + sortBy.ToString());
                    }

                    using (SQLiteCommand command = new SQLiteCommand("select subscriptions.progid from subscriptions, programmes where programmes.progid=subscriptions.progid order by " + orderBy, FetchDbConn()))
                    {
                        using (SQLiteMonDataReader reader = new SQLiteMonDataReader(command.ExecuteReader()))
                        {
                            int progidOrdinal = reader.GetOrdinal("progid");

                            while (reader.Read())
                            {
                                sortCache.Add(reader.GetInt32(progidOrdinal), sort);
                                sort += 1;
                            }
                        }
                    }
                }

                return(sortCache[progid1] - sortCache[progid2]);
            }
        }
Exemplo n.º 15
0
        public static List <Favourite> FetchAll()
        {
            List <Favourite> items = new List <Favourite>();

            using (SQLiteCommand command = new SQLiteCommand("select " + Columns + " from favourites, programmes where favourites.progid=programmes.progid", FetchDbConn()))
            {
                using (SQLiteMonDataReader reader = new SQLiteMonDataReader(command.ExecuteReader()))
                {
                    while (reader.Read())
                    {
                        items.Add(new Favourite(reader));
                    }
                }
            }

            return(items);
        }
Exemplo n.º 16
0
        public Episode(int epid)
        {
            using (SQLiteCommand command = new SQLiteCommand("select " + Columns + " from episodes where epid=@epid", FetchDbConn()))
            {
                command.Parameters.Add(new SQLiteParameter("@epid", epid));

                using (SQLiteMonDataReader reader = new SQLiteMonDataReader(command.ExecuteReader()))
                {
                    if (!reader.Read())
                    {
                        throw new DataNotFoundException(epid, "Episode does not exist");
                    }

                    this.FetchData(reader);
                }
            }
        }
Exemplo n.º 17
0
        public Download(int epid)
        {
            using (SQLiteCommand command = new SQLiteCommand("select " + Columns + " from episodes, downloads where episodes.epid=@epid and downloads.epid=episodes.epid", FetchDbConn()))
            {
                command.Parameters.Add(new SQLiteParameter("@epid", epid));

                using (SQLiteMonDataReader reader = new SQLiteMonDataReader(command.ExecuteReader()))
                {
                    if (!reader.Read())
                    {
                        throw new DataNotFoundException(epid, "Download does not exist");
                    }

                    this.FetchData(reader);
                }
            }
        }
Exemplo n.º 18
0
        public Programme(int progid)
        {
            using (SQLiteCommand command = new SQLiteCommand("select " + Columns + " from programmes where progid=@progid", FetchDbConn()))
            {
                command.Parameters.Add(new SQLiteParameter("@progid", progid));

                using (SQLiteMonDataReader reader = new SQLiteMonDataReader(command.ExecuteReader()))
                {
                    if (!reader.Read())
                    {
                        throw new DataNotFoundException(progid, "Programme does not exist");
                    }

                    this.FetchData(reader);
                }
            }
        }
Exemplo n.º 19
0
        public Programme(int progid)
        {
            using (SQLiteCommand command = new SQLiteCommand("select " + Columns + " from programmes where progid=@progid", FetchDbConn()))
            {
                command.Parameters.Add(new SQLiteParameter("@progid", progid));

                using (SQLiteMonDataReader reader = new SQLiteMonDataReader(command.ExecuteReader()))
                {
                    if (!reader.Read())
                    {
                        throw new DataNotFoundException(progid, "Programme does not exist");
                    }

                    this.FetchData(reader);
                }
            }
        }
Exemplo n.º 20
0
        private void FetchData(SQLiteMonDataReader reader)
        {
            int linkOrdinal  = reader.GetOrdinal("link");
            int imageOrdinal = reader.GetOrdinal("image");

            this.Start = TimeSpan.FromMilliseconds(reader.GetInt32(reader.GetOrdinal("start")));
            this.Name  = reader.GetString(reader.GetOrdinal("name"));

            if (!reader.IsDBNull(linkOrdinal))
            {
                this.Link = new Uri(reader.GetString(linkOrdinal));
            }

            if (!reader.IsDBNull(imageOrdinal))
            {
                this.imgid = reader.GetInt32(imageOrdinal);
            }
        }
Exemplo n.º 21
0
        public static void ReportError(int epid)
        {
            ErrorReporting report = null;

            using (SQLiteCommand command = new SQLiteCommand("select errordetails from downloads where epid=@epid and errordetails is not null", FetchDbConn()))
            {
                command.Parameters.Add(new SQLiteParameter("@epid", epid));

                using (SQLiteMonDataReader reader = new SQLiteMonDataReader(command.ExecuteReader()))
                {
                    if (reader.Read())
                    {
                        int errordetailsOrdinal = reader.GetOrdinal("errordetails");

                        // Get the length of the content by passing null to getbytes
                        int contentLength = (int)reader.GetBytes(errordetailsOrdinal, 0, null, 0, 0);

                        byte[] content = new byte[contentLength];
                        reader.GetBytes(errordetailsOrdinal, 0, content, 0, contentLength);

                        using (MemoryStream stream = new MemoryStream(content))
                        {
                            BinaryFormatter formatter = new BinaryFormatter();
                            report = (ErrorReporting)formatter.Deserialize(stream);
                        }
                    }
                }
            }

            if (report == null)
            {
                MessageBox.Show("Please retry this download before reporting the error again.", Application.ProductName);
                return;
            }

            if (report.SendReport())
            {
                using (SQLiteCommand command = new SQLiteCommand("update downloads set errordetails=null where epid=@epid", FetchDbConn()))
                {
                    command.Parameters.Add(new SQLiteParameter("@epid", epid));
                    command.ExecuteNonQuery();
                }
            }
        }
Exemplo n.º 22
0
        public static ICollection <Chapter> FetchAll(Download download)
        {
            var results = new List <Chapter>();

            using (SQLiteCommand command = new SQLiteCommand("select " + Columns + " from chapters where epid=@epid", FetchDbConn()))
            {
                command.Parameters.Add(new SQLiteParameter("@epid", download.Epid));

                using (SQLiteMonDataReader reader = new SQLiteMonDataReader(command.ExecuteReader()))
                {
                    while (reader.Read())
                    {
                        results.Add(new Chapter(reader));
                    }
                }
            }

            return(results);
        }
Exemplo n.º 23
0
        private static void UpdateInfoIfRequiredAsync(int progid)
        {
            Guid   providerId  = Guid.Empty;
            string updateExtid = null;

            // Test to see if an update is required, and then free up the database
            using (SQLiteCommand command = new SQLiteCommand("select pluginid, extid, lastupdate from programmes where progid=@progid", FetchDbConn()))
            {
                command.Parameters.Add(new SQLiteParameter("@progid", progid));

                using (SQLiteMonDataReader reader = new SQLiteMonDataReader(command.ExecuteReader()))
                {
                    if (reader.Read())
                    {
                        providerId = new Guid(reader.GetString(reader.GetOrdinal("pluginid")));

                        if (Provider.Exists(providerId))
                        {
                            IRadioProvider pluginInstance = Provider.GetFromId(providerId).CreateInstance();

                            if (reader.GetDateTime(reader.GetOrdinal("lastupdate")).AddDays(pluginInstance.ProgInfoUpdateFreqDays) < DateTime.Now)
                            {
                                updateExtid = reader.GetString(reader.GetOrdinal("extid"));
                            }
                        }
                    }
                }
            }

            // Now perform the update if required
            if (updateExtid != null)
            {
                try
                {
                    UpdateInfo(providerId, updateExtid);
                }
                catch (ProviderException)
                {
                    // Suppress any provider exceptions, as the user isn't waiting for this action
                }
            }
        }
Exemplo n.º 24
0
        public static List <Download> FetchVisible(DataSearch dataSearch)
        {
            List <Download> items = new List <Download>();

            using (SQLiteCommand command = new SQLiteCommand("select " + Columns + " from episodes, downloads where downloads.epid=episodes.epid", FetchDbConn()))
                using (SQLiteMonDataReader reader = new SQLiteMonDataReader(command.ExecuteReader()))
                {
                    int epidOrdinal = reader.GetOrdinal("epid");

                    while (reader.Read())
                    {
                        if (dataSearch.DownloadIsVisible(reader.GetInt32(epidOrdinal)))
                        {
                            items.Add(new Download(reader));
                        }
                    }
                }

            return(items);
        }
Exemplo n.º 25
0
        public static List <Download> FetchLatest(int count)
        {
            List <Download> items = new List <Download>();

            using (SQLiteCommand command = new SQLiteCommand("select " + Columns + " from episodes, downloads where downloads.epid=episodes.epid and status=@status order by episodes.epid desc limit @count", FetchDbConn()))
            {
                command.Parameters.Add(new SQLiteParameter("@status", DownloadStatus.Downloaded));
                command.Parameters.Add(new SQLiteParameter("@count", count));

                using (SQLiteMonDataReader reader = new SQLiteMonDataReader(command.ExecuteReader()))
                {
                    while (reader.Read())
                    {
                        items.Add(new Download(reader));
                    }
                }
            }

            return(items);
        }
Exemplo n.º 26
0
        public Chapter(Download download, int start)
        {
            using (SQLiteCommand command = new SQLiteCommand("select " + Columns + " from chapters where epid=@epid and start=@start", FetchDbConn()))
            {
                command.Parameters.Add(new SQLiteParameter("@epid", download.Epid));
                command.Parameters.Add(new SQLiteParameter("@start", start));

                using (SQLiteMonDataReader reader = new SQLiteMonDataReader(command.ExecuteReader()))
                {
                    if (!reader.Read())
                    {
                        throw new DataNotFoundException(start, "Chapter does not exist");
                    }

                    if (reader.Read())
                    {
                        this.FetchData(reader);
                    }
                }
            }
        }
Exemplo n.º 27
0
        public static void UpdateInfoIfRequired(int epid)
        {
            int    progid      = 0;
            string updateExtid = null;

            // Test to see if the episode is marked as unavailable, and then free up the database
            using (SQLiteCommand command = new SQLiteCommand("select progid, extid from episodes where epid=@epid and available=0", FetchDbConn()))
            {
                command.Parameters.Add(new SQLiteParameter("@epid", epid));

                using (SQLiteMonDataReader reader = new SQLiteMonDataReader(command.ExecuteReader()))
                {
                    if (reader.Read())
                    {
                        progid      = reader.GetInt32(reader.GetOrdinal("progid"));
                        updateExtid = reader.GetString(reader.GetOrdinal("extid"));
                    }
                }
            }

            // Perform an update if the episode was marked as unavailable
            if (updateExtid != null)
            {
                if (Download.IsDownload(epid))
                {
                    // The episode is in the downloads list, so just mark as available
                    using (SQLiteCommand command = new SQLiteCommand("update episodes set available=1 where epid=@epid", FetchDbConn()))
                    {
                        command.Parameters.Add(new SQLiteParameter("@epid", epid));
                        command.ExecuteNonQuery();
                    }
                }
                else
                {
                    UpdateInfo(progid, updateExtid);
                }
            }
        }
Exemplo n.º 28
0
        public static int?FetchInfo(Guid pluginId, string progExtId)
        {
            if (!Provider.Exists(pluginId))
            {
                return(null);
            }

            int?progid = null;

            using (SQLiteCommand command = new SQLiteCommand("select progid from programmes where pluginid=@pluginid and extid=@extid", FetchDbConn()))
            {
                command.Parameters.Add(new SQLiteParameter("@pluginid", pluginId.ToString()));
                command.Parameters.Add(new SQLiteParameter("@extid", progExtId));

                using (SQLiteMonDataReader reader = new SQLiteMonDataReader(command.ExecuteReader()))
                {
                    if (reader.Read())
                    {
                        progid = reader.GetInt32(reader.GetOrdinal("progid"));
                    }
                }
            }

            if (progid == null)
            {
                // Need to fetch the data synchronously as the progid is currently unknown
                progid = UpdateInfo(pluginId, progExtId);
            }
            else
            {
                // Kick off an update in the background if required
                UpdateInfoIfRequired(progid.Value);
            }

            return(progid);
        }
Exemplo n.º 29
0
        private static int? UpdateInfo(Guid pluginId, string progExtId)
        {
            if (!Provider.Exists(pluginId))
            {
                return null;
            }

            IRadioProvider pluginInstance = Provider.GetFromId(pluginId).CreateInstance();
            ProgrammeInfo progInfo;

            try
            {
                progInfo = pluginInstance.GetProgrammeInfo(progExtId);
            }
            catch (Exception provExp)
            {
                provExp.Data.Add("Programme ExtID", progExtId);
                throw new ProviderException("Call to GetProgrammeInfo failed", provExp, pluginId);
            }

            if (progInfo == null)
            {
                return null;
            }

            int? progid = null;

            lock (DbUpdateLock)
            {
                using (SQLiteCommand command = new SQLiteCommand("select progid from programmes where pluginid=@pluginid and extid=@extid", FetchDbConn()))
                {
                    command.Parameters.Add(new SQLiteParameter("@pluginid", pluginId.ToString()));
                    command.Parameters.Add(new SQLiteParameter("@extid", progExtId));

                    using (SQLiteMonDataReader reader = new SQLiteMonDataReader(command.ExecuteReader()))
                    {
                        if (reader.Read())
                        {
                            progid = reader.GetInt32(reader.GetOrdinal("progid"));
                        }
                    }
                }

                using (SQLiteMonTransaction transMon = new SQLiteMonTransaction(FetchDbConn().BeginTransaction()))
                {
                    if (progid == null)
                    {
                        using (SQLiteCommand command = new SQLiteCommand("insert into programmes (pluginid, extid, name) values (@pluginid, @extid, @name)", FetchDbConn()))
                        {
                            command.Parameters.Add(new SQLiteParameter("@pluginid", pluginId.ToString()));
                            command.Parameters.Add(new SQLiteParameter("@extid", progExtId));
                            command.Parameters.Add(new SQLiteParameter("@name", progExtId));
                            command.ExecuteNonQuery();
                        }

                        using (SQLiteCommand command = new SQLiteCommand("select last_insert_rowid()", FetchDbConn()))
                        {
                            progid = (int)(long)command.ExecuteScalar();
                        }
                    }

                    using (SQLiteCommand command = new SQLiteCommand("update programmes set name=@name, description=@description, image=@image, singleepisode=@singleepisode, lastupdate=@lastupdate where progid=@progid", FetchDbConn()))
                    {
                        command.Parameters.Add(new SQLiteParameter("@name", progInfo.Name));
                        command.Parameters.Add(new SQLiteParameter("@description", progInfo.Description));
                        command.Parameters.Add(new SQLiteParameter("@image", StoreImage(progInfo.Image)));
                        command.Parameters.Add(new SQLiteParameter("@singleepisode", progInfo.SingleEpisode));
                        command.Parameters.Add(new SQLiteParameter("@lastupdate", DateTime.Now));
                        command.Parameters.Add(new SQLiteParameter("@progid", progid));
                        command.ExecuteNonQuery();
                    }

                    transMon.Trans.Commit();
                }
            }

            if (Updated != null)
            {
                Updated(progid.Value);
            }

            return progid;
        }
Exemplo n.º 30
0
 public Programme(SQLiteMonDataReader reader)
 {
     this.FetchData(reader);
 }
Exemplo n.º 31
0
        protected void FetchData(SQLiteMonDataReader reader)
        {
            int descriptionOrdinal = reader.GetOrdinal("description");
            int latestdownloadOrdinal = reader.GetOrdinal("latestdownload");

            this.Progid = reader.GetInt32(reader.GetOrdinal("progid"));
            this.extId = reader.GetString(reader.GetOrdinal("extid"));
            this.Name = reader.GetString(reader.GetOrdinal("name"));

            if (!reader.IsDBNull(descriptionOrdinal))
            {
                this.Description = reader.GetString(descriptionOrdinal);
            }

            this.SingleEpisode = reader.GetBoolean(reader.GetOrdinal("singleepisode"));

            Guid pluginId = new Guid(reader.GetString(reader.GetOrdinal("pluginid")));
            Provider provider = Provider.GetFromId(pluginId);

            if (provider != null)
            {
                this.ProviderName = provider.Name;
                this.moreInfoHandler = provider.ShowMoreProgInfoHandler;
            }
            else
            {
                this.ProviderName = "<missing>";
            }

            if (!reader.IsDBNull(latestdownloadOrdinal))
            {
                this.LatestDownload = reader.GetDateTime(latestdownloadOrdinal);
            }
        }
Exemplo n.º 32
0
        private static int?UpdateInfo(Guid pluginId, string progExtId)
        {
            if (!Provider.Exists(pluginId))
            {
                return(null);
            }

            IRadioProvider pluginInstance = Provider.GetFromId(pluginId).CreateInstance();
            ProgrammeInfo  progInfo;

            try
            {
                progInfo = pluginInstance.GetProgrammeInfo(progExtId);
            }
            catch (Exception provExp)
            {
                provExp.Data.Add("Programme ExtID", progExtId);
                throw new ProviderException("Call to GetProgrammeInfo failed", provExp, pluginId);
            }

            if (progInfo == null)
            {
                return(null);
            }

            int?progid = null;

            lock (Database.DbUpdateLock)
            {
                using (SQLiteCommand command = new SQLiteCommand("select progid from programmes where pluginid=@pluginid and extid=@extid", FetchDbConn()))
                {
                    command.Parameters.Add(new SQLiteParameter("@pluginid", pluginId.ToString()));
                    command.Parameters.Add(new SQLiteParameter("@extid", progExtId));

                    using (SQLiteMonDataReader reader = new SQLiteMonDataReader(command.ExecuteReader()))
                    {
                        if (reader.Read())
                        {
                            progid = reader.GetInt32(reader.GetOrdinal("progid"));
                        }
                    }
                }

                using (SQLiteMonTransaction transMon = new SQLiteMonTransaction(FetchDbConn().BeginTransaction()))
                {
                    if (progid == null)
                    {
                        using (SQLiteCommand command = new SQLiteCommand("insert into programmes (pluginid, extid, name) values (@pluginid, @extid, @name)", FetchDbConn()))
                        {
                            command.Parameters.Add(new SQLiteParameter("@pluginid", pluginId.ToString()));
                            command.Parameters.Add(new SQLiteParameter("@extid", progExtId));
                            command.Parameters.Add(new SQLiteParameter("@name", progExtId));
                            command.ExecuteNonQuery();
                        }

                        using (SQLiteCommand command = new SQLiteCommand("select last_insert_rowid()", FetchDbConn()))
                        {
                            progid = (int)(long)command.ExecuteScalar();
                        }
                    }

                    using (SQLiteCommand command = new SQLiteCommand("update programmes set name=@name, description=@description, image=@image, singleepisode=@singleepisode, lastupdate=@lastupdate where progid=@progid", FetchDbConn()))
                    {
                        command.Parameters.Add(new SQLiteParameter("@name", progInfo.Name));
                        command.Parameters.Add(new SQLiteParameter("@description", progInfo.Description));
                        command.Parameters.Add(new SQLiteParameter("@image", StoreImage(progInfo.Image)));
                        command.Parameters.Add(new SQLiteParameter("@singleepisode", progInfo.SingleEpisode));
                        command.Parameters.Add(new SQLiteParameter("@lastupdate", DateTime.Now));
                        command.Parameters.Add(new SQLiteParameter("@progid", progid));
                        command.ExecuteNonQuery();
                    }

                    transMon.Trans.Commit();
                }
            }

            if (Updated != null)
            {
                Updated(progid.Value);
            }

            return(progid);
        }
Exemplo n.º 33
0
 public Download(SQLiteMonDataReader reader)
 {
     this.FetchData(reader);
 }
Exemplo n.º 34
0
 public Favourite(SQLiteMonDataReader reader)
     : base(reader)
 {
 }
Exemplo n.º 35
0
        public static int Compare(int progid1, int progid2)
        {
            lock (sortCacheLock)
            {
                if (sortCache == null || !sortCache.ContainsKey(progid1) || !sortCache.ContainsKey(progid2))
                {
                    // The sort cache is either empty or missing one of the values that are required, so recreate it
                    sortCache = new Dictionary<int, int>();

                    int sort = 0;
                    string orderBy = null;

                    switch (sortBy)
                    {
                        case FavouriteCols.ProgrammeName:
                            orderBy = "programmes.name" + (sortAsc ? string.Empty : " desc");
                            break;
                        case FavouriteCols.Provider:
                            orderBy = "programmes.pluginid" + (sortAsc ? " desc" : string.Empty);
                            break;
                        default:
                            throw new InvalidDataException("Invalid column: " + sortBy.ToString());
                    }

                    using (SQLiteCommand command = new SQLiteCommand("select favourites.progid from favourites, programmes where programmes.progid=favourites.progid order by " + orderBy, FetchDbConn()))
                    {
                        using (SQLiteMonDataReader reader = new SQLiteMonDataReader(command.ExecuteReader()))
                        {
                            int progidOrdinal = reader.GetOrdinal("progid");

                            while (reader.Read())
                            {
                                sortCache.Add(reader.GetInt32(progidOrdinal), sort);
                                sort += 1;
                            }
                        }
                    }
                }

                return sortCache[progid1] - sortCache[progid2];
            }
        }
Exemplo n.º 36
0
        public static void Cleanup(Status status, DateTime?olderThan, int?progid, bool orphans, bool played, bool noDeleteAudio)
        {
            if (!(olderThan != null || progid != null || orphans || played))
            {
                throw new ArgumentException("At least one kind of cleanup filter must be set!");
            }
            else if (orphans && noDeleteAudio)
            {
                throw new ArgumentException("Cannot remove orphans and not delete audio files at the same time!");
            }

            status.StatusText = "Fetching downloads...";

            string query = "select " + Columns + " from downloads, episodes where downloads.epid=episodes.epid and status=@status";

            if (olderThan != null)
            {
                query += " and date < @date";
            }

            if (progid != null)
            {
                query += " and progid=@progid";
            }

            if (played)
            {
                query += " and playcount > 0";
            }

            // Fetch a list of the downloads first to prevent locking the database during cleanup
            List <Download> downloads = new List <Download>();

            using (SQLiteCommand command = new SQLiteCommand(query, FetchDbConn()))
            {
                command.Parameters.Add(new SQLiteParameter("@status", DownloadStatus.Downloaded));

                if (olderThan != null)
                {
                    command.Parameters.Add(new SQLiteParameter("@date", olderThan.Value));
                }

                if (progid != null)
                {
                    command.Parameters.Add(new SQLiteParameter("@progid", progid.Value));
                }

                using (SQLiteMonDataReader reader = new SQLiteMonDataReader(command.ExecuteReader()))
                {
                    while (reader.Read())
                    {
                        downloads.Add(new Download(reader));
                    }
                }
            }

            status.ProgressBarMax     = downloads.Count;
            status.StatusText         = "Cleaning up downloads...";
            status.ProgressBarMarquee = false;

            List <string> ignoreRoots = new List <string>();

            foreach (Download download in downloads)
            {
                bool exists = File.Exists(download.DownloadPath);

                if (!orphans || !exists)
                {
                    if (orphans || !noDeleteAudio)
                    {
                        // Test that the drive or share that the file is on still exists, and ask the user if not
                        string pathRoot = Path.GetPathRoot(download.DownloadPath);

                        if (!Directory.Exists(pathRoot) && !ignoreRoots.Contains(pathRoot))
                        {
                            if (MessageBox.Show("\"" + pathRoot + "\" is not currently available." + Environment.NewLine + Environment.NewLine + "Continue cleaning up anyway?", Application.ProductName, MessageBoxButtons.YesNo) == DialogResult.No)
                            {
                                break;
                            }

                            ignoreRoots.Add(pathRoot);
                        }
                    }

                    // Take the download out of the list and set the auto download flag to false
                    RemoveAsync(download.Epid, false);

                    // Delete the audio file too (if it exists, and the user wants to remove it)
                    if (exists && !noDeleteAudio)
                    {
                        File.Delete(download.DownloadPath);
                    }
                }

                status.ProgressBarValue++;
            }

            status.ProgressBarValue = status.ProgressBarMax;
        }
Exemplo n.º 37
0
        public static int Compare(int epid1, int epid2)
        {
            lock (sortCacheLock)
            {
                if (sortCache == null || !sortCache.ContainsKey(epid1) || !sortCache.ContainsKey(epid2))
                {
                    // The sort cache is either empty or missing one of the values that are required, so recreate it
                    sortCache = new Dictionary<int, int>();

                    int sort = 0;
                    string orderBy = null;

                    switch (sortBy)
                    {
                        case DownloadCols.EpisodeName:
                            orderBy = "name" + (sortAsc ? string.Empty : " desc");
                            break;
                        case DownloadCols.EpisodeDate:
                            orderBy = "date" + (sortAsc ? string.Empty : " desc");
                            break;
                        case DownloadCols.Status:
                            orderBy = "status = 0" + (sortAsc ? " desc" : string.Empty) + ", status" + (sortAsc ? " desc" : string.Empty) + ", playcount > 0" + (sortAsc ? string.Empty : " desc") + ", date" + (sortAsc ? " desc" : string.Empty);
                            break;
                        case DownloadCols.Duration:
                            orderBy = "duration" + (sortAsc ? string.Empty : " desc");
                            break;
                        default:
                            throw new InvalidDataException("Invalid column: " + sortBy.ToString());
                    }

                    using (SQLiteCommand command = new SQLiteCommand("select downloads.epid from downloads, episodes where downloads.epid=episodes.epid order by " + orderBy, FetchDbConn()))
                    {
                        using (SQLiteMonDataReader reader = new SQLiteMonDataReader(command.ExecuteReader()))
                        {
                            int epidOrdinal = reader.GetOrdinal("epid");

                            while (reader.Read())
                            {
                                sortCache.Add(reader.GetInt32(epidOrdinal), sort);
                                sort += 1;
                            }
                        }
                    }
                }

                try
                {
                    return sortCache[epid1] - sortCache[epid2];
                }
                catch (KeyNotFoundException)
                {
                    // One of the entries has been removed from the database, but not yet from the list
                    return 0;
                }
            }
        }
Exemplo n.º 38
0
        public static List<Download> FetchAll()
        {
            List<Download> items = new List<Download>();

            using (SQLiteCommand command = new SQLiteCommand("select " + Columns + " from episodes, downloads where downloads.epid=episodes.epid", FetchDbConn()))
            {
                using (SQLiteMonDataReader reader = new SQLiteMonDataReader(command.ExecuteReader()))
                {
                    while (reader.Read())
                    {
                        items.Add(new Download(reader));
                    }
                }
            }

            return items;
        }
Exemplo n.º 39
0
        public static List<Download> FetchLatest(int count)
        {
            List<Download> items = new List<Download>();

            using (SQLiteCommand command = new SQLiteCommand("select " + Columns + " from episodes, downloads where downloads.epid=episodes.epid and status=@status order by episodes.epid desc limit @count", FetchDbConn()))
            {
                command.Parameters.Add(new SQLiteParameter("@status", Download.DownloadStatus.Downloaded));
                command.Parameters.Add(new SQLiteParameter("@count", count));

                using (SQLiteMonDataReader reader = new SQLiteMonDataReader(command.ExecuteReader()))
                {
                    while (reader.Read())
                    {
                        items.Add(new Download(reader));
                    }
                }
            }

            return items;
        }
Exemplo n.º 40
0
        public static void UpdatePaths(Status status, string newPath, string newFormat)
        {
            status.StatusText = "Fetching downloads...";

            List<Download> downloads = new List<Download>();

            using (SQLiteCommand command = new SQLiteCommand("select episodes.epid, progid, name, description, date, duration, autodownload, status, errortype, errordetails, filepath, playcount from episodes, downloads where episodes.epid=downloads.epid", FetchDbConn()))
            {
                using (SQLiteMonDataReader reader = new SQLiteMonDataReader(command.ExecuteReader()))
                {
                    while (reader.Read())
                    {
                        downloads.Add(new Download(reader));
                    }
                }
            }

            if (downloads.Count > 0)
            {
                Dictionary<int, Programme> programmes = new Dictionary<int, Programme>();
                int progress = 0;

                status.StatusText = "Updating download paths...";
                status.ProgressBarMax = downloads.Count;
                status.ProgressBarMarquee = false;

                using (SQLiteCommand command = new SQLiteCommand("update downloads set filepath=@filepath where epid=@epid", FetchDbConn()))
                {
                    SQLiteParameter epidParam = new SQLiteParameter("epid");
                    SQLiteParameter filepathParam = new SQLiteParameter("filepath");

                    command.Parameters.Add(epidParam);
                    command.Parameters.Add(filepathParam);

                    foreach (Download download in downloads)
                    {
                        if (File.Exists(download.DownloadPath))
                        {
                            if (!programmes.ContainsKey(download.Progid))
                            {
                                programmes.Add(download.Progid, new Programme(download.Progid));
                            }

                            string newDownloadPath = FindFreeSaveFileName(newFormat, programmes[download.Progid], download, newPath) + Path.GetExtension(download.DownloadPath);

                            if (newDownloadPath != download.DownloadPath)
                            {
                                lock (Database.DbUpdateLock)
                                {
                                    using (SQLiteMonTransaction transMon = new SQLiteMonTransaction(FetchDbConn().BeginTransaction()))
                                    {
                                        epidParam.Value = download.Epid;
                                        filepathParam.Value = newDownloadPath;
                                        command.ExecuteNonQuery();

                                        File.Move(download.DownloadPath, newDownloadPath);
                                        transMon.Trans.Commit();
                                    }
                                }
                            }
                        }

                        status.ProgressBarValue = ++progress;
                    }
                }

                status.ProgressBarValue = status.ProgressBarMax;
            }
        }
Exemplo n.º 41
0
        public static void ReportError(int epid)
        {
            ErrorReporting report = null;

            using (SQLiteCommand command = new SQLiteCommand("select errordetails from downloads where epid=@epid and errordetails is not null", FetchDbConn()))
            {
                command.Parameters.Add(new SQLiteParameter("@epid", epid));

                using (SQLiteMonDataReader reader = new SQLiteMonDataReader(command.ExecuteReader()))
                {
                    if (reader.Read())
                    {
                        int errordetailsOrdinal = reader.GetOrdinal("errordetails");

                        // Get the length of the content by passing null to getbytes
                        int contentLength = (int)reader.GetBytes(errordetailsOrdinal, 0, null, 0, 0);

                        byte[] content = new byte[contentLength];
                        reader.GetBytes(errordetailsOrdinal, 0, content, 0, contentLength);

                        using (MemoryStream stream = new MemoryStream(content))
                        {
                            BinaryFormatter formatter = new BinaryFormatter();
                            report = (ErrorReporting)formatter.Deserialize(stream);
                        }
                    }
                }
            }

            if (report == null)
            {
                MessageBox.Show("Please retry this download before reporting the error again.", Application.ProductName);
                return;
            }

            if (report.SendReport())
            {
                using (SQLiteCommand command = new SQLiteCommand("update downloads set errordetails=null where epid=@epid", FetchDbConn()))
                {
                    command.Parameters.Add(new SQLiteParameter("@epid", epid));
                    command.ExecuteNonQuery();
                }
            }
        }
Exemplo n.º 42
0
        public static System.Drawing.Bitmap GetImage(int epid)
        {
            using (SQLiteCommand command = new SQLiteCommand("select image, progid from episodes where epid=@epid", FetchDbConn()))
            {
                command.Parameters.Add(new SQLiteParameter("@epid", epid));

                using (SQLiteMonDataReader reader = new SQLiteMonDataReader(command.ExecuteReader()))
                {
                    if (reader.Read())
                    {
                        int imageOrdinal = reader.GetOrdinal("image");

                        if (!reader.IsDBNull(imageOrdinal))
                        {
                            return RetrieveImage(reader.GetInt32(imageOrdinal));
                        }

                        using (SQLiteCommand progCmd = new SQLiteCommand("select image from programmes where progid=@progid and image not null", FetchDbConn()))
                        {
                            progCmd.Parameters.Add(new SQLiteParameter("@progid", reader.GetInt32(reader.GetOrdinal("progid"))));

                            using (SQLiteMonDataReader progReader = new SQLiteMonDataReader(progCmd.ExecuteReader()))
                            {
                                if (progReader.Read())
                                {
                                    return RetrieveImage(progReader.GetInt32(progReader.GetOrdinal("image")));
                                }
                            }
                        }
                    }
                }
            }

            return null;
        }
Exemplo n.º 43
0
        private static void UpdateInfoIfRequiredAsync(int progid)
        {
            Guid providerId = Guid.Empty;
            string updateExtid = null;

            // Test to see if an update is required, and then free up the database
            using (SQLiteCommand command = new SQLiteCommand("select pluginid, extid, lastupdate from programmes where progid=@progid", FetchDbConn()))
            {
                command.Parameters.Add(new SQLiteParameter("@progid", progid));

                using (SQLiteMonDataReader reader = new SQLiteMonDataReader(command.ExecuteReader()))
                {
                    if (reader.Read())
                    {
                        providerId = new Guid(reader.GetString(reader.GetOrdinal("pluginid")));

                        if (Provider.Exists(providerId))
                        {
                            IRadioProvider pluginInstance = Provider.GetFromId(providerId).CreateInstance();

                            if (reader.GetDateTime(reader.GetOrdinal("lastupdate")).AddDays(pluginInstance.ProgInfoUpdateFreqDays) < DateTime.Now)
                            {
                                updateExtid = reader.GetString(reader.GetOrdinal("extid"));
                            }
                        }
                    }
                }
            }

            // Now perform the update if required
            if (updateExtid != null)
            {
                try
                {
                    UpdateInfo(providerId, updateExtid);
                }
                catch (ProviderException)
                {
                    // Suppress any provider exceptions, as the user isn't waiting for this action
                }
            }
        }
Exemplo n.º 44
0
        protected void FetchData(SQLiteMonDataReader reader)
        {
            int descriptionOrdinal = reader.GetOrdinal("description");
            int durationOrdinal = reader.GetOrdinal("duration");

            this.Epid = reader.GetInt32(reader.GetOrdinal("epid"));
            this.Progid = reader.GetInt32(reader.GetOrdinal("progid"));
            this.Date = reader.GetDateTime(reader.GetOrdinal("date"));
            this.Name = reader.GetString(reader.GetOrdinal("name"));

            if (!reader.IsDBNull(descriptionOrdinal))
            {
                this.Description = reader.GetString(descriptionOrdinal);
            }

            if (!reader.IsDBNull(durationOrdinal))
            {
                this.Duration = reader.GetInt32(durationOrdinal);
            }

            this.AutoDownload = reader.GetInt32(reader.GetOrdinal("autodownload")) == 1;
        }
Exemplo n.º 45
0
        public static List<Favourite> FetchAll()
        {
            List<Favourite> items = new List<Favourite>();

            using (SQLiteCommand command = new SQLiteCommand("select " + Columns + " from favourites, programmes where favourites.progid=programmes.progid", FetchDbConn()))
            {
                using (SQLiteMonDataReader reader = new SQLiteMonDataReader(command.ExecuteReader()))
                {
                    while (reader.Read())
                    {
                        items.Add(new Favourite(reader));
                    }
                }
            }

            return items;
        }
Exemplo n.º 46
0
 public Episode(SQLiteMonDataReader reader)
 {
     this.FetchData(reader);
 }
Exemplo n.º 47
0
        private static int?UpdateInfo(int progid, string episodeExtId)
        {
            Guid   pluginId;
            string progExtId;

            Provider.ProgrammeInfo progInfo;

            using (SQLiteCommand command = new SQLiteCommand("select pluginid, extid, name, description, singleepisode from programmes where progid=@progid", FetchDbConn()))
            {
                command.Parameters.Add(new SQLiteParameter("@progid", progid));

                using (SQLiteMonDataReader reader = new SQLiteMonDataReader(command.ExecuteReader()))
                {
                    if (!reader.Read())
                    {
                        throw new DataNotFoundException(progid, "Programme does not exist");
                    }

                    pluginId  = new Guid(reader.GetString(reader.GetOrdinal("pluginid")));
                    progExtId = reader.GetString(reader.GetOrdinal("extid"));

                    progInfo      = new Provider.ProgrammeInfo();
                    progInfo.Name = reader.GetString(reader.GetOrdinal("name"));
                    int descriptionOrdinal = reader.GetOrdinal("description");

                    if (!reader.IsDBNull(descriptionOrdinal))
                    {
                        progInfo.Description = reader.GetString(descriptionOrdinal);
                    }

                    progInfo.SingleEpisode = reader.GetBoolean(reader.GetOrdinal("singleepisode"));
                }
            }

            Provider.RadioProvider providerInst = Provider.Handler.GetFromId(pluginId).CreateInstance();
            Provider.EpisodeInfo   episodeInfo;

            try
            {
                episodeInfo = providerInst.GetEpisodeInfo(progExtId, progInfo, episodeExtId);

                if (episodeInfo == null)
                {
                    return(null);
                }

                if (string.IsNullOrEmpty(episodeInfo.Name))
                {
                    throw new InvalidDataException("Episode name cannot be null or an empty string");
                }
            }
            catch (Exception provExp)
            {
                provExp.Data.Add("Programme", progInfo.ToString() + "\r\nExtID: " + progExtId);
                provExp.Data.Add("Episode ExtID", episodeExtId);
                throw new ProviderException("Call to GetEpisodeInfo failed", provExp, pluginId);
            }

            if (episodeInfo.Date == null)
            {
                // The date of the episode isn't known, so use the current date
                episodeInfo.Date = DateTime.Now;
            }

            lock (DbUpdateLock)
            {
                using (SQLiteMonTransaction transMon = new SQLiteMonTransaction(FetchDbConn().BeginTransaction()))
                {
                    int?epid = null;

                    using (SQLiteCommand command = new SQLiteCommand("select epid from episodes where progid=@progid and extid=@extid", FetchDbConn(), transMon.Trans))
                    {
                        command.Parameters.Add(new SQLiteParameter("@progid", progid));
                        command.Parameters.Add(new SQLiteParameter("@extid", episodeExtId));

                        using (SQLiteMonDataReader reader = new SQLiteMonDataReader(command.ExecuteReader()))
                        {
                            if (reader.Read())
                            {
                                epid = reader.GetInt32(reader.GetOrdinal("epid"));
                            }
                        }
                    }

                    if (epid == null)
                    {
                        using (SQLiteCommand command = new SQLiteCommand("insert into episodes (progid, extid, name, date) values (@progid, @extid, @name, @date)", FetchDbConn(), transMon.Trans))
                        {
                            command.Parameters.Add(new SQLiteParameter("@progid", progid));
                            command.Parameters.Add(new SQLiteParameter("@extid", episodeExtId));
                            command.Parameters.Add(new SQLiteParameter("@name", episodeInfo.Name));
                            command.Parameters.Add(new SQLiteParameter("@date", episodeInfo.Date));
                            command.ExecuteNonQuery();
                        }

                        using (SQLiteCommand command = new SQLiteCommand("select last_insert_rowid()", FetchDbConn(), transMon.Trans))
                        {
                            epid = (int)(long)command.ExecuteScalar();
                        }
                    }

                    using (SQLiteCommand command = new SQLiteCommand("update episodes set name=@name, description=@description, duration=@duration, date=@date, image=@image, available=1 where epid=@epid", FetchDbConn(), transMon.Trans))
                    {
                        command.Parameters.Add(new SQLiteParameter("@name", episodeInfo.Name));
                        command.Parameters.Add(new SQLiteParameter("@description", episodeInfo.Description));
                        command.Parameters.Add(new SQLiteParameter("@duration", episodeInfo.Duration));
                        command.Parameters.Add(new SQLiteParameter("@date", episodeInfo.Date));
                        command.Parameters.Add(new SQLiteParameter("@image", StoreImage(episodeInfo.Image)));
                        command.Parameters.Add(new SQLiteParameter("@epid", epid));
                        command.ExecuteNonQuery();
                    }

                    using (SQLiteCommand command = new SQLiteCommand("insert or replace into episodeext (epid, name, value) values (@epid, @name, @value)", FetchDbConn(), transMon.Trans))
                    {
                        foreach (KeyValuePair <string, string> extItem in episodeInfo.ExtInfo)
                        {
                            command.Parameters.Add(new SQLiteParameter("@epid", epid));
                            command.Parameters.Add(new SQLiteParameter("@name", extItem.Key));
                            command.Parameters.Add(new SQLiteParameter("@value", extItem.Value));
                            command.ExecuteNonQuery();
                        }
                    }

                    transMon.Trans.Commit();
                    return(epid);
                }
            }
        }
Exemplo n.º 48
0
        public static List<Download> FetchVisible(DataSearch dataSearch)
        {
            List<Download> items = new List<Download>();

            using (SQLiteCommand command = new SQLiteCommand("select " + Columns + " from episodes, downloads where downloads.epid=episodes.epid", FetchDbConn()))
            {
                using (SQLiteMonDataReader reader = new SQLiteMonDataReader(command.ExecuteReader()))
                {
                    int epidOrdinal = reader.GetOrdinal("epid");

                    while (reader.Read())
                    {
                        if (dataSearch.DownloadIsVisible(reader.GetInt32(epidOrdinal)))
                        {
                            items.Add(new Download(reader));
                        }
                    }
                }
            }

            return items;
        }
Exemplo n.º 49
0
 public Download(SQLiteMonDataReader reader)
 {
     this.FetchData(reader);
 }
Exemplo n.º 50
0
 public Episode(SQLiteMonDataReader reader)
 {
     this.FetchData(reader);
 }
Exemplo n.º 51
0
        public static void UpdatePaths(Status status, string newPath, string newFormat)
        {
            status.StatusText = "Fetching downloads...";

            List <Download> downloads = new List <Download>();

            using (SQLiteCommand command = new SQLiteCommand("select episodes.epid, progid, name, description, date, duration, autodownload, status, errortype, errordetails, filepath, playcount from episodes, downloads where episodes.epid=downloads.epid", FetchDbConn()))
            {
                using (SQLiteMonDataReader reader = new SQLiteMonDataReader(command.ExecuteReader()))
                {
                    while (reader.Read())
                    {
                        downloads.Add(new Download(reader));
                    }
                }
            }

            if (downloads.Count > 0)
            {
                Dictionary <int, Programme> programmes = new Dictionary <int, Programme>();
                int progress = 0;

                status.StatusText         = "Updating download paths...";
                status.ProgressBarMax     = downloads.Count;
                status.ProgressBarMarquee = false;

                using (SQLiteCommand command = new SQLiteCommand("update downloads set filepath=@filepath where epid=@epid", FetchDbConn()))
                {
                    SQLiteParameter epidParam     = new SQLiteParameter("epid");
                    SQLiteParameter filepathParam = new SQLiteParameter("filepath");

                    command.Parameters.Add(epidParam);
                    command.Parameters.Add(filepathParam);

                    foreach (Download download in downloads)
                    {
                        if (File.Exists(download.DownloadPath))
                        {
                            if (!programmes.ContainsKey(download.Progid))
                            {
                                programmes.Add(download.Progid, new Programme(download.Progid));
                            }

                            string newDownloadPath = FindFreeSaveFileName(newFormat, programmes[download.Progid], download, newPath) + Path.GetExtension(download.DownloadPath);

                            if (newDownloadPath != download.DownloadPath)
                            {
                                lock (DbUpdateLock)
                                {
                                    using (SQLiteMonTransaction transMon = new SQLiteMonTransaction(FetchDbConn().BeginTransaction()))
                                    {
                                        epidParam.Value     = download.Epid;
                                        filepathParam.Value = newDownloadPath;
                                        command.ExecuteNonQuery();

                                        File.Move(download.DownloadPath, newDownloadPath);
                                        transMon.Trans.Commit();
                                    }
                                }
                            }
                        }

                        status.ProgressBarValue = ++progress;
                    }
                }

                status.ProgressBarValue = status.ProgressBarMax;
            }
        }
Exemplo n.º 52
0
 public Subscription(SQLiteMonDataReader reader)
     : base(reader)
 {
 }
Exemplo n.º 53
0
        public static int? FetchInfo(int progid, string episodeExtId)
        {
            int? epid = null;

            using (SQLiteCommand command = new SQLiteCommand("select epid from episodes where progid=@progid and extid=@extid", FetchDbConn()))
            {
                command.Parameters.Add(new SQLiteParameter("@progid", progid));
                command.Parameters.Add(new SQLiteParameter("@extid", episodeExtId));

                using (SQLiteMonDataReader reader = new SQLiteMonDataReader(command.ExecuteReader()))
                {
                    if (reader.Read())
                    {
                        epid = reader.GetInt32(reader.GetOrdinal("epid"));
                    }
                }
            }

            if (epid == null)
            {
                // Fetch episode information, as it currently doesn't have an ID
                epid = UpdateInfo(progid, episodeExtId);
            }

            return epid;
        }
Exemplo n.º 54
0
        public static List<Programme> FetchAllWithDownloads()
        {
            List<Programme> items = new List<Programme>();

            using (SQLiteCommand command = new SQLiteCommand("select distinct " + Columns + " from programmes, episodes, downloads where downloads.epid=episodes.epid and episodes.progid=programmes.progid", FetchDbConn()))
            {
                using (SQLiteMonDataReader reader = new SQLiteMonDataReader(command.ExecuteReader()))
                {
                    while (reader.Read())
                    {
                        items.Add(new Programme(reader));
                    }
                }
            }

            return items;
        }
Exemplo n.º 55
0
        public static void UpdateInfoIfRequired(int epid)
        {
            int progid = 0;
            string updateExtid = null;

            // Test to see if the episode is marked as unavailable, and then free up the database
            using (SQLiteCommand command = new SQLiteCommand("select progid, extid from episodes where epid=@epid and available=0", FetchDbConn()))
            {
                command.Parameters.Add(new SQLiteParameter("@epid", epid));

                using (SQLiteMonDataReader reader = new SQLiteMonDataReader(command.ExecuteReader()))
                {
                    if (reader.Read())
                    {
                        progid = reader.GetInt32(reader.GetOrdinal("progid"));
                        updateExtid = reader.GetString(reader.GetOrdinal("extid"));
                    }
                }
            }

            // Perform an update if the episode was marked as unavailable
            if (updateExtid != null)
            {
                if (Download.IsDownload(epid))
                {
                    // The episode is in the downloads list, so just mark as available
                    using (SQLiteCommand command = new SQLiteCommand("update episodes set available=1 where epid=@epid", FetchDbConn()))
                    {
                        command.Parameters.Add(new SQLiteParameter("@epid", epid));
                        command.ExecuteNonQuery();
                    }
                }
                else
                {
                    UpdateInfo(progid, updateExtid);
                }
            }
        }
Exemplo n.º 56
0
        public static int? FetchInfo(Guid pluginId, string progExtId)
        {
            if (!Provider.Exists(pluginId))
            {
                return null;
            }

            int? progid = null;

            using (SQLiteCommand command = new SQLiteCommand("select progid from programmes where pluginid=@pluginid and extid=@extid", FetchDbConn()))
            {
                command.Parameters.Add(new SQLiteParameter("@pluginid", pluginId.ToString()));
                command.Parameters.Add(new SQLiteParameter("@extid", progExtId));

                using (SQLiteMonDataReader reader = new SQLiteMonDataReader(command.ExecuteReader()))
                {
                    if (reader.Read())
                    {
                        progid = reader.GetInt32(reader.GetOrdinal("progid"));
                    }
                }
            }

            if (progid == null)
            {
                // Need to fetch the data synchronously as the progid is currently unknown
                progid = UpdateInfo(pluginId, progExtId);
            }
            else
            {
                // Kick off an update in the background if required
                UpdateInfoIfRequired(progid.Value);
            }

            return progid;
        }
Exemplo n.º 57
0
        private static int? UpdateInfo(int progid, string episodeExtId)
        {
            Guid pluginId;
            string progExtId;
            ProgrammeInfo progInfo;

            using (SQLiteCommand command = new SQLiteCommand("select pluginid, extid, name, description, singleepisode from programmes where progid=@progid", FetchDbConn()))
            {
                command.Parameters.Add(new SQLiteParameter("@progid", progid));

                using (SQLiteMonDataReader reader = new SQLiteMonDataReader(command.ExecuteReader()))
                {
                    if (!reader.Read())
                    {
                        throw new DataNotFoundException(progid, "Programme does not exist");
                    }

                    pluginId = new Guid(reader.GetString(reader.GetOrdinal("pluginid")));
                    progExtId = reader.GetString(reader.GetOrdinal("extid"));

                    progInfo = new ProgrammeInfo();
                    progInfo.Name = reader.GetString(reader.GetOrdinal("name"));
                    int descriptionOrdinal = reader.GetOrdinal("description");

                    if (!reader.IsDBNull(descriptionOrdinal))
                    {
                        progInfo.Description = reader.GetString(descriptionOrdinal);
                    }

                    progInfo.SingleEpisode = reader.GetBoolean(reader.GetOrdinal("singleepisode"));
                }
            }

            IRadioProvider providerInst = Provider.GetFromId(pluginId).CreateInstance();
            EpisodeInfo episodeInfo;

            try
            {
                episodeInfo = providerInst.GetEpisodeInfo(progExtId, progInfo, episodeExtId);

                if (episodeInfo == null)
                {
                    return null;
                }

                if (string.IsNullOrEmpty(episodeInfo.Name))
                {
                    throw new InvalidDataException("Episode name cannot be null or an empty string");
                }
            }
            catch (Exception provExp)
            {
                provExp.Data.Add("Programme", progInfo.ToString() + "\r\nExtID: " + progExtId);
                provExp.Data.Add("Episode ExtID", episodeExtId);
                throw new ProviderException("Call to GetEpisodeInfo failed", provExp, pluginId);
            }

            if (episodeInfo.Date == null)
            {
                // The date of the episode isn't known, so use the current date
                episodeInfo.Date = DateTime.Now;
            }

            lock (DbUpdateLock)
            {
                using (SQLiteMonTransaction transMon = new SQLiteMonTransaction(FetchDbConn().BeginTransaction()))
                {
                    int? epid = null;

                    using (SQLiteCommand command = new SQLiteCommand("select epid from episodes where progid=@progid and extid=@extid", FetchDbConn(), transMon.Trans))
                    {
                        command.Parameters.Add(new SQLiteParameter("@progid", progid));
                        command.Parameters.Add(new SQLiteParameter("@extid", episodeExtId));

                        using (SQLiteMonDataReader reader = new SQLiteMonDataReader(command.ExecuteReader()))
                        {
                            if (reader.Read())
                            {
                                epid = reader.GetInt32(reader.GetOrdinal("epid"));
                            }
                        }
                    }

                    if (epid == null)
                    {
                        using (SQLiteCommand command = new SQLiteCommand("insert into episodes (progid, extid, name, date) values (@progid, @extid, @name, @date)", FetchDbConn(), transMon.Trans))
                        {
                            command.Parameters.Add(new SQLiteParameter("@progid", progid));
                            command.Parameters.Add(new SQLiteParameter("@extid", episodeExtId));
                            command.Parameters.Add(new SQLiteParameter("@name", episodeInfo.Name));
                            command.Parameters.Add(new SQLiteParameter("@date", episodeInfo.Date));
                            command.ExecuteNonQuery();
                        }

                        using (SQLiteCommand command = new SQLiteCommand("select last_insert_rowid()", FetchDbConn(), transMon.Trans))
                        {
                            epid = (int)(long)command.ExecuteScalar();
                        }
                    }

                    using (SQLiteCommand command = new SQLiteCommand("update episodes set name=@name, description=@description, duration=@duration, date=@date, image=@image, available=1 where epid=@epid", FetchDbConn(), transMon.Trans))
                    {
                        command.Parameters.Add(new SQLiteParameter("@name", episodeInfo.Name));
                        command.Parameters.Add(new SQLiteParameter("@description", episodeInfo.Description));
                        command.Parameters.Add(new SQLiteParameter("@duration", episodeInfo.Duration));
                        command.Parameters.Add(new SQLiteParameter("@date", episodeInfo.Date));
                        command.Parameters.Add(new SQLiteParameter("@image", StoreImage(episodeInfo.Image)));
                        command.Parameters.Add(new SQLiteParameter("@epid", epid));
                        command.ExecuteNonQuery();
                    }

                    using (SQLiteCommand command = new SQLiteCommand("insert or replace into episodeext (epid, name, value) values (@epid, @name, @value)", FetchDbConn(), transMon.Trans))
                    {
                        foreach (KeyValuePair<string, string> extItem in episodeInfo.ExtInfo)
                        {
                            command.Parameters.Add(new SQLiteParameter("@epid", epid));
                            command.Parameters.Add(new SQLiteParameter("@name", extItem.Key));
                            command.Parameters.Add(new SQLiteParameter("@value", extItem.Value));
                            command.ExecuteNonQuery();
                        }
                    }

                    transMon.Trans.Commit();
                    return epid;
                }
            }
        }
Exemplo n.º 58
0
        public static List<string> GetAvailableEpisodes(int progid, bool fetchAll)
        {
            Guid providerId;
            string progExtId;
            ProgrammeInfo progInfo;

            using (SQLiteCommand command = new SQLiteCommand("select pluginid, extid, name, description, singleepisode from programmes where progid=@progid", FetchDbConn()))
            {
                command.Parameters.Add(new SQLiteParameter("@progid", progid));

                using (SQLiteMonDataReader reader = new SQLiteMonDataReader(command.ExecuteReader()))
                {
                    if (!reader.Read())
                    {
                        throw new DataNotFoundException(progid, "Programme does not exist");
                    }

                    providerId = new Guid(reader.GetString(reader.GetOrdinal("pluginid")));
                    progExtId = reader.GetString(reader.GetOrdinal("extid"));

                    progInfo = new ProgrammeInfo();
                    progInfo.Name = reader.GetString(reader.GetOrdinal("name"));
                    int descriptionOrdinal = reader.GetOrdinal("description");

                    if (!reader.IsDBNull(descriptionOrdinal))
                    {
                        progInfo.Description = reader.GetString(descriptionOrdinal);
                    }

                    progInfo.SingleEpisode = reader.GetBoolean(reader.GetOrdinal("singleepisode"));
                }
            }

            if (!Provider.Exists(providerId))
            {
                return null;
            }

            // Fetch a list of previously available episodes for the programme
            List<string> previousAvailable = new List<string>();

            using (SQLiteCommand command = new SQLiteCommand("select extid from episodes where progid=@progid and available=1 order by date desc", FetchDbConn()))
            {
                command.Parameters.Add(new SQLiteParameter("@progid", progid));

                using (SQLiteMonDataReader reader = new SQLiteMonDataReader(command.ExecuteReader()))
                {
                    int epidOrdinal = reader.GetOrdinal("extid");

                    while (reader.Read())
                    {
                        previousAvailable.Add(reader.GetString(epidOrdinal));
                    }
                }
            }

            List<string> allEpExtIds = new List<string>();
            int page = 1;

            IRadioProvider providerInst = Provider.GetFromId(providerId).CreateInstance();
            AvailableEpisodes available;

            do
            {
                try
                {
                    available = providerInst.GetAvailableEpisodes(progExtId, progInfo, page);
                }
                catch (Exception provExp)
                {
                    provExp.Data.Add("Programme ExtID", progExtId);
                    throw new ProviderException("Call to GetAvailableEpisodeIds failed", provExp, providerId);
                }

                if (available.EpisodeIds.Count == 0)
                {
                    break;
                }

                int trackOverlap = -1;

                foreach (string epExtId in available.EpisodeIds)
                {
                    // Append the returned IDs to the list of all episodes (minus duplicates)
                    if (!allEpExtIds.Contains(epExtId))
                    {
                        allEpExtIds.Add(epExtId);
                    }

                    if (previousAvailable.Contains(epExtId))
                    {
                        // Store where the available & previously available ID lists overlap
                        trackOverlap = previousAvailable.IndexOf(epExtId);
                    }
                    else if (trackOverlap >= 0)
                    {
                        // Bump up the overlap index to show there are more after the overlap
                        trackOverlap++;
                    }
                }

                if (available.MoreAvailable && !fetchAll)
                {
                    if (trackOverlap >= 0)
                    {
                        // Remove previously available programmes before this page from the list so that they
                        // are not incorrectly un-flagged as available in the database
                        if (trackOverlap < previousAvailable.Count - 1)
                        {
                            previousAvailable.RemoveRange(trackOverlap + 1, previousAvailable.Count - (trackOverlap + 1));
                        }

                        // Stop fetching available episode pages
                        break;
                    }
                }

                page++;
            }
            while (available.MoreAvailable);

            // Remove the still available episodes from the previously available list
            foreach (string epExtId in allEpExtIds)
            {
                previousAvailable.Remove(epExtId);
            }

            // Unflag any no-longer available episodes in the database
            if (previousAvailable.Count > 0)
            {
                lock (DbUpdateLock)
                {
                    using (SQLiteMonTransaction transMon = new SQLiteMonTransaction(FetchDbConn().BeginTransaction()))
                    {
                        using (SQLiteCommand command = new SQLiteCommand("update episodes set available=0 where progid=@progid and extid=@extid", FetchDbConn(), transMon.Trans))
                        {
                            SQLiteParameter extidParam = new SQLiteParameter("@extid");
                            command.Parameters.Add(new SQLiteParameter("@progid", progid));
                            command.Parameters.Add(extidParam);

                            foreach (string epExtId in previousAvailable)
                            {
                                extidParam.Value = epExtId;
                                command.ExecuteNonQuery();
                            }
                        }

                        transMon.Trans.Commit();
                    }
                }
            }

            return allEpExtIds;
        }
Exemplo n.º 59
0
        protected new void FetchData(SQLiteMonDataReader reader)
        {
            base.FetchData(reader);

            int filepathOrdinal = reader.GetOrdinal("filepath");

            this.Status = (DownloadStatus)reader.GetInt32(reader.GetOrdinal("status"));

            if (this.Status == DownloadStatus.Errored)
            {
                this.ErrorType = (ErrorType)reader.GetInt32(reader.GetOrdinal("errortype"));

                if (this.ErrorType != ErrorType.UnknownError)
                {
                    this.ErrorDetails = reader.GetString(reader.GetOrdinal("errordetails"));
                }
            }

            if (!reader.IsDBNull(filepathOrdinal))
            {
                this.DownloadPath = reader.GetString(filepathOrdinal);
            }

            this.PlayCount = reader.GetInt32(reader.GetOrdinal("playcount"));
        }
Exemplo n.º 60
0
        public static System.Drawing.Bitmap GetImage(int progid)
        {
            using (SQLiteCommand command = new SQLiteCommand("select image from programmes where progid=@progid and image not null", FetchDbConn()))
            {
                command.Parameters.Add(new SQLiteParameter("@progid", progid));

                using (SQLiteMonDataReader reader = new SQLiteMonDataReader(command.ExecuteReader()))
                {
                    if (reader.Read())
                    {
                        return RetrieveImage(reader.GetInt32(reader.GetOrdinal("image")));
                    }
                    else
                    {
                        // Find the id of the latest episode's image
                        using (SQLiteCommand latestCmd = new SQLiteCommand("select image from episodes where progid=@progid and image not null order by date desc limit 1", FetchDbConn()))
                        {
                            latestCmd.Parameters.Add(new SQLiteParameter("@progid", progid));

                            using (SQLiteMonDataReader latestRdr = new SQLiteMonDataReader(latestCmd.ExecuteReader()))
                            {
                                if (latestRdr.Read())
                                {
                                    return RetrieveImage(latestRdr.GetInt32(latestRdr.GetOrdinal("image")));
                                }
                            }
                        }
                    }
                }
            }

            return null;
        }