Пример #1
0
 public Grabber()
 {
     Jobs = new ObservableCollection<GrabJob>();
     Logger = new ConsoleLogger();
     Arguments = new GrabEventArgs();
     //ThreadCount = 4;
     _config = WPFConfiguration.GetConfig();
 }
Пример #2
0
 public static WPFConfiguration GetConfig()
 {
     string appPath = Utils.GetApplicationPath();
     WPFConfiguration config = new WPFConfiguration()
     {
         FilePath = string.IsNullOrWhiteSpace(Settings.Default.FilePath)?System.IO.Path.Combine(appPath, "data"):Settings.Default.FilePath,
         LogToFile = Settings.Default.LogToFile,
         DatabasePath = string.IsNullOrWhiteSpace(Settings.Default.DBPath)?System.IO.Path.Combine(appPath, "data.db3"):Settings.Default.DBPath,
         LogToDatabase = Settings.Default.LogToDatabase,
         LogRawResponse = Settings.Default.LogRawResponse,
         AppendLogFile = Settings.Default.AppendLogFile,
         TrimExtraWhitespace=Settings.Default.TrimExtraWhitespace,
         LogDbPath = Settings.Default.LogDbPath,
     };
     return config;
 }
Пример #3
0
        /// <summary>
        /// Loads saved settings when the Window loads.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="System.Windows.RoutedEventArgs"/> instance containing the event data.</param>
        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            try {
                //string serializedSavedUrls = Settings.Default.UrlList;
                //IEnumerable<GrabbableUrl> savedUrls = CsvGrabber.Core.Utils.DeserializeUrls(serializedSavedUrls);
                //ScheduledGrabs = new ObservableCollection<ScheduledGrab>(savedUrls);
                WPFConfiguration.LoadConfiguration();
                _config = WPFConfiguration.GetConfig();
                var db = new SqLiteDal();
                if (!db.EnsureExists()) {
                    DialogBox.ShowAlert(this, string.Format("The SQLite Database {0} could not be created", db.FileName), "Error");
                    Close();
                }
                RefreshScheduledGrabs();
            } catch (Exception ex) {
                Console.WriteLine("Error loading saved URL list: " + ex.Message);
            }

            try {
                string serializedFilenames = Settings.Default.FilePath;
                IEnumerable<string> items = CsvGrabber.Core.Utils.DeserializeList(serializedFilenames);
                if (items.Any()) {
                    foreach (string item in items) {
                        cboFileName.Items.Add(item);
                    }
                    cboFileName.SelectedIndex = 0;
                } else {
                    cboFileName.Text = System.IO.Path.Combine(Lime49.Utils.GetApplicationPath(), string.Format("grabbeddata{0:yyyy-MM-ddTHHmm}.csv", DateTime.Now));
                }
            } catch (Exception ex) {
                Console.WriteLine("Error loading saved expression list: " + ex.Message);
                Settings.Default.FilePath = CsvGrabber.Core.Utils.SerializeList(new string[0]);
            }

            cboDbPath.Text = Settings.Default.LogDbPath;
            /*string lastFilename = Settings.Default.FilePath;
            if (string.IsNullOrWhiteSpace(lastFilename)) {
                Settings.Default.FilePath = System.IO.Path.Combine(Lime49.Utils.GetApplicationPath(), string.Format("grabbeddata{0:yyyy-MM-ddTHHmm}.csv", DateTime.Now));
            }
            txtFilePath.Text = Settings.Default.FilePath;*/
            chkLogDatabase.IsChecked = Settings.Default.LogToDatabase;
            chkLogFile.IsChecked = Settings.Default.LogToFile;
            chkTrimWhitespace.IsChecked = Settings.Default.TrimExtraWhitespace;
            Settings.Default.Save();
        }
Пример #4
0
        /// <summary>
        /// Validates, then starts grabbing.
        /// </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 StartGrabbing(object sender, ExecutedRoutedEventArgs e)
        {
            var scheduledGrab = e.Parameter as ScheduledGrab;
            List<string> paths = new List<string>();
            foreach (var item in cboFileName.Items) {
                string path = Convert.ToString(item);
                if (!string.IsNullOrWhiteSpace(path) && !paths.Contains(path)) {
                    paths.Add(path);
                }
            }
            paths.RemoveAll(p => p == cboFileName.Text);
            if (!string.IsNullOrWhiteSpace(cboFileName.Text)) {
                paths.Insert(0, cboFileName.Text);
                cboFileName.Items.Insert(0, cboFileName.Text);
            };
            Settings.Default.LogToDatabase = chkLogDatabase.IsChecked == true;
            Settings.Default.LogToFile = chkLogFile.IsChecked == true;
            Settings.Default.TrimExtraWhitespace = chkTrimWhitespace.IsChecked == true;
            Settings.Default.LogDbPath = cboDbPath.Text;
            Settings.Default.FilePath = CsvGrabber.Core.Utils.SerializeList(paths);

            Settings.Default.Save();
            _config = WPFConfiguration.GetConfig();
            _grabber = new Grabber();
            _grabber.Logger = new CompositeLogger(new ConsoleLogger(), new RichTextBoxLogger(rtbLog));
            _grabber.GrabComplete += new EventHandler<GrabCompleteEventArgs>(grabber_GrabComplete);
            _grabber.GrabFailed += new EventHandler(grabber_GrabFailed);
            if (scheduledGrab == null)
            {

                _grabber.Start();
            } else {
                _grabber.GrabSingle(scheduledGrab);
            }
        }