UIAutomation.PatternCmdletBase.CallScrollPattern C# (CSharp) Method

CallScrollPattern() private method

private CallScrollPattern ( PatternCmdletBase cmdlet, IUiElement control, IUiElement inputObject ) : void
cmdlet PatternCmdletBase
control IUiElement
inputObject IUiElement
return void
        internal void CallScrollPattern(PatternCmdletBase cmdlet, IUiElement control, IUiElement inputObject)
        {
            try {
                // 20131208
                // ScrollPattern scPattern = control.GetCurrentPattern(classic.ScrollPattern.Pattern) as ScrollPattern;
                // ScrollPattern scPattern = control.GetCurrentPattern<IScrollPattern, ScrollPattern>(classic.ScrollPattern.Pattern) as ScrollPattern;
                // IScrollPattern scPattern = control.GetScrollPattern();
                // IScrollPattern scPattern = control.GetCurrentPattern<IScrollPattern, ScrollPattern>();
                IScrollPattern scPattern = control.GetCurrentPattern<IScrollPattern>(classic.ScrollPattern.Pattern);
                if (scPattern == null) return;
                try {
                    bool horizontal = ((InvokeUiaScrollPatternCommand)this).Horizontal;
                    bool vertical = ((InvokeUiaScrollPatternCommand)this).Vertical;
                    int horPercent = ((InvokeUiaScrollPatternCommand)this).HorizontalPercent;
                    int verPercent = ((InvokeUiaScrollPatternCommand)this).VerticalPercent;
                    classic.ScrollAmount horAmount = classic.ScrollAmount.NoAmount;
                    classic.ScrollAmount verAmount = classic.ScrollAmount.NoAmount;
                    horAmount = (classic.ScrollAmount)((InvokeUiaScrollPatternCommand)this).HorizontalAmount;
                    verAmount = (classic.ScrollAmount)((InvokeUiaScrollPatternCommand)this).VerticalAmount;
                    // for refactoring
                    //System.Windows.Automation.ScrollAmount horAmount, verAmount = System.Windows.Automation.ScrollAmount.NoAmount;
                    //horAmount = (System.Windows.Automation.ScrollAmount)((InvokeUiaScrollPatternCommand)this).HorizontalAmount;
                    //verAmount = (System.Windows.Automation.ScrollAmount)((InvokeUiaScrollPatternCommand)this).VerticalAmount;
                    if ((horPercent + verPercent) > 0) {
                        scPattern.SetScrollPercent(horPercent, verPercent);
                    }
                    if (horizontal) {
                        if (horAmount > 0) {
                            scPattern.ScrollHorizontal(horAmount);
                        }
                    }
                    if (vertical) {
                        if (verAmount > 0) {
                            scPattern.ScrollVertical(verAmount);
                        }
                    }
                    
                    if (PassThru && null != (inputObject as IUiElement)) {
                        WriteObject(this, inputObject);
                    } else {
                        WriteObject(this, true);
                    }
                } catch {
                    WriteObject(this, false);
                }

                /*
                if (scPattern != null) {
                    try {
                        bool horizontal = ((InvokeUiaScrollPatternCommand)this).Horizontal;
                        bool vertical = ((InvokeUiaScrollPatternCommand)this).Vertical;
                        int horPercent = ((InvokeUiaScrollPatternCommand)this).HorizontalPercent;
                        int verPercent = ((InvokeUiaScrollPatternCommand)this).VerticalPercent;
                        System.Windows.Automation.ScrollAmount horAmount, verAmount = System.Windows.Automation.ScrollAmount.NoAmount;
                        horAmount = (System.Windows.Automation.ScrollAmount)((InvokeUiaScrollPatternCommand)this).HorizontalAmount;
                        verAmount = (System.Windows.Automation.ScrollAmount)((InvokeUiaScrollPatternCommand)this).VerticalAmount;
                        if ((horPercent + verPercent) > 0) {
                            scPattern.SetScrollPercent(horPercent, verPercent);
                        }
                        if (horizontal) {
                            if (horAmount > 0) {
                                scPattern.ScrollHorizontal(horAmount);
                            }
                        }
                        if (vertical) {
                            if (verAmount > 0) {
                                scPattern.ScrollVertical(verAmount);
                            }
                        }
                        if (this.PassThru && null != (inputObject as AutomationElement)) {
                            WriteObject(this, inputObject);
                        } else {
                            WriteObject(this, true);
                        }
                    } catch {
                        WriteObject(this, false);
                    }
                }
                */
            } catch {
                WriteObject(this, false);
            }
        }