Exemple #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);
            }
        }
Exemple #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);
                }
            }
        }
Exemple #3
0
        // 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
        }
Exemple #4
0
        public void T()
        {
            if (content is byte[] bytes)
            {
                SetRequestContent(request, bytes);
            }

            try
            {
                a = b.GetValue(c);
            }
            catch (Exception e)
            {
                if (e is System.TimeoutException)
                {
                    throw;
                }

                if (e is AccessViolationException || e is StackOverflowException)
                {
                    throw;
                }
            }

            Debug.Assert(a is Run, "test");

            ParameterProcessor processor = cmdlet is SortObjectCommand ?
                                           new ParameterProcessor(new SortObjectExpressionParameterDefinition()) :
                                           new ParameterProcessor(new GroupObjectExpressionParameterDefinition());
        }
Exemple #5
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));
        }
Exemple #6
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);
        }
Exemple #7
0
        private static ParameterProcessor GetProcessorFor(Type type)
        {
            Assert.IsNotNull(type);

            ParameterProcessor ret = null;

            if (!Processors.TryGetValue(type, out ret))
            {
                int subClassDepth = int.MaxValue;
                foreach (var typeProcPair in Processors)
                {
                    Type handledType             = typeProcPair.Key;
                    ParameterProcessor processor = typeProcPair.Value;

                    if (type.IsSubclassOf(handledType))
                    {
                        Type baseType = type;
                        for (int i = 0; i < subClassDepth; i++, baseType = baseType.BaseType)
                        {
                            if (baseType == handledType)
                            {
                                subClassDepth = i;
                                ret           = processor;
                                break;
                            }
                        }
                    }
                }
            }

            if (!ret)
            {
                // special cases
                if (type.IsEnum)
                {
                    ret = EnumProcessor;
                }
                else if (type.IsInterface)
                {
                    ret = ComponentProcessor;
                }
                else
                {
                    ret = DefaultProcessor;
                }
            }

            Assert.IsNotNull(ret);
            return(ret);
        }
        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);
            }
        }
Exemple #9
0
        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);
        }
Exemple #10
0
        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);
                        }
                    }
                }
            }
        }
        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);
        }
Exemple #12
0
        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);
        }