コード例 #1
0
        internal static void ThrowParameterBindingException(TerminatingErrorContext invocationContext, string errorId, string msg)
        {
            ErrorRecord errorRecord = new ErrorRecord(new NotSupportedException(), errorId, ErrorCategory.InvalidArgument, null)
            {
                ErrorDetails = new ErrorDetails(msg)
            };

            invocationContext.ThrowTerminatingError(errorRecord);
        }
コード例 #2
0
        /// <summary>
        /// Helper method to process Unknown error message.
        /// It helps is creating appropriate error message to
        /// be displayed to the user.
        /// </summary>
        /// <param name="errorContext">Error context.</param>
        /// <param name="viewName">Uses supplied view name.</param>
        /// <param name="so">Source object.</param>
        /// <param name="db">Types info database.</param>
        /// <param name="formatShape">Requested format shape.</param>
        private static void ProcessUnknownViewName(TerminatingErrorContext errorContext, string viewName, PSObject so, TypeInfoDataBase db, FormatShape formatShape)
        {
            string        msg              = null;
            bool          foundValidViews  = false;
            string        formatTypeName   = null;
            string        separator        = ", ";
            StringBuilder validViewFormats = new StringBuilder();

            if (so != null && so.BaseObject != null &&
                db != null && db.viewDefinitionsSection != null &&
                db.viewDefinitionsSection.viewDefinitionList != null &&
                db.viewDefinitionsSection.viewDefinitionList.Count > 0)
            {
                StringBuilder validViews            = new StringBuilder();
                string        currentObjectTypeName = so.BaseObject.GetType().ToString();

                Type formatType = null;
                if (formatShape == FormatShape.Table)
                {
                    formatType     = typeof(TableControlBody);
                    formatTypeName = "Table";
                }
                else if (formatShape == FormatShape.List)
                {
                    formatType     = typeof(ListControlBody);
                    formatTypeName = "List";
                }
                else if (formatShape == FormatShape.Wide)
                {
                    formatType     = typeof(WideControlBody);
                    formatTypeName = "Wide";
                }
                else if (formatShape == FormatShape.Complex)
                {
                    formatType     = typeof(ComplexControlBody);
                    formatTypeName = "Custom";
                }

                if (formatType != null)
                {
                    foreach (ViewDefinition currentViewDefinition in db.viewDefinitionsSection.viewDefinitionList)
                    {
                        if (currentViewDefinition.mainControl != null)
                        {
                            foreach (TypeOrGroupReference currentTypeOrGroupReference in currentViewDefinition.appliesTo.referenceList)
                            {
                                if (!string.IsNullOrEmpty(currentTypeOrGroupReference.name) &&
                                    String.Equals(currentObjectTypeName, currentTypeOrGroupReference.name, StringComparison.OrdinalIgnoreCase))
                                {
                                    if (currentViewDefinition.mainControl.GetType() == formatType)
                                    {
                                        validViews.Append(currentViewDefinition.name);
                                        validViews.Append(separator);
                                    }
                                    else if (String.Equals(viewName, currentViewDefinition.name, StringComparison.OrdinalIgnoreCase))
                                    {
                                        string cmdletFormatName = null;
                                        if (currentViewDefinition.mainControl is TableControlBody)
                                        {
                                            cmdletFormatName = "Format-Table";
                                        }
                                        else if (currentViewDefinition.mainControl is ListControlBody)
                                        {
                                            cmdletFormatName = "Format-List";
                                        }
                                        else if (currentViewDefinition.mainControl is WideControlBody)
                                        {
                                            cmdletFormatName = "Format-Wide";
                                        }
                                        else if (currentViewDefinition.mainControl is ComplexControlBody)
                                        {
                                            cmdletFormatName = "Format-Custom";
                                        }

                                        if (validViewFormats.Length == 0)
                                        {
                                            string suggestValidViewNamePrefix = StringUtil.Format(FormatAndOut_format_xxx.SuggestValidViewNamePrefix);
                                            validViewFormats.Append(suggestValidViewNamePrefix);
                                        }
                                        else
                                        {
                                            validViewFormats.Append(", ");
                                        }

                                        validViewFormats.Append(cmdletFormatName);
                                    }
                                }
                            }
                        }
                    }
                }

                if (validViews.Length > 0)
                {
                    validViews.Remove(validViews.Length - separator.Length, separator.Length);
                    msg             = StringUtil.Format(FormatAndOut_format_xxx.InvalidViewNameError, viewName, formatTypeName, validViews.ToString());
                    foundValidViews = true;
                }
            }

            if (!foundValidViews)
            {
                StringBuilder unKnowViewFormatStringBuilder = new StringBuilder();
                if (validViewFormats.Length > 0)
                {
                    //unKnowViewFormatStringBuilder.Append(StringUtil.Format(FormatAndOut_format_xxx.UnknownViewNameError, viewName));
                    unKnowViewFormatStringBuilder.Append(StringUtil.Format(FormatAndOut_format_xxx.UnknownViewNameErrorSuffix, viewName, formatTypeName));
                    unKnowViewFormatStringBuilder.Append(validViewFormats.ToString());
                }
                else
                {
                    unKnowViewFormatStringBuilder.Append(StringUtil.Format(FormatAndOut_format_xxx.UnknownViewNameError, viewName));
                    unKnowViewFormatStringBuilder.Append(StringUtil.Format(FormatAndOut_format_xxx.NonExistingViewNameError, formatTypeName, so.BaseObject.GetType()));
                }

                msg = unKnowViewFormatStringBuilder.ToString();;
            }

            ErrorRecord errorRecord = new ErrorRecord(
                new PipelineStoppedException(),
                "FormatViewNotFound",
                ErrorCategory.ObjectNotFound,
                viewName);

            errorRecord.ErrorDetails = new ErrorDetails(msg);
            errorContext.ThrowTerminatingError(errorRecord);
        }
コード例 #3
0
ファイル: FormatViewManager.cs プロジェクト: 40a/PowerShell
        /// <summary>
        /// Helper method to process Unknown error message.
        /// It helps is creating appropriate error message to 
        /// be displayed to the user.
        /// </summary>
        /// <param name="errorContext">Error context.</param>
        /// <param name="viewName">Uses supplied view name.</param>
        /// <param name="so">Source object.</param>
        /// <param name="db">Types info database.</param>
        /// <param name="formatShape">Requested format shape.</param>
        private static void ProcessUnknownViewName(TerminatingErrorContext errorContext, string viewName, PSObject so, TypeInfoDataBase db, FormatShape formatShape)
        {
            string msg = null;
            bool foundValidViews = false;
            string formatTypeName = null;
            string separator = ", ";
            StringBuilder validViewFormats = new StringBuilder();

            if (so != null && so.BaseObject != null &&
                db != null && db.viewDefinitionsSection != null &&
                db.viewDefinitionsSection.viewDefinitionList != null &&
                db.viewDefinitionsSection.viewDefinitionList.Count > 0)
            {
                StringBuilder validViews = new StringBuilder();
                string currentObjectTypeName = so.BaseObject.GetType().ToString();

                Type formatType = null;
                if (formatShape == FormatShape.Table)
                {
                    formatType = typeof(TableControlBody);
                    formatTypeName = "Table";
                }
                else if (formatShape == FormatShape.List)
                {
                    formatType = typeof(ListControlBody);
                    formatTypeName = "List";
                }
                else if (formatShape == FormatShape.Wide)
                {
                    formatType = typeof(WideControlBody);
                    formatTypeName = "Wide";
                }
                else if (formatShape == FormatShape.Complex)
                {
                    formatType = typeof(ComplexControlBody);
                    formatTypeName = "Custom";
                }

                if (formatType != null)
                {
                    foreach (ViewDefinition currentViewDefinition in db.viewDefinitionsSection.viewDefinitionList)
                    {
                        if (currentViewDefinition.mainControl != null)
                        {
                            foreach (TypeOrGroupReference currentTypeOrGroupReference in currentViewDefinition.appliesTo.referenceList)
                            {
                                if (!string.IsNullOrEmpty(currentTypeOrGroupReference.name) &&
                                    String.Equals(currentObjectTypeName, currentTypeOrGroupReference.name, StringComparison.OrdinalIgnoreCase))
                                {
                                    if (currentViewDefinition.mainControl.GetType() == formatType)
                                    {
                                        validViews.Append(currentViewDefinition.name);
                                        validViews.Append(separator);
                                    }
                                    else if (String.Equals(viewName, currentViewDefinition.name, StringComparison.OrdinalIgnoreCase))
                                    {
                                        string cmdletFormatName = null;
                                        if (currentViewDefinition.mainControl is TableControlBody)
                                        {
                                            cmdletFormatName = "Format-Table";
                                        }
                                        else if (currentViewDefinition.mainControl is ListControlBody)
                                        {
                                            cmdletFormatName = "Format-List";
                                        }
                                        else if (currentViewDefinition.mainControl is WideControlBody)
                                        {
                                            cmdletFormatName = "Format-Wide";
                                        }
                                        else if (currentViewDefinition.mainControl is ComplexControlBody)
                                        {
                                            cmdletFormatName = "Format-Custom";
                                        }

                                        if (validViewFormats.Length == 0)
                                        {
                                            string suggestValidViewNamePrefix = StringUtil.Format(FormatAndOut_format_xxx.SuggestValidViewNamePrefix);
                                            validViewFormats.Append(suggestValidViewNamePrefix);
                                        }
                                        else
                                        {
                                            validViewFormats.Append(", ");
                                        }

                                        validViewFormats.Append(cmdletFormatName);
                                    }
                                }
                            }
                        }
                    }
                }

                if (validViews.Length > 0)
                {
                    validViews.Remove(validViews.Length - separator.Length, separator.Length);
                    msg = StringUtil.Format(FormatAndOut_format_xxx.InvalidViewNameError, viewName, formatTypeName, validViews.ToString());
                    foundValidViews = true;
                }
            }

            if (!foundValidViews)
            {
                StringBuilder unKnowViewFormatStringBuilder = new StringBuilder();
                if (validViewFormats.Length > 0)
                {
                    //unKnowViewFormatStringBuilder.Append(StringUtil.Format(FormatAndOut_format_xxx.UnknownViewNameError, viewName));
                    unKnowViewFormatStringBuilder.Append(StringUtil.Format(FormatAndOut_format_xxx.UnknownViewNameErrorSuffix, viewName, formatTypeName));
                    unKnowViewFormatStringBuilder.Append(validViewFormats.ToString());
                }
                else
                {
                    unKnowViewFormatStringBuilder.Append(StringUtil.Format(FormatAndOut_format_xxx.UnknownViewNameError, viewName));
                    unKnowViewFormatStringBuilder.Append(StringUtil.Format(FormatAndOut_format_xxx.NonExistingViewNameError, formatTypeName, so.BaseObject.GetType()));
                }

                msg = unKnowViewFormatStringBuilder.ToString(); ;
            }

            ErrorRecord errorRecord = new ErrorRecord(
                                            new PipelineStoppedException(),
                                            "FormatViewNotFound",
                                            ErrorCategory.ObjectNotFound,
                                            viewName);

            errorRecord.ErrorDetails = new ErrorDetails(msg);
            errorContext.ThrowTerminatingError(errorRecord);
        }
コード例 #4
0
ファイル: MshParameter.cs プロジェクト: 40a/PowerShell
        internal static void ThrowParameterBindingException(TerminatingErrorContext invocationContext,
                                                            string errorId,
                                                            string msg)
        {
            ErrorRecord errorRecord = new ErrorRecord(
                                new NotSupportedException(),
                                errorId,
                                ErrorCategory.InvalidArgument,
                                null);

            errorRecord.ErrorDetails = new ErrorDetails(msg);
            invocationContext.ThrowTerminatingError(errorRecord);
        }
コード例 #5
0
        private static void ProcessUnknownViewName(TerminatingErrorContext errorContext, string viewName, PSObject so, TypeInfoDataBase db, FormatShape formatShape)
        {
            string        message = null;
            bool          flag    = false;
            string        str2    = null;
            string        str3    = ", ";
            StringBuilder builder = new StringBuilder();

            if ((((so != null) && (so.BaseObject != null)) && ((db != null) && (db.viewDefinitionsSection != null))) && ((db.viewDefinitionsSection.viewDefinitionList != null) && (db.viewDefinitionsSection.viewDefinitionList.Count > 0)))
            {
                StringBuilder builder2 = new StringBuilder();
                string        a        = so.BaseObject.GetType().ToString();
                Type          type     = null;
                if (formatShape == FormatShape.Table)
                {
                    type = typeof(TableControlBody);
                    str2 = "Table";
                }
                else if (formatShape == FormatShape.List)
                {
                    type = typeof(ListControlBody);
                    str2 = "List";
                }
                else if (formatShape == FormatShape.Wide)
                {
                    type = typeof(WideControlBody);
                    str2 = "Wide";
                }
                else if (formatShape == FormatShape.Complex)
                {
                    type = typeof(ComplexControlBody);
                    str2 = "Custom";
                }
                if (type != null)
                {
                    foreach (ViewDefinition definition in db.viewDefinitionsSection.viewDefinitionList)
                    {
                        if (definition.mainControl != null)
                        {
                            foreach (TypeOrGroupReference reference in definition.appliesTo.referenceList)
                            {
                                if (!string.IsNullOrEmpty(reference.name) && string.Equals(a, reference.name, StringComparison.OrdinalIgnoreCase))
                                {
                                    if (definition.mainControl.GetType() == type)
                                    {
                                        builder2.Append(definition.name);
                                        builder2.Append(str3);
                                    }
                                    else if (string.Equals(viewName, definition.name, StringComparison.OrdinalIgnoreCase))
                                    {
                                        string str5 = null;
                                        if (definition.mainControl.GetType() == typeof(TableControlBody))
                                        {
                                            str5 = "Format-Table";
                                        }
                                        else if (definition.mainControl.GetType() == typeof(ListControlBody))
                                        {
                                            str5 = "Format-List";
                                        }
                                        else if (definition.mainControl.GetType() == typeof(WideControlBody))
                                        {
                                            str5 = "Format-Wide";
                                        }
                                        else if (definition.mainControl.GetType() == typeof(ComplexControlBody))
                                        {
                                            str5 = "Format-Custom";
                                        }
                                        if (builder.Length == 0)
                                        {
                                            string str6 = StringUtil.Format(FormatAndOut_format_xxx.SuggestValidViewNamePrefix, new object[0]);
                                            builder.Append(str6);
                                        }
                                        else
                                        {
                                            builder.Append(", ");
                                        }
                                        builder.Append(str5);
                                    }
                                }
                            }
                        }
                    }
                }
                if (builder2.Length > 0)
                {
                    builder2.Remove(builder2.Length - str3.Length, str3.Length);
                    message = StringUtil.Format(FormatAndOut_format_xxx.InvalidViewNameError, new object[] { viewName, str2, builder2.ToString() });
                    flag    = true;
                }
            }
            if (!flag)
            {
                StringBuilder builder3 = new StringBuilder();
                if (builder.Length > 0)
                {
                    builder3.Append(StringUtil.Format(FormatAndOut_format_xxx.UnknownViewNameErrorSuffix, viewName, str2));
                    builder3.Append(builder.ToString());
                }
                else
                {
                    builder3.Append(StringUtil.Format(FormatAndOut_format_xxx.UnknownViewNameError, viewName));
                    builder3.Append(StringUtil.Format(FormatAndOut_format_xxx.NonExistingViewNameError, str2, so.BaseObject.GetType()));
                }
                message = builder3.ToString();
            }
            ErrorRecord errorRecord = new ErrorRecord(new PipelineStoppedException(), "FormatViewNotFound", ErrorCategory.ObjectNotFound, viewName)
            {
                ErrorDetails = new ErrorDetails(message)
            };

            errorContext.ThrowTerminatingError(errorRecord);
        }
コード例 #6
0
ファイル: FormatViewManager.cs プロジェクト: nickchal/pash
 private static void ProcessUnknownViewName(TerminatingErrorContext errorContext, string viewName, PSObject so, TypeInfoDataBase db, FormatShape formatShape)
 {
     string message = null;
     bool flag = false;
     string str2 = null;
     string str3 = ", ";
     StringBuilder builder = new StringBuilder();
     if ((((so != null) && (so.BaseObject != null)) && ((db != null) && (db.viewDefinitionsSection != null))) && ((db.viewDefinitionsSection.viewDefinitionList != null) && (db.viewDefinitionsSection.viewDefinitionList.Count > 0)))
     {
         StringBuilder builder2 = new StringBuilder();
         string a = so.BaseObject.GetType().ToString();
         Type type = null;
         if (formatShape == FormatShape.Table)
         {
             type = typeof(TableControlBody);
             str2 = "Table";
         }
         else if (formatShape == FormatShape.List)
         {
             type = typeof(ListControlBody);
             str2 = "List";
         }
         else if (formatShape == FormatShape.Wide)
         {
             type = typeof(WideControlBody);
             str2 = "Wide";
         }
         else if (formatShape == FormatShape.Complex)
         {
             type = typeof(ComplexControlBody);
             str2 = "Custom";
         }
         if (type != null)
         {
             foreach (ViewDefinition definition in db.viewDefinitionsSection.viewDefinitionList)
             {
                 if (definition.mainControl != null)
                 {
                     foreach (TypeOrGroupReference reference in definition.appliesTo.referenceList)
                     {
                         if (!string.IsNullOrEmpty(reference.name) && string.Equals(a, reference.name, StringComparison.OrdinalIgnoreCase))
                         {
                             if (definition.mainControl.GetType() == type)
                             {
                                 builder2.Append(definition.name);
                                 builder2.Append(str3);
                             }
                             else if (string.Equals(viewName, definition.name, StringComparison.OrdinalIgnoreCase))
                             {
                                 string str5 = null;
                                 if (definition.mainControl.GetType() == typeof(TableControlBody))
                                 {
                                     str5 = "Format-Table";
                                 }
                                 else if (definition.mainControl.GetType() == typeof(ListControlBody))
                                 {
                                     str5 = "Format-List";
                                 }
                                 else if (definition.mainControl.GetType() == typeof(WideControlBody))
                                 {
                                     str5 = "Format-Wide";
                                 }
                                 else if (definition.mainControl.GetType() == typeof(ComplexControlBody))
                                 {
                                     str5 = "Format-Custom";
                                 }
                                 if (builder.Length == 0)
                                 {
                                     string str6 = StringUtil.Format(FormatAndOut_format_xxx.SuggestValidViewNamePrefix, new object[0]);
                                     builder.Append(str6);
                                 }
                                 else
                                 {
                                     builder.Append(", ");
                                 }
                                 builder.Append(str5);
                             }
                         }
                     }
                 }
             }
         }
         if (builder2.Length > 0)
         {
             builder2.Remove(builder2.Length - str3.Length, str3.Length);
             message = StringUtil.Format(FormatAndOut_format_xxx.InvalidViewNameError, new object[] { viewName, str2, builder2.ToString() });
             flag = true;
         }
     }
     if (!flag)
     {
         StringBuilder builder3 = new StringBuilder();
         if (builder.Length > 0)
         {
             builder3.Append(StringUtil.Format(FormatAndOut_format_xxx.UnknownViewNameErrorSuffix, viewName, str2));
             builder3.Append(builder.ToString());
         }
         else
         {
             builder3.Append(StringUtil.Format(FormatAndOut_format_xxx.UnknownViewNameError, viewName));
             builder3.Append(StringUtil.Format(FormatAndOut_format_xxx.NonExistingViewNameError, str2, so.BaseObject.GetType()));
         }
         message = builder3.ToString();
     }
     ErrorRecord errorRecord = new ErrorRecord(new PipelineStoppedException(), "FormatViewNotFound", ErrorCategory.ObjectNotFound, viewName) {
         ErrorDetails = new ErrorDetails(message)
     };
     errorContext.ThrowTerminatingError(errorRecord);
 }