Beispiel #1
0
        public static GrabEventArgs Deserialize(string serialized)
        {
            XElement ele = XElement.Parse(serialized);
            RegexOptions opts=RegexOptions.None;
            bool ignoreWhiteSpace = Convert.ToBoolean(ele.Element("ignorewhitespace").Value);
            if(ignoreWhiteSpace)
                opts |= RegexOptions.IgnorePatternWhitespace;
            bool ignoreCase = Convert.ToBoolean(ele.Element("ignorecase").Value);
            if (ignoreCase)
                opts |= RegexOptions.IgnoreCase;
            bool cultureinvariant = Convert.ToBoolean(ele.Element("cultureinvariant").Value);
            if (cultureinvariant)
                opts |= RegexOptions.CultureInvariant;
            bool multiline = Convert.ToBoolean(ele.Element("multiline").Value);
            if (multiline)
                opts |= RegexOptions.Multiline;
            bool singleline = Convert.ToBoolean(ele.Element("singleline").Value);
            if (singleline)
                opts |= RegexOptions.Singleline;

            GrabEventArgs args = new GrabEventArgs()
            {
                GrabExpression = new Regex(HtmlUtils.HtmlDecode(ele.Element("grabexpression").Value),opts),
                Url = new GrabbableUrl(ele.Element("url")),
            };
            return args;
        }
Beispiel #2
0
 public Grabber()
 {
     Jobs = new ObservableCollection<GrabJob>();
     Logger = new ConsoleLogger();
     Arguments = new GrabEventArgs();
     //ThreadCount = 4;
     _config = WPFConfiguration.GetConfig();
 }
Beispiel #3
0
 public ScheduledGrab()
 {
     IsActive = true;
     Interval = 1000;
     GrabParams = new GrabEventArgs();
     GrabSchedule = Constants.GrabSchedules.OneTime;
     GrabMode = Constants.GrabModes.Scrape;
     GrabSource = Constants.GrabSource.Url;
 }
Beispiel #4
0
        private void SaveGrab(object sender, ExecutedRoutedEventArgs e)
        {
            if (!Validate())
                return;
            //Settings.Default.UrlList = CsvGrabber.Core.Utils.SerializeUrls(UrlsToGrab);
            List<string> expressions = new List<string>();
            foreach (var exp in cboExpressions.Items) {
                string expression = Convert.ToString(exp);
                if (!string.IsNullOrWhiteSpace(expression) && !expressions.Contains(expression)) {
                    expressions.Insert(0, expression);
                }
            }
            if (!expressions.Contains(cboExpressions.Text) && !string.IsNullOrWhiteSpace(cboExpressions.Text)) {
                expressions.Insert(0,cboExpressions.Text);
                cboExpressions.Items.Insert(0, cboExpressions.Text);
            }
            Settings.Default.GrabExpressions = CsvGrabber.Core.Utils.SerializeList(expressions);

            Settings.Default.Save();
            GrabEventArgs args = new GrabEventArgs(new GrabbableUrl(txtUrl.Text));
            RegexOptions options = 0;
            if (chkCultureInvariant.IsChecked == true) {
                options |= RegexOptions.CultureInvariant;
            }
            if (chkCaseInsensitive.IsChecked == true) {
                options |= RegexOptions.IgnoreCase;
            }
            if (chkDotNewLine.IsChecked == true) {
                options |= RegexOptions.Singleline;
            }
            if (chkMultiline.IsChecked == true) {
                options |= RegexOptions.Multiline;
            }
            if (chkFreeSpacing.IsChecked == true) {
                options |= RegexOptions.IgnorePatternWhitespace;
            }
            args.GrabExpression = new Regex(cboExpressions.Text, options);

            CurrentGrab.GrabParams = args;
            DialogResult = true;
            Close();
        }
Beispiel #5
0
 public GrabTemplate()
 {
     GrabParameters = new GrabEventArgs();
 }
Beispiel #6
0
 public Grabber(GrabEventArgs args)
     : this()
 {
     this.Arguments = args;
 }
        private void SaveTemplate(object sender, ExecutedRoutedEventArgs e)
        {
            if (!Validate())
                return;
            //Settings.Default.UrlList = CsvGrabber.Core.Utils.SerializeUrls(UrlsToGrab);
            List<string> expressions = new List<string>();
            foreach (var exp in cboExpressions.Items) {
                string expression = Convert.ToString(exp);
                if (!string.IsNullOrWhiteSpace(expression) && !expressions.Contains(expression)) {
                    expressions.Insert(0, expression);
                }
            }
            if (!expressions.Contains(cboExpressions.Text) && !string.IsNullOrWhiteSpace(cboExpressions.Text)) {
                expressions.Add(cboExpressions.Text);
                cboExpressions.Items.Add(cboExpressions.Text);
            }
            Settings.Default.GrabExpressions = CsvGrabber.Core.Utils.SerializeList(expressions);

            Settings.Default.Save();
            GrabEventArgs args = new GrabEventArgs(new GrabbableUrl(txtUrlFormatString.Text));
            RegexOptions options = 0;
            if (chkCaseInsensitive.IsChecked == true) {
                options |= RegexOptions.IgnoreCase;
            }
            if (chkDotNewLine.IsChecked == true) {
                options |= RegexOptions.Singleline;
            }
            if (chkFreeSpacing.IsChecked == true) {
                options |= RegexOptions.IgnorePatternWhitespace;
            }
            args.GrabExpression = new Regex(cboExpressions.Text, options);

            CurrentTemplate.GrabParameters = args;

            var templateToSave = CurrentTemplate;
            BackgroundWorker saveWorker = new BackgroundWorker();
            saveWorker.DoWork += (s, dwe) =>
            {
                    var db = new SqLiteDal();
                    if (string.IsNullOrWhiteSpace(templateToSave.TemplateID)) {
                        templateToSave.TemplateID = Lime49.Utils.GenID(true);
                        db.AddGrabTemplates(new[] { templateToSave });
                    } else
                    {
                        db.EditGrabTemplate(templateToSave);
                    }
            };
            saveWorker.RunWorkerCompleted += (Fs, rwe) =>
            {
                if (rwe.Error != null) {
                    DialogBox.ShowAlert(this, rwe.Error.Message, "Error Saving Job Results");
                } else
                {
                    CurrentTemplate = templateToSave;
                }
            };
            saveWorker.RunWorkerAsync();
        }