コード例 #1
0
        public bool LoadDownloads(
            out List <InProgressDownloadItem> inProgressDownloads,
            out List <FinishedDownloadItem> finishedDownloads, QueryMode queryMode = QueryMode.All)
        {
            lock (db)
            {
                inProgressDownloads = new List <InProgressDownloadItem>();
                finishedDownloads   = new List <FinishedDownloadItem>();
                try
                {
                    SQLiteCommand sqlCommand;
                    if (queryMode == QueryMode.All)
                    {
                        if (cmdFetchAll == null)
                        {
                            cmdFetchAll = new SQLiteCommand("SELECT * FROM downloads", db);
                        }
                        sqlCommand = cmdFetchAll;
                    }
                    else
                    {
                        if (cmdFetchConditional == null)
                        {
                            cmdFetchConditional = new SQLiteCommand("SELECT * FROM downloads WHERE completed=@completed", db);
                        }
                        SetParam("@completed", queryMode == QueryMode.InProgress ? 0 : 1, cmdFetchConditional.Parameters);
                        sqlCommand = cmdFetchConditional;
                    }
                    using SQLiteDataReader r = sqlCommand.ExecuteReader();
                    while (r.Read())
                    {
                        var id                 = r.GetSafeString(0);
                        var inProgress         = r.GetInt32(1) == 0;
                        DownloadItemBase entry = r.GetInt32(1) == 0 ? new InProgressDownloadItem() : new FinishedDownloadItem();
                        entry.Id                 = id;
                        entry.Name               = r.GetSafeString(2);
                        entry.DateAdded          = DateTime.FromBinary(r.GetInt64(3));
                        entry.Size               = r.GetInt64(4);
                        entry.DownloadType       = r.GetSafeString(7);
                        entry.FileNameFetchMode  = (FileNameFetchMode)r.GetInt32(8);
                        entry.MaxSpeedLimitInKiB = r.GetInt32(9);
                        entry.TargetDir          = r.GetSafeString(10);
                        entry.PrimaryUrl         = r.GetSafeString(11);
                        entry.RefererUrl         = r.GetSafeString(12);
                        if (r.GetInt32(13) == 1)
                        {
                            var user = r.GetSafeString(14);
                            var pass = r.GetSafeString(15);
                            if (user != null)
                            {
                                entry.Authentication = new AuthenticationInfo
                                {
                                    UserName = user,
                                    Password = pass
                                };
                            }
                        }
                        var proxy = new ProxyInfo {
                        };
                        proxy.ProxyType = (ProxyType)r.GetInt32(16);
                        proxy.Host      = r.GetSafeString(17);
                        proxy.Port      = r.GetInt32(18);
                        proxy.UserName  = r.GetSafeString(19);
                        proxy.Password  = r.GetSafeString(20);
                        entry.Proxy     = proxy;

                        if (inProgress)
                        {
                            var inp = (InProgressDownloadItem)entry;
                            inp.Status   = DownloadStatus.Stopped;
                            inp.Progress = r.GetInt32(6);
                            inProgressDownloads.Add(inp);
                        }
                        else
                        {
                            finishedDownloads.Add((FinishedDownloadItem)entry);
                        }
                    }
                    return(true);
                }
                catch (Exception ex)
                {
                    Log.Debug(ex, ex.Message);
                }
                return(false);
            }
        }
コード例 #2
0
        public DownloadItemBase?GetDownloadById(string id)
        {
            lock (db)
            {
                try
                {
                    if (cmdFetchOne == null)
                    {
                        cmdFetchOne = new SQLiteCommand("SELECT * FROM downloads WHERE id=@id", db);
                    }
                    SetParam("@id", id, cmdFetchOne.Parameters);
                    //cmdFetchOne.Parameters["@id"].Value = id;
                    using SQLiteDataReader r = cmdFetchOne.ExecuteReader();
                    if (r.Read())
                    {
                        var inProgress         = r.GetInt32(1) == 0;
                        DownloadItemBase entry = r.GetInt32(1) == 0 ? new InProgressDownloadItem() : new FinishedDownloadItem();
                        entry.Id                 = id;
                        entry.Name               = r.GetSafeString(2);
                        entry.DateAdded          = DateTime.FromBinary(r.GetInt64(3));
                        entry.Size               = r.GetInt64(4);
                        entry.DownloadType       = r.GetSafeString(7);
                        entry.FileNameFetchMode  = (FileNameFetchMode)r.GetInt32(8);
                        entry.MaxSpeedLimitInKiB = r.GetInt32(9);
                        entry.TargetDir          = r.GetSafeString(10);
                        entry.PrimaryUrl         = r.GetSafeString(11);
                        entry.RefererUrl         = r.GetSafeString(12);
                        if (r.GetInt32(13) == 1)
                        {
                            var user = r.GetSafeString(14);
                            var pass = r.GetSafeString(15);
                            if (user != null)
                            {
                                entry.Authentication = new AuthenticationInfo
                                {
                                    UserName = user,
                                    Password = pass
                                };
                            }
                        }
                        var proxy = new ProxyInfo {
                        };
                        proxy.ProxyType = (ProxyType)r.GetInt32(16);
                        proxy.Host      = r.GetSafeString(17);
                        proxy.Port      = r.GetInt32(18);
                        proxy.UserName  = r.GetSafeString(19);
                        proxy.Password  = r.GetSafeString(20);
                        entry.Proxy     = proxy;

                        if (inProgress)
                        {
                            var inp = (InProgressDownloadItem)entry;
                            inp.Status   = DownloadStatus.Stopped;
                            inp.Progress = r.GetInt32(6);
                        }
                        return(entry);
                    }
                }
                catch (Exception ex)
                {
                    Log.Debug(ex, ex.Message);
                }
                return(null);
            }
        }