예제 #1
0
        private void LoadHeadersSection(TableControlBody tableBody, XmlNode headersNode)
        {
            using (this.StackFrame(headersNode))
            {
                int columnIndex = 0;
                foreach (XmlNode n in headersNode.ChildNodes)
                {
                    if (MatchNodeName(n, XmlTags.TableColumnHeaderNode))
                    {
                        TableColumnHeaderDefinition chd = LoadColumnHeaderDefinition(n, columnIndex++);

                        if (chd != null)
                        {
                            tableBody.header.columnHeaderDefinitionList.Add(chd);
                        }
                        else
                        {
                            //Error at XPath {0} in file {1}: Column header definition is invalid; all headers are discarded.
                            this.ReportError(StringUtil.Format(FormatAndOutXmlLoadingStrings.InvalidColumnHeader, ComputeCurrentXPath(), FilePath));
                            tableBody.header.columnHeaderDefinitionList = null;
                            return; // fatal error
                        }
                    }
                    else
                    {
                        this.ProcessUnknownNode(n);
                    }
                }
                // NOTICE: the list can be empty if no entries were found
            }
        }
        /// <summary>
        /// Let the view prepare itself for RemoteObjects. This will add "ComputerName" to the
        /// table columns.
        /// </summary>
        /// <param name="so"></param>
        internal override void PrepareForRemoteObjects(PSObject so)
        {
            Diagnostics.Assert(so != null, "so cannot be null");

            // make sure computername property exists.
            Diagnostics.Assert(so.Properties[RemotingConstants.ComputerNameNoteProperty] != null,
                               "PrepareForRemoteObjects cannot be called when the object does not contain ComputerName property.");

            if ((dataBaseInfo != null) && (dataBaseInfo.view != null) && (dataBaseInfo.view.mainControl != null))
            {
                // dont change the original format definition in the database..just make a copy and work
                // with the copy
                _tableBody = (TableControlBody)this.dataBaseInfo.view.mainControl.Copy();

                TableRowItemDefinition cnRowDefinition = new TableRowItemDefinition();
                PropertyTokenBase      propToken       = new FieldPropertyToken();
                propToken.expression = new ExpressionToken(RemotingConstants.ComputerNameNoteProperty, false);
                cnRowDefinition.formatTokenList.Add(propToken);
                _tableBody.defaultDefinition.rowItemDefinitionList.Add(cnRowDefinition);

                // add header only if there are other header definitions
                if (_tableBody.header.columnHeaderDefinitionList.Count > 0)
                {
                    TableColumnHeaderDefinition cnHeaderDefinition = new TableColumnHeaderDefinition();
                    cnHeaderDefinition.label      = new TextToken();
                    cnHeaderDefinition.label.text = RemotingConstants.ComputerNameNoteProperty;
                    _tableBody.header.columnHeaderDefinitionList.Add(cnHeaderDefinition);
                }
            }
        }
 internal override void Initialize(TerminatingErrorContext terminatingErrorContext, PSPropertyExpressionFactory mshExpressionFactory, TypeInfoDataBase db, ViewDefinition view, FormattingCommandLineParameters formatParameters)
 {
     base.Initialize(terminatingErrorContext, mshExpressionFactory, db, view, formatParameters);
     if ((this.dataBaseInfo != null) && (this.dataBaseInfo.view != null))
     {
         _tableBody = (TableControlBody)this.dataBaseInfo.view.mainControl;
     }
 }
예제 #4
0
 internal override void Initialize(TerminatingErrorContext terminatingErrorContext, MshExpressionFactory mshExpressionFactory, TypeInfoDataBase db, ViewDefinition view, FormattingCommandLineParameters formatParameters)
 {
     base.Initialize(terminatingErrorContext, mshExpressionFactory, db, view, formatParameters);
     if ((null != this.dataBaseInfo) && (null != this.dataBaseInfo.view))
     {
         _tableBody = (TableControlBody)this.dataBaseInfo.view.mainControl;
     }
 }
        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>();
        }
예제 #6
0
        internal override void Initialize(TerminatingErrorContext errorContext, MshExpressionFactory expressionFactory,
                                        PSObject so, TypeInfoDataBase db,
            FormattingCommandLineParameters parameters)
        {
            base.Initialize(errorContext, expressionFactory, so, db, parameters);

            if ((null != this.dataBaseInfo) && (null != this.dataBaseInfo.view))
            {
                _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 MshExpression(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>();
        }
예제 #7
0
        private void LoadRowEntriesSection(TableControlBody tableBody, XmlNode rowEntriesNode)
        {
            using (this.StackFrame(rowEntriesNode))
            {
                int rowEntryIndex = 0;
                foreach (XmlNode n in rowEntriesNode.ChildNodes)
                {
                    if (MatchNodeName(n, XmlTags.TableRowEntryNode))
                    {
                        TableRowDefinition trd = LoadRowEntryDefinition(n, rowEntryIndex++);
                        if (trd == null)
                        {
                            //Error at XPath {0} in file {1}: {2} failed to load.
                            this.ReportError(StringUtil.Format(FormatAndOutXmlLoadingStrings.LoadTagFailed, ComputeCurrentXPath(), FilePath, XmlTags.TableRowEntryNode));
                            tableBody.defaultDefinition = null;
                            return; // fatal error
                        }

                        // determine if we have a default entry and if it's already set
                        if (trd.appliesTo == null)
                        {
                            if (tableBody.defaultDefinition == null)
                            {
                                tableBody.defaultDefinition = trd;
                            }
                            else
                            {
                                //Error at XPath {0} in file {1}: There cannot be more than one default {2}.
                                this.ReportError(StringUtil.Format(FormatAndOutXmlLoadingStrings.TooManyDefaultShapeEntry, ComputeCurrentXPath(), FilePath, XmlTags.TableRowEntryNode));
                                tableBody.defaultDefinition = null;
                                return; // fatal error
                            }
                        }
                        else
                        {
                            tableBody.optionalDefinitionList.Add(trd);
                        }
                    }
                    else
                    {
                        this.ProcessUnknownNode(n);
                    }
                }

                if (tableBody.defaultDefinition == null)
                {
                    //Error at XPath {0} in file {1}: There must be at least one default {2}.
                    this.ReportError(StringUtil.Format(FormatAndOutXmlLoadingStrings.NoDefaultShapeEntry, ComputeCurrentXPath(), FilePath, XmlTags.TableRowEntryNode));
                }
            }
        }
예제 #8
0
 internal override ControlBase Copy()
 {
     TableControlBody body = new TableControlBody {
         autosize = base.autosize,
         header = this.header.Copy()
     };
     if (this.defaultDefinition != null)
     {
         body.defaultDefinition = this.defaultDefinition.Copy();
     }
     foreach (TableRowDefinition definition in this.optionalDefinitionList)
     {
         body.optionalDefinitionList.Add(definition);
     }
     return body;
 }
예제 #9
0
        internal override ControlBase Copy()
        {
            TableControlBody tableControlBody = new TableControlBody();

            tableControlBody.autosize = this.autosize;
            tableControlBody.header   = this.header.Copy();
            if (this.defaultDefinition != null)
            {
                tableControlBody.defaultDefinition = this.defaultDefinition.Copy();
            }
            foreach (TableRowDefinition optionalDefinition in this.optionalDefinitionList)
            {
                tableControlBody.optionalDefinitionList.Add(optionalDefinition);
            }
            return((ControlBase)tableControlBody);
        }
예제 #10
0
        internal override ControlBase Copy()
        {
            TableControlBody body = new TableControlBody {
                autosize = base.autosize,
                header   = this.header.Copy()
            };

            if (this.defaultDefinition != null)
            {
                body.defaultDefinition = this.defaultDefinition.Copy();
            }
            foreach (TableRowDefinition definition in this.optionalDefinitionList)
            {
                body.optionalDefinitionList.Add(definition);
            }
            return(body);
        }
예제 #11
0
 internal TableControl(TableControlBody tcb)
 {
     this._headers = new List<TableControlColumnHeader>();
     this._rows = new List<TableControlRow>();
     TableControlRow item = new TableControlRow(tcb.defaultDefinition);
     this._rows.Add(item);
     foreach (TableRowDefinition definition in tcb.optionalDefinitionList)
     {
         item = new TableControlRow(definition);
         this._rows.Add(item);
     }
     foreach (TableColumnHeaderDefinition definition2 in tcb.header.columnHeaderDefinitionList)
     {
         TableControlColumnHeader header = new TableControlColumnHeader(definition2);
         this._headers.Add(header);
     }
 }
예제 #12
0
        internal override ControlBase Copy()
        {
            TableControlBody result = new TableControlBody
            {
                autosize = this.autosize,
                header = this.header.Copy()
            };
            if (null != defaultDefinition)
            {
                result.defaultDefinition = this.defaultDefinition.Copy();
            }

            foreach (TableRowDefinition trd in this.optionalDefinitionList)
            {
                result.optionalDefinitionList.Add(trd);
            }

            return result;
        }
예제 #13
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>();
                    }
                }
            }
        }
        internal override ControlBase Copy()
        {
            TableControlBody result = new TableControlBody
            {
                autosize = this.autosize,
                header   = this.header.Copy()
            };

            if (null != defaultDefinition)
            {
                result.defaultDefinition = this.defaultDefinition.Copy();
            }

            foreach (TableRowDefinition trd in this.optionalDefinitionList)
            {
                result.optionalDefinitionList.Add(trd);
            }

            return(result);
        }
예제 #15
0
        internal override void PrepareForRemoteObjects(PSObject so)
        {
            PSPropertyInfo local1 = so.Properties[RemotingConstants.ComputerNameNoteProperty];

            if (((base.dataBaseInfo != null) && (base.dataBaseInfo.view != null)) && (base.dataBaseInfo.view.mainControl != null))
            {
                this.tableBody = (TableControlBody)base.dataBaseInfo.view.mainControl.Copy();
                TableRowItemDefinition item  = new TableRowItemDefinition();
                PropertyTokenBase      base2 = new FieldPropertyToken {
                    expression = new ExpressionToken(RemotingConstants.ComputerNameNoteProperty, false)
                };
                item.formatTokenList.Add(base2);
                this.tableBody.defaultDefinition.rowItemDefinitionList.Add(item);
                if (this.tableBody.header.columnHeaderDefinitionList.Count > 0)
                {
                    TableColumnHeaderDefinition definition2 = new TableColumnHeaderDefinition {
                        label = new TextToken()
                    };
                    definition2.label.text = RemotingConstants.ComputerNameNoteProperty;
                    this.tableBody.header.columnHeaderDefinitionList.Add(definition2);
                }
            }
        }
예제 #16
0
 private ControlBase LoadTableControl(System.Xml.XmlNode controlNode)
 {
     using (base.StackFrame(controlNode))
     {
         TableControlBody tableBody = new TableControlBody();
         bool flag = false;
         bool flag2 = false;
         bool flag3 = false;
         bool flag4 = false;
         foreach (System.Xml.XmlNode node in controlNode.ChildNodes)
         {
             if (base.MatchNodeName(node, "HideTableHeaders"))
             {
                 if (flag3)
                 {
                     base.ProcessDuplicateNode(node);
                     return null;
                 }
                 flag3 = true;
                 if (!this.ReadBooleanNode(node, out tableBody.header.hideHeader))
                 {
                     return null;
                 }
             }
             else if (base.MatchNodeName(node, "AutoSize"))
             {
                 bool flag5;
                 if (flag4)
                 {
                     base.ProcessDuplicateNode(node);
                     return null;
                 }
                 flag4 = true;
                 if (!this.ReadBooleanNode(node, out flag5))
                 {
                     return null;
                 }
                 tableBody.autosize = new bool?(flag5);
             }
             else if (base.MatchNodeName(node, "TableHeaders"))
             {
                 if (flag)
                 {
                     base.ProcessDuplicateNode(node);
                     return null;
                 }
                 flag = true;
                 this.LoadHeadersSection(tableBody, node);
                 if (tableBody.header.columnHeaderDefinitionList == null)
                 {
                     return null;
                 }
             }
             else if (base.MatchNodeName(node, "TableRowEntries"))
             {
                 if (flag2)
                 {
                     base.ProcessDuplicateNode(node);
                     return null;
                 }
                 flag2 = true;
                 this.LoadRowEntriesSection(tableBody, node);
                 if (tableBody.defaultDefinition == null)
                 {
                     return null;
                 }
             }
             else
             {
                 base.ProcessUnknownNode(node);
             }
         }
         if (!flag2)
         {
             base.ReportMissingNode("TableRowEntries");
             return null;
         }
         if ((tableBody.header.columnHeaderDefinitionList.Count != 0) && (tableBody.header.columnHeaderDefinitionList.Count != tableBody.defaultDefinition.rowItemDefinitionList.Count))
         {
             base.ReportError(StringUtil.Format(FormatAndOutXmlLoadingStrings.IncorrectHeaderItemCount, new object[] { base.ComputeCurrentXPath(), base.FilePath, tableBody.header.columnHeaderDefinitionList.Count, tableBody.defaultDefinition.rowItemDefinitionList.Count }));
             return null;
         }
         if (tableBody.optionalDefinitionList.Count != 0)
         {
             int num = 0;
             foreach (TableRowDefinition definition in tableBody.optionalDefinitionList)
             {
                 if (definition.rowItemDefinitionList.Count != tableBody.defaultDefinition.rowItemDefinitionList.Count)
                 {
                     base.ReportError(StringUtil.Format(FormatAndOutXmlLoadingStrings.IncorrectRowItemCount, new object[] { base.ComputeCurrentXPath(), base.FilePath, definition.rowItemDefinitionList.Count, tableBody.defaultDefinition.rowItemDefinitionList.Count, num + 1 }));
                     return null;
                 }
                 num++;
             }
         }
         return tableBody;
     }
 }
예제 #17
0
        internal TableControl(TableControlBody tcb, ViewDefinition viewDefinition) : this()
        {
            this.OutOfBand = viewDefinition.outOfBand;
            this.GroupBy = PSControlGroupBy.Get(viewDefinition.groupBy);

            this.AutoSize = tcb.autosize.HasValue && tcb.autosize.Value;
            this.HideTableHeaders = tcb.header.hideHeader;

            TableControlRow row = new TableControlRow(tcb.defaultDefinition);

            Rows.Add(row);

            foreach (TableRowDefinition rd in tcb.optionalDefinitionList)
            {
                row = new TableControlRow(rd);

                Rows.Add(row);
            }

            foreach (TableColumnHeaderDefinition hd in tcb.header.columnHeaderDefinitionList)
            {
                TableControlColumnHeader header = new TableControlColumnHeader(hd);
                Headers.Add(header);
            }
        }
예제 #18
0
파일: TableView.cs 프로젝트: nickchal/pash
 private List<TableRowItemDefinition> GetActiveTableRowDefinition(TableControlBody tableBody, PSObject so)
 {
     if (tableBody.optionalDefinitionList.Count == 0)
     {
         return tableBody.defaultDefinition.rowItemDefinitionList;
     }
     TableRowDefinition bestMatch = null;
     ConsolidatedString internalTypeNames = so.InternalTypeNames;
     TypeMatch match = new TypeMatch(this.expressionFactory, this.typeInfoDatabase, internalTypeNames);
     foreach (TableRowDefinition definition2 in tableBody.optionalDefinitionList)
     {
         if (match.PerfectMatch(new TypeMatchItem(definition2, definition2.appliesTo)))
         {
             bestMatch = definition2;
             break;
         }
     }
     if (bestMatch == null)
     {
         bestMatch = match.BestMatch as TableRowDefinition;
     }
     if (bestMatch == null)
     {
         Collection<string> typeNames = Deserializer.MaskDeserializationPrefix(internalTypeNames);
         if (typeNames != null)
         {
             match = new TypeMatch(this.expressionFactory, this.typeInfoDatabase, typeNames);
             foreach (TableRowDefinition definition3 in tableBody.optionalDefinitionList)
             {
                 if (match.PerfectMatch(new TypeMatchItem(definition3, definition3.appliesTo)))
                 {
                     bestMatch = definition3;
                     break;
                 }
             }
             if (bestMatch == null)
             {
                 bestMatch = match.BestMatch as TableRowDefinition;
             }
         }
     }
     if (bestMatch == null)
     {
         return tableBody.defaultDefinition.rowItemDefinitionList;
     }
     List<TableRowItemDefinition> list = new List<TableRowItemDefinition>();
     int num = 0;
     foreach (TableRowItemDefinition definition4 in bestMatch.rowItemDefinitionList)
     {
         if (definition4.formatTokenList.Count == 0)
         {
             list.Add(tableBody.defaultDefinition.rowItemDefinitionList[num]);
         }
         else
         {
             list.Add(definition4);
         }
         num++;
     }
     return list;
 }
        private List <TableRowItemDefinition> GetActiveTableRowDefinition(TableControlBody tableBody, PSObject so,
                                                                          out bool multiLine)
        {
            multiLine = tableBody.defaultDefinition.multiLine;
            if (tableBody.optionalDefinitionList.Count == 0)
            {
                // we do not have any override, use default
                return(tableBody.defaultDefinition.rowItemDefinitionList);
            }

            // see if we have an override that matches
            TableRowDefinition matchingRowDefinition = null;

            var       typeNames = so.InternalTypeNames;
            TypeMatch match     = new TypeMatch(expressionFactory, this.dataBaseInfo.db, typeNames);

            foreach (TableRowDefinition x in tableBody.optionalDefinitionList)
            {
                if (match.PerfectMatch(new TypeMatchItem(x, x.appliesTo)))
                {
                    matchingRowDefinition = x;
                    break;
                }
            }

            if (matchingRowDefinition == null)
            {
                matchingRowDefinition = match.BestMatch as TableRowDefinition;
            }

            if (matchingRowDefinition == null)
            {
                Collection <string> typesWithoutPrefix = Deserializer.MaskDeserializationPrefix(typeNames);
                if (typesWithoutPrefix != null)
                {
                    match = new TypeMatch(expressionFactory, this.dataBaseInfo.db, typesWithoutPrefix);

                    foreach (TableRowDefinition x in tableBody.optionalDefinitionList)
                    {
                        if (match.PerfectMatch(new TypeMatchItem(x, x.appliesTo)))
                        {
                            matchingRowDefinition = x;
                            break;
                        }
                    }

                    if (matchingRowDefinition == null)
                    {
                        matchingRowDefinition = match.BestMatch as TableRowDefinition;
                    }
                }
            }

            if (matchingRowDefinition == null)
            {
                // no matching override, use default
                return(tableBody.defaultDefinition.rowItemDefinitionList);
            }

            // the overriding row definition takes the precedence
            if (matchingRowDefinition.multiLine)
            {
                multiLine = matchingRowDefinition.multiLine;
            }

            // we have an override, we need to compute the merge of the active cells
            List <TableRowItemDefinition> activeRowItemDefinitionList = new List <TableRowItemDefinition>();
            int col = 0;

            foreach (TableRowItemDefinition rowItem in matchingRowDefinition.rowItemDefinitionList)
            {
                // check if the row is an override or not
                if (rowItem.formatTokenList.Count == 0)
                {
                    // it's a place holder, use the default
                    activeRowItemDefinitionList.Add(tableBody.defaultDefinition.rowItemDefinitionList[col]);
                }
                else
                {
                    // use the override
                    activeRowItemDefinitionList.Add(rowItem);
                }

                col++;
            }

            return(activeRowItemDefinitionList);
        }
예제 #20
0
파일: TableView.cs 프로젝트: nickchal/pash
 internal HeaderInfo GenerateHeaderInfo(PSObject input, TableControlBody tableBody, OutGridViewCommand parentCmdlet)
 {
     HeaderInfo info = new HeaderInfo();
     bool flag = typeof(FileSystemInfo).IsInstanceOfType(input.BaseObject);
     if (tableBody != null)
     {
         List<TableRowItemDefinition> activeTableRowDefinition = this.GetActiveTableRowDefinition(tableBody, input);
         int num = 0;
         foreach (TableRowItemDefinition definition in activeTableRowDefinition)
         {
             Microsoft.PowerShell.Commands.ColumnInfo col = null;
             string staleObjectPropertyName = null;
             TableColumnHeaderDefinition definition2 = null;
             if (tableBody.header.columnHeaderDefinitionList.Count >= (num - 1))
             {
                 definition2 = tableBody.header.columnHeaderDefinitionList[num];
             }
             if ((definition2 != null) && (definition2.label != null))
             {
                 staleObjectPropertyName = this.typeInfoDatabase.displayResourceManagerCache.GetTextTokenString(definition2.label);
             }
             FormatToken token = null;
             if (definition.formatTokenList.Count > 0)
             {
                 token = definition.formatTokenList[0];
             }
             if (token != null)
             {
                 FieldPropertyToken token2 = token as FieldPropertyToken;
                 if (token2 != null)
                 {
                     if (staleObjectPropertyName == null)
                     {
                         staleObjectPropertyName = token2.expression.expressionValue;
                     }
                     if (token2.expression.isScriptBlock)
                     {
                         MshExpression expression = this.expressionFactory.CreateFromExpressionToken(token2.expression);
                         if (flag && staleObjectPropertyName.Equals("LastWriteTime", StringComparison.OrdinalIgnoreCase))
                         {
                             col = new OriginalColumnInfo(staleObjectPropertyName, staleObjectPropertyName, "LastWriteTime", parentCmdlet);
                         }
                         else
                         {
                             col = new ExpressionColumnInfo(staleObjectPropertyName, staleObjectPropertyName, expression);
                         }
                     }
                     else
                     {
                         col = new OriginalColumnInfo(token2.expression.expressionValue, staleObjectPropertyName, token2.expression.expressionValue, parentCmdlet);
                     }
                 }
                 else
                 {
                     TextToken tt = token as TextToken;
                     if (tt != null)
                     {
                         staleObjectPropertyName = this.typeInfoDatabase.displayResourceManagerCache.GetTextTokenString(tt);
                         col = new OriginalColumnInfo(tt.text, staleObjectPropertyName, tt.text, parentCmdlet);
                     }
                 }
             }
             if (col != null)
             {
                 info.AddColumn(col);
             }
             num++;
         }
     }
     return info;
 }
예제 #21
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)
                            {
                                MshExpression 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;
        }
예제 #22
0
 internal void AddColumnsAndItem(PSObject liveObject, TableView tableView, TableControlBody tableBody)
 {
     this.headerInfo = tableView.GenerateHeaderInfo(liveObject, tableBody, this.parentCmdlet);
     this.AddColumnsAndItemEnd(liveObject);
 }
예제 #23
0
 private void LoadHeadersSection(TableControlBody tableBody, System.Xml.XmlNode headersNode)
 {
     using (base.StackFrame(headersNode))
     {
         int num = 0;
         foreach (System.Xml.XmlNode node in headersNode.ChildNodes)
         {
             if (base.MatchNodeName(node, "TableColumnHeader"))
             {
                 TableColumnHeaderDefinition item = this.LoadColumnHeaderDefinition(node, num++);
                 if (item != null)
                 {
                     tableBody.header.columnHeaderDefinitionList.Add(item);
                     continue;
                 }
                 base.ReportError(StringUtil.Format(FormatAndOutXmlLoadingStrings.InvalidColumnHeader, base.ComputeCurrentXPath(), base.FilePath));
                 tableBody.header.columnHeaderDefinitionList = null;
                 return;
             }
             base.ProcessUnknownNode(node);
         }
     }
 }
예제 #24
0
        /// <summary>
        /// Load the headers defined for columns
        /// </summary>
        /// <param name="tableBody"></param>
        /// <param name="headers"></param>
        private void LoadHeadersSectionFromObjectModel(TableControlBody tableBody, List<TableControlColumnHeader> headers)
        {
            foreach (TableControlColumnHeader header in headers)
            {
                TableColumnHeaderDefinition chd = new TableColumnHeaderDefinition();

                // Contains:
                //   Label     --- Label     cardinality 0..1
                //   Width     --- Width     cardinality 0..1
                //   Alignment --- Alignment cardinality 0..1
                if (!String.IsNullOrEmpty(header.Label))
                {
                    TextToken tt = new TextToken();
                    tt.text = header.Label;
                    chd.label = tt;
                }

                chd.width = header.Width;
                chd.alignment = (int)header.Alignment;
                tableBody.header.columnHeaderDefinitionList.Add(chd);
            }
        }
예제 #25
0
 private void LoadRowEntriesSection(TableControlBody tableBody, System.Xml.XmlNode rowEntriesNode)
 {
     using (base.StackFrame(rowEntriesNode))
     {
         int num = 0;
         foreach (System.Xml.XmlNode node in rowEntriesNode.ChildNodes)
         {
             if (base.MatchNodeName(node, "TableRowEntry"))
             {
                 TableRowDefinition item = this.LoadRowEntryDefinition(node, num++);
                 if (item == null)
                 {
                     base.ReportError(StringUtil.Format(FormatAndOutXmlLoadingStrings.LoadTagFailed, new object[] { base.ComputeCurrentXPath(), base.FilePath, "TableRowEntry" }));
                     tableBody.defaultDefinition = null;
                     return;
                 }
                 if (item.appliesTo == null)
                 {
                     if (tableBody.defaultDefinition == null)
                     {
                         tableBody.defaultDefinition = item;
                         continue;
                     }
                     base.ReportError(StringUtil.Format(FormatAndOutXmlLoadingStrings.TooManyDefaultShapeEntry, new object[] { base.ComputeCurrentXPath(), base.FilePath, "TableRowEntry" }));
                     tableBody.defaultDefinition = null;
                     return;
                 }
                 tableBody.optionalDefinitionList.Add(item);
             }
             else
             {
                 base.ProcessUnknownNode(node);
             }
         }
         if (tableBody.defaultDefinition == null)
         {
             base.ReportError(StringUtil.Format(FormatAndOutXmlLoadingStrings.NoDefaultShapeEntry, new object[] { base.ComputeCurrentXPath(), base.FilePath, "TableRowEntry" }));
         }
     }
 }
예제 #26
0
        private ControlBase LoadTableControl(XmlNode controlNode)
        {
            using (this.StackFrame(controlNode))
            {
                TableControlBody tableBody = new TableControlBody();
                bool headersNodeFound = false;      // cardinality 0..1
                bool rowEntriesNodeFound = false;   // cardinality 1
                bool hideHeadersNodeFound = false;   // cardinality 0..1
                bool autosizeNodeFound = false;   // cardinality 0..1

                foreach (XmlNode n in controlNode.ChildNodes)
                {
                    if (MatchNodeName(n, XmlTags.HideTableHeadersNode))
                    {
                        if (hideHeadersNodeFound)
                        {
                            this.ProcessDuplicateNode(n);
                            return null; // fatal error
                        }

                        hideHeadersNodeFound = true;
                        if (!this.ReadBooleanNode(n, out tableBody.header.hideHeader))
                        {
                            return null; //fatal error
                        }
                    }
                    else if (MatchNodeName(n, XmlTags.AutoSizeNode))
                    {
                        if (autosizeNodeFound)
                        {
                            this.ProcessDuplicateNode(n);
                            return null; // fatal error
                        }
                        autosizeNodeFound = true;
                        bool tempVal;
                        if (!this.ReadBooleanNode(n, out tempVal))
                        {
                            return null; // fatal error
                        }
                        tableBody.autosize = tempVal;
                    }
                    else if (MatchNodeName(n, XmlTags.TableHeadersNode))
                    {
                        if (headersNodeFound)
                        {
                            this.ProcessDuplicateNode(n);
                            return null; // fatal error
                        }

                        headersNodeFound = true;

                        // now read the columns header section
                        LoadHeadersSection(tableBody, n);
                        if (tableBody.header.columnHeaderDefinitionList == null)
                        {
                            // if we have an empty list, it means there was a failure
                            return null; // fatal error
                        }
                    }
                    else if (MatchNodeName(n, XmlTags.TableRowEntriesNode))
                    {
                        if (rowEntriesNodeFound)
                        {
                            this.ProcessDuplicateNode(n);
                            return null; // fatal error
                        }

                        rowEntriesNodeFound = true;

                        // now read the columns section
                        LoadRowEntriesSection(tableBody, n);
                        if (tableBody.defaultDefinition == null)
                        {
                            return null; // fatal error
                        }
                    }
                    else
                    {
                        this.ProcessUnknownNode(n);
                    }
                }

                if (!rowEntriesNodeFound)
                {
                    this.ReportMissingNode(XmlTags.TableRowEntriesNode);
                    return null; // fatal error
                }

                // CHECK: verify consistency of headers and row entries
                if (tableBody.header.columnHeaderDefinitionList.Count != 0)
                {
                    // CHECK: if there are headers in the list, their number has to match
                    // the default row definition item count
                    if (tableBody.header.columnHeaderDefinitionList.Count !=
                        tableBody.defaultDefinition.rowItemDefinitionList.Count)
                    {
                        //Error at XPath {0} in file {1}: Header item count = {2} does not match default row item count = {3}.
                        this.ReportError(StringUtil.Format(FormatAndOutXmlLoadingStrings.IncorrectHeaderItemCount, ComputeCurrentXPath(), FilePath,
                            tableBody.header.columnHeaderDefinitionList.Count,
                            tableBody.defaultDefinition.rowItemDefinitionList.Count));

                        return null; // fatal error
                    }
                }

                // CHECK: if there are alternative row definitions, they should have the same # of items
                if (tableBody.optionalDefinitionList.Count != 0)
                {
                    int k = 0;
                    foreach (TableRowDefinition trd in tableBody.optionalDefinitionList)
                    {
                        if (trd.rowItemDefinitionList.Count !=
                            tableBody.defaultDefinition.rowItemDefinitionList.Count)
                        {
                            //Error at XPath {0} in file {1}: Row item count = {2} on alternative set #{3} does not match default row item count = {4}.
                            this.ReportError(StringUtil.Format(FormatAndOutXmlLoadingStrings.IncorrectRowItemCount, ComputeCurrentXPath(), FilePath,
                                trd.rowItemDefinitionList.Count,
                                tableBody.defaultDefinition.rowItemDefinitionList.Count, k + 1));

                            return null; // fatal error
                        }
                        k++;
                    }
                }

                return tableBody;
            }
        }
예제 #27
0
        private List <TableRowItemDefinition> GetActiveTableRowDefinition(TableControlBody tableBody, PSObject so, out bool multiLine)
        {
            multiLine = tableBody.defaultDefinition.multiLine;
            if (tableBody.optionalDefinitionList.Count == 0)
            {
                return(tableBody.defaultDefinition.rowItemDefinitionList);
            }
            TableRowDefinition bestMatch         = null;
            ConsolidatedString internalTypeNames = so.InternalTypeNames;
            TypeMatch          match             = new TypeMatch(base.expressionFactory, base.dataBaseInfo.db, internalTypeNames);

            foreach (TableRowDefinition definition2 in tableBody.optionalDefinitionList)
            {
                if (match.PerfectMatch(new TypeMatchItem(definition2, definition2.appliesTo)))
                {
                    bestMatch = definition2;
                    break;
                }
            }
            if (bestMatch == null)
            {
                bestMatch = match.BestMatch as TableRowDefinition;
            }
            if (bestMatch == null)
            {
                Collection <string> typeNames = Deserializer.MaskDeserializationPrefix(internalTypeNames);
                if (typeNames != null)
                {
                    match = new TypeMatch(base.expressionFactory, base.dataBaseInfo.db, typeNames);
                    foreach (TableRowDefinition definition3 in tableBody.optionalDefinitionList)
                    {
                        if (match.PerfectMatch(new TypeMatchItem(definition3, definition3.appliesTo)))
                        {
                            bestMatch = definition3;
                            break;
                        }
                    }
                    if (bestMatch == null)
                    {
                        bestMatch = match.BestMatch as TableRowDefinition;
                    }
                }
            }
            if (bestMatch == null)
            {
                return(tableBody.defaultDefinition.rowItemDefinitionList);
            }
            if (bestMatch.multiLine)
            {
                multiLine = bestMatch.multiLine;
            }
            List <TableRowItemDefinition> list = new List <TableRowItemDefinition>();
            int num = 0;

            foreach (TableRowItemDefinition definition4 in bestMatch.rowItemDefinitionList)
            {
                if (definition4.formatTokenList.Count == 0)
                {
                    list.Add(tableBody.defaultDefinition.rowItemDefinitionList[num]);
                }
                else
                {
                    list.Add(definition4);
                }
                num++;
            }
            return(list);
        }
예제 #28
0
        /// <summary>
        /// Load the TableControl to ControlBase.
        /// </summary>
        /// <param name="table"></param>
        /// <param name="viewIndex"></param>
        /// <param name="typeName"></param>
        /// <returns></returns>
        private ControlBase LoadTableControlFromObjectModel(TableControl table, int viewIndex, string typeName)
        {
            TableControlBody tableBody = new TableControlBody { autosize = table.AutoSize };

            LoadHeadersSectionFromObjectModel(tableBody, table.Headers);

            // No 'SelectedBy' data supplied, so the rowEntry will only be set to
            // tableBody.defaultDefinition. There cannot be more than one 'defaultDefinition'
            // defined for the tableBody.
            if (table.Rows.Count > 1)
            {
                this.ReportErrorForLoadingFromObjectModel(
                    StringUtil.Format(FormatAndOutXmlLoadingStrings.MultipleRowEntriesFoundInFormattingData, typeName, viewIndex, XmlTags.TableRowEntryNode), typeName);
                return null;
            }

            LoadRowEntriesSectionFromObjectModel(tableBody, table.Rows, viewIndex, typeName);
            // When error occurs while loading rowEntry, the tableBody.defaultDefinition would be null
            if (tableBody.defaultDefinition == null)
            {
                return null;
            }

            // CHECK: verify consistency of headers and row entries
            if (tableBody.header.columnHeaderDefinitionList.Count != 0)
            {
                // CHECK: if there are headers in the list, their number has to match
                // the default row definition item count
                if (tableBody.header.columnHeaderDefinitionList.Count !=
                    tableBody.defaultDefinition.rowItemDefinitionList.Count)
                {
                    //Error at XPath {0} in file {1}: Header item count = {2} does not match default row item count = {3}.
                    this.ReportErrorForLoadingFromObjectModel(
                        StringUtil.Format(FormatAndOutXmlLoadingStrings.IncorrectHeaderItemCountInFormattingData, typeName, viewIndex,
                        tableBody.header.columnHeaderDefinitionList.Count,
                        tableBody.defaultDefinition.rowItemDefinitionList.Count), typeName);

                    return null; // fatal error
                }
            }
            // CHECK: if there are alternative row definitions. There should be no alternative row definitions here.
            Diagnostics.Assert(tableBody.optionalDefinitionList.Count == 0,
                "there should be no alternative row definitions because no SelectedBy is defined for TableControlRow");

            return tableBody;
        }
예제 #29
0
        private void LoadHeadersSection(TableControlBody tableBody, XmlNode headersNode)
        {
            using (this.StackFrame(headersNode))
            {
                int columnIndex = 0;
                foreach (XmlNode n in headersNode.ChildNodes)
                {
                    if (MatchNodeName(n, XmlTags.TableColumnHeaderNode))
                    {
                        TableColumnHeaderDefinition chd = LoadColumnHeaderDefinition(n, columnIndex++);

                        if (chd != null)
                            tableBody.header.columnHeaderDefinitionList.Add(chd);
                        else
                        {
                            //Error at XPath {0} in file {1}: Column header definition is invalid; all headers are discarded.
                            this.ReportError(StringUtil.Format(FormatAndOutXmlLoadingStrings.InvalidColumnHeader, ComputeCurrentXPath(), FilePath));
                            tableBody.header.columnHeaderDefinitionList = null;
                            return; // fatal error
                        }
                    }
                    else
                    {
                        this.ProcessUnknownNode(n);
                    }
                }
                // NOTICE: the list can be empty if no entries were found
            }
        }
예제 #30
0
        /// <summary>
        /// Load row enties, set the defaultDefinition of the TableControlBody.
        /// </summary>
        /// <param name="tableBody"></param>
        /// <param name="rowEntries"></param>
        /// <param name="viewIndex"></param>
        /// <param name="typeName"></param>
        private void LoadRowEntriesSectionFromObjectModel(TableControlBody tableBody, List<TableControlRow> rowEntries, int viewIndex, string typeName)
        {
            foreach (TableControlRow row in rowEntries)
            {
                TableRowDefinition trd = new TableRowDefinition { multiLine = row.Wrap };

                // Contains:
                //   Columns --- TableColumnItems  cardinality: 0..1
                // No SelectedBy is supplied in the TableControlRow
                if (row.Columns.Count > 0)
                {
                    LoadColumnEntriesFromObjectModel(trd, row.Columns, viewIndex, typeName);
                    // trd.rowItemDefinitionList is null, it means there was a failure
                    if (trd.rowItemDefinitionList == null)
                    {
                        tableBody.defaultDefinition = null;
                        return;
                    }
                }

                if (row.SelectedBy != null)
                {
                    trd.appliesTo = LoadAppliesToSectionFromObjectModel(row.SelectedBy.TypeNames, row.SelectedBy.SelectionCondition);
                    tableBody.optionalDefinitionList.Add(trd);
                }
                else
                {
                    tableBody.defaultDefinition = trd;
                }
            }

            // rowEntries must not be empty 
            if (tableBody.defaultDefinition == null)
            {
                this.ReportErrorForLoadingFromObjectModel(
                    StringUtil.Format(FormatAndOutXmlLoadingStrings.NoDefaultShapeEntryInFormattingData, typeName, viewIndex, XmlTags.TableRowEntryNode), typeName);
                return;
            }
        }
예제 #31
0
 internal override void PrepareForRemoteObjects(PSObject so)
 {
     PSPropertyInfo local1 = so.Properties[RemotingConstants.ComputerNameNoteProperty];
     if (((base.dataBaseInfo != null) && (base.dataBaseInfo.view != null)) && (base.dataBaseInfo.view.mainControl != null))
     {
         this.tableBody = (TableControlBody) base.dataBaseInfo.view.mainControl.Copy();
         TableRowItemDefinition item = new TableRowItemDefinition();
         PropertyTokenBase base2 = new FieldPropertyToken {
             expression = new ExpressionToken(RemotingConstants.ComputerNameNoteProperty, false)
         };
         item.formatTokenList.Add(base2);
         this.tableBody.defaultDefinition.rowItemDefinitionList.Add(item);
         if (this.tableBody.header.columnHeaderDefinitionList.Count > 0)
         {
             TableColumnHeaderDefinition definition2 = new TableColumnHeaderDefinition {
                 label = new TextToken()
             };
             definition2.label.text = RemotingConstants.ComputerNameNoteProperty;
             this.tableBody.header.columnHeaderDefinitionList.Add(definition2);
         }
     }
 }
예제 #32
0
 private void LoadHeadersSectionFromObjectModel(TableControlBody tableBody, List<TableControlColumnHeader> headers)
 {
     foreach (TableControlColumnHeader header in headers)
     {
         TableColumnHeaderDefinition item = new TableColumnHeaderDefinition();
         if (!string.IsNullOrEmpty(header.Label))
         {
             TextToken token = new TextToken {
                 text = header.Label
             };
             item.label = token;
         }
         item.width = header.Width;
         item.alignment = (int) header.Alignment;
         tableBody.header.columnHeaderDefinitionList.Add(item);
     }
 }
예제 #33
0
        private void LoadRowEntriesSection(TableControlBody tableBody, XmlNode rowEntriesNode)
        {
            using (this.StackFrame(rowEntriesNode))
            {
                int rowEntryIndex = 0;
                foreach (XmlNode n in rowEntriesNode.ChildNodes)
                {
                    if (MatchNodeName(n, XmlTags.TableRowEntryNode))
                    {
                        TableRowDefinition trd = LoadRowEntryDefinition(n, rowEntryIndex++);
                        if (trd == null)
                        {
                            //Error at XPath {0} in file {1}: {2} failed to load.
                            this.ReportError(StringUtil.Format(FormatAndOutXmlLoadingStrings.LoadTagFailed, ComputeCurrentXPath(), FilePath, XmlTags.TableRowEntryNode));
                            tableBody.defaultDefinition = null;
                            return; // fatal error
                        }

                        // determine if we have a default entry and if it's already set
                        if (trd.appliesTo == null)
                        {
                            if (tableBody.defaultDefinition == null)
                            {
                                tableBody.defaultDefinition = trd;
                            }
                            else
                            {
                                //Error at XPath {0} in file {1}: There cannot be more than one default {2}.
                                this.ReportError(StringUtil.Format(FormatAndOutXmlLoadingStrings.TooManyDefaultShapeEntry, ComputeCurrentXPath(), FilePath, XmlTags.TableRowEntryNode));
                                tableBody.defaultDefinition = null;
                                return; // fatal error
                            }
                        }
                        else
                        {
                            tableBody.optionalDefinitionList.Add(trd);
                        }
                    }
                    else
                    {
                        this.ProcessUnknownNode(n);
                    }
                }
                if (tableBody.defaultDefinition == null)
                {
                    //Error at XPath {0} in file {1}: There must be at least one default {2}.
                    this.ReportError(StringUtil.Format(FormatAndOutXmlLoadingStrings.NoDefaultShapeEntry, ComputeCurrentXPath(), FilePath, XmlTags.TableRowEntryNode));
                }
            }
        }
예제 #34
0
 private void LoadRowEntriesSectionFromObjectModel(TableControlBody tableBody, List<TableControlRow> rowEntries, int viewIndex, string typeName)
 {
     foreach (TableControlRow row in rowEntries)
     {
         TableRowDefinition trd = new TableRowDefinition();
         if (row.Columns.Count > 0)
         {
             this.LoadColumnEntriesFromObjectModel(trd, row.Columns, viewIndex, typeName);
             if (trd.rowItemDefinitionList == null)
             {
                 tableBody.defaultDefinition = null;
                 return;
             }
         }
         tableBody.defaultDefinition = trd;
     }
     if (tableBody.defaultDefinition == null)
     {
         base.ReportErrorForLoadingFromObjectModel(StringUtil.Format(FormatAndOutXmlLoadingStrings.NoDefaultShapeEntryInFormattingData, new object[] { typeName, viewIndex, "TableRowEntry" }), typeName);
     }
 }
예제 #35
0
        private List<TableRowItemDefinition> GetActiveTableRowDefinition(TableControlBody tableBody, PSObject so,
                                                out bool multiLine)
        {
            multiLine = tableBody.defaultDefinition.multiLine;
            if (tableBody.optionalDefinitionList.Count == 0)
            {
                // we do not have any override, use default
                return tableBody.defaultDefinition.rowItemDefinitionList;
            }

            // see if we have an override that matches
            TableRowDefinition matchingRowDefinition = null;

            var typeNames = so.InternalTypeNames;
            TypeMatch match = new TypeMatch(expressionFactory, this.dataBaseInfo.db, typeNames);

            foreach (TableRowDefinition x in tableBody.optionalDefinitionList)
            {
                if (match.PerfectMatch(new TypeMatchItem(x, x.appliesTo)))
                {
                    matchingRowDefinition = x;
                    break;
                }
            }
            if (matchingRowDefinition == null)
            {
                matchingRowDefinition = match.BestMatch as TableRowDefinition;
            }

            if (matchingRowDefinition == null)
            {
                Collection<string> typesWithoutPrefix = Deserializer.MaskDeserializationPrefix(typeNames);
                if (null != typesWithoutPrefix)
                {
                    match = new TypeMatch(expressionFactory, this.dataBaseInfo.db, typesWithoutPrefix);

                    foreach (TableRowDefinition x in tableBody.optionalDefinitionList)
                    {
                        if (match.PerfectMatch(new TypeMatchItem(x, x.appliesTo)))
                        {
                            matchingRowDefinition = x;
                            break;
                        }
                    }
                    if (matchingRowDefinition == null)
                    {
                        matchingRowDefinition = match.BestMatch as TableRowDefinition;
                    }
                }
            }

            if (matchingRowDefinition == null)
            {
                // no matching override, use default
                return tableBody.defaultDefinition.rowItemDefinitionList;
            }

            // the overriding row definition takes the precedence
            if (matchingRowDefinition.multiLine)
                multiLine = matchingRowDefinition.multiLine;

            // we have an override, we need to compute the merge of the active cells
            List<TableRowItemDefinition> activeRowItemDefinitionList = new List<TableRowItemDefinition>();
            int col = 0;
            foreach (TableRowItemDefinition rowItem in matchingRowDefinition.rowItemDefinitionList)
            {
                // check if the row is an override or not
                if (rowItem.formatTokenList.Count == 0)
                {
                    // it's a place holder, use the default
                    activeRowItemDefinitionList.Add(tableBody.defaultDefinition.rowItemDefinitionList[col]);
                }
                else
                {
                    // use the override
                    activeRowItemDefinitionList.Add(rowItem);
                }
                col++;
            }

            return activeRowItemDefinitionList;
        }
예제 #36
0
 private ControlBase LoadTableControlFromObjectModel(TableControl table, int viewIndex, string typeName)
 {
     TableControlBody tableBody = new TableControlBody();
     this.LoadHeadersSectionFromObjectModel(tableBody, table.Headers);
     if (table.Rows.Count > 1)
     {
         base.ReportErrorForLoadingFromObjectModel(StringUtil.Format(FormatAndOutXmlLoadingStrings.MultipleRowEntriesFoundInFormattingData, new object[] { typeName, viewIndex, "TableRowEntry" }), typeName);
         return null;
     }
     this.LoadRowEntriesSectionFromObjectModel(tableBody, table.Rows, viewIndex, typeName);
     if (tableBody.defaultDefinition == null)
     {
         return null;
     }
     if ((tableBody.header.columnHeaderDefinitionList.Count != 0) && (tableBody.header.columnHeaderDefinitionList.Count != tableBody.defaultDefinition.rowItemDefinitionList.Count))
     {
         base.ReportErrorForLoadingFromObjectModel(StringUtil.Format(FormatAndOutXmlLoadingStrings.IncorrectHeaderItemCountInFormattingData, new object[] { typeName, viewIndex, tableBody.header.columnHeaderDefinitionList.Count, tableBody.defaultDefinition.rowItemDefinitionList.Count }), typeName);
         return null;
     }
     return tableBody;
 }
예제 #37
0
        /// <summary>
        /// Let the view prepare itself for RemoteObjects. This will add "ComputerName" to the 
        /// table columns.
        /// </summary>
        /// <param name="so"></param>
        internal override void PrepareForRemoteObjects(PSObject so)
        {
            Diagnostics.Assert(null != so, "so cannot be null");

            // make sure computername property exists.
            Diagnostics.Assert(null != so.Properties[RemotingConstants.ComputerNameNoteProperty],
                "PrepareForRemoteObjects cannot be called when the object does not contain ComputerName property.");

            if ((dataBaseInfo != null) && (dataBaseInfo.view != null) && (dataBaseInfo.view.mainControl != null))
            {
                // dont change the original format definition in the database..just make a copy and work
                // with the copy
                _tableBody = (TableControlBody)this.dataBaseInfo.view.mainControl.Copy();

                TableRowItemDefinition cnRowDefinition = new TableRowItemDefinition();
                PropertyTokenBase propToken = new FieldPropertyToken();
                propToken.expression = new ExpressionToken(RemotingConstants.ComputerNameNoteProperty, false);
                cnRowDefinition.formatTokenList.Add(propToken);
                _tableBody.defaultDefinition.rowItemDefinitionList.Add(cnRowDefinition);

                // add header only if there are other header definitions
                if (_tableBody.header.columnHeaderDefinitionList.Count > 0)
                {
                    TableColumnHeaderDefinition cnHeaderDefinition = new TableColumnHeaderDefinition();
                    cnHeaderDefinition.label = new TextToken();
                    cnHeaderDefinition.label.text = RemotingConstants.ComputerNameNoteProperty;
                    _tableBody.header.columnHeaderDefinitionList.Add(cnHeaderDefinition);
                }
            }
        }
예제 #38
0
        private ControlBase LoadTableControl(XmlNode controlNode)
        {
            using (this.StackFrame(controlNode))
            {
                TableControlBody tableBody            = new TableControlBody();
                bool             headersNodeFound     = false; // cardinality 0..1
                bool             rowEntriesNodeFound  = false; // cardinality 1
                bool             hideHeadersNodeFound = false; // cardinality 0..1
                bool             autosizeNodeFound    = false; // cardinality 0..1

                foreach (XmlNode n in controlNode.ChildNodes)
                {
                    if (MatchNodeName(n, XmlTags.HideTableHeadersNode))
                    {
                        if (hideHeadersNodeFound)
                        {
                            this.ProcessDuplicateNode(n);
                            return(null); // fatal error
                        }

                        hideHeadersNodeFound = true;
                        if (!this.ReadBooleanNode(n, out tableBody.header.hideHeader))
                        {
                            return(null); //fatal error
                        }
                    }
                    else if (MatchNodeName(n, XmlTags.AutoSizeNode))
                    {
                        if (autosizeNodeFound)
                        {
                            this.ProcessDuplicateNode(n);
                            return(null); // fatal error
                        }
                        autosizeNodeFound = true;
                        bool tempVal;
                        if (!this.ReadBooleanNode(n, out tempVal))
                        {
                            return(null); // fatal error
                        }
                        tableBody.autosize = tempVal;
                    }
                    else if (MatchNodeName(n, XmlTags.TableHeadersNode))
                    {
                        if (headersNodeFound)
                        {
                            this.ProcessDuplicateNode(n);
                            return(null); // fatal error
                        }

                        headersNodeFound = true;

                        // now read the columns header section
                        LoadHeadersSection(tableBody, n);
                        if (tableBody.header.columnHeaderDefinitionList == null)
                        {
                            // if we have an empty list, it means there was a failure
                            return(null); // fatal error
                        }
                    }
                    else if (MatchNodeName(n, XmlTags.TableRowEntriesNode))
                    {
                        if (rowEntriesNodeFound)
                        {
                            this.ProcessDuplicateNode(n);
                            return(null); // fatal error
                        }

                        rowEntriesNodeFound = true;

                        // now read the columns section
                        LoadRowEntriesSection(tableBody, n);
                        if (tableBody.defaultDefinition == null)
                        {
                            return(null); // fatal error
                        }
                    }
                    else
                    {
                        this.ProcessUnknownNode(n);
                    }
                }

                if (!rowEntriesNodeFound)
                {
                    this.ReportMissingNode(XmlTags.TableRowEntriesNode);
                    return(null); // fatal error
                }

                // CHECK: verify consistency of headers and row entries
                if (tableBody.header.columnHeaderDefinitionList.Count != 0)
                {
                    // CHECK: if there are headers in the list, their number has to match
                    // the default row definition item count
                    if (tableBody.header.columnHeaderDefinitionList.Count !=
                        tableBody.defaultDefinition.rowItemDefinitionList.Count)
                    {
                        //Error at XPath {0} in file {1}: Header item count = {2} does not match default row item count = {3}.
                        this.ReportError(StringUtil.Format(FormatAndOutXmlLoadingStrings.IncorrectHeaderItemCount, ComputeCurrentXPath(), FilePath,
                                                           tableBody.header.columnHeaderDefinitionList.Count,
                                                           tableBody.defaultDefinition.rowItemDefinitionList.Count));

                        return(null); // fatal error
                    }
                }

                // CHECK: if there are alternative row definitions, they should have the same # of items
                if (tableBody.optionalDefinitionList.Count != 0)
                {
                    int k = 0;
                    foreach (TableRowDefinition trd in tableBody.optionalDefinitionList)
                    {
                        if (trd.rowItemDefinitionList.Count !=
                            tableBody.defaultDefinition.rowItemDefinitionList.Count)
                        {
                            //Error at XPath {0} in file {1}: Row item count = {2} on alternative set #{3} does not match default row item count = {4}.
                            this.ReportError(StringUtil.Format(FormatAndOutXmlLoadingStrings.IncorrectRowItemCount, ComputeCurrentXPath(), FilePath,
                                                               trd.rowItemDefinitionList.Count,
                                                               tableBody.defaultDefinition.rowItemDefinitionList.Count, k + 1));

                            return(null); // fatal error
                        }
                        k++;
                    }
                }

                return(tableBody);
            }
        }
예제 #39
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>();
             }
         }
     }
 }