Exemple #1
0
        private ObservableCollection <RssListBinding> GetRssListFromDatabase()
        {
            using (SQLiteConnection connection = new SQLiteConnection("Data Source=" + DatabaseFile))
            {
                using (SQLiteCommand command = new SQLiteCommand())
                {
                    command.Connection = connection;
                    connection.Open();
                    SQLiteHelper helper = new SQLiteHelper(command);

                    string    cmd = "select * from RssList;";
                    DataTable dt  = helper.Select(cmd);
                    ObservableCollection <RssListBinding> rlbc = new ObservableCollection <RssListBinding>();
                    foreach (DataRow dr in dt.Rows)
                    {
                        RssListBinding rlb = new RssListBinding();
                        rlb.Name            = dr["Name"] as string;
                        rlb.Selected        = (dr["Selected"] as string).Equals("True");
                        rlb.UpdateTimeValue = Convert.ToDateTime(dr["UpdateTime"]);
                        rlb.URL             = dr["Url"] as string;
                        rlbc.Add(rlb);
                    }
                    connection.Close();
                    return(rlbc);
                }
            }
        }
Exemple #2
0
        public void UpdateRssList(RssListBinding rlb)
        {
            lock (lockThis)
            {
                using (SQLiteConnection connection = new SQLiteConnection("Data Source=" + DatabaseFile))
                {
                    using (SQLiteCommand command = new SQLiteCommand())
                    {
                        command.Connection = connection;
                        connection.Open();
                        SQLiteHelper helper = new SQLiteHelper(command);

                        Dictionary <string, object> dic = new Dictionary <string, object>();
                        dic["Name"]       = rlb.Name;
                        dic["Url"]        = rlb.URL;
                        dic["UpdateTime"] = rlb.UpdateTimeValue.ToString("s");
                        dic["Md5"]        = rlb.MD5;
                        dic["Selected"]   = rlb.Selected ? "True" : "False";

                        helper.Update("RssList", dic, "Md5", rlb.MD5);

                        connection.Close();
                    }
                }
            }
        }
Exemple #3
0
        private void buttonDeleteRss_Click(object sender, RoutedEventArgs e)
        {
            RssListBinding rlb = this.dataGridRssList.SelectedItem as RssListBinding;

            if (rlb == null)
            {
                return;
            }
            this.viewModel.RssList.Remove(rlb);
            this.viewModel.RssListEx.Remove(rlb);
            this.database.RemoveRssList(rlb);
        }
Exemple #4
0
        private async void buttonAddRss_Click(object sender, RoutedEventArgs e)
        {
            this.rssDialog.Title = "添加RSS源";
            await this.ShowMetroDialogAsync(this.rssDialog);

            Button  buttonOK       = rssDialog.FindChild <Button>("buttonOK");
            Button  buttonCancel   = rssDialog.FindChild <Button>("buttonCancel");
            TextBox textBoxRssName = rssDialog.FindChild <TextBox>("textBoxRssName");
            TextBox textBoxRssUrl  = rssDialog.FindChild <TextBox>("textBoxRssUrl");

            RssListBinding rlb = new RssListBinding();

            textBoxRssName.Text = rlb.Name;
            textBoxRssUrl.Text  = rlb.Name;

            RoutedEventHandler addRssDialogButtonOKClick     = null;
            RoutedEventHandler addRssDialogButtonCancelClick = null;

            addRssDialogButtonOKClick = async(o, args) =>
            {
                buttonOK.Click     -= addRssDialogButtonOKClick;
                buttonCancel.Click -= addRssDialogButtonCancelClick;

                rlb.Name     = textBoxRssName.Text;
                rlb.URL      = textBoxRssUrl.Text;
                rlb.Selected = true;
                if (this.viewModel.RssList.Contains(rlb))
                {
                    this.viewModel.RssList.Remove(rlb);
                    this.viewModel.RssListEx.Remove(rlb);
                    this.database.RemoveRssList(rlb);
                }

                this.viewModel.RssList.Add(rlb);
                this.viewModel.RssListEx.Add(rlb);
                this.database.AddRssList(rlb);

                await this.HideMetroDialogAsync(this.rssDialog);
            };
            addRssDialogButtonCancelClick = async(o, args) =>
            {
                buttonOK.Click     -= addRssDialogButtonOKClick;
                buttonCancel.Click -= addRssDialogButtonCancelClick;

                await this.HideMetroDialogAsync(this.rssDialog);
            };

            buttonOK.Click     += addRssDialogButtonOKClick;
            buttonCancel.Click += addRssDialogButtonCancelClick;
        }
Exemple #5
0
        private async void buttonEditRss_Click(object sender, RoutedEventArgs e)
        {
            RssListBinding rlb = this.dataGridRssList.SelectedItem as RssListBinding;

            if (rlb == null)
            {
                return;
            }

            this.rssDialog.Title = "编辑RSS源";
            await this.ShowMetroDialogAsync(this.rssDialog);

            Button  buttonOK       = rssDialog.FindChild <Button>("buttonOK");
            Button  buttonCancel   = rssDialog.FindChild <Button>("buttonCancel");
            TextBox textBoxRssName = rssDialog.FindChild <TextBox>("textBoxRssName");
            TextBox textBoxRssUrl  = rssDialog.FindChild <TextBox>("textBoxRssUrl");

            textBoxRssName.Text = rlb.Name;
            textBoxRssUrl.Text  = rlb.URL;

            RoutedEventHandler addRssDialogButtonOKClick     = null;
            RoutedEventHandler addRssDialogButtonCancelClick = null;

            addRssDialogButtonOKClick = async(o, args) =>
            {
                buttonOK.Click     -= addRssDialogButtonOKClick;
                buttonCancel.Click -= addRssDialogButtonCancelClick;

                this.database.RemoveRssList(rlb);

                rlb.Name = textBoxRssName.Text;
                rlb.URL  = textBoxRssUrl.Text;

                this.database.AddRssList(rlb);

                await this.HideMetroDialogAsync(this.rssDialog);
            };
            addRssDialogButtonCancelClick = async(o, args) =>
            {
                buttonOK.Click     -= addRssDialogButtonOKClick;
                buttonCancel.Click -= addRssDialogButtonCancelClick;

                await this.HideMetroDialogAsync(this.rssDialog);
            };

            buttonOK.Click     += addRssDialogButtonOKClick;
            buttonCancel.Click += addRssDialogButtonCancelClick;
        }
Exemple #6
0
        public void RemoveRssList(RssListBinding rlb)
        {
            lock (lockThis)
            {
                using (SQLiteConnection connection = new SQLiteConnection("Data Source=" + DatabaseFile))
                {
                    using (SQLiteCommand command = new SQLiteCommand())
                    {
                        command.Connection = connection;
                        connection.Open();
                        SQLiteHelper helper = new SQLiteHelper(command);

                        string cmd = "delete from RssList where Md5='" + rlb.MD5 + "';";
                        helper.Execute(cmd);

                        connection.Close();
                    }
                }
            }
        }
Exemple #7
0
        private async Task GetRSS(RssListBinding rlb)
        {
            HttpWebRequest httpWebRequest = WebRequest.Create(rlb.URL) as HttpWebRequest;

            httpWebRequest.UserAgent = UserAgent;

            if (this.useSystemProxy)
            {
                httpWebRequest.Proxy = WebRequest.GetSystemWebProxy();
            }
            else
            {
                httpWebRequest.Proxy = new WebProxy(this.proxyServer, this.proxyPort);
            }
            try
            {
                using (HttpWebResponse httpWebResponse = (await httpWebRequest.GetResponseAsync()) as HttpWebResponse)
                {
                    using (Stream responseStream = httpWebResponse.GetResponseStream())
                    {
                        using (XmlReader xmlReader = XmlReader.Create(responseStream))
                        {
                            SyndicationFeed syndicationFeed = SyndicationFeed.Load(xmlReader);

                            DateTime lastUpdateTime = rlb.UpdateTimeValue;

                            foreach (SyndicationItem si in syndicationFeed.Items)
                            {
                                DownloadListBinding dlb = new DownloadListBinding();
                                dlb.RSS             = rlb;
                                dlb.Title           = si.Title.Text;
                                dlb.UpdateTimeValue = si.PublishDate.DateTime;
                                foreach (SyndicationLink sl in si.Links)
                                {
                                    if (sl.MediaType != null && sl.MediaType.Equals("application/x-bittorrent"))
                                    {
                                        dlb.MagnetLink = sl.Uri.AbsoluteUri;
                                    }
                                }
                                dlb.GUID       = si.Id;
                                dlb.Downloaded = this.database.IsDownloaded(dlb);
                                dlb.Selected   = !dlb.Downloaded;
                                lock (LockdownloadListAll)
                                {
                                    if (!this.downloadListAll.Contains(dlb.MD5))
                                    {
                                        this.downloadListAll.Add(dlb.MD5, dlb);
                                    }
                                }
                                if (dlb.UpdateTimeValue > lastUpdateTime)
                                {
                                    lastUpdateTime = dlb.UpdateTimeValue;
                                }
                            }

                            rlb.UpdateTimeValue = lastUpdateTime;
                            this.database.UpdateRssList(rlb);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "错误", MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }