Пример #1
0
        public static ParseFilter Create(string filter_pattern)
        {
            ParseFilter filter = new ParseFilter();
            int place = 0;
            filter.ParseName(filter_pattern, ref place);
            filter.ParseChildren(filter_pattern, ref place);

            return filter;
        }
Пример #2
0
        public bool FilterNodes(ParseFilter filter, out HtmlTag parent)
        {
            parent = null;
            foreach (HtmlTag tag in _nodes)
            {
                if (tag.Name == filter.Name)
                {
                    if (filter.isParent())
                        parent = tag.VanillaCopy(null);
                    else
                        parent = new HtmlTag();

                    return _FilterNodes(ref filter, ref parent, tag);
                }
            }
            return false;
        }
Пример #3
0
        private bool _FilterNodes(ref ParseFilter filter, ref HtmlTag new_parent, HtmlTag current_parent)
        {
            if (!filter.AllChildren)
            {
                if (filter.AcceptableChildren.Count == 0)
                {
                    if (current_parent.Children.Count == 0)
                        return true;

                    return false;
                }
            }

            foreach (HtmlTag tag in current_parent.Children)
            {
                ParseFilter child_filter = null;
                if (filter.AllChildren || filter.AcceptableChildren.TryGetValue(tag.Name, out child_filter))
                {
                    if (child_filter.isParent())
                    {
                        new_parent = tag.VanillaCopy(null);
                        if (_FilterNodes(ref child_filter, ref new_parent, tag))
                        {
                            filter = child_filter;
                            return true;
                        }
                    }
                    else
                    {
                        HtmlTag new_child = tag.VanillaCopy(new_parent);
                        if (_FilterNodes(ref child_filter, ref new_child, tag))
                        {
                            if (child_filter.isParent())
                            {
                                filter = child_filter;
                                new_parent = new_child;
                                return true;
                            }
                            new_parent.Children.Add(new_child);
                        }
                    }
                }
            }

            if (filter.AcceptableChildren.Count > 0 && new_parent.Children.Count == 0)
                return false;

            return true;
        }
 protected new void OnEntryParsed(EntryInfo info, ParseFilter filter)
 {
     lock (EntryParsedLock)
     {
         BaseBackgroundPoller.EntryParsedHandler handler = null;
         if (entryCallbacks.TryGetValue(info.URL, out handler))
             handler(this, info);
         if (++entriesSearched == numEntriesToSearch)
             waitHandle.Set();
     }
 }
Пример #5
0
 public BackgroundPoller(PollHandler parent, ref CityDetails details, HtmlParser.ParseFilter filter)
     : base(false, EventResetMode.ManualReset)
 {
     Parent_ = parent;
     Details_ = details;
     matchingEntriesFound = 0;
     Worker_ = new BackgroundWorker();
     filter_ = filter;
     entries_searched_ = 0;
     stop_watch_ = new System.Diagnostics.Stopwatch();
     Worker_.DoWork += this.PollCity;
     Worker_.RunWorkerCompleted += this.PollDone;
     Worker_.RunWorkerAsync();
 }
Пример #6
0
 void InitializeMembers()
 {
     lock_object_ = new object();
     timer_ = new System.Timers.Timer();
     timer_.Elapsed += new ElapsedEventHandler(Tick);
     timeout = new TimeSpan(0, 0, 1);
     polling_ = false;
     polling_ = false;
     total_searched_ = 0;
     matchingEntriesFound = 0;
     stop_watch_ = new System.Diagnostics.Stopwatch();
     filter_ = HtmlParser.ParseFilter.Create("html(body(blockquote[parent](p(a),font(a))))");
 }
Пример #7
0
 private void ParseAttributes(string format, ref int place)
 {
     place++;
     int name_start = place;
     char current = format[place];
     while (place != format.Length)
     {
         place++;
         current = format[place];
         if (current == ',')
         {
             string attribute = format.Substring(name_start, place - name_start);
             if (attribute == "parent")
                 parent_ = this;
             place++;
             name_start = place;
             current = format[place];
             continue;
         }
         else if (current == ']')
         {
             string attribute = format.Substring(name_start, place - name_start);
             if (attribute == "parent")
                 parent_ = this;
             place++;
             return;
         }
     }
 }
Пример #8
0
 public ParseFilter(ParseFilter parent)
 {
     AcceptableChildren = new Dictionary<string, ParseFilter>();
     AllChildren = false;
     parent_ = parent;
 }
Пример #9
0
 private void ParseChildren(string format, ref int place)
 {
     char current = format[place];
     while ((place < format.Length) && (current != ')'))
     {
         place++;
         ParseFilter child = new ParseFilter(parent_);
         child.ParseName(format, ref place);
         if (child.Name == "*")
         {
             this.AllChildren = true;
             place = format.IndexOf(')', place);
             break;
         }
         current = format[place];
         if (current == '[')
         {
             child.ParseAttributes(format, ref place);
         }
         current = format[place];
         if (current == '(')
         {
             child.ParseChildren(format, ref place);
         }
         current = format[place];
         this.AcceptableChildren.Add(child.Name, child);
     }
     place++;
 }
Пример #10
0
 protected void OnEntryFound(EntryInfo info, ParseFilter filter)
 {
     lock (EntryFoundLock)
     {
         entriesSearched++;
         if (EntryFound != null)
             EntryFound(info);
     }
 }