/**************************************************************************/

        public void SetCssSelector(
            int Slot,
            string CssSelectorLabel,
            string CssSelectorString,
            MacroscopeConstants.DataExtractorType ExtractorType
            )
        {
            MacroscopeDataExtractorExpression DataExtractorCssSelectorExpression;
            KeyValuePair <string,  MacroscopeDataExtractorExpression> ExpressionSlot;

            if (
                (!string.IsNullOrEmpty(CssSelectorString)) &&
                (SyntaxCheckCssSelector(CssSelectorString: CssSelectorString)))
            {
                DataExtractorCssSelectorExpression = new MacroscopeDataExtractorExpression(
                    NewLabel: CssSelectorLabel,
                    NewExpression: CssSelectorString,
                    NewExtractorType: ExtractorType
                    );

                ExpressionSlot = new KeyValuePair <string, MacroscopeDataExtractorExpression> (
                    CssSelectorLabel,
                    DataExtractorCssSelectorExpression
                    );

                this.ExtractCssSelectors[Slot] = ExpressionSlot;

                this.SetEnabled();
            }
        }
Example #2
0
        /**************************************************************************/

        public void SetXpath(
            int Slot,
            string XpathLabel,
            string XpathString,
            MacroscopeConstants.DataExtractorType ExtractorType
            )
        {
            MacroscopeDataExtractorExpression DataExtractorXpathsExpression;
            KeyValuePair <string,  MacroscopeDataExtractorExpression> ExpressionSlot;

            if (
                (!string.IsNullOrEmpty(XpathString)) &&
                (SyntaxCheckXpath(XpathString: XpathString)))
            {
                DataExtractorXpathsExpression = new MacroscopeDataExtractorExpression(
                    NewLabel: XpathLabel,
                    NewExpression: XpathString,
                    NewExtractorType: ExtractorType
                    );

                ExpressionSlot = new KeyValuePair <string, MacroscopeDataExtractorExpression> (
                    XpathLabel,
                    DataExtractorXpathsExpression
                    );

                this.ExtractXpaths[Slot] = ExpressionSlot;

                this.SetEnabled();
            }
        }
        /**************************************************************************/

        public MacroscopeDataExtractorExpression(
            string NewLabel,
            string NewExpression,
            MacroscopeConstants.DataExtractorType NewExtractorType
            )
        {
            this.SuppressDebugMsg = true;

            this.Label = NewLabel;

            this.Expression = NewExpression;

            this.ExtractorType = NewExtractorType;
        }
        /** -------------------------------------------------------------------- **/

        public List <KeyValuePair <string,  string> > AnalyzeHtmlDoc(HtmlDocument HtmlDoc)
        {
            List <KeyValuePair <string,  string> > ResultList = new List <KeyValuePair <string,  string> > (32);

            if (this.IsEnabled())
            {
                for (int Slot = 0; Slot < this.GetSize(); Slot++)
                {
                    IList <HtmlNode> NodeSet;
                    string           Label      = this.ExtractCssSelectors[Slot].Key;
                    string           Expression = this.ExtractCssSelectors[Slot].Value.Expression;
                    MacroscopeConstants.DataExtractorType ExtractorType = this.ExtractCssSelectors[Slot].Value.ExtractorType;

                    if (this.GetActiveInactive(Slot).Equals(MacroscopeConstants.ActiveInactive.INACTIVE))
                    {
                        continue;
                    }
                    else
                    if (!SyntaxCheckCssSelector(CssSelectorString: Expression))
                    {
                        continue;
                    }

                    NodeSet = HtmlDoc.QuerySelectorAll(Expression);

                    if (
                        (NodeSet != null) &&
                        (NodeSet.Count > 0))
                    {
                        foreach (HtmlNode Node in NodeSet)
                        {
                            KeyValuePair <string,  string> Pair;
                            string Text;

                            switch (ExtractorType)
                            {
                            case MacroscopeConstants.DataExtractorType.OUTERHTML:
                                Text = Node.OuterHtml;
                                Pair = new KeyValuePair <string,  string> (key: Label, value: Text);
                                ResultList.Add(item: Pair);
                                break;

                            case MacroscopeConstants.DataExtractorType.INNERHTML:
                                Text = Node.InnerHtml;
                                Pair = new KeyValuePair <string,  string> (key: Label, value: Text);
                                ResultList.Add(item: Pair);
                                break;

                            case MacroscopeConstants.DataExtractorType.INNERTEXT:

                                Text = Node.InnerText;

                                if (MacroscopePreferencesManager.GetDataExtractorsCleanWhiteSpace())
                                {
                                    Text = this.CleanWhiteSpace(Text: Text);
                                }

                                Pair = new KeyValuePair <string,  string> (key: Label, value: Text);

                                ResultList.Add(item: Pair);

                                break;

                            default:
                                break;
                            }
                        }
                    }
                }
            }

            return(ResultList);
        }
        /**************************************************************************/

        public MacroscopeConstants.DataExtractorType GetExtractorType(int Slot)
        {
            MacroscopeConstants.DataExtractorType ExtractorType = this.ExtractCssSelectors[Slot].Value.ExtractorType;

            return(ExtractorType);
        }
Example #6
0
        /**************************************************************************/

        public void SetDataExtractor()
        {
            int Max = this.DataExtractor.GetSize();

            for (int Slot = 0; Slot < Max; Slot++)
            {
                ComboBox StateComboBox;
                TextBox  TextBoxLabel;
                TextBox  TextBoxExpression;
                ComboBox ExtractToComboBox;

                StateComboBox = this.Controls.Find(
                    string.Format("StateComboBox{0}", Slot + 1),
                    true
                    ).FirstOrDefault() as ComboBox;

                TextBoxLabel = this.Controls.Find(
                    string.Format("TextBoxLabel{0}", Slot + 1),
                    true
                    ).FirstOrDefault() as TextBox;

                TextBoxExpression = this.Controls.Find(
                    string.Format("TextBoxExpression{0}", Slot + 1),
                    true
                    ).FirstOrDefault() as TextBox;

                ExtractToComboBox = this.Controls.Find(
                    string.Format("ExtractToComboBox{0}", Slot + 1),
                    true
                    ).FirstOrDefault() as ComboBox;

                if (this.DataExtractor.IsEnabled())
                {
                    MacroscopeConstants.ActiveInactive    State         = this.DataExtractor.GetActiveInactive(Slot: Slot);
                    MacroscopeConstants.DataExtractorType ExtractorType = this.DataExtractor.GetExtractorType(Slot: Slot);

                    switch (State)
                    {
                    case MacroscopeConstants.ActiveInactive.ACTIVE:
                        StateComboBox.SelectedIndex = 1;
                        break;

                    default:
                        StateComboBox.SelectedIndex = 0;
                        break;
                    }

                    TextBoxLabel.Text = this.DataExtractor.GetLabel(Slot: Slot);

                    TextBoxExpression.Text = this.DataExtractor.GetCssSelector(Slot: Slot);

                    if (
                        string.IsNullOrEmpty(TextBoxLabel.Text) ||
                        string.IsNullOrEmpty(TextBoxExpression.Text))
                    {
                        StateComboBox.SelectedIndex = 0;
                    }

                    switch (ExtractorType)
                    {
                    case MacroscopeConstants.DataExtractorType.OUTERHTML:
                        ExtractToComboBox.SelectedIndex = 0;
                        break;

                    case MacroscopeConstants.DataExtractorType.INNERHTML:
                        ExtractToComboBox.SelectedIndex = 1;
                        break;

                    case MacroscopeConstants.DataExtractorType.INNERTEXT:
                        ExtractToComboBox.SelectedIndex = 2;
                        break;

                    default:
                        ExtractToComboBox.SelectedIndex = 0;
                        break;
                    }
                }
                else
                {
                    StateComboBox.SelectedIndex     = 0;
                    TextBoxLabel.Text               = "";
                    TextBoxExpression.Text          = "";
                    ExtractToComboBox.SelectedIndex = 0;
                }
            }
        }