public void AddDownloadedList(DownloadListBinding dlb) { 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["RssUrl"] = dlb.RSS.URL; dic["Title"] = dlb.Title; dic["UpdateTime"] = dlb.UpdateTimeValue.ToString("s"); dic["MagnetLink"] = dlb.MagnetLink; dic["Guid"] = dlb.GUID; dic["Md5"] = dlb.MD5; helper.Insert("DownloadedList", dic); connection.Close(); } } } }
public bool IsDownloaded(DownloadListBinding dlb) { 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 = "select * from DownloadedList where Md5='" + dlb.MD5 + "';"; DataTable dt = helper.Select(cmd); connection.Close(); if (dt.Rows.Count > 0) { return(true); } else { return(false); } } } } }
private async void buttonSaveDownloadList_Click(object sender, RoutedEventArgs e) { SaveFileDialog dialog = new SaveFileDialog(); dialog.Title = "选择保存位置"; dialog.Filter = "TXT文件(*.txt)|*.txt"; if (dialog.ShowDialog() == true) { ProgressDialogController pdc = await this.ShowProgressAsync("导出下载列表", "操作进行中", false); pdc.SetIndeterminate(); try { using (MemoryStream ms = new MemoryStream()) { foreach (DictionaryEntry de in this.downloadListAll) { DownloadListBinding dlb = de.Value as DownloadListBinding; if (dlb.Selected) { byte[] tmpData = System.Text.Encoding.Default.GetBytes(dlb.MagnetLink + Environment.NewLine); await ms.WriteAsync(tmpData, 0, tmpData.Length).ConfigureAwait(false); if (!dlb.Downloaded) { await Task.Run(new Action(() => this.database.AddDownloadedList(dlb))).ConfigureAwait(false); } dlb.Downloaded = true; } } string tmpStr = System.Text.Encoding.Default.GetString(ms.ToArray()); this.Dispatcher.Invoke(new Action(() => { Clipboard.Clear(); Clipboard.SetDataObject(tmpStr); })); using (FileStream fs = new FileStream(dialog.FileName, FileMode.Create)) { await fs.WriteAsync(ms.ToArray(), 0, (int)ms.Length).ConfigureAwait(false); } } } catch (Exception ex) { MessageBox.Show(ex.Message, "错误", MessageBoxButton.OK, MessageBoxImage.Error); } await pdc.CloseAsync(); } }
private void dataGridDownloadList_MouseDoubleClick(object sender, System.Windows.Input.MouseButtonEventArgs e) { DownloadListBinding dlb = (sender as DataGrid).SelectedItem as DownloadListBinding; if (dlb != null) { try { Process.Start(DefaultExplorer, dlb.GUID); } catch { Process.Start(dlb.GUID); } } }
private void UpdateDataGridDownloadList() { this.viewModel.DownloadList.Clear(); foreach (DictionaryEntry de in this.downloadListAll) { DownloadListBinding dlb = de.Value as DownloadListBinding; if (this.viewModel.SelectedRss.Equals(RssListBinding.SpecialRss)) { this.viewModel.DownloadList.Add(dlb); } else { if (dlb.RSS.Equals(this.viewModel.SelectedRss)) { this.viewModel.DownloadList.Add(dlb); } } } }
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); } }