private static ViewGenerator SelectViewGeneratorFromViewDefinition(
            TerminatingErrorContext errorContext,
            MshExpressionFactory expressionFactory,
            TypeInfoDataBase db,
            ViewDefinition view,
            FormattingCommandLineParameters parameters)
        {
            ViewGenerator viewGenerator = null;

            if (view.mainControl is TableControlBody)
            {
                viewGenerator = new TableViewGenerator();
            }
            else if (view.mainControl is ListControlBody)
            {
                viewGenerator = new ListViewGenerator();
            }
            else if (view.mainControl is WideControlBody)
            {
                viewGenerator = new WideViewGenerator();
            }
            else if (view.mainControl is ComplexControlBody)
            {
                viewGenerator = new ComplexViewGenerator();
            }

            Diagnostics.Assert(viewGenerator != null, "viewGenerator != null");
            viewGenerator.Initialize(errorContext, expressionFactory, db, view, parameters);
            return(viewGenerator);
        }
示例#2
0
        internal static FormatEntryData GenerateOutOfBandData(TerminatingErrorContext errorContext, PSPropertyExpressionFactory expressionFactory,
                                                              TypeInfoDataBase db, PSObject so, int enumerationLimit, bool useToStringFallback, out List <ErrorRecord> errors)
        {
            errors = null;

            var            typeNames = so.InternalTypeNames;
            ViewDefinition view      = DisplayDataQuery.GetOutOfBandView(expressionFactory, db, typeNames);

            ViewGenerator outOfBandViewGenerator;

            if (view != null)
            {
                // process an out of band view retrieved from the display database
                if (view.mainControl is ComplexControlBody)
                {
                    outOfBandViewGenerator = new ComplexViewGenerator();
                }
                else
                {
                    outOfBandViewGenerator = new ListViewGenerator();
                }

                outOfBandViewGenerator.Initialize(errorContext, expressionFactory, db, view, null);
            }
            else
            {
                if (DefaultScalarTypes.IsTypeInList(typeNames) ||
                    IsPropertyLessObject(so))
                {
                    // we force a ToString() on well known types
                    return(GenerateOutOfBandObjectAsToString(so));
                }

                if (!useToStringFallback)
                {
                    return(null);
                }

                // we must check we have enough properties for a list view
                if (new PSPropertyExpression("*").ResolveNames(so).Count <= 0)
                {
                    return(null);
                }

                // we do not have a view, we default to list view
                // process an out of band view as a default
                outOfBandViewGenerator = new ListViewGenerator();
                outOfBandViewGenerator.Initialize(errorContext, expressionFactory, so, db, null);
            }

            FormatEntryData fed = outOfBandViewGenerator.GeneratePayload(so, enumerationLimit);

            fed.outOfBand = true;
            fed.SetStreamTypeFromPSObject(so);

            errors = outOfBandViewGenerator.ErrorManager.DrainFailedResultList();

            return(fed);
        }
示例#3
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);
        }
示例#4
0
        internal static FormatEntryData GenerateOutOfBandData(TerminatingErrorContext errorContext, MshExpressionFactory expressionFactory, TypeInfoDataBase db, PSObject so, int enumerationLimit, bool useToStringFallback, out List <ErrorRecord> errors)
        {
            ViewGenerator generator;

            errors = null;
            ConsolidatedString internalTypeNames = so.InternalTypeNames;
            ViewDefinition     view = DisplayDataQuery.GetOutOfBandView(expressionFactory, db, internalTypeNames);

            if (view != null)
            {
                if (view.mainControl is ComplexControlBody)
                {
                    generator = new ComplexViewGenerator();
                }
                else
                {
                    generator = new ListViewGenerator();
                }
                generator.Initialize(errorContext, expressionFactory, db, view, null);
            }
            else
            {
                if (DefaultScalarTypes.IsTypeInList(internalTypeNames) || IsPropertyLessObject(so))
                {
                    return(GenerateOutOfBandObjectAsToString(so));
                }
                if (!useToStringFallback)
                {
                    return(null);
                }
                if (new MshExpression("*").ResolveNames(so).Count <= 0)
                {
                    return(null);
                }
                generator = new ListViewGenerator();
                generator.Initialize(errorContext, expressionFactory, so, db, null);
            }
            FormatEntryData data = generator.GeneratePayload(so, enumerationLimit);

            data.outOfBand = true;
            data.SetStreamTypeFromPSObject(so);
            errors = generator.ErrorManager.DrainFailedResultList();
            return(data);
        }
 internal static FormatEntryData GenerateOutOfBandData(TerminatingErrorContext errorContext, MshExpressionFactory expressionFactory, TypeInfoDataBase db, PSObject so, int enumerationLimit, bool useToStringFallback, out List<ErrorRecord> errors)
 {
     ViewGenerator generator;
     errors = null;
     ConsolidatedString internalTypeNames = so.InternalTypeNames;
     ViewDefinition view = DisplayDataQuery.GetOutOfBandView(expressionFactory, db, internalTypeNames);
     if (view != null)
     {
         if (view.mainControl is ComplexControlBody)
         {
             generator = new ComplexViewGenerator();
         }
         else
         {
             generator = new ListViewGenerator();
         }
         generator.Initialize(errorContext, expressionFactory, db, view, null);
     }
     else
     {
         if (DefaultScalarTypes.IsTypeInList(internalTypeNames) || IsPropertyLessObject(so))
         {
             return GenerateOutOfBandObjectAsToString(so);
         }
         if (!useToStringFallback)
         {
             return null;
         }
         if (new MshExpression("*").ResolveNames(so).Count <= 0)
         {
             return null;
         }
         generator = new ListViewGenerator();
         generator.Initialize(errorContext, expressionFactory, so, db, null);
     }
     FormatEntryData data = generator.GeneratePayload(so, enumerationLimit);
     data.outOfBand = true;
     data.SetStreamTypeFromPSObject(so);
     errors = generator.ErrorManager.DrainFailedResultList();
     return data;
 }
示例#6
0
 private static Microsoft.PowerShell.Commands.Internal.Format.ViewGenerator SelectViewGeneratorFromViewDefinition(TerminatingErrorContext errorContext, MshExpressionFactory expressionFactory, TypeInfoDataBase db, ViewDefinition view, FormattingCommandLineParameters parameters)
 {
     Microsoft.PowerShell.Commands.Internal.Format.ViewGenerator generator = null;
     if (view.mainControl is TableControlBody)
     {
         generator = new TableViewGenerator();
     }
     else if (view.mainControl is ListControlBody)
     {
         generator = new ListViewGenerator();
     }
     else if (view.mainControl is WideControlBody)
     {
         generator = new WideViewGenerator();
     }
     else if (view.mainControl is ComplexControlBody)
     {
         generator = new ComplexViewGenerator();
     }
     generator.Initialize(errorContext, expressionFactory, db, view, parameters);
     return(generator);
 }
示例#7
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);
 }
示例#8
0
        internal static FormatEntryData GenerateOutOfBandData(TerminatingErrorContext errorContext, MshExpressionFactory expressionFactory,
                    TypeInfoDataBase db, PSObject so, int enumerationLimit, bool useToStringFallback, out List<ErrorRecord> errors)
        {
            errors = null;

            var typeNames = so.InternalTypeNames;
            ViewDefinition view = DisplayDataQuery.GetOutOfBandView(expressionFactory, db, typeNames);

            ViewGenerator outOfBandViewGenerator;
            if (view != null)
            {
                // process an out of band view retrieved from the display database
                if (view.mainControl is ComplexControlBody)
                {
                    outOfBandViewGenerator = new ComplexViewGenerator();
                }
                else
                {
                    outOfBandViewGenerator = new ListViewGenerator();
                }
                outOfBandViewGenerator.Initialize(errorContext, expressionFactory, db, view, null);
            }
            else
            {
                if (DefaultScalarTypes.IsTypeInList(typeNames) ||
                    IsPropertyLessObject(so))
                {
                    // we force a ToString() on well known types
                    return GenerateOutOfBandObjectAsToString(so);
                }

                if (!useToStringFallback)
                {
                    return null;
                }

                // we must check we have enough properties for a list view
                if (new MshExpression("*").ResolveNames(so).Count <= 0)
                {
                    return null;
                }

                // we do not have a view, we default to list view
                // process an out of band view as a default
                outOfBandViewGenerator = new ListViewGenerator();
                outOfBandViewGenerator.Initialize(errorContext, expressionFactory, so, db, null);
            }

            FormatEntryData fed = outOfBandViewGenerator.GeneratePayload(so, enumerationLimit);
            fed.outOfBand = true;
            fed.SetStreamTypeFromPSObject(so);

            errors = outOfBandViewGenerator.ErrorManager.DrainFailedResultList();

            return fed;
        }
示例#9
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;
        }
示例#10
0
        private static ViewGenerator SelectViewGeneratorFromViewDefinition(
                                        TerminatingErrorContext errorContext,
                                        MshExpressionFactory expressionFactory,
                                        TypeInfoDataBase db,
                                        ViewDefinition view,
                                        FormattingCommandLineParameters parameters)
        {
            ViewGenerator viewGenerator = null;
            if (view.mainControl is TableControlBody)
            {
                viewGenerator = new TableViewGenerator();
            }
            else if (view.mainControl is ListControlBody)
            {
                viewGenerator = new ListViewGenerator();
            }
            else if (view.mainControl is WideControlBody)
            {
                viewGenerator = new WideViewGenerator();
            }
            else if (view.mainControl is ComplexControlBody)
            {
                viewGenerator = new ComplexViewGenerator();
            }

            Diagnostics.Assert(viewGenerator != null, "viewGenerator != null");
            viewGenerator.Initialize(errorContext, expressionFactory, db, view, parameters);
            return viewGenerator;
        }
示例#11
0
 private static Microsoft.PowerShell.Commands.Internal.Format.ViewGenerator SelectViewGeneratorFromViewDefinition(TerminatingErrorContext errorContext, MshExpressionFactory expressionFactory, TypeInfoDataBase db, ViewDefinition view, FormattingCommandLineParameters parameters)
 {
     Microsoft.PowerShell.Commands.Internal.Format.ViewGenerator generator = null;
     if (view.mainControl is TableControlBody)
     {
         generator = new TableViewGenerator();
     }
     else if (view.mainControl is ListControlBody)
     {
         generator = new ListViewGenerator();
     }
     else if (view.mainControl is WideControlBody)
     {
         generator = new WideViewGenerator();
     }
     else if (view.mainControl is ComplexControlBody)
     {
         generator = new ComplexViewGenerator();
     }
     generator.Initialize(errorContext, expressionFactory, db, view, parameters);
     return generator;
 }
示例#12
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;
 }