コード例 #1
0
ファイル: WinMain.xaml.cs プロジェクト: Echilon/CsvGrabber
 private void EditUrl(object sender, ExecutedRoutedEventArgs e)
 {
     ScheduledGrab url = lstUrls.SelectedValue as ScheduledGrab;
     WinAddJob dlg = new WinAddJob(url.Clone())
     {
         Owner = this,
     };
     if (dlg.ShowDialog() == true) {
         BackgroundWorker worker = new BackgroundWorker();
         ScheduledGrab jobToGrab = dlg.CurrentGrab;
         worker.DoWork += (s, dwe) =>
         {
             var db = new SqLiteDal();
             db.EditScheduledGrab(jobToGrab);
         };
         worker.RunWorkerCompleted += (Fs, rwe) =>
         {
             if (rwe.Error != null) {
                 DialogBox.ShowAlert(this, rwe.Error.Message, "Error");
             }
         };
         worker.RunWorkerAsync();
         WPFUtils.WaitForWorker(worker);
         CommandManager.InvalidateRequerySuggested();
         RefreshScheduledGrabs();
     }
 }
コード例 #2
0
ファイル: WinMain.xaml.cs プロジェクト: Echilon/CsvGrabber
        ///// <summary>
        ///// Adds a new category when the return key is pressed.
        ///// </summary>
        ///// <param name="sender">The source of the event.</param>
        ///// <param name="e">The <see cref="System.Windows.Input.KeyEventArgs"/> instance containing the event data.</param>
        //private void txtUrl_KeyDown(object sender, System.Windows.Input.KeyEventArgs e)
        //{
        //    if (e.Key == Key.Enter || e.Key == Key.Return || e.Key == Key.OemComma) {
        //        ApplicationCommands.New.Execute(this, null);
        //        e.Handled = true;
        //    }
        //}
        /// <summary>
        /// Adds a URL to the queue.
        /// </summary>
        /// <param name="sender">The sender.</param>
        /// <param name="e">The <see cref="System.Windows.Input.ExecutedRoutedEventArgs"/> instance containing the event data.</param>
        private void AddUrl(object sender, ExecutedRoutedEventArgs e)
        {
            WinAddJob dlg = new WinAddJob()
            {
                Owner = this,
            };
            if(e.Parameter is GrabTemplate)
            {
                WinAddFromTemplate dlgTemplate = new WinAddFromTemplate(){ Owner=this};
                dlgTemplate.GrabTemplate = e.Parameter as GrabTemplate;
                if (dlg.ShowDialog() == true) {
                    dlg.CurrentGrab = dlgTemplate.ScheduledGrab;
                } else
                {
                    return;
                }
            }
            if (dlg.ShowDialog() == true) {
                BackgroundWorker worker = new BackgroundWorker();
                ScheduledGrab jobToGrab = dlg.CurrentGrab;
                worker.DoWork += (s, dwe) =>
                {
                    var db = new SqLiteDal();
                    db.AddScheduledGrabs(new[]{jobToGrab});
                };
                worker.RunWorkerCompleted += (Fs, rwe) =>
                {
                    if (rwe.Error != null) {
                        DialogBox.ShowAlert(this, rwe.Error.Message, "Error");
                    }
                };
                worker.RunWorkerAsync();
                WPFUtils.WaitForWorker(worker);
                CommandManager.InvalidateRequerySuggested();
                RefreshScheduledGrabs();
            }

            //string url = txtUrl.Text;
            //if (UrlsToGrab.Any(u=>u.Url.ToLowerInvariant() == url.ToLowerInvariant())) {
            //    DialogBox.ShowAlert(this, "URL already in queue", "Error");
            //} else if (!string.IsNullOrWhiteSpace(url)) {
            //    UrlsToGrab.Add(new GrabbableUrl(url));
            //    txtUrl.Text = string.Empty;
            //}
        }