コード例 #1
0
        private void ProcessExpressionParameter()
        {
            TerminatingErrorContext invocationContext = new TerminatingErrorContext(this);
            ParameterProcessor      processor         =
                new ParameterProcessor(new SelectObjectExpressionParameterDefinition());

            if ((Property != null) && (Property.Length != 0))
            {
                _propertyMshParameterList = processor.ProcessParameters(Property, invocationContext);
            }
            else
            {
                _propertyMshParameterList = new List <MshParameter>();
            }

            if (!string.IsNullOrEmpty(ExpandProperty))
            {
                _expandMshParameterList = processor.ProcessParameters(new string[] { ExpandProperty }, invocationContext);
            }

            if (ExcludeProperty != null)
            {
                _exclusionFilter = new MshExpressionFilter(ExcludeProperty);
            }
        }
コード例 #2
0
        private void ProcessExpressionParameter()
        {
            TerminatingErrorContext invocationContext = new TerminatingErrorContext(this);
            ParameterProcessor      processor         =
                new ParameterProcessor(new SelectObjectExpressionParameterDefinition());

            if ((Property != null) && (Property.Length != 0))
            {
                // Build property list taking into account the wildcards and @{name=;expression=}
                _propertyMshParameterList = processor.ProcessParameters(Property, invocationContext);
            }
            else
            {
                // Property don't exist
                _propertyMshParameterList = new List <MshParameter>();
            }

            if (!string.IsNullOrEmpty(ExpandProperty))
            {
                _expandMshParameterList = processor.ProcessParameters(new string[] { ExpandProperty }, invocationContext);
            }

            if (ExcludeProperty != null)
            {
                _exclusionFilter = new MshExpressionFilter(ExcludeProperty);
                // ExcludeProperty implies -Property * for better UX
                if ((Property == null) || (Property.Length == 0))
                {
                    Property = new Object[] { "*" };
                    _propertyMshParameterList = processor.ProcessParameters(Property, invocationContext);
                }
            }
        }
コード例 #3
0
ファイル: OrderObjectBase.cs プロジェクト: x1m0/PowerShell
        // These are made static for Measure-Object's GroupBy parameter that measure the outputs of Group-Object
        // However, Measure-Object differs from Group-Object and Sort-Object considerably that it should not
        // be built on the same base class, i.e., this class. Moreover, Measure-Object's Property parameter is
        // a string array and allows wildcard.
        // Yes, the Cmdlet is needed. It's used to get the TerminatingErrorContext, WriteError and WriteDebug.

        #region process MshExpression and MshParameter

        private static void ProcessExpressionParameter(
            List <PSObject> inputObjects,
            PSCmdlet cmdlet,
            object[] expr,
            out List <MshParameter> mshParameterList)
        {
            mshParameterList = null;
            TerminatingErrorContext invocationContext = new TerminatingErrorContext(cmdlet);
            // compare-object and group-object use the same definition here
            ParameterProcessor processor = cmdlet is SortObjectCommand ?
                                           new ParameterProcessor(new SortObjectExpressionParameterDefinition()) :
                                           new ParameterProcessor(new GroupObjectExpressionParameterDefinition());

            if (expr == null && inputObjects != null && inputObjects.Count > 0)
            {
                expr = GetDefaultKeyPropertySet(inputObjects[0]);
            }
            if (expr != null)
            {
                List <MshParameter> unexpandedParameterList = processor.ProcessParameters(expr, invocationContext);
                mshParameterList = ExpandExpressions(inputObjects, unexpandedParameterList);
            }
            // NOTE: if no parameters are passed, we will look at the default keys of the first
            // incoming object
        }
コード例 #4
0
        private List <MshParameter> ProcessParameter(object[] properties)
        {
            TerminatingErrorContext invocationContext = new TerminatingErrorContext(this);
            ParameterProcessor      processor         = new ParameterProcessor(new ConvertHTMLExpressionParameterDefinition());

            if (properties == null)
            {
                properties = new object[] { "*" };
            }
            return(processor.ProcessParameters(properties, invocationContext));
        }
コード例 #5
0
        internal override FormattingCommandLineParameters GetCommandLineParameters()
        {
            FormattingCommandLineParameters parameters = new FormattingCommandLineParameters();

            if (this.prop != null)
            {
                ParameterProcessor      processor         = new ParameterProcessor(new FormatWideParameterDefinition());
                TerminatingErrorContext invocationContext = new TerminatingErrorContext(this);
                parameters.mshParameterList = processor.ProcessParameters(new object[] { this.prop }, invocationContext);
            }
            if (!string.IsNullOrEmpty(base.View))
            {
                if (parameters.mshParameterList.Count != 0)
                {
                    base.ReportCannotSpecifyViewAndProperty();
                }
                parameters.viewName = base.View;
            }
            if ((this.autosize.HasValue && this.column.HasValue) && this.autosize.Value)
            {
                string      message     = StringUtil.Format(FormatAndOut_format_xxx.CannotSpecifyAutosizeAndColumnsError, new object[0]);
                ErrorRecord errorRecord = new ErrorRecord(new InvalidDataException(), "FormatCannotSpecifyAutosizeAndColumns", ErrorCategory.InvalidArgument, null)
                {
                    ErrorDetails = new ErrorDetails(message)
                };
                base.ThrowTerminatingError(errorRecord);
            }
            parameters.groupByParameter = base.ProcessGroupByParameter();
            parameters.forceFormattingAlsoOnOutOfBand = (bool)base.Force;
            if (this.showErrorsAsMessages.HasValue)
            {
                parameters.showErrorsAsMessages = base.showErrorsAsMessages;
            }
            if (this.showErrorsInFormattedOutput.HasValue)
            {
                parameters.showErrorsInFormattedOutput = base.showErrorsInFormattedOutput;
            }
            parameters.expansion = base.ProcessExpandParameter();
            if (this.autosize.HasValue)
            {
                parameters.autosize = new bool?(this.autosize.Value);
            }
            WideSpecificParameters parameters2 = new WideSpecificParameters();

            parameters.shapeParameters = parameters2;
            if (this.column.HasValue)
            {
                parameters2.columns = new int?(this.column.Value);
            }
            return(parameters);
        }
コード例 #6
0
ファイル: OrderByProperty.cs プロジェクト: modulexcite/pash-1
        private static void ProcessExpressionParameter(List <PSObject> inputObjects, PSCmdlet cmdlet, object[] expr, out List <MshParameter> mshParameterList)
        {
            mshParameterList = null;
            TerminatingErrorContext invocationContext = new TerminatingErrorContext(cmdlet);
            ParameterProcessor      processor         = (cmdlet is SortObjectCommand) ? new ParameterProcessor(new SortObjectExpressionParameterDefinition()) : new ParameterProcessor(new GroupObjectExpressionParameterDefinition());

            if (((expr == null) && (inputObjects != null)) && (inputObjects.Count > 0))
            {
                expr = GetDefaultKeyPropertySet(inputObjects[0]);
            }
            if (expr != null)
            {
                List <MshParameter> unexpandedParameterList = processor.ProcessParameters(expr, invocationContext);
                mshParameterList = ExpandExpressions(inputObjects, unexpandedParameterList);
            }
        }
コード例 #7
0
ファイル: Format-Object.cs プロジェクト: zwcloud/PowerShell
        internal override FormattingCommandLineParameters GetCommandLineParameters()
        {
            FormattingCommandLineParameters parameters = new FormattingCommandLineParameters();

            if (_props != null)
            {
                ParameterProcessor      processor         = new ParameterProcessor(new FormatObjectParameterDefinition());
                TerminatingErrorContext invocationContext = new TerminatingErrorContext(this);
                parameters.mshParameterList = processor.ProcessParameters(_props, invocationContext);
            }

            if (!string.IsNullOrEmpty(this.View))
            {
                // we have a view command line switch
                if (parameters.mshParameterList.Count != 0)
                {
                    ReportCannotSpecifyViewAndProperty();
                }

                parameters.viewName = this.View;
            }

            parameters.groupByParameter = this.ProcessGroupByParameter();
            parameters.forceFormattingAlsoOnOutOfBand = this.Force;
            if (this.showErrorsAsMessages.HasValue)
            {
                parameters.showErrorsAsMessages = this.showErrorsAsMessages;
            }
            if (this.showErrorsInFormattedOutput.HasValue)
            {
                parameters.showErrorsInFormattedOutput = this.showErrorsInFormattedOutput;
            }

            parameters.expansion = ProcessExpandParameter();

            ComplexSpecificParameters csp = new ComplexSpecificParameters();

            csp.maxDepth = _depth;
            parameters.shapeParameters = csp;

            return(parameters);
        }
コード例 #8
0
ファイル: OrderObjectBase.cs プロジェクト: x1m0/PowerShell
        internal void ProcessExpressionParameter(
            PSCmdlet cmdlet,
            object[] expr)
        {
            TerminatingErrorContext invocationContext = new TerminatingErrorContext(cmdlet);
            // compare-object and group-object use the same definition here
            ParameterProcessor processor = cmdlet is SortObjectCommand ?
                                           new ParameterProcessor(new SortObjectExpressionParameterDefinition()) :
                                           new ParameterProcessor(new GroupObjectExpressionParameterDefinition());

            if (expr != null)
            {
                if (_unexpandedParameterList == null)
                {
                    _unexpandedParameterList = processor.ProcessParameters(expr, invocationContext);

                    foreach (MshParameter unexpandedParameter in _unexpandedParameterList)
                    {
                        MshExpression mshExpression = (MshExpression)unexpandedParameter.GetEntry(FormatParameterDefinitionKeys.ExpressionEntryKey);
                        if (!mshExpression.HasWildCardCharacters) // this special cases 1) script blocks and 2) wildcard-less strings
                        {
                            _mshParameterList.Add(unexpandedParameter);
                        }
                        else
                        {
                            if (_unExpandedParametersWithWildCardPattern == null)
                            {
                                _unExpandedParametersWithWildCardPattern = new List <MshParameter>();
                            }

                            _unExpandedParametersWithWildCardPattern.Add(unexpandedParameter);
                        }
                    }
                }
            }
        }
コード例 #9
0
        internal override FormattingCommandLineParameters GetCommandLineParameters()
        {
            FormattingCommandLineParameters parameters = new FormattingCommandLineParameters();

            if (this.props != null)
            {
                ParameterProcessor      processor         = new ParameterProcessor(new FormatObjectParameterDefinition());
                TerminatingErrorContext invocationContext = new TerminatingErrorContext(this);
                parameters.mshParameterList = processor.ProcessParameters(this.props, invocationContext);
            }
            if (!string.IsNullOrEmpty(base.View))
            {
                if (parameters.mshParameterList.Count != 0)
                {
                    base.ReportCannotSpecifyViewAndProperty();
                }
                parameters.viewName = base.View;
            }
            parameters.groupByParameter = base.ProcessGroupByParameter();
            parameters.forceFormattingAlsoOnOutOfBand = (bool)base.Force;
            if (this.showErrorsAsMessages.HasValue)
            {
                parameters.showErrorsAsMessages = base.showErrorsAsMessages;
            }
            if (this.showErrorsInFormattedOutput.HasValue)
            {
                parameters.showErrorsInFormattedOutput = base.showErrorsInFormattedOutput;
            }
            parameters.expansion = base.ProcessExpandParameter();
            ComplexSpecificParameters parameters2 = new ComplexSpecificParameters {
                maxDepth = this.depth
            };

            parameters.shapeParameters = parameters2;
            return(parameters);
        }
コード例 #10
0
ファイル: Format-Wide.cs プロジェクト: 5l1v3r1/PowerShell-7
        internal override FormattingCommandLineParameters GetCommandLineParameters()
        {
            FormattingCommandLineParameters parameters = new FormattingCommandLineParameters();

            if (_prop != null)
            {
                ParameterProcessor      processor         = new ParameterProcessor(new FormatWideParameterDefinition());
                TerminatingErrorContext invocationContext = new TerminatingErrorContext(this);
                parameters.mshParameterList = processor.ProcessParameters(new object[] { _prop }, invocationContext);
            }

            if (!string.IsNullOrEmpty(this.View))
            {
                // we have a view command line switch
                if (parameters.mshParameterList.Count != 0)
                {
                    ReportCannotSpecifyViewAndProperty();
                }

                parameters.viewName = this.View;
            }

            // we cannot specify -column and -autosize, they are mutually exclusive
            if (_autosize.HasValue && _column.HasValue)
            {
                if (_autosize.Value)
                {
                    // the user specified -autosize:true AND a column number
                    string msg = StringUtil.Format(FormatAndOut_format_xxx.CannotSpecifyAutosizeAndColumnsError);

                    ErrorRecord errorRecord = new ErrorRecord(
                        new InvalidDataException(),
                        "FormatCannotSpecifyAutosizeAndColumns",
                        ErrorCategory.InvalidArgument,
                        null);

                    errorRecord.ErrorDetails = new ErrorDetails(msg);
                    this.ThrowTerminatingError(errorRecord);
                }
            }

            parameters.groupByParameter = this.ProcessGroupByParameter();
            parameters.forceFormattingAlsoOnOutOfBand = this.Force;
            if (this.showErrorsAsMessages.HasValue)
            {
                parameters.showErrorsAsMessages = this.showErrorsAsMessages;
            }
            if (this.showErrorsInFormattedOutput.HasValue)
            {
                parameters.showErrorsInFormattedOutput = this.showErrorsInFormattedOutput;
            }

            parameters.expansion = ProcessExpandParameter();

            if (_autosize.HasValue)
            {
                parameters.autosize = _autosize.Value;
            }

            WideSpecificParameters wideSpecific = new WideSpecificParameters();

            parameters.shapeParameters = wideSpecific;
            if (_column.HasValue)
            {
                wideSpecific.columns = _column.Value;
            }

            return(parameters);
        }