Exemplo n.º 1
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);
        }
Exemplo n.º 2
0
 /// <summary>
 /// Prepares a given view for remote object processing ie., lets the view
 /// display (or not) ComputerName property. This will query the object to 
 /// check if ComputerName property is present. If present, this will prepare
 /// the view.
 /// </summary>
 /// <param name="viewGenerator"></param>
 /// <param name="so"></param>
 private static void PrepareViewForRemoteObjects(ViewGenerator viewGenerator, PSObject so)
 {
     if (PSObjectHelper.ShouldShowComputerNameProperty(so))
     {
         viewGenerator.PrepareForRemoteObjects(so);
     }
 }