Пример #1
0
        protected override void ProcessRecord()
        {
            base.ProcessRecord();

            // 20140312
            // if (InputObject.Current.ControlType == classic.ControlType.Window)
            if (InputObject.GetCurrent().ControlType == classic.ControlType.Window)
            {
                // 20131208
                // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
                // WindowPattern windowPattern = InputObject.GetCurrentPattern(classic.WindowPattern.Pattern) as WindowPattern;
                // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
                IWindowPattern windowPattern = InputObject.GetCurrentPattern <IWindowPattern>(classic.WindowPattern.Pattern);

                try
                {
                    switch (PatternName.ToLower())
                    {
                    case "close":
                        windowPattern.Close();
                        break;

                    case "maximize":
                        windowPattern.SetWindowVisualState(classic.WindowVisualState.Maximized);
                        break;

                    case "minimize":
                        windowPattern.SetWindowVisualState(classic.WindowVisualState.Minimized);
                        break;

                    case "restore":
                        windowPattern.SetWindowVisualState(classic.WindowVisualState.Normal);
                        break;
                    }
                }
                catch (InvalidOperationException)
                {
                    ArgumentException ex = new ArgumentException("Target window doesn't support '" + PatternName + "' pattern.");
                    ThrowTerminatingError(new ErrorRecord(ex, "WrongInputObject", ErrorCategory.InvalidArgument, null));
                }
            }
            else
            {
                ArgumentException ex = new ArgumentException("Cannot call WindowPattern on object that is not a Window.");
                ThrowTerminatingError(new ErrorRecord(ex, "WrongInputObject", ErrorCategory.InvalidArgument, null));
            }
        }
Пример #2
0
        public static IWindowPattern GetWindowPattern(PatternsData data)
        {
            IWindowPattern windowPattern = Substitute.For <IWindowPattern>();

            // windowPattern.Close()
            windowPattern.SetWindowVisualState(Arg.Do <WindowVisualState>(state => data.WindowPattern_WindowVisualState = state));
            windowPattern.WaitForInputIdle(data.WindowPattern_Milliseconds);

            windowPattern.Current.CanMaximize.Returns(data.WindowPattern_CanMaximize);
            windowPattern.Current.CanMinimize.Returns(data.WindowPattern_CanMinimize);
            windowPattern.Current.IsModal.Returns(data.WindowPattern_IsModal);
            windowPattern.Current.IsTopmost.Returns(data.WindowPattern_IsTopmost);
            windowPattern.Current.WindowInteractionState.Returns(data.WindowPattern_WindowInteractionState);
            windowPattern.Current.WindowVisualState.Returns(data.WindowPattern_WindowVisualState);
            return(windowPattern);
        }