Example #1
0
        private bool AssertEqual(FindAction findElementAction, string x, string y)
        {
            bool result = false;

            if (string.IsNullOrEmpty(x) || string.IsNullOrEmpty(y))
            {
                return(result);
            }

            if (findElementAction.Trim)
            {
                x = x.Trim();
            }

            if (findElementAction.Contains)
            {
                result = x.Contains(y);
            }
            else if (findElementAction.WildCard)
            {
                result = WildCard.Test(y, x);
            }
            else
            {
                result = x == y;
            }

            return(result);
        }
Example #2
0
        private void FindID(FindAction findElementAction)
        {
            if (!string.IsNullOrEmpty(findElementAction.ID))
            {
                LoggerManager.Debug("FindElementTask FindID");

                HtmlElement element = this.GetData(findElementAction) as HtmlElement;
                if (element == null)
                {
                    HtmlDocument document = GetHtmlDocument(findElementAction);
                    if (document == null)
                    {
                        LoggerManager.Debug("FindElementTask HtmlDocument document Error");
                        return;
                    }

                    element = document.GetElementById(findElementAction.ID);
                }
                else
                {
                    element = FindIDRecusive(element, findElementAction.ID);
                }

                this.SaveData(findElementAction, element);
            }
        }
Example #3
0
        private void FindXPath(FindAction findElementAction)
        {
            if (string.IsNullOrEmpty(findElementAction.XPath))
            {
                return;
            }

            LoggerManager.Debug("FindElementTask FindXPath");

            HtmlElement element = this.GetData(findElementAction) as HtmlElement;

            if (element == null)
            {
                HtmlDocument document = GetHtmlDocument(findElementAction);
                if (document == null)
                {
                    LoggerManager.Debug("FindElementTask HtmlDocument document Error");
                    return;
                }

                element = document.Body;
            }

            element = HtmlHelp.SelectHtmlNode(findElementAction.XPath, element);
            this.SaveData(findElementAction, element);
        }
Example #4
0
        private void FindClassName(FindAction findElementAction)
        {
            if (string.IsNullOrEmpty(findElementAction.ClassName))
            {
                return;
            }

            LoggerManager.Debug("FindElementTask FindClassName");

            wholeWordRegex = new Regex(string.Format("\\b{0}\\b", findElementAction.ClassName));

            HtmlElement element = this.GetData(findElementAction) as HtmlElement;

            if (element == null)
            {
                HtmlDocument document = GetHtmlDocument(findElementAction);
                if (document == null)
                {
                    LoggerManager.Debug("FindElementTask HtmlDocument document Error");
                    return;
                }

                element = document.Body;
                this.SaveData(findElementAction, FindClassRecusive(element, findElementAction.ClassName));
            }
            else
            {
                this.SaveData(findElementAction, FindClassRecusive(element, findElementAction.ClassName));
            }
        }
Example #5
0
        private HtmlDocument GetHtmlDocument(FindAction findElementAction)
        {
            if (findElementAction.ActionContext != null)
            {
                HtmlWindow htmlWindow = null;
                if (findElementAction.ActionContext.FrameIndex >= 0)
                {
                    htmlWindow = this.webBrowser.Document.Window.Frames[findElementAction.ActionContext.FrameIndex];
                }
                else if (!string.IsNullOrEmpty(findElementAction.ActionContext.FrameName))
                {
                    htmlWindow = this.webBrowser.Document.Window.Frames[findElementAction.ActionContext.FrameName];
                }

                if (htmlWindow == null)
                {
                    return(null);
                }

                //IHTMLWindow2 htmlWindow2 = (IHTMLWindow2)htmlWindow.DomWindow;
                //IHTMLDocument2 document2 = CrossFrameIE.GetDocumentFromWindow(htmlWindow2);
                //mshtml.HTMLDocument d = (mshtml.HTMLDocument)document2;

                return(htmlWindow.Document);
            }
            else
            {
                return(this.Call <WebBrowserEx, HtmlDocument>(delegate(WebBrowserEx ex)
                {
                    return ex.Document;
                }, this.webBrowser));
            }
        }
Example #6
0
 private void findAllButton_Click(object sender, EventArgs e)
 {
     this.Action = FindAction.FindAll;
     if (this.GetState() == true)
     {
         this.DialogResult = DialogResult.OK;
     }
     else
     {
         this.DialogResult = DialogResult.Cancel;
     }
     this.Close();
 }
Example #7
0
 private void findButton_Click(object sender, EventArgs e)
 {
     this.Action = (_didChange == true) ? FindAction.FindFirst : FindAction.FindNext;
     if (this.GetState() == true)
     {
         this.DialogResult = DialogResult.OK;
     }
     else
     {
         this.DialogResult = DialogResult.Cancel;
     }
     this.Close();
 }
Example #8
0
 public void FindAgain()
 {
     _findSettings.SelectionOnly = false;              // never use selection only on a repeat find, since selection was set by last find
     if (_findAction == FindAction.ReplaceAll)
     {
         _findAction = FindAction.Find;                  // never repeat Find and Replace All
     }
     if (_findSettings.FindText == String.Empty)
     {
         PromptFindReplace(false);
     }
     else
     {
         PerformFind();
     }
 }
Example #9
0
 public FindReplaceForm(FindAction action)
 {
     InitializeComponent();
     if (action == FindAction.Find)
     {
         AcceptButton = FindButton;
         PerformLayout();
         panel2.Visible = false;
         Height        -= panel2.Height;
         Text           = FindTitle;
     }
     else
     {
         AcceptButton = ReplaceButton;
     }
 }
Example #10
0
        private bool AssertCanFindContidion(FindAction findElementAction)
        {
            if (string.IsNullOrEmpty(findElementAction.TagName))
            {
                return(false);
            }

            if (string.IsNullOrEmpty(findElementAction.ID) &&
                string.IsNullOrEmpty(findElementAction.Type) &&
                string.IsNullOrEmpty(findElementAction.Title) &&
                string.IsNullOrEmpty(findElementAction.ClassName) &&
                string.IsNullOrEmpty(findElementAction.Name) &&
                string.IsNullOrEmpty(findElementAction.Url) &&
                string.IsNullOrEmpty(findElementAction.InnerText) &&
                (findElementAction.EmbedAttribute == null || findElementAction.EmbedAttribute.Count == 0))
            {
                return(false);
            }

            return(true);
        }
Example #11
0
        public void PromptFindReplace(bool replace)
        {
            DoBeginningFind();
            using (FindReplaceForm form = new FindReplaceForm((replace ? FindAction.Replace : FindAction.Find)))
            {
                _findSettings.SelectionOnly = false;
                if (ActiveTextAreaControl.SelectionManager.HasSomethingSelected)
                {
                    if (ActiveTextAreaControl.SelectionManager.SelectedText.IndexOf("\n") != -1)
                    {
                        _findSettings.SelectionOnly = true;
                    }
                    else
                    {
                        _findSettings.FindText = ActiveTextAreaControl.SelectionManager.SelectedText;
                    }
                }
                else
                {
                    int    wordStart = FindWordStart(Document, ActiveTextAreaControl.Caret.Offset);
                    string findText  = Document.GetText(wordStart, Math.Max(0, FindWordEnd(Document, wordStart) - wordStart));
                    if (findText != String.Empty)
                    {
                        _findSettings.FindText = findText;
                    }
                }

                form.Settings = _findSettings;

                if (form.ShowDialog() != DialogResult.OK)
                {
                    throw new AbortException();
                }
                _findSettings = form.Settings;
                _findAction   = form.Action;
                PerformFind();
            }
        }
Example #12
0
        protected override void OnProcess(IAction action)
        {
            FindAction findElementAction = action as FindAction;

            if (findElementAction == null)
            {
                return;
            }

            LoggerManager.Debug(action.AutomationActionData);

            if (findElementAction.Combine)
            {
                FindContidion(findElementAction);
            }
            else
            {
                FindID(findElementAction);
                FindClassName(findElementAction);
                FindUrl(findElementAction);
                FindXPath(findElementAction);
            }
        }
Example #13
0
        private void FindUrl(FindAction findElementAction)
        {
            if (string.IsNullOrEmpty(findElementAction.Url))
            {
                return;
            }

            LoggerManager.Debug("FindElementTask FindUrl");

            HtmlElement element = this.GetData(findElementAction) as HtmlElement;

            if (element == null)
            {
                HtmlDocument document = GetHtmlDocument(findElementAction);
                if (document == null)
                {
                    LoggerManager.Debug("FindElementTask HtmlDocument document Error");
                    return;
                }

                element = document.Body;
            }

            HtmlElementCollection elementCollection = element.GetElementsByTagName("a");

            if (elementCollection != null && elementCollection.Count > 0)
            {
                foreach (HtmlElement find in elementCollection)
                {
                    if (find.GetAttribute("href") == findElementAction.Url)
                    {
                        this.SaveData(findElementAction, find);
                        break;
                    }
                }
            }
        }
Example #14
0
        private void PerformFindChecked(FindAction action)
        {
            SaveSettings();

            var options = Options & (NiFindOptions.OptionsMask | NiFindOptions.SyntaxMark | NiFindOptions.TargetMask);

            options &= ~(NiFindOptions.ActionMask | NiFindOptions.Backwards);

            switch (action)
            {
                case FindAction.FindNext:
                    options |= NiFindOptions.Find;
                    break;

                case FindAction.FindPrevious:
                    options |= NiFindOptions.Find | NiFindOptions.Backwards;
                    break;

                case FindAction.Replace:
                    options |= NiFindOptions.Replace;
                    break;

                case FindAction.ReplaceAll:
                    options |= NiFindOptions.ReplaceAll;
                    break;

                case FindAction.FindAll:
                    options |= NiFindOptions.FindAll;
                    break;

                case FindAction.SkipFile:
                    throw new NotImplementedException();

                default:
                    throw new ArgumentOutOfRangeException("action");
            }

            var currentFindState = FindState.Create(this, options, FindTarget);

            if (_state == null || !_state.SettingsEqual(currentFindState))
            {
                _state = currentFindState;
                _state.CreateIterator(_view);
            }

            _state.Options = options;

            switch (action)
            {
                case FindAction.FindNext:
                    PerformFindSingle();
                    break;

                case FindAction.FindPrevious:
                    PerformFindSingle();
                    break;

                case FindAction.Replace:
                    PerformReplaceSingle();
                    break;

                case FindAction.ReplaceAll:
                    PerformReplaceAll();
                    break;

                case FindAction.FindAll:
                    PerformFindAll();
                    break;

                case FindAction.SkipFile:
                    throw new NotImplementedException();

                default:
                    throw new ArgumentOutOfRangeException("action");
            }
        }
Example #15
0
 private void PerformFind(FindAction action)
 {
     _findManager.PerformFind(action);
 }
Example #16
0
 private void findButton_Click( object sender, EventArgs e )
 {
     this.Action = ( _didChange == true ) ? FindAction.FindFirst : FindAction.FindNext;
     if( this.GetState() == true )
     {
         this.DialogResult = DialogResult.OK;
     }
     else
         this.DialogResult = DialogResult.Cancel;
     this.Close();
 }
Example #17
0
 private void findAllButton_Click( object sender, EventArgs e )
 {
     this.Action = FindAction.FindAll;
     if( this.GetState() == true )
     {
         this.DialogResult = DialogResult.OK;
     }
     else
         this.DialogResult = DialogResult.Cancel;
     this.Close();
 }
Example #18
0
        private void FindContidion(FindAction findElementAction)
        {
            LoggerManager.Debug("FindElementTask FindContidion");
            if (!AssertCanFindContidion(findElementAction))
            {
                LoggerManager.Debug("FindElementTask AssertCanFindContidion Error");
                return;
            }

            // TagName type id name xxxx
            HtmlElement findElement = null;

            HtmlElement           saveElement = this.GetData(findElementAction) as HtmlElement;
            HtmlElementCollection htmlElementCollection;

            if (saveElement == null)
            {
                HtmlDocument document = GetHtmlDocument(findElementAction);
                if (document == null)
                {
                    LoggerManager.Debug("FindElementTask HtmlDocument document Error");
                    return;
                }

                htmlElementCollection = document.GetElementsByTagName(findElementAction.TagName);
            }
            else
            {
                htmlElementCollection = saveElement.GetElementsByTagName(findElementAction.TagName);

                // clear
                this.SaveData(findElementAction, null);
            }

            if (htmlElementCollection != null && htmlElementCollection.Count > 0)
            {
                List <HtmlElement> tmpHtmlElementList = new List <HtmlElement>();
                foreach (HtmlElement element in htmlElementCollection)
                {
                    #region Condition Check

                    if (!string.IsNullOrEmpty(findElementAction.ID) && !AssertEqual(findElementAction, element.Id, findElementAction.ID))
                    {
                        continue;
                    }
                    if (!string.IsNullOrEmpty(findElementAction.Type) && !AssertEqual(findElementAction, element.GetAttribute("type"), findElementAction.Type))
                    {
                        continue;
                    }
                    if (!string.IsNullOrEmpty(findElementAction.Title) && !AssertEqual(findElementAction, element.GetAttribute("title"), findElementAction.Title))
                    {
                        continue;
                    }
                    if (!string.IsNullOrEmpty(findElementAction.ClassName) && !AssertEqual(findElementAction, element.GetAttribute("className"), findElementAction.ClassName))
                    {
                        continue;
                    }
                    if (!string.IsNullOrEmpty(findElementAction.Name) && !AssertEqual(findElementAction, element.Name, findElementAction.Name))
                    {
                        continue;
                    }
                    if (!string.IsNullOrEmpty(findElementAction.Url) && !AssertEqual(findElementAction, element.GetAttribute("href"), findElementAction.Url))
                    {
                        continue;
                    }
                    if (!string.IsNullOrEmpty(findElementAction.InnerText) && !AssertEqual(findElementAction, element.InnerText, findElementAction.InnerText))
                    {
                        continue;
                    }

                    if (findElementAction.EmbedAttribute != null && findElementAction.EmbedAttribute.Count > 0)
                    {
                        bool find = true;
                        Dictionary <string, string> .Enumerator e = findElementAction.EmbedAttribute.GetEnumerator();
                        while (e.MoveNext())
                        {
                            if (!AssertEqual(findElementAction, element.GetAttribute(e.Current.Key), e.Current.Value))
                            {
                                find = false;
                                break;
                            }
                        }

                        if (!find)
                        {
                            continue;
                        }
                    }

                    #endregion Condition Check

                    tmpHtmlElementList.Add(element);
                }

                if (tmpHtmlElementList.Count > 0)
                {
                    if (tmpHtmlElementList.Count > 1)
                    {
                        if (findElementAction.Index != -1)
                        {
                            findElement = tmpHtmlElementList[findElementAction.Index];
                        }
                        else
                        {
                            // TODO: MUTI FIND
                        }
                    }
                    else
                    {
                        findElement = tmpHtmlElementList[0];
                    }

                    this.SaveData(findElementAction, findElement);
                }
            }
        }
Example #19
0
 private void ReplaceAll_Click(object sender, System.EventArgs e)
 {
     Action       = FindAction.ReplaceAll;
     DialogResult = DialogResult.OK;
 }
Example #20
0
 private void Find_Click(object sender, System.EventArgs e)
 {
     Action       = FindAction.Find;
     DialogResult = DialogResult.OK;
 }
Example #21
0
        private void PerformFindChecked(FindAction action)
        {
            SaveSettings();

            var options = Options & (NiFindOptions.OptionsMask | NiFindOptions.SyntaxMark | NiFindOptions.TargetMask);

            options &= ~(NiFindOptions.ActionMask | NiFindOptions.Backwards);

            switch (action)
            {
            case FindAction.FindNext:
                options |= NiFindOptions.Find;
                break;

            case FindAction.FindPrevious:
                options |= NiFindOptions.Find | NiFindOptions.Backwards;
                break;

            case FindAction.Replace:
                options |= NiFindOptions.Replace;
                break;

            case FindAction.ReplaceAll:
                options |= NiFindOptions.ReplaceAll;
                break;

            case FindAction.FindAll:
                options |= NiFindOptions.FindAll;
                break;

            case FindAction.SkipFile:
                throw new NotImplementedException();

            default:
                throw new ArgumentOutOfRangeException("action");
            }

            var currentFindState = FindState.Create(this, options, FindTarget);

            if (_state == null || !_state.SettingsEqual(currentFindState))
            {
                _state = currentFindState;
                _state.CreateIterator(_view);
            }

            _state.Options = options;

            switch (action)
            {
            case FindAction.FindNext:
                PerformFindSingle();
                break;

            case FindAction.FindPrevious:
                PerformFindSingle();
                break;

            case FindAction.Replace:
                PerformReplaceSingle();
                break;

            case FindAction.ReplaceAll:
                PerformReplaceAll();
                break;

            case FindAction.FindAll:
                PerformFindAll();
                break;

            case FindAction.SkipFile:
                throw new NotImplementedException();

            default:
                throw new ArgumentOutOfRangeException("action");
            }
        }
Example #22
0
 public void PerformFind(FindAction action)
 {
     Checked.Execute(_view, () => PerformFindChecked(action));
 }
Example #23
0
 private void PerformFind(FindAction action)
 {
     _findManager.PerformFind(action);
 }
Example #24
0
 public void PerformFind(FindAction action)
 {
     Checked.Execute(_view, () => PerformFindChecked(action));
 }