/// <summary>Create a default TableControl</summary>
        public static TableControlBuilder Create(bool outOfBand = false, bool autoSize = false, bool hideTableHeaders = false)
        {
            var table = new TableControl {
                OutOfBand = outOfBand, AutoSize = autoSize, HideTableHeaders = hideTableHeaders
            };

            return(new TableControlBuilder(table));
        }
Ejemplo n.º 2
0
 protected override void ProcessRecord()
 {
     List<ViewDefinition> viewDefinitionList = base.Context.FormatDBManager.Database.viewDefinitionsSection.viewDefinitionList;
     Dictionary<string, List<FormatViewDefinition>> dictionary = new Dictionary<string, List<FormatViewDefinition>>();
     foreach (ViewDefinition definition in viewDefinitionList)
     {
         foreach (TypeOrGroupReference reference in definition.appliesTo.referenceList)
         {
             PSControl control = null;
             if (definition.mainControl is TableControlBody)
             {
                 control = new TableControl((TableControlBody) definition.mainControl);
             }
             if (definition.mainControl is ListControlBody)
             {
                 control = new ListControl((ListControlBody) definition.mainControl);
             }
             if (definition.mainControl is WideControlBody)
             {
                 control = new WideControl((WideControlBody) definition.mainControl);
             }
             if (control != null)
             {
                 FormatViewDefinition item = new FormatViewDefinition(definition.name, control, definition.InstanceId);
                 foreach (WildcardPattern pattern in this._filter)
                 {
                     if (pattern.IsMatch(reference.name))
                     {
                         if (!dictionary.ContainsKey(reference.name))
                         {
                             dictionary.Add(reference.name, new List<FormatViewDefinition>());
                         }
                         dictionary[reference.name].Add(item);
                     }
                 }
             }
         }
     }
     foreach (string str in dictionary.Keys)
     {
         base.WriteObject(new ExtendedTypeDefinition(str, dictionary[str]));
     }
 }
Ejemplo n.º 3
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;
 }
Ejemplo n.º 4
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;
        }
 internal TableControlBuilder(TableControl table)
 {
     _table = table;
 }
Ejemplo n.º 6
0
 internal TableControlBuilder(TableControl table)
 {
     _table = table;
 }
Ejemplo n.º 7
0
 /// <summary>Create a default TableControl</summary>
 public static TableControlBuilder Create(bool outOfBand = false, bool autoSize = false, bool hideTableHeaders = false)
 {
     var table = new TableControl { OutOfBand = outOfBand, AutoSize = autoSize, HideTableHeaders = hideTableHeaders };
     return new TableControlBuilder(table);
 }
Ejemplo n.º 8
0
        /// <summary>
        /// Takes out the content from the database and writes them
        /// out
        /// </summary>
        protected override void ProcessRecord()
        {
            bool writeOldWay = PowerShellVersion == null ||
                               PowerShellVersion.Major < 5 ||
                               PowerShellVersion.Build < 11086;

            TypeInfoDataBase db = this.Context.FormatDBManager.Database;

            List<ViewDefinition> viewdefinitions = db.viewDefinitionsSection.viewDefinitionList;
            Dictionary<string, List<string>> typeGroupMap = GetTypeGroupMap(db.typeGroupSection.typeGroupDefinitionList);

            var typedefs = new Dictionary<ConsolidatedString, List<FormatViewDefinition>>(ConsolidatedString.EqualityComparer);

            foreach (ViewDefinition definition in viewdefinitions)
            {
                if (definition.isHelpFormatter)
                    continue;

                var consolidatedTypeName = CreateConsolidatedTypeName(definition, typeGroupMap);

                if (!ShouldGenerateView(consolidatedTypeName))
                    continue;

                PSControl control;

                var tableControlBody = definition.mainControl as TableControlBody;
                if (tableControlBody != null)
                {
                    control = new TableControl(tableControlBody, definition);
                }
                else
                {
                    var listControlBody = definition.mainControl as ListControlBody;
                    if (listControlBody != null)
                    {
                        control = new ListControl(listControlBody, definition);
                    }
                    else
                    {
                        var wideControlBody = definition.mainControl as WideControlBody;
                        if (wideControlBody != null)
                        {
                            control = new WideControl(wideControlBody, definition);
                            if (writeOldWay)
                            {
                                // Alignment was added to WideControl in V2, but wasn't
                                // used.  It was removed in V5, but old PowerShell clients
                                // expect this property or fail to rehydrate the remote object.
                                var psobj = new PSObject(control);
                                psobj.Properties.Add(new PSNoteProperty("Alignment", 0));
                            }
                        }
                        else
                        {
                            var complexControlBody = (ComplexControlBody)definition.mainControl;
                            control = new CustomControl(complexControlBody, definition);
                        }
                    }
                }

                // Older version of PowerShell do not know about something in the control, so
                // don't return it.
                if (writeOldWay && !control.CompatibleWithOldPowerShell())
                    continue;

                var formatdef = new FormatViewDefinition(definition.name, control, definition.InstanceId);

                List<FormatViewDefinition> viewList;
                if (!typedefs.TryGetValue(consolidatedTypeName, out viewList))
                {
                    viewList = new List<FormatViewDefinition>();
                    typedefs.Add(consolidatedTypeName, viewList);
                }
                viewList.Add(formatdef);
            }// foreach(ViewDefinition...

            // write out all the available type definitions
            foreach (var pair in typedefs)
            {
                var typeNames = pair.Key;

                if (writeOldWay)
                {
                    foreach (var typeName in typeNames)
                    {
                        var etd = new ExtendedTypeDefinition(typeName, pair.Value);
                        WriteObject(etd);
                    }
                }
                else
                {
                    var etd = new ExtendedTypeDefinition(typeNames[0], pair.Value);
                    for (int i = 1; i < typeNames.Count; i++)
                    {
                        etd.TypeNames.Add(typeNames[i]);
                    }
                    WriteObject(etd);
                }
            }
        }
Ejemplo n.º 9
0
        internal void WriteTableControl(TableControl tableControl)
        {
            _writer.WriteStartElement("TableControl");
            if (tableControl.AutoSize)
            {
                _writer.WriteElementString("AutoSize", "");
            }
            if (tableControl.HideTableHeaders)
            {
                _writer.WriteElementString("HideTableHeaders", "");
            }

            _writer.WriteStartElement("TableHeaders");
            foreach (TableControlColumnHeader columnheader in tableControl.Headers)
            {
                _writer.WriteStartElement("TableColumnHeader");
                if (!string.IsNullOrEmpty(columnheader.Label))
                {
                    _writer.WriteElementString("Label", columnheader.Label);
                }
                if (columnheader.Width > 0)
                {
                    _writer.WriteElementString("Width", columnheader.Width.ToString(CultureInfo.InvariantCulture));
                }
                if (columnheader.Alignment != Alignment.Undefined)
                {
                    _writer.WriteElementString("Alignment", columnheader.Alignment.ToString());
                }
                _writer.WriteEndElement(/*</TableColumnHeader>*/);
            }
            _writer.WriteEndElement(/*</TableHeaders>*/);

            _writer.WriteStartElement("TableRowEntries");
            foreach (TableControlRow row in tableControl.Rows)
            {
                _writer.WriteStartElement("TableRowEntry");
                if (row.Wrap)
                {
                    _writer.WriteStartElement("Wrap");
                    _writer.WriteEndElement(/*</Wrap>*/);
                }
                if (row.SelectedBy != null)
                {
                    WriteEntrySelectedBy(row.SelectedBy);
                }
                _writer.WriteStartElement("TableColumnItems");
                foreach (TableControlColumn coldefn in row.Columns)
                {
                    _writer.WriteStartElement("TableColumnItem");
                    if (coldefn.Alignment != Alignment.Undefined)
                    {
                        _writer.WriteElementString("Alignment", coldefn.Alignment.ToString());
                    }
                    if (!string.IsNullOrEmpty(coldefn.FormatString))
                    {
                        _writer.WriteElementString("FormatString", coldefn.FormatString);
                    }
                    WriteDisplayEntry(coldefn.DisplayEntry);
                    _writer.WriteEndElement(/*</TableColumnItem>*/);
                }

                _writer.WriteEndElement(/*<TableColumnItems>*/);
                _writer.WriteEndElement(/*<TableRowEntry>*/);
            }
            _writer.WriteEndElement(/*</TableRowEntries>*/);

            _writer.WriteEndElement(/*</TableControl>*/);
        }