public static TranscriptCmdletBase CreateTranscriptingCmdlet() { var cmdlet = new TranscriptCmdletBase { NoClassInformation = false, NoScriptHeader = true, NoUI = true, WriteCurrentPattern = true, Timeout = 600000000, Highlight = true, HighlightParent = true, PassThru = false }; Preferences.TranscriptInterval = 500; return(cmdlet); }
/// <summary> /// /// </summary> /// <param name="cmdlet"></param> /// <param name="element"></param> internal static void CollectAncestors(this IUiElement element, TranscriptCmdletBase cmdlet, ref string errorMessage, ref bool errorOccured) { var walker = new classic.TreeWalker( classic.Condition.TrueCondition); /* TreeWalker walker = new TreeWalker( System.Windows.Automation.Condition.TrueCondition); */ try { // commented out 201206210 //testparent = // walker.GetParent(element); IUiElement testParent = element; // 20140312 // while (testParent != null && (int)testParent.Current.ProcessId > 0) { while (testParent != null && (int)testParent.GetCurrent().ProcessId > 0) { testParent = // 20140102 // AutomationFactory.GetUiElement(walker.GetParent(testParent.GetSourceElement())); AutomationFactory.GetUiElement(walker.GetParent(testParent.GetSourceElement() as classic.AutomationElement)); // 20140312 // if (testParent == null || (int) testParent.Current.ProcessId <= 0) continue; if (testParent == null || (int) testParent.GetCurrent().ProcessId <= 0) continue; if (testParent == cmdlet.OddRootElement) { testParent = null; } else{ string parentControlType = // getControlTypeNameOfAutomationElement(testparent, element); // testparent.Current.ControlType.ProgrammaticName.Substring( // element.Current.ControlType.ProgrammaticName.IndexOf('.') + 1); // // experimental // 20140312 // testParent.Current.ControlType.ProgrammaticName.Substring( // testParent.Current.ControlType.ProgrammaticName.IndexOf('.') + 1); testParent.GetCurrent().ControlType.ProgrammaticName.Substring( testParent.GetCurrent().ControlType.ProgrammaticName.IndexOf('.') + 1); // // if (parentControlType.Length == 0) { // break; //} // in case this element is an upper-level Pane // residing directrly under the RootElement // change type to window // i.e. Get-UiaPane - > Get-UiaWindow // since Get-UiaPane is unable to get something more than // a window's child pane control if (parentControlType == "Pane" || parentControlType == "Menu") { // 20131109 //if (walker.GetParent(testParent) == cmdlet.rootElement) { // 20131112 //if ((new UiElement(walker.GetParent(testParent.SourceElement))) == cmdlet.oddRootElement) { // 20131118 // property to method //if (ObjectsFactory.GetUiElement(walker.GetParent(testParent.SourceElement)) == cmdlet.oddRootElement) { // 20140102 // if (AutomationFactory.GetUiElement(walker.GetParent(testParent.GetSourceElement())) == cmdlet.OddRootElement) { if (AutomationFactory.GetUiElement(walker.GetParent(testParent.GetSourceElement() as classic.AutomationElement)) == cmdlet.OddRootElement) { parentControlType = "Window"; } } string parentVerbosity = @"Get-Uia" + parentControlType; try { // 20140312 // if (testParent.Current.AutomationId.Length > 0) { // parentVerbosity += (" -AutomationId '" + testParent.Current.AutomationId + "'"); if (testParent.GetCurrent().AutomationId.Length > 0) { parentVerbosity += (" -AutomationId '" + testParent.GetCurrent().AutomationId + "'"); } } catch { } if (!cmdlet.NoClassInformation) { try { // 20140312 // if (testParent.Current.ClassName.Length > 0) { // parentVerbosity += (" -Class '" + testParent.Current.ClassName + "'"); if (testParent.GetCurrent().ClassName.Length > 0) { parentVerbosity += (" -Class '" + testParent.GetCurrent().ClassName + "'"); } } catch { } } try { // 20140312 // if (testParent.Current.Name.Length > 0) { // parentVerbosity += (" -Name '" + testParent.Current.Name + "'"); if (testParent.GetCurrent().Name.Length > 0) { parentVerbosity += (" -Name '" + testParent.GetCurrent().Name + "'"); } } catch { } if (cmdlet.LastRecordedItem[cmdlet.LastRecordedItem.Count - 1].ToString() == parentVerbosity) continue; cmdlet.LastRecordedItem.Add(parentVerbosity); cmdlet.WriteVerbose(parentVerbosity); } } } catch (Exception eErrorInTheInnerCycle) { cmdlet.WriteDebug(cmdlet, eErrorInTheInnerCycle.Message); // _errorMessageInTheInnerCycle = errorMessage = eErrorInTheInnerCycle.Message; // _errorInTheInnerCycle = true; errorOccured = true; } }
public static TranscriptCmdletBase CreateTranscriptingCmdlet() { var cmdlet = new TranscriptCmdletBase { NoClassInformation = false, NoScriptHeader = true, NoUI = true, WriteCurrentPattern = true, Timeout = 600000000, Highlight = true, HighlightParent = true, PassThru = false }; Preferences.TranscriptInterval = 500; return cmdlet; }
/// <summary> /// /// </summary> /// <param name="cmdlet"></param> /// <param name="element"></param> internal static void CollectAncestors(this IUiElement element, TranscriptCmdletBase cmdlet, ref string errorMessage, ref bool errorOccured) { var walker = new classic.TreeWalker( classic.Condition.TrueCondition); /* * TreeWalker walker = * new TreeWalker( * System.Windows.Automation.Condition.TrueCondition); */ try { // commented out 201206210 //testparent = // walker.GetParent(element); IUiElement testParent = element; // 20140312 // while (testParent != null && (int)testParent.Current.ProcessId > 0) { while (testParent != null && (int)testParent.GetCurrent().ProcessId > 0) { testParent = // 20140102 // AutomationFactory.GetUiElement(walker.GetParent(testParent.GetSourceElement())); AutomationFactory.GetUiElement(walker.GetParent(testParent.GetSourceElement() as classic.AutomationElement)); // 20140312 // if (testParent == null || (int) testParent.Current.ProcessId <= 0) continue; if (testParent == null || (int)testParent.GetCurrent().ProcessId <= 0) { continue; } if (testParent == cmdlet.OddRootElement) { testParent = null; } else { string parentControlType = // getControlTypeNameOfAutomationElement(testparent, element); // testparent.Current.ControlType.ProgrammaticName.Substring( // element.Current.ControlType.ProgrammaticName.IndexOf('.') + 1); // // experimental // 20140312 // testParent.Current.ControlType.ProgrammaticName.Substring( // testParent.Current.ControlType.ProgrammaticName.IndexOf('.') + 1); testParent.GetCurrent().ControlType.ProgrammaticName.Substring( testParent.GetCurrent().ControlType.ProgrammaticName.IndexOf('.') + 1); // // if (parentControlType.Length == 0) { // break; //} // in case this element is an upper-level Pane // residing directrly under the RootElement // change type to window // i.e. Get-UiaPane - > Get-UiaWindow // since Get-UiaPane is unable to get something more than // a window's child pane control if (parentControlType == "Pane" || parentControlType == "Menu") { // 20131109 //if (walker.GetParent(testParent) == cmdlet.rootElement) { // 20131112 //if ((new UiElement(walker.GetParent(testParent.SourceElement))) == cmdlet.oddRootElement) { // 20131118 // property to method //if (ObjectsFactory.GetUiElement(walker.GetParent(testParent.SourceElement)) == cmdlet.oddRootElement) { // 20140102 // if (AutomationFactory.GetUiElement(walker.GetParent(testParent.GetSourceElement())) == cmdlet.OddRootElement) { if (AutomationFactory.GetUiElement(walker.GetParent(testParent.GetSourceElement() as classic.AutomationElement)) == cmdlet.OddRootElement) { parentControlType = "Window"; } } string parentVerbosity = @"Get-Uia" + parentControlType; try { // 20140312 // if (testParent.Current.AutomationId.Length > 0) { // parentVerbosity += (" -AutomationId '" + testParent.Current.AutomationId + "'"); if (testParent.GetCurrent().AutomationId.Length > 0) { parentVerbosity += (" -AutomationId '" + testParent.GetCurrent().AutomationId + "'"); } } catch { } if (!cmdlet.NoClassInformation) { try { // 20140312 // if (testParent.Current.ClassName.Length > 0) { // parentVerbosity += (" -Class '" + testParent.Current.ClassName + "'"); if (testParent.GetCurrent().ClassName.Length > 0) { parentVerbosity += (" -Class '" + testParent.GetCurrent().ClassName + "'"); } } catch { } } try { // 20140312 // if (testParent.Current.Name.Length > 0) { // parentVerbosity += (" -Name '" + testParent.Current.Name + "'"); if (testParent.GetCurrent().Name.Length > 0) { parentVerbosity += (" -Name '" + testParent.GetCurrent().Name + "'"); } } catch { } if (cmdlet.LastRecordedItem[cmdlet.LastRecordedItem.Count - 1].ToString() == parentVerbosity) { continue; } cmdlet.LastRecordedItem.Add(parentVerbosity); cmdlet.WriteVerbose(parentVerbosity); } } } catch (Exception eErrorInTheInnerCycle) { cmdlet.WriteDebug(cmdlet, eErrorInTheInnerCycle.Message); // _errorMessageInTheInnerCycle = errorMessage = eErrorInTheInnerCycle.Message; // _errorInTheInnerCycle = true; errorOccured = true; } }