示例#1
0
        protected internal void RunEventScriptBlocks(HasControlInputCmdletBase cmdlet)
        {
            var blocks = new List<ScriptBlock>();
            
//            WriteVerbose(cmdlet,
//                              blocks.Count +
//                              " events to fire");
            if (cmdlet.EventAction != null && cmdlet.EventAction.Length > 0) {
                foreach (ScriptBlock sb in cmdlet.EventAction) {
                    blocks.Add(sb);
//                    WriteVerbose(cmdlet,
//                                      "the scriptblock: " +
//                                      sb +
//                                      " is ready to be fired");
                }
            }
            
            try {
                runScriptBlocks(blocks, cmdlet, true, null);
            }
            catch (Exception eScriptBlocks) {
                
                cmdlet.WriteError(
                    cmdlet,
                    eScriptBlocks.Message,
                    "ScriptblocksFailed",
                    ErrorCategory.InvalidResult,
                    true);
            }
            // runEventScriptBlocks(blocks, cmdlet); //, true);
        }
示例#2
0
        // 20120209 protected void RunEventScriptBlocks(EventCmdletBase cmdlet)
        //protected internal void RunEventScriptBlocks(EventCmdletBase cmdlet)
        protected internal void RunEventScriptBlocks(HasControlInputCmdletBase cmdlet)
        {
            System.Collections.Generic.List<ScriptBlock >  blocks =
                new System.Collections.Generic.List<ScriptBlock > ();
            this.WriteVerbose(cmdlet,
                              blocks.Count.ToString() +
                              " events to fire");
            if (cmdlet.EventAction != null &&
                cmdlet.EventAction.Length > 0) {
                foreach (ScriptBlock sb in cmdlet.EventAction) {
                    blocks.Add(sb);
                    this.WriteVerbose(cmdlet,
                                      "the scriptblock: " +
                                      sb.ToString() +
                                      " is ready to be fired");
                }
            }
            // 20130318
            //runScriptBlocks(blocks, cmdlet, true);
            // 20130319
            try {
                runScriptBlocks(blocks, cmdlet, true, null);
            }
            catch (Exception eScriptBlocks) {

                cmdlet.WriteError(
                    cmdlet,
                    eScriptBlocks.Message,
                    "ScriptblocksFailed",
                    ErrorCategory.InvalidResult,
                    true);
            }
            // runEventScriptBlocks(blocks, cmdlet); //, true);
        }
        internal bool CheckAndPrepareInput(HasControlInputCmdletBase cmdlet)
        {
            bool result = false;
            
            if (null == cmdlet.InputObject) {
                
                WriteVerbose(cmdlet, "[checking the input] Control(s) are null");
                
                cmdlet.WriteError(
                    cmdlet,
                    "The pipeline input is null",
                    "InputIsNull",
                    ErrorCategory.InvalidArgument,
                    true);
                
            }
            
            foreach (var inputObject in cmdlet.InputObject) {
                
                if (null == inputObject) {
                    
                    WriteVerbose(cmdlet, "[checking the input] Control is null");
                    if (PassThru) {
                        
                        WriteObject(this, inputObject);
                    } else {
                        
                        result = false;
                        WriteObject(this, result);
                    }
                    
                    result = false;
                    
                    cmdlet.WriteError(
                        cmdlet,
                        "A part of the pipeline input is null",
                        "PartOfInputIsNull",
                        ErrorCategory.InvalidArgument,
                        false);
                    
                }
                
                // 20131109
                //System.Windows.Automation.AutomationElement _control = null;
                //IUiElement _controlAdapter = null;
                var _controlAdapter = inputObject;
                
                try {
                    
                    // 20131109
                    //_control = 
                    //    (AutomationElement)inputObject;
                    
                    // 20131109
//                    this.WriteVerbose(
//                        cmdlet,
//                        "[checking the input] the input control is of the " +
//                        inputObject.Current.ControlType.ProgrammaticName +
//                        " type");
                    
                    // 20131109
                    //cmdlet.currentWindow = _control;
                    //if (inputObject is IUiElement) {
                    if (null != (inputObject as IUiElement))
                    {
                    /*
                    if (inputObject is IUiElement) {
                    */
                        cmdlet.CurrentInputElement = (IUiElement)_controlAdapter;
                    }
//                    if (inputObject is AutomationElement) {
//                        cmdlet.currentWindow = new UiElement((AutomationElement)inputObject);
//                    }
                    
                    result = true;
                    
                    // there's no need to output the True value
                    // since the output will be what we want 
                    // (some part of AutomationElement, as an example)
                } catch (Exception) {
                    
                    if (PassThru) {
                        
                        // 20131109
                        //WriteObject(this, _control);
                        WriteObject(this, _controlAdapter);
                        
                    } else {
                        
                        result = false;
                        WriteObject(this, result);
                        
                    }
                    result = false;
                    return result;
                }
            
            } // 20120823
            
            return result;
        }
        internal bool CheckControl(HasControlInputCmdletBase cmdlet)
        {
            bool result = false;
            // string cmdletName = cmdlet.GetType().Name.Replace("UIA", "-UIA");
            // 20120228 string cmdletName = CmdletName(cmdlet);

            // 20130918
            if (null == cmdlet.InputObject) {

                this.WriteVerbose(cmdlet, "[checking the control] Control(s) are null");
                //return result;
                cmdlet.WriteError(
                    cmdlet,
                    "The pipeline input is null",
                    "InputIsNull",
                    ErrorCategory.InvalidArgument,
                    true);
            }

            // 20120823
            foreach (AutomationElement inputObject in cmdlet.InputObject) {

            // 20120823
            //if (cmdlet.InputObject == null)
            if (null == inputObject) {

            // 20120823
            //{
                //WriteVerbose(cmdletName + ": Control is null");
                this.WriteVerbose(cmdlet, "[checking the control] Control is null");
                if (this.PassThru) {
                    //WriteObject(this, null);
                    // 20120823
                    //WriteObject(this, this.InputObject);
                    this.WriteObject(this, inputObject);
                } else {
                    result = false;
                    this.WriteObject(this, result);
                }
                // 20120830
                //return false;
                result = false;
                // 20130918
                //return result;
                cmdlet.WriteError(
                    cmdlet,
                    "The pipeline input is null",
                    "InputIsNull",
                    ErrorCategory.InvalidArgument,
                    true);
            }
            System.Windows.Automation.AutomationElement _control = null;
            try {

                _control =
                    // 20120823
                    //(System.Windows.Automation.AutomationElement)(cmdlet.InputObject);
                    (AutomationElement)inputObject;

                this.WriteVerbose(cmdlet,
                             //"[checking the control] the given control is of the " +
                             // 20130108
                             "[checking the control] the input control is of the " +
                             // 20120823
                             //cmdlet.InputObject.Current.ControlType.ProgrammaticName +
                             inputObject.Current.ControlType.ProgrammaticName +
                             " type");

                //WriteVerbose(cmdlet,
                //             "[checking the control] the given control is of the " +
                //             _control.Current.ControlType.ProgrammaticName +
                //             " type");
                cmdlet._window = _control;

                result = true;
                // WriteObject(result);
                // there's no need to output the True value
                // since the output will be what we want
                // (some part of AutomationElement, as an example)
            } catch (Exception eControlTypeException) {

                this.WriteDebug(cmdlet, "[checking the control] Control is not an AutomationElement");
                this.WriteDebug(cmdlet, "[checking the control] " + eControlTypeException.Message);
                if (this.PassThru) {

                    // result = null;
                    //WriteObject(this, null);
                    WriteObject(this, _control);
                } else {

                    result = false;
                    this.WriteObject(this, result);
                }
                // result = false;
                // WriteObject(result);
                // return result;
                // 20120830
                //return false;
                result = false;
                return result;
            }

            } // 20120823

            return result;
        }