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); }
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); } }
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); }
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)); } }
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)); } }
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(); }
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(); }
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(); } }
public FindReplaceForm(FindAction action) { InitializeComponent(); if (action == FindAction.Find) { AcceptButton = FindButton; PerformLayout(); panel2.Visible = false; Height -= panel2.Height; Text = FindTitle; } else { AcceptButton = ReplaceButton; } }
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); }
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(); } }
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); } }
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; } } } }
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"); } }
private void PerformFind(FindAction action) { _findManager.PerformFind(action); }
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(); }
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(); }
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); } } }
private void ReplaceAll_Click(object sender, System.EventArgs e) { Action = FindAction.ReplaceAll; DialogResult = DialogResult.OK; }
private void Find_Click(object sender, System.EventArgs e) { Action = FindAction.Find; DialogResult = DialogResult.OK; }
public void PerformFind(FindAction action) { Checked.Execute(_view, () => PerformFindChecked(action)); }