internal static ViewDefinition GetViewByShapeAndType(PSPropertyExpressionFactory expressionFactory, TypeInfoDataBase db,
                                                      FormatShape shape, Collection <string> typeNames, string viewName)
 {
     if (shape == FormatShape.Undefined)
     {
         return(GetDefaultView(expressionFactory, db, typeNames));
     }
     // map the FormatShape to a type derived from ViewDefinition
     System.Type t = null;
     if (shape == FormatShape.Table)
     {
         t = typeof(TableControlBody);
     }
     else if (shape == FormatShape.List)
     {
         t = typeof(ListControlBody);
     }
     else if (shape == FormatShape.Wide)
     {
         t = typeof(WideControlBody);
     }
     else if (shape == FormatShape.Complex)
     {
         t = typeof(ComplexControlBody);
     }
     else
     {
         Diagnostics.Assert(false, "unknown shape: this should never happen unless a new shape is added");
         return(null);
     }
     return(GetView(expressionFactory, db, t, typeNames, viewName));
 }
Beispiel #2
0
 internal ErrorFormatEntryData(FormatShape shape, string message, string categoryInfo, string errorId)
     : base(shape)
 {
     Message = message;
     CategoryInfo = categoryInfo;
     FullyQualifiedErrorId = errorId;
 }
Beispiel #3
0
 internal ErrorFormatEntryData(FormatShape shape, string message, string categoryInfo, string errorId)
     : base(shape)
 {
     Message               = message;
     CategoryInfo          = categoryInfo;
     FullyQualifiedErrorId = errorId;
 }
        internal static ViewDefinition GetViewByShapeAndType(
            MshExpressionFactory expressionFactory,
            TypeInfoDataBase db,
            FormatShape shape,
            Collection <string> typeNames,
            string viewName)
        {
            if (shape == FormatShape.Undefined)
            {
                return(DisplayDataQuery.GetDefaultView(expressionFactory, db, typeNames));
            }
            Type mainControlType;

            if (shape == FormatShape.Table)
            {
                mainControlType = typeof(TableControlBody);
            }
            else if (shape == FormatShape.List)
            {
                mainControlType = typeof(ListControlBody);
            }
            else if (shape == FormatShape.Wide)
            {
                mainControlType = typeof(WideControlBody);
            }
            else
            {
                if (shape != FormatShape.Complex)
                {
                    return((ViewDefinition)null);
                }
                mainControlType = typeof(ComplexControlBody);
            }
            return(DisplayDataQuery.GetView(expressionFactory, db, mainControlType, typeNames, viewName));
        }
        internal static FormatShape GetShapeFromType(PSPropertyExpressionFactory expressionFactory, TypeInfoDataBase db, Collection <string> typeNames)
        {
            ShapeSelectionDirectives shapeDirectives = db.defaultSettingsSection.shapeSelectionDirectives;

            TypeMatch match = new TypeMatch(expressionFactory, db, typeNames);

            foreach (FormatShapeSelectionOnType shapeSelOnType in shapeDirectives.formatShapeSelectionOnTypeList)
            {
                if (match.PerfectMatch(new TypeMatchItem(shapeSelOnType, shapeSelOnType.appliesTo)))
                {
                    return(shapeSelOnType.formatShape);
                }
            }
            if (match.BestMatch != null)
            {
                return(((FormatShapeSelectionOnType)(match.BestMatch)).formatShape);
            }
            else
            {
                Collection <string> typesWithoutPrefix = Deserializer.MaskDeserializationPrefix(typeNames);
                if (typesWithoutPrefix != null)
                {
                    FormatShape result = GetShapeFromType(expressionFactory, db, typesWithoutPrefix);
                    return(result);
                }

                // return a default value if no matches were found
                return(FormatShape.Undefined);
            }
        }
Beispiel #6
0
        private static ViewGenerator SelectViewGeneratorFromProperties(FormatShape shape, PSObject so,
                                                                       TerminatingErrorContext errorContext,
                                                                       PSPropertyExpressionFactory expressionFactory,
                                                                       TypeInfoDataBase db,
                                                                       FormattingCommandLineParameters parameters)
        {
            // use some heuristics to determine the shape if none is specified
            if (shape == FormatShape.Undefined && parameters == null)
            {
                // check first if we have a known shape for a type
                var typeNames = so.InternalTypeNames;
                shape = DisplayDataQuery.GetShapeFromType(expressionFactory, db, typeNames);

                if (shape == FormatShape.Undefined)
                {
                    // check if we can have a table:
                    // we want to get the # of properties we are going to display
                    List <PSPropertyExpression> expressionList = PSObjectHelper.GetDefaultPropertySet(so);
                    if (expressionList.Count == 0)
                    {
                        // we failed to get anything from a property set
                        // we just get the first properties out of the first object
                        foreach (MshResolvedExpressionParameterAssociation mrepa in AssociationManager.ExpandAll(so))
                        {
                            expressionList.Add(mrepa.ResolvedExpression);
                        }
                    }

                    // decide what shape we want for the given number of properties
                    shape = DisplayDataQuery.GetShapeFromPropertyCount(db, expressionList.Count);
                }
            }

            ViewGenerator viewGenerator = null;

            if (shape == FormatShape.Table)
            {
                viewGenerator = new TableViewGenerator();
            }
            else if (shape == FormatShape.List)
            {
                viewGenerator = new ListViewGenerator();
            }
            else if (shape == FormatShape.Wide)
            {
                viewGenerator = new WideViewGenerator();
            }
            else if (shape == FormatShape.Complex)
            {
                viewGenerator = new ComplexViewGenerator();
            }

            Diagnostics.Assert(viewGenerator != null, "viewGenerator != null");

            viewGenerator.Initialize(errorContext, expressionFactory, so, db, parameters);
            return(viewGenerator);
        }
Beispiel #7
0
        public Collection<FormatData> Process(PSObject psobj)
        {
            var formatData = new Collection<FormatData>();
            if (psobj.BaseObject is FormatData)
            {
                formatData.Add((FormatData)psobj.BaseObject);
                return formatData;
            }
            if (_generator == null)
            {
                if (Shape.Equals(FormatShape.Undefined))
                {
                    Shape = FormatShapeHelper.SelectByData(psobj);
                }
                _generator = FormatGenerator.Get(_executionContext, Shape, Options);
            }
            // check if we have a simple type or an error type. if yes, then we don't need a document structure
            if (psobj.BaseObject == null || psobj.BaseObject.GetType().IsSimple())
            {
                formatData.Add(_generator.GenerateSimpleFormatEntry(psobj));
                return formatData;
            }
            if (psobj.BaseObject is ErrorRecord || psobj.BaseObject is Exception)
            {
                formatData.Add(_generator.GenerateErrorFormatEntry(psobj));
                return formatData;
            }

            // object to be printed get a complete document structure
            if (_state.Equals(FormattingState.FormatEnd))
            {
                formatData.Add(_generator.GenerateFormatStart());
                _state = FormattingState.FormatStart;
            }
            if (_state.Equals(FormattingState.GroupStart) && ShouldChangeGroup(psobj))
            {
                formatData.Add(_generator.GenerateGroupEnd());
                _state = FormattingState.GroupEnd;
            }
            if (_state.Equals(FormattingState.GroupEnd) || _state.Equals(FormattingState.FormatStart))
            {
                formatData.Add(_generator.GenerateGroupStart(psobj));
                _state = FormattingState.GroupStart;
            }
            // we have to be in the state GroupStart where we can write the data itself
            formatData.Add(_generator.GenerateObjectFormatEntry(psobj));
            return formatData;
        }
Beispiel #8
0
 public static FormatGenerator Get(ExecutionContext context, FormatShape shape, FormatGeneratorOptions options)
 {
     if (_lastGenerator != null && _lastGenerator.Shape.Equals(shape) && _lastGenerator.Options.Equals(options))
     {
         return _lastGenerator;
     }
     switch (shape)
     {
         case FormatShape.List:
             _lastGenerator = new ListFormatGenerator(context, options);
             break;
         case FormatShape.Table:
             _lastGenerator = new TableFormatGenerator(context, options);
             break;
         default:
             throw new PSInvalidOperationException("Cannot get a FormatGenerator with undefined shape");
     }
     return _lastGenerator;
 }
Beispiel #9
0
 public static FormatProcessor Get(OutputWriter outputWriter, FormatShape shape)
 {
     // we use cached instances as the instance is able then to continue old output
     if (_lastProcessor != null && _lastProcessor.Shape.Equals(shape) &&
         _lastProcessor.OutputWriter.Equals(outputWriter))
     {
         return _lastProcessor;
     }
     switch (shape)
     {
         case FormatShape.List:
             _lastProcessor = new ListFormatProcessor(outputWriter);
             break;
         case FormatShape.Table:
             _lastProcessor = new TableFormatProcessor(outputWriter);
             break;
         default:
             throw new PSInvalidOperationException("Cannot get FormatProcessor for undefined shape");
     }
     return _lastProcessor;
 }
Beispiel #10
0
        public static FormatGenerator Get(ExecutionContext context, FormatShape shape, FormatGeneratorOptions options)
        {
            if (_lastGenerator != null && _lastGenerator.Shape.Equals(shape) && _lastGenerator.Options.Equals(options))
            {
                return(_lastGenerator);
            }
            switch (shape)
            {
            case FormatShape.List:
                _lastGenerator = new ListFormatGenerator(context, options);
                break;

            case FormatShape.Table:
                _lastGenerator = new TableFormatGenerator(context, options);
                break;

            default:
                throw new PSInvalidOperationException("Cannot get a FormatGenerator with undefined shape");
            }
            return(_lastGenerator);
        }
Beispiel #11
0
        public static FormatProcessor Get(OutputWriter outputWriter, FormatShape shape)
        {
            // we use cached instances as the instance is able then to continue old output
            if (_lastProcessor != null && _lastProcessor.Shape.Equals(shape) &&
                _lastProcessor.OutputWriter.Equals(outputWriter))
            {
                return(_lastProcessor);
            }
            switch (shape)
            {
            case FormatShape.List:
                _lastProcessor = new ListFormatProcessor(outputWriter);
                break;

            case FormatShape.Table:
                _lastProcessor = new TableFormatProcessor(outputWriter);
                break;

            default:
                throw new PSInvalidOperationException("Cannot get FormatProcessor for undefined shape");
            }
            return(_lastProcessor);
        }
Beispiel #12
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);
        }
Beispiel #13
0
        internal void Initialize(TerminatingErrorContext errorContext, MshExpressionFactory expressionFactory, TypeInfoDataBase db, PSObject so, FormatShape shape, FormattingCommandLineParameters parameters)
        {
            ViewDefinition view = null;

            try
            {
                DisplayDataQuery.SetTracer(formatViewBindingTracer);
                ConsolidatedString internalTypeNames = so.InternalTypeNames;
                if (shape == FormatShape.Undefined)
                {
                    using (formatViewBindingTracer.TraceScope("FINDING VIEW  TYPE: {0}", new object[] { PSObjectTypeName(so) }))
                    {
                        view = DisplayDataQuery.GetViewByShapeAndType(expressionFactory, db, shape, internalTypeNames, null);
                    }
                    if (view != null)
                    {
                        this.viewGenerator = SelectViewGeneratorFromViewDefinition(errorContext, expressionFactory, db, view, parameters);
                        formatViewBindingTracer.WriteLine("An applicable view has been found", new object[0]);
                        PrepareViewForRemoteObjects(this.ViewGenerator, so);
                    }
                    else
                    {
                        formatViewBindingTracer.WriteLine("No applicable view has been found", new object[0]);
                        this.viewGenerator = SelectViewGeneratorFromProperties(shape, so, errorContext, expressionFactory, db, null);
                        PrepareViewForRemoteObjects(this.ViewGenerator, so);
                    }
                }
                else if ((parameters != null) && (parameters.mshParameterList.Count > 0))
                {
                    this.viewGenerator = SelectViewGeneratorFromProperties(shape, so, errorContext, expressionFactory, db, parameters);
                }
                else
                {
                    if ((parameters != null) && !string.IsNullOrEmpty(parameters.viewName))
                    {
                        using (formatViewBindingTracer.TraceScope("FINDING VIEW NAME: {0}  TYPE: {1}", new object[] { parameters.viewName, PSObjectTypeName(so) }))
                        {
                            view = DisplayDataQuery.GetViewByShapeAndType(expressionFactory, db, shape, internalTypeNames, parameters.viewName);
                        }
                        if (view != null)
                        {
                            this.viewGenerator = SelectViewGeneratorFromViewDefinition(errorContext, expressionFactory, db, view, parameters);
                            formatViewBindingTracer.WriteLine("An applicable view has been found", new object[0]);
                            return;
                        }
                        formatViewBindingTracer.WriteLine("No applicable view has been found", new object[0]);
                        ProcessUnknownViewName(errorContext, parameters.viewName, so, db, shape);
                    }
                    using (formatViewBindingTracer.TraceScope("FINDING VIEW {0} TYPE: {1}", new object[] { shape, PSObjectTypeName(so) }))
                    {
                        view = DisplayDataQuery.GetViewByShapeAndType(expressionFactory, db, shape, internalTypeNames, null);
                    }
                    if (view != null)
                    {
                        this.viewGenerator = SelectViewGeneratorFromViewDefinition(errorContext, expressionFactory, db, view, parameters);
                        formatViewBindingTracer.WriteLine("An applicable view has been found", new object[0]);
                        PrepareViewForRemoteObjects(this.ViewGenerator, so);
                    }
                    else
                    {
                        formatViewBindingTracer.WriteLine("No applicable view has been found", new object[0]);
                        this.viewGenerator = SelectViewGeneratorFromProperties(shape, so, errorContext, expressionFactory, db, parameters);
                        PrepareViewForRemoteObjects(this.ViewGenerator, so);
                    }
                }
            }
            finally
            {
                DisplayDataQuery.ResetTracer();
            }
        }
Beispiel #14
0
 private static Microsoft.PowerShell.Commands.Internal.Format.ViewGenerator SelectViewGeneratorFromProperties(FormatShape shape, PSObject so, TerminatingErrorContext errorContext, MshExpressionFactory expressionFactory, TypeInfoDataBase db, FormattingCommandLineParameters parameters)
 {
     if ((shape == FormatShape.Undefined) && (parameters == null))
     {
         ConsolidatedString internalTypeNames = so.InternalTypeNames;
         shape = DisplayDataQuery.GetShapeFromType(expressionFactory, db, internalTypeNames);
         if (shape == FormatShape.Undefined)
         {
             List <MshExpression> defaultPropertySet = PSObjectHelper.GetDefaultPropertySet(so);
             if (defaultPropertySet.Count == 0)
             {
                 foreach (MshResolvedExpressionParameterAssociation association in AssociationManager.ExpandAll(so))
                 {
                     defaultPropertySet.Add(association.ResolvedExpression);
                 }
             }
             shape = DisplayDataQuery.GetShapeFromPropertyCount(db, defaultPropertySet.Count);
         }
     }
     Microsoft.PowerShell.Commands.Internal.Format.ViewGenerator generator = null;
     if (shape == FormatShape.Table)
     {
         generator = new TableViewGenerator();
     }
     else if (shape == FormatShape.List)
     {
         generator = new ListViewGenerator();
     }
     else if (shape == FormatShape.Wide)
     {
         generator = new WideViewGenerator();
     }
     else if (shape == FormatShape.Complex)
     {
         generator = new ComplexViewGenerator();
     }
     generator.Initialize(errorContext, expressionFactory, so, db, parameters);
     return(generator);
 }
Beispiel #15
0
 internal SimpleFormatEntryData(FormatShape shape, string value) : base(shape)
 {
     Value = value;
 }
Beispiel #16
0
 private static Microsoft.PowerShell.Commands.Internal.Format.ViewGenerator SelectViewGeneratorFromProperties(FormatShape shape, PSObject so, TerminatingErrorContext errorContext, MshExpressionFactory expressionFactory, TypeInfoDataBase db, FormattingCommandLineParameters parameters)
 {
     if ((shape == FormatShape.Undefined) && (parameters == null))
     {
         ConsolidatedString internalTypeNames = so.InternalTypeNames;
         shape = DisplayDataQuery.GetShapeFromType(expressionFactory, db, internalTypeNames);
         if (shape == FormatShape.Undefined)
         {
             List<MshExpression> defaultPropertySet = PSObjectHelper.GetDefaultPropertySet(so);
             if (defaultPropertySet.Count == 0)
             {
                 foreach (MshResolvedExpressionParameterAssociation association in AssociationManager.ExpandAll(so))
                 {
                     defaultPropertySet.Add(association.ResolvedExpression);
                 }
             }
             shape = DisplayDataQuery.GetShapeFromPropertyCount(db, defaultPropertySet.Count);
         }
     }
     Microsoft.PowerShell.Commands.Internal.Format.ViewGenerator generator = null;
     if (shape == FormatShape.Table)
     {
         generator = new TableViewGenerator();
     }
     else if (shape == FormatShape.List)
     {
         generator = new ListViewGenerator();
     }
     else if (shape == FormatShape.Wide)
     {
         generator = new WideViewGenerator();
     }
     else if (shape == FormatShape.Complex)
     {
         generator = new ComplexViewGenerator();
     }
     generator.Initialize(errorContext, expressionFactory, so, db, parameters);
     return generator;
 }
Beispiel #17
0
 internal static ViewDefinition GetViewByShapeAndType(MshExpressionFactory expressionFactory, TypeInfoDataBase db,
         FormatShape shape, Collection<string> typeNames, string viewName)
 {
     if (shape == FormatShape.Undefined)
     {
         return GetDefaultView(expressionFactory, db, typeNames);
     }
     // map the FormatShape to a type derived from ViewDefinition
     System.Type t = null;
     if (shape == FormatShape.Table)
     {
         t = typeof(TableControlBody);
     }
     else if (shape == FormatShape.List)
     {
         t = typeof(ListControlBody);
     }
     else if (shape == FormatShape.Wide)
     {
         t = typeof(WideControlBody);
     }
     else if (shape == FormatShape.Complex)
     {
         t = typeof(ComplexControlBody);
     }
     else
     {
         Diagnostics.Assert(false, "unknonw shape: this should never happen unless a new shape is added");
         return null;
     }
     return GetView(expressionFactory, db, t, typeNames, viewName);
 }
Beispiel #18
0
 /// <summary>
 /// constructor to glue to the CRO
 /// </summary>
 internal InnerFormatShapeCommand(FormatShape shape)
 {
     _shape = shape;
 }
Beispiel #19
0
        private static ViewGenerator SelectViewGeneratorFromProperties(FormatShape shape, PSObject so,
                                    TerminatingErrorContext errorContext,
                                    MshExpressionFactory expressionFactory,
                                    TypeInfoDataBase db,
                                    FormattingCommandLineParameters parameters)
        {
            // use some heuristics to determine the shape if none is specified
            if (shape == FormatShape.Undefined && parameters == null)
            {
                // check first if we have a known shape for a type
                var typeNames = so.InternalTypeNames;
                shape = DisplayDataQuery.GetShapeFromType(expressionFactory, db, typeNames);

                if (shape == FormatShape.Undefined)
                {
                    // check if we can have a table:
                    // we want to get the # of properties we are going to display
                    List<MshExpression> expressionList = PSObjectHelper.GetDefaultPropertySet(so);
                    if (expressionList.Count == 0)
                    {
                        // we failed to get anything from a property set
                        // we just get the first properties out of the first object
                        foreach (MshResolvedExpressionParameterAssociation mrepa in AssociationManager.ExpandAll(so))
                        {
                            expressionList.Add(mrepa.ResolvedExpression);
                        }
                    }

                    // decide what shape we want for the given number of properties
                    shape = DisplayDataQuery.GetShapeFromPropertyCount(db, expressionList.Count);
                }
            }

            ViewGenerator viewGenerator = null;
            if (shape == FormatShape.Table)
            {
                viewGenerator = new TableViewGenerator();
            }
            else if (shape == FormatShape.List)
            {
                viewGenerator = new ListViewGenerator();
            }
            else if (shape == FormatShape.Wide)
            {
                viewGenerator = new WideViewGenerator();
            }
            else if (shape == FormatShape.Complex)
            {
                viewGenerator = new ComplexViewGenerator();
            }
            Diagnostics.Assert(viewGenerator != null, "viewGenerator != null");

            viewGenerator.Initialize(errorContext, expressionFactory, so, db, parameters);
            return viewGenerator;
        }
Beispiel #20
0
 internal GroupEndData(FormatShape shape) : base(shape)
 {
 }
 internal FormatShapeCommandBase(FormatShape shape) : base(shape)
 {
 }
Beispiel #22
0
 internal FormatManager(FormatShape shape, ExecutionContext context)
 {
     Shape   = shape;
     Options = new FormatGeneratorOptions();
     _state  = FormattingState.FormatEnd;
 }
Beispiel #23
0
 internal FormatStartData(FormatShape shape) : base(shape)
 {
 }
Beispiel #24
0
 internal static ViewDefinition GetViewByShapeAndType(MshExpressionFactory expressionFactory, TypeInfoDataBase db, FormatShape shape, Collection<string> typeNames, string viewName)
 {
     if (shape == FormatShape.Undefined)
     {
         return GetDefaultView(expressionFactory, db, typeNames);
     }
     Type mainControlType = null;
     if (shape == FormatShape.Table)
     {
         mainControlType = typeof(TableControlBody);
     }
     else if (shape == FormatShape.List)
     {
         mainControlType = typeof(ListControlBody);
     }
     else if (shape == FormatShape.Wide)
     {
         mainControlType = typeof(WideControlBody);
     }
     else if (shape == FormatShape.Complex)
     {
         mainControlType = typeof(ComplexControlBody);
     }
     else
     {
         return null;
     }
     return GetView(expressionFactory, db, mainControlType, typeNames, viewName);
 }
Beispiel #25
0
 internal FormatCommandBase(FormatShape shape)
 {
     FormatManager = new FormatManager(shape, ExecutionContext);
 }
Beispiel #26
0
 protected FormatGenerator(ExecutionContext context, FormatShape shape, FormatGeneratorOptions options)
 {
     Options = options;
     Shape = shape;
     ExecutionContext = context;
 }
        internal void Initialize(TerminatingErrorContext errorContext,
                                 MshExpressionFactory expressionFactory,
                                 TypeInfoDataBase db,
                                 PSObject so,
                                 FormatShape shape,
                                 FormattingCommandLineParameters parameters)
        {
            ViewDefinition view              = null;
            const string   findViewType      = "FINDING VIEW TYPE: {0}";
            const string   findViewShapeType = "FINDING VIEW {0} TYPE: {1}";
            const string   findViewNameType  = "FINDING VIEW NAME: {0} TYPE: {1}";
            const string   viewFound         = "An applicable view has been found";
            const string   viewNotFound      = "No applicable view has been found";

            try
            {
                DisplayDataQuery.SetTracer(s_formatViewBindingTracer);

                // shape not specified: we need to select one
                var typeNames = so.InternalTypeNames;
                if (shape == FormatShape.Undefined)
                {
                    using (s_formatViewBindingTracer.TraceScope(findViewType, PSObjectTypeName(so)))
                    {
                        view = DisplayDataQuery.GetViewByShapeAndType(expressionFactory, db, shape, typeNames, null);
                    }
                    if (view != null)
                    {
                        // we got a matching view from the database
                        // use this and we are done
                        _viewGenerator = SelectViewGeneratorFromViewDefinition(
                            errorContext,
                            expressionFactory,
                            db,
                            view,
                            parameters);
                        s_formatViewBindingTracer.WriteLine(viewFound);
                        PrepareViewForRemoteObjects(ViewGenerator, so);
                        return;
                    }

                    s_formatViewBindingTracer.WriteLine(viewNotFound);
                    // we did not get any default view (and shape), we need to force one
                    // we just select properties out of the object itself, since they were not
                    // specified on the command line
                    _viewGenerator = SelectViewGeneratorFromProperties(shape, so, errorContext, expressionFactory, db, null);
                    PrepareViewForRemoteObjects(ViewGenerator, so);

                    return;
                }

                // we have a predefined shape: did the user specify properties on the command line?
                if (parameters != null && parameters.mshParameterList.Count > 0)
                {
                    _viewGenerator = SelectViewGeneratorFromProperties(shape, so, errorContext, expressionFactory, db, parameters);
                    return;
                }

                // predefined shape: did the user specify the name of a view?
                if (parameters != null && !string.IsNullOrEmpty(parameters.viewName))
                {
                    using (s_formatViewBindingTracer.TraceScope(findViewNameType, parameters.viewName,
                                                                PSObjectTypeName(so)))
                    {
                        view = DisplayDataQuery.GetViewByShapeAndType(expressionFactory, db, shape, typeNames, parameters.viewName);
                    }
                    if (view != null)
                    {
                        _viewGenerator = SelectViewGeneratorFromViewDefinition(
                            errorContext,
                            expressionFactory,
                            db,
                            view,
                            parameters);
                        s_formatViewBindingTracer.WriteLine(viewFound);
                        return;
                    }
                    s_formatViewBindingTracer.WriteLine(viewNotFound);
                    // illegal input, we have to terminate
                    ProcessUnknownViewName(errorContext, parameters.viewName, so, db, shape);
                }

                // predefined shape: do we have a default view in format.ps1xml?
                using (s_formatViewBindingTracer.TraceScope(findViewShapeType, shape, PSObjectTypeName(so)))
                {
                    view = DisplayDataQuery.GetViewByShapeAndType(expressionFactory, db, shape, typeNames, null);
                }
                if (view != null)
                {
                    _viewGenerator = SelectViewGeneratorFromViewDefinition(
                        errorContext,
                        expressionFactory,
                        db,
                        view,
                        parameters);
                    s_formatViewBindingTracer.WriteLine(viewFound);
                    PrepareViewForRemoteObjects(ViewGenerator, so);

                    return;
                }
                s_formatViewBindingTracer.WriteLine(viewNotFound);
                // we just select properties out of the object itself
                _viewGenerator = SelectViewGeneratorFromProperties(shape, so, errorContext, expressionFactory, db, parameters);
                PrepareViewForRemoteObjects(ViewGenerator, so);
            }
            finally
            {
                DisplayDataQuery.ResetTracer();
            }
        }
Beispiel #28
0
 internal GroupStartData(FormatShape shape) : base(shape)
 {
 }
Beispiel #29
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);
 }
Beispiel #30
0
 internal FormatShapeCommandBase(FormatShape shape) : base(shape)
 {
 }
Beispiel #31
0
 internal GroupStartData(FormatShape shape) : base(shape)
 {
 }
Beispiel #32
0
 internal FormatManager(FormatShape shape, ExecutionContext context)
 {
     Shape = shape;
     Options = new FormatGeneratorOptions();
     _state = FormattingState.FormatEnd;
 }
Beispiel #33
0
 internal FormatCommandBase(FormatShape shape)
 {
     FormatManager = new FormatManager(shape, ExecutionContext);
 }
Beispiel #34
0
 internal FormatEntryData(FormatShape shape) : base(shape)
 {
 }
Beispiel #35
0
 internal SimpleFormatEntryData(FormatShape shape, string value) : base(shape)
 {
     Value = value;
 }
Beispiel #36
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);
        }
Beispiel #37
0
 protected FormatProcessor(FormatShape shape, OutputWriter outputWriter)
 {
     Shape = shape;
     OutputWriter = outputWriter;
     _state = FormattingState.FormatEnd;
 }
Beispiel #38
0
        internal void Initialize(TerminatingErrorContext errorContext,
                                    MshExpressionFactory expressionFactory,
                                    TypeInfoDataBase db,
                                    PSObject so,
                                    FormatShape shape,
                                    FormattingCommandLineParameters parameters)
        {
            ViewDefinition view = null;
            const string findViewType = "FINDING VIEW  TYPE: {0}";
            const string findViewShapeType = "FINDING VIEW {0} TYPE: {1}";
            const string findViewNameType = "FINDING VIEW NAME: {0}  TYPE: {1}";
            const string viewFound = "An applicable view has been found";
            const string viewNotFound = "No applicable view has been found";
            try
            {
                DisplayDataQuery.SetTracer(s_formatViewBindingTracer);

                // shape not specified: we need to select one
                var typeNames = so.InternalTypeNames;
                if (shape == FormatShape.Undefined)
                {
                    using (s_formatViewBindingTracer.TraceScope(findViewType, PSObjectTypeName(so)))
                    {
                        view = DisplayDataQuery.GetViewByShapeAndType(expressionFactory, db, shape, typeNames, null);
                    }
                    if (view != null)
                    {
                        // we got a matching view from the database
                        // use this and we are done
                        _viewGenerator = SelectViewGeneratorFromViewDefinition(
                                                errorContext,
                                                expressionFactory,
                                                db,
                                                view,
                                                parameters);
                        s_formatViewBindingTracer.WriteLine(viewFound);
                        PrepareViewForRemoteObjects(ViewGenerator, so);
                        return;
                    }

                    s_formatViewBindingTracer.WriteLine(viewNotFound);
                    // we did not get any default view (and shape), we need to force one
                    // we just select properties out of the object itself, since they were not
                    // specified on the command line
                    _viewGenerator = SelectViewGeneratorFromProperties(shape, so, errorContext, expressionFactory, db, null);
                    PrepareViewForRemoteObjects(ViewGenerator, so);

                    return;
                }

                // we have a predefined shape: did the user specify properties on the command line?
                if (parameters != null && parameters.mshParameterList.Count > 0)
                {
                    _viewGenerator = SelectViewGeneratorFromProperties(shape, so, errorContext, expressionFactory, db, parameters);
                    return;
                }

                // predefined shape: did the user specify the name of a view?
                if (parameters != null && !string.IsNullOrEmpty(parameters.viewName))
                {
                    using (s_formatViewBindingTracer.TraceScope(findViewNameType, parameters.viewName,
                        PSObjectTypeName(so)))
                    {
                        view = DisplayDataQuery.GetViewByShapeAndType(expressionFactory, db, shape, typeNames, parameters.viewName);
                    }
                    if (view != null)
                    {
                        _viewGenerator = SelectViewGeneratorFromViewDefinition(
                                                    errorContext,
                                                    expressionFactory,
                                                    db,
                                                    view,
                                                    parameters);
                        s_formatViewBindingTracer.WriteLine(viewFound);
                        return;
                    }
                    s_formatViewBindingTracer.WriteLine(viewNotFound);
                    // illegal input, we have to terminate
                    ProcessUnknownViewName(errorContext, parameters.viewName, so, db, shape);
                }

                // predefined shape: do we have a default view in format.ps1xml?
                using (s_formatViewBindingTracer.TraceScope(findViewShapeType, shape, PSObjectTypeName(so)))
                {
                    view = DisplayDataQuery.GetViewByShapeAndType(expressionFactory, db, shape, typeNames, null);
                }
                if (view != null)
                {
                    _viewGenerator = SelectViewGeneratorFromViewDefinition(
                                                errorContext,
                                                expressionFactory,
                                                db,
                                                view,
                                                parameters);
                    s_formatViewBindingTracer.WriteLine(viewFound);
                    PrepareViewForRemoteObjects(ViewGenerator, so);

                    return;
                }
                s_formatViewBindingTracer.WriteLine(viewNotFound);
                // we just select properties out of the object itself
                _viewGenerator = SelectViewGeneratorFromProperties(shape, so, errorContext, expressionFactory, db, parameters);
                PrepareViewForRemoteObjects(ViewGenerator, so);
            }
            finally
            {
                DisplayDataQuery.ResetTracer();
            }
        }
Beispiel #39
0
 internal FormatData(FormatShape shape)
 {
     Shape = shape;
 }
        /// <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);
        }
Beispiel #41
0
 internal FormatEntryData(FormatShape shape) : base(shape)
 {
 }
Beispiel #42
0
 protected FormatProcessor(FormatShape shape, OutputWriter outputWriter)
 {
     Shape        = shape;
     OutputWriter = outputWriter;
     _state       = FormattingState.FormatEnd;
 }
Beispiel #43
0
 internal FormatData(FormatShape shape)
 {
     Shape = shape;
 }
Beispiel #44
0
 protected FormatGenerator(ExecutionContext context, FormatShape shape, FormatGeneratorOptions options)
 {
     Options          = options;
     Shape            = shape;
     ExecutionContext = context;
 }
Beispiel #45
0
 internal FormatStartData(FormatShape shape) : base(shape)
 {
 }
 /// <summary>
 /// constructor to glue to the CRO
 /// </summary>
 internal InnerFormatShapeCommand(FormatShape shape)
 {
     _shape = shape;
 }
Beispiel #47
0
 internal void Initialize(TerminatingErrorContext errorContext, MshExpressionFactory expressionFactory, TypeInfoDataBase db, PSObject so, FormatShape shape, FormattingCommandLineParameters parameters)
 {
     ViewDefinition view = null;
     try
     {
         DisplayDataQuery.SetTracer(formatViewBindingTracer);
         ConsolidatedString internalTypeNames = so.InternalTypeNames;
         if (shape == FormatShape.Undefined)
         {
             using (formatViewBindingTracer.TraceScope("FINDING VIEW  TYPE: {0}", new object[] { PSObjectTypeName(so) }))
             {
                 view = DisplayDataQuery.GetViewByShapeAndType(expressionFactory, db, shape, internalTypeNames, null);
             }
             if (view != null)
             {
                 this.viewGenerator = SelectViewGeneratorFromViewDefinition(errorContext, expressionFactory, db, view, parameters);
                 formatViewBindingTracer.WriteLine("An applicable view has been found", new object[0]);
                 PrepareViewForRemoteObjects(this.ViewGenerator, so);
             }
             else
             {
                 formatViewBindingTracer.WriteLine("No applicable view has been found", new object[0]);
                 this.viewGenerator = SelectViewGeneratorFromProperties(shape, so, errorContext, expressionFactory, db, null);
                 PrepareViewForRemoteObjects(this.ViewGenerator, so);
             }
         }
         else if ((parameters != null) && (parameters.mshParameterList.Count > 0))
         {
             this.viewGenerator = SelectViewGeneratorFromProperties(shape, so, errorContext, expressionFactory, db, parameters);
         }
         else
         {
             if ((parameters != null) && !string.IsNullOrEmpty(parameters.viewName))
             {
                 using (formatViewBindingTracer.TraceScope("FINDING VIEW NAME: {0}  TYPE: {1}", new object[] { parameters.viewName, PSObjectTypeName(so) }))
                 {
                     view = DisplayDataQuery.GetViewByShapeAndType(expressionFactory, db, shape, internalTypeNames, parameters.viewName);
                 }
                 if (view != null)
                 {
                     this.viewGenerator = SelectViewGeneratorFromViewDefinition(errorContext, expressionFactory, db, view, parameters);
                     formatViewBindingTracer.WriteLine("An applicable view has been found", new object[0]);
                     return;
                 }
                 formatViewBindingTracer.WriteLine("No applicable view has been found", new object[0]);
                 ProcessUnknownViewName(errorContext, parameters.viewName, so, db, shape);
             }
             using (formatViewBindingTracer.TraceScope("FINDING VIEW {0} TYPE: {1}", new object[] { shape, PSObjectTypeName(so) }))
             {
                 view = DisplayDataQuery.GetViewByShapeAndType(expressionFactory, db, shape, internalTypeNames, null);
             }
             if (view != null)
             {
                 this.viewGenerator = SelectViewGeneratorFromViewDefinition(errorContext, expressionFactory, db, view, parameters);
                 formatViewBindingTracer.WriteLine("An applicable view has been found", new object[0]);
                 PrepareViewForRemoteObjects(this.ViewGenerator, so);
             }
             else
             {
                 formatViewBindingTracer.WriteLine("No applicable view has been found", new object[0]);
                 this.viewGenerator = SelectViewGeneratorFromProperties(shape, so, errorContext, expressionFactory, db, parameters);
                 PrepareViewForRemoteObjects(this.ViewGenerator, so);
             }
         }
     }
     finally
     {
         DisplayDataQuery.ResetTracer();
     }
 }