Пример #1
0
 internal void GetCommandLineProperties(FormattingCommandLineParameters parameters, bool isTable)
 {
     if (this.props != null)
     {
         CommandParameterDefinition definition;
         if (isTable)
         {
             definition = new FormatTableParameterDefinition();
         }
         else
         {
             definition = new FormatListParameterDefinition();
         }
         ParameterProcessor processor = new ParameterProcessor(definition);
         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;
     }
 }
Пример #2
0
        private static void ProcessIllegalKey(TerminatingErrorContext invocationContext,
                                              string keyName)
        {
            string msg = StringUtil.Format(FormatAndOut_MshParameter.IllegalKeyError, keyName);

            ParameterProcessor.ThrowParameterBindingException(invocationContext, "DictionaryKeyIllegal", msg);
        }
        internal void GetCommandLineProperties(FormattingCommandLineParameters parameters, bool isTable)
        {
            if (Property != null)
            {
                CommandParameterDefinition def;

                if (isTable)
                {
                    def = new FormatTableParameterDefinition();
                }
                else
                {
                    def = new FormatListParameterDefinition();
                }
                ParameterProcessor      processor         = new ParameterProcessor(def);
                TerminatingErrorContext invocationContext = new TerminatingErrorContext(this);

                parameters.mshParameterList = processor.ProcessParameters(Property, invocationContext);
            }

            if (!string.IsNullOrEmpty(this.View))
            {
                // we have a view command line switch
                if (parameters.mshParameterList.Count != 0)
                {
                    ReportCannotSpecifyViewAndProperty();
                }
                parameters.viewName = this.View;
            }
        }
Пример #4
0
        private static void ProcessDuplicateHashTableKey(TerminatingErrorContext invocationContext, string duplicateKey, string existingKey)
        {
            string msg = StringUtil.Format(FormatAndOut_MshParameter.DuplicateKeyError,
                                           duplicateKey, existingKey);

            ParameterProcessor.ThrowParameterBindingException(invocationContext, "DictionaryKeyDuplicate", msg);
        }
Пример #5
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;
 }
Пример #6
0
        private static void ProcessIllegalHashTableKeyValue(TerminatingErrorContext invocationContext, string key, Type actualType, Type[] allowedTypes)
        {
            string msg;
            string errorID;

            if (allowedTypes.Length > 1)
            {
                string legalTypes = CatenateTypeArray(allowedTypes);

                msg = StringUtil.Format(FormatAndOut_MshParameter.IllegalTypeMultiError,
                                        key,
                                        actualType.FullName,
                                        legalTypes
                                        );

                errorID = "DictionaryKeyIllegalValue1";
            }
            else
            {
                msg = StringUtil.Format(FormatAndOut_MshParameter.IllegalTypeSingleError,
                                        key,
                                        actualType.FullName,
                                        allowedTypes[0]
                                        );

                errorID = "DictionaryKeyIllegalValue2";
            }

            ParameterProcessor.ThrowParameterBindingException(invocationContext, errorID, msg);
        }
Пример #7
0
        internal override object Verify(object val,
                                        TerminatingErrorContext invocationContext,
                                        bool originalParameterWasHashTable)
        {
            if (!originalParameterWasHashTable)
            {
                // this should never happen
                throw PSTraceSource.NewInvalidOperationException();
            }

            string s = val as string;

            if (string.IsNullOrEmpty(s))
            {
                string msg = StringUtil.Format(FormatAndOut_MshParameter.EmptyFormatStringValueError,
                                               this.KeyName
                                               );

                ParameterProcessor.ThrowParameterBindingException(invocationContext, "FormatStringEmpty", msg);
            }

            // we expect a string and we build a field formatting directive
            FieldFormattingDirective directive = new FieldFormattingDirective();

            directive.formatString = s;
            return(directive);
        }
Пример #8
0
 private void VerifyRange(int width, TerminatingErrorContext invocationContext)
 {
     if (width <= 0)
     {
         string msg = StringUtil.Format(FormatAndOut_MshParameter.OutOfRangeWidthValueError, width, base.KeyName);
         ParameterProcessor.ThrowParameterBindingException(invocationContext, "WidthOutOfRange", msg);
     }
 }
Пример #9
0
        private void ProcessIllegalValue(string s, TerminatingErrorContext invocationContext)
        {
            string msg = StringUtil.Format(FormatAndOut_MshParameter.IllegalAlignmentValueError,
                                           s,
                                           this.KeyName,
                                           ParameterProcessor.CatenateStringArray(s_legalValues)
                                           );

            ParameterProcessor.ThrowParameterBindingException(invocationContext, "AlignmentIllegalValue", msg);
        }
Пример #10
0
        private static void ProcessAmbiguousKey(TerminatingErrorContext invocationContext,
                                                string keyName,
                                                HashtableEntryDefinition matchingEntry,
                                                HashtableEntryDefinition currentEntry)
        {
            string msg = StringUtil.Format(FormatAndOut_MshParameter.AmbiguousKeyError,
                                           keyName, matchingEntry.KeyName, currentEntry.KeyName);

            ParameterProcessor.ThrowParameterBindingException(invocationContext, "DictionaryKeyAmbiguous", msg);
        }
 internal MshParameter ProcessGroupByParameter()
 {
     if (this.groupByParameter != null)
     {
         TerminatingErrorContext invocationContext = new TerminatingErrorContext(this);
         List<MshParameter> list = new ParameterProcessor(new FormatGroupByParameterDefinition()).ProcessParameters(new object[] { this.groupByParameter }, invocationContext);
         if (list.Count != 0)
         {
             return list[0];
         }
     }
     return null;
 }
Пример #12
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;
 }
Пример #13
0
        private static void ProcessUnknownParameterType(TerminatingErrorContext invocationContext, object actualObject, Type[] allowedTypes)
        {
            string allowedTypesList = CatenateTypeArray(allowedTypes);
            string msg;

            if (actualObject != null)
            {
                msg = StringUtil.Format(FormatAndOut_MshParameter.UnknownParameterTypeError,
                                        actualObject.GetType().FullName, allowedTypesList);
            }
            else
            {
                msg = StringUtil.Format(FormatAndOut_MshParameter.NullParameterTypeError,
                                        allowedTypesList);
            }
            ParameterProcessor.ThrowParameterBindingException(invocationContext, "DictionaryKeyUnknownType", msg);
        }
Пример #14
0
        private void ProcessGlobbingCharactersError(bool originalParameterWasHashTable, string expression, TerminatingErrorContext invocationContext)
        {
            string str;
            string str2;

            if (originalParameterWasHashTable)
            {
                str  = StringUtil.Format(FormatAndOut_MshParameter.MshExGlobbingHashError, base.KeyName, expression);
                str2 = "ExpressionGlobbing1";
            }
            else
            {
                str  = StringUtil.Format(FormatAndOut_MshParameter.MshExGlobbingStringError, expression);
                str2 = "ExpressionGlobbing2";
            }
            ParameterProcessor.ThrowParameterBindingException(invocationContext, str2, str);
        }
Пример #15
0
        private void ProcessEmptyStringError(bool originalParameterWasHashTable, TerminatingErrorContext invocationContext)
        {
            string str;
            string str2;

            if (originalParameterWasHashTable)
            {
                str  = StringUtil.Format(FormatAndOut_MshParameter.MshExEmptyStringHashError, base.KeyName);
                str2 = "ExpressionEmptyString1";
            }
            else
            {
                str  = StringUtil.Format(FormatAndOut_MshParameter.MshExEmptyStringError, new object[0]);
                str2 = "ExpressionEmptyString2";
            }
            ParameterProcessor.ThrowParameterBindingException(invocationContext, str2, str);
        }
Пример #16
0
        internal override object Verify(object val, TerminatingErrorContext invocationContext, bool originalParameterWasHashTable)
        {
            if (!originalParameterWasHashTable)
            {
                throw PSTraceSource.NewInvalidOperationException();
            }
            string str = val as string;

            if (string.IsNullOrEmpty(str))
            {
                string msg = StringUtil.Format(FormatAndOut_MshParameter.EmptyFormatStringValueError, base.KeyName);
                ParameterProcessor.ThrowParameterBindingException(invocationContext, "FormatStringEmpty", msg);
            }
            return(new FieldFormattingDirective {
                formatString = str
            });
        }
Пример #17
0
        internal MshParameter ProcessGroupByParameter()
        {
            if (GroupBy != null)
            {
                TerminatingErrorContext invocationContext =
                    new TerminatingErrorContext(this);
                ParameterProcessor  processor          = new ParameterProcessor(new FormatGroupByParameterDefinition());
                List <MshParameter> groupParameterList =
                    processor.ProcessParameters(new object[] { GroupBy },
                                                invocationContext);

                if (groupParameterList.Count != 0)
                {
                    return(groupParameterList[0]);
                }
            }

            return(null);
        }
Пример #18
0
        private void ProcessGlobbingCharactersError(bool originalParameterWasHashTable, string expression, TerminatingErrorContext invocationContext)
        {
            string msg;
            string errorID;

            if (originalParameterWasHashTable)
            {
                msg = StringUtil.Format(FormatAndOut_MshParameter.MshExGlobbingHashError,
                                        this.KeyName, expression);
                errorID = "ExpressionGlobbing1";
            }
            else
            {
                msg = StringUtil.Format(FormatAndOut_MshParameter.MshExGlobbingStringError,
                                        expression);
                errorID = "ExpressionGlobbing2";
            }

            ParameterProcessor.ThrowParameterBindingException(invocationContext, errorID, msg);
        }
Пример #19
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;
        }
Пример #20
0
        private static void ProcessMissingMandatoryKey(TerminatingErrorContext invocationContext, string keyName)
        {
            string msg = StringUtil.Format(FormatAndOut_MshParameter.MissingKeyMandatoryEntryError, keyName);

            ParameterProcessor.ThrowParameterBindingException(invocationContext, "DictionaryKeyMandatoryEntry", msg);
        }
Пример #21
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);
 }
Пример #22
0
        private static void ProcessNonStringHashTableKey(TerminatingErrorContext invocationContext, object key)
        {
            string msg = StringUtil.Format(FormatAndOut_MshParameter.DictionaryKeyNonStringError, key.GetType().Name);

            ParameterProcessor.ThrowParameterBindingException(invocationContext, "DictionaryKeyNonString", msg);
        }
Пример #23
0
        private static void ProcessNullHashTableKey(TerminatingErrorContext invocationContext)
        {
            string msg = StringUtil.Format(FormatAndOut_MshParameter.DictionaryKeyNullError);

            ParameterProcessor.ThrowParameterBindingException(invocationContext, "DictionaryKeyNull", msg);
        }
Пример #24
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;
        }
Пример #25
0
        internal MshParameter ProcessGroupByParameter()
        {
            if (GroupBy != null)
            {
                TerminatingErrorContext invocationContext =
                        new TerminatingErrorContext(this);
                ParameterProcessor processor = new ParameterProcessor(new FormatGroupByParameterDefinition());
                List<MshParameter> groupParameterList =
                    processor.ProcessParameters(new object[] { GroupBy },
                                                invocationContext);

                if (groupParameterList.Count != 0)
                    return groupParameterList[0];
            }

            return null;
        }
Пример #26
0
        internal void GetCommandLineProperties(FormattingCommandLineParameters parameters, bool isTable)
        {
            if (Property != null)
            {
                CommandParameterDefinition def;

                if (isTable)
                    def = new FormatTableParameterDefinition();
                else
                    def = new FormatListParameterDefinition();
                ParameterProcessor processor = new ParameterProcessor(def);
                TerminatingErrorContext invocationContext = new TerminatingErrorContext(this);

                parameters.mshParameterList = processor.ProcessParameters(Property, invocationContext);
            }

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