/// <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);
     }
 }
示例#2
0
 private static void PrepareViewForRemoteObjects(Microsoft.PowerShell.Commands.Internal.Format.ViewGenerator viewGenerator, PSObject so)
 {
     if (PSObjectHelper.ShouldShowComputerNameProperty(so))
     {
         viewGenerator.PrepareForRemoteObjects(so);
     }
 }
        internal static List <MshResolvedExpressionParameterAssociation> SetupActiveProperties(List <MshParameter> rawMshParameterList,
                                                                                               PSObject target, MshExpressionFactory expressionFactory)
        {
            // check if we received properties from the command line
            if (rawMshParameterList != null && rawMshParameterList.Count > 0)
            {
                return(AssociationManager.ExpandParameters(rawMshParameterList, target));
            }

            // we did not get any properties:
            //try to get properties from the default property set of the object
            List <MshResolvedExpressionParameterAssociation> activeAssociationList = AssociationManager.ExpandDefaultPropertySet(target, expressionFactory);

            if (activeAssociationList.Count > 0)
            {
                // we got a valid set of properties from the default property set..add computername for
                // remoteobjects (if available)
                if (PSObjectHelper.ShouldShowComputerNameProperty(target))
                {
                    activeAssociationList.Add(new MshResolvedExpressionParameterAssociation(null,
                                                                                            new MshExpression(RemotingConstants.ComputerNameNoteProperty)));
                }

                return(activeAssociationList);
            }

            // we failed to get anything from the default property set
            // just get all the properties
            activeAssociationList = AssociationManager.ExpandAll(target);
            // Remove PSComputerName and PSShowComputerName from the display as needed.
            AssociationManager.HandleComputerNameProperties(target, activeAssociationList);

            return(activeAssociationList);
        }
        internal override void Initialize(TerminatingErrorContext errorContext, PSPropertyExpressionFactory expressionFactory,
                                          PSObject so, TypeInfoDataBase db,
                                          FormattingCommandLineParameters parameters)
        {
            base.Initialize(errorContext, expressionFactory, so, db, parameters);

            if ((this.dataBaseInfo != null) && (this.dataBaseInfo.view != null))
            {
                _tableBody = (TableControlBody)this.dataBaseInfo.view.mainControl;
            }

            List <MshParameter> rawMshParameterList = null;

            if (parameters != null)
            {
                rawMshParameterList = parameters.mshParameterList;
            }

            // check if we received properties from the command line
            if (rawMshParameterList != null && rawMshParameterList.Count > 0)
            {
                this.activeAssociationList = AssociationManager.ExpandTableParameters(rawMshParameterList, so);
                return;
            }

            // we did not get any properties:
            // try to get properties from the default property set of the object
            this.activeAssociationList = AssociationManager.ExpandDefaultPropertySet(so, this.expressionFactory);
            if (this.activeAssociationList.Count > 0)
            {
                // we got a valid set of properties from the default property set..add computername for
                // remoteobjects (if available)
                if (PSObjectHelper.ShouldShowComputerNameProperty(so))
                {
                    activeAssociationList.Add(new MshResolvedExpressionParameterAssociation(null,
                                                                                            new PSPropertyExpression(RemotingConstants.ComputerNameNoteProperty)));
                }

                return;
            }

            // we failed to get anything from the default property set
            this.activeAssociationList = AssociationManager.ExpandAll(so);
            if (this.activeAssociationList.Count > 0)
            {
                // Remove PSComputerName and PSShowComputerName from the display as needed.
                AssociationManager.HandleComputerNameProperties(so, activeAssociationList);
                FilterActiveAssociationList();
                return;
            }

            // we were unable to retrieve any properties, so we leave an empty list
            this.activeAssociationList = new List <MshResolvedExpressionParameterAssociation>();
        }
        /// <summary>
        /// Helper method to handle PSComputerName and PSShowComputerName properties from
        /// the formating objects. If PSShowComputerName exists and is false, removes
        /// PSComputerName from the display.
        ///
        /// PSShowComputerName is an internal property..so this property is always
        /// removed from the display.
        /// </summary>
        /// <param name="so"></param>
        /// <param name="activeAssociationList"></param>
        internal static void HandleComputerNameProperties(PSObject so, List <MshResolvedExpressionParameterAssociation> activeAssociationList)
        {
            if (null != so.Properties[RemotingConstants.ShowComputerNameNoteProperty])
            {
                // always remove PSShowComputerName for the display. This is an internal property
                // that should never be visible to the user.
                Collection <MshResolvedExpressionParameterAssociation> itemsToRemove = new Collection <MshResolvedExpressionParameterAssociation>();
                foreach (MshResolvedExpressionParameterAssociation cpProp in activeAssociationList)
                {
                    if (cpProp.ResolvedExpression.ToString().Equals(RemotingConstants.ShowComputerNameNoteProperty,
                                                                    StringComparison.OrdinalIgnoreCase))
                    {
                        itemsToRemove.Add(cpProp);
                        break;
                    }
                }

                // remove computername for remoteobjects..only if PSShowComputerName property exists
                // otherwise the PSComputerName property does not belong to a remote object:
                // Ex: icm $s { gps } | select pscomputername --> In this case we want to show
                // PSComputerName
                if ((null != so.Properties[RemotingConstants.ComputerNameNoteProperty]) &&
                    (!PSObjectHelper.ShouldShowComputerNameProperty(so)))
                {
                    foreach (MshResolvedExpressionParameterAssociation cpProp in activeAssociationList)
                    {
                        if (cpProp.ResolvedExpression.ToString().Equals(RemotingConstants.ComputerNameNoteProperty,
                                                                        StringComparison.OrdinalIgnoreCase))
                        {
                            itemsToRemove.Add(cpProp);
                            break;
                        }
                    }
                }

                if (itemsToRemove.Count > 0)
                {
                    foreach (MshResolvedExpressionParameterAssociation itemToRemove in itemsToRemove)
                    {
                        activeAssociationList.Remove(itemToRemove);
                    }
                }
            }
        }
示例#6
0
        internal override void Initialize(TerminatingErrorContext errorContext, MshExpressionFactory expressionFactory, PSObject so, TypeInfoDataBase db, FormattingCommandLineParameters parameters)
        {
            base.Initialize(errorContext, expressionFactory, so, db, parameters);
            if ((base.dataBaseInfo != null) && (base.dataBaseInfo.view != null))
            {
                this.tableBody = (TableControlBody)base.dataBaseInfo.view.mainControl;
            }
            List <MshParameter> mshParameterList = null;

            if (parameters != null)
            {
                mshParameterList = parameters.mshParameterList;
            }
            if ((mshParameterList != null) && (mshParameterList.Count > 0))
            {
                base.activeAssociationList = AssociationManager.ExpandTableParameters(mshParameterList, so);
            }
            else
            {
                base.activeAssociationList = AssociationManager.ExpandDefaultPropertySet(so, base.expressionFactory);
                if (base.activeAssociationList.Count > 0)
                {
                    if (PSObjectHelper.ShouldShowComputerNameProperty(so))
                    {
                        base.activeAssociationList.Add(new MshResolvedExpressionParameterAssociation(null, new MshExpression(RemotingConstants.ComputerNameNoteProperty)));
                    }
                }
                else
                {
                    base.activeAssociationList = AssociationManager.ExpandAll(so);
                    if (base.activeAssociationList.Count > 0)
                    {
                        AssociationManager.HandleComputerNameProperties(so, base.activeAssociationList);
                        this.FilterActiveAssociationList();
                    }
                    else
                    {
                        base.activeAssociationList = new List <MshResolvedExpressionParameterAssociation>();
                    }
                }
            }
        }
示例#7
0
        internal static List <MshResolvedExpressionParameterAssociation> SetupActiveProperties(List <MshParameter> rawMshParameterList, PSObject target, MshExpressionFactory expressionFactory)
        {
            if ((rawMshParameterList != null) && (rawMshParameterList.Count > 0))
            {
                return(ExpandParameters(rawMshParameterList, target));
            }
            List <MshResolvedExpressionParameterAssociation> activeAssociationList = ExpandDefaultPropertySet(target, expressionFactory);

            if (activeAssociationList.Count > 0)
            {
                if (PSObjectHelper.ShouldShowComputerNameProperty(target))
                {
                    activeAssociationList.Add(new MshResolvedExpressionParameterAssociation(null, new MshExpression(RemotingConstants.ComputerNameNoteProperty)));
                }
                return(activeAssociationList);
            }
            activeAssociationList = ExpandAll(target);
            HandleComputerNameProperties(target, activeAssociationList);
            return(activeAssociationList);
        }
示例#8
0
 internal static void HandleComputerNameProperties(PSObject so, List <MshResolvedExpressionParameterAssociation> activeAssociationList)
 {
     if (so.Properties[RemotingConstants.ShowComputerNameNoteProperty] != null)
     {
         Collection <MshResolvedExpressionParameterAssociation> collection = new Collection <MshResolvedExpressionParameterAssociation>();
         foreach (MshResolvedExpressionParameterAssociation association in activeAssociationList)
         {
             if (association.ResolvedExpression.ToString().Equals(RemotingConstants.ShowComputerNameNoteProperty, StringComparison.OrdinalIgnoreCase))
             {
                 collection.Add(association);
                 break;
             }
         }
         if ((so.Properties[RemotingConstants.ComputerNameNoteProperty] != null) && !PSObjectHelper.ShouldShowComputerNameProperty(so))
         {
             foreach (MshResolvedExpressionParameterAssociation association2 in activeAssociationList)
             {
                 if (association2.ResolvedExpression.ToString().Equals(RemotingConstants.ComputerNameNoteProperty, StringComparison.OrdinalIgnoreCase))
                 {
                     collection.Add(association2);
                     break;
                 }
             }
         }
         if (collection.Count > 0)
         {
             foreach (MshResolvedExpressionParameterAssociation association3 in collection)
             {
                 activeAssociationList.Remove(association3);
             }
         }
     }
 }