Exemplo n.º 1
0
 internal void AddColumn(ColumnInfo col)
 {
     this.columns.Add(col);
 }
Exemplo n.º 2
0
 internal void AddColumn(ColumnInfo col)
 {
     _columns.Add(col);
 }
Exemplo n.º 3
0
        internal HeaderInfo GenerateHeaderInfo(PSObject input, TableControlBody tableBody, OutGridViewCommand parentCmdlet)
        {
            HeaderInfo headerInfo = new HeaderInfo();

            // This verification is needed because the database returns "LastWriteTime" value for file system objects
            // as strings and it is used to detect this situation and use the actual field value.
            bool fileSystemObject = typeof(FileSystemInfo).IsInstanceOfType(input.BaseObject);

            if (tableBody != null) // If the tableBody is null, the TableControlBody info was not put into the database.
            {
                // Generate HeaderInfo from the type information database.
                List <TableRowItemDefinition> activeRowItemDefinitionList = GetActiveTableRowDefinition(tableBody, input);

                int col = 0;
                foreach (TableRowItemDefinition rowItem in activeRowItemDefinitionList)
                {
                    ColumnInfo columnInfo  = null;
                    string     displayName = null;
                    TableColumnHeaderDefinition colHeader = null;
                    // Retrieve a matching TableColumnHeaderDefinition
                    if (col < tableBody.header.columnHeaderDefinitionList.Count)
                    {
                        colHeader = tableBody.header.columnHeaderDefinitionList[col];
                    }

                    if (colHeader != null && colHeader.label != null)
                    {
                        displayName = _typeInfoDatabase.displayResourceManagerCache.GetTextTokenString(colHeader.label);
                    }

                    FormatToken token = null;
                    if (rowItem.formatTokenList.Count > 0)
                    {
                        token = rowItem.formatTokenList[0];
                    }

                    if (token != null)
                    {
                        FieldPropertyToken fpt = token as FieldPropertyToken;
                        if (fpt != null)
                        {
                            if (displayName == null)
                            {
                                // Database does not provide a label(DisplayName) for the current property, use the expression value instead.
                                displayName = fpt.expression.expressionValue;
                            }
                            if (fpt.expression.isScriptBlock)
                            {
                                PSPropertyExpression ex = _expressionFactory.CreateFromExpressionToken(fpt.expression);
                                // Using the displayName as a propertyName for a stale PSObject.
                                const string LastWriteTimePropertyName = "LastWriteTime";

                                // For FileSystem objects "LastWriteTime" property value should be used although the database indicates that a script should be executed to get the value.
                                if (fileSystemObject && displayName.Equals(LastWriteTimePropertyName, StringComparison.OrdinalIgnoreCase))
                                {
                                    columnInfo = new OriginalColumnInfo(displayName, displayName, LastWriteTimePropertyName, parentCmdlet);
                                }
                                else
                                {
                                    columnInfo = new ExpressionColumnInfo(displayName, displayName, ex);
                                }
                            }
                            else
                            {
                                columnInfo = new OriginalColumnInfo(fpt.expression.expressionValue, displayName, fpt.expression.expressionValue, parentCmdlet);
                            }
                        }
                        else
                        {
                            TextToken tt = token as TextToken;
                            if (tt != null)
                            {
                                displayName = _typeInfoDatabase.displayResourceManagerCache.GetTextTokenString(tt);
                                columnInfo  = new OriginalColumnInfo(tt.text, displayName, tt.text, parentCmdlet);
                            }
                        }
                    }
                    if (columnInfo != null)
                    {
                        headerInfo.AddColumn(columnInfo);
                    }
                    col++;
                }
            }

            return(headerInfo);
        }
Exemplo n.º 4
0
 internal override object GetValue(PSObject liveObject)
 {
     // Convert to a string preserving PowerShell formatting.
     return(ColumnInfo.LimitString(_parentCmdlet.ConvertToString(liveObject)));
 }