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])); } }
private ListControlBody LoadListControlFromObjectModel(ListControl list, int viewIndex, string typeName) { ListControlBody listBody = new ListControlBody(); this.LoadListControlEntriesFromObjectModel(listBody, list.Entries, viewIndex, typeName); if (listBody.defaultEntryDefinition == null) { return null; } return listBody; }
/// <summary> /// Load LoisControl into the ListControlBody /// </summary> /// <param name="list"></param> /// <param name="viewIndex"></param> /// <param name="typeName"></param> /// <returns></returns> private ListControlBody LoadListControlFromObjectModel(ListControl list, int viewIndex, string typeName) { ListControlBody listBody = new ListControlBody(); // load the list entries section LoadListControlEntriesFromObjectModel(listBody, list.Entries, viewIndex, typeName); if (listBody.defaultEntryDefinition == null) { return null; // fatal error } return listBody; }
internal ListControlBuilder(ListControl list) { _list = list; }
/// <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); } } }
/// <summary></summary> public static ListControlBuilder Create(bool outOfBand = false) { var list = new ListControl { OutOfBand = false }; return new ListControlBuilder(list); }
internal void WriteListControl(ListControl listControl) { _writer.WriteStartElement("ListControl"); _writer.WriteStartElement("ListEntries"); // write the list entry's one by one foreach (ListControlEntry entry in listControl.Entries) { _writer.WriteStartElement("ListEntry"); // write entry selected by if available WriteEntrySelectedBy(entry.EntrySelectedBy); if (entry.Items.Count > 0) { _writer.WriteStartElement("ListItems"); // write the list items foreach (ListControlEntryItem item in entry.Items) { _writer.WriteStartElement("ListItem"); if (!string.IsNullOrEmpty(item.Label)) { _writer.WriteElementString("Label", item.Label); } if (!string.IsNullOrEmpty(item.FormatString)) { _writer.WriteElementString("FormatString", item.FormatString); } if (item.ItemSelectionCondition != null) { _writer.WriteStartElement("ItemSelectionCondition"); WriteDisplayEntry(item.ItemSelectionCondition); _writer.WriteEndElement(/*</ItemSelectionCondition>*/); } // write the entry WriteDisplayEntry(item.DisplayEntry); _writer.WriteEndElement(/*</ListItem>*/); } _writer.WriteEndElement(/*</ListItems>*/); } _writer.WriteEndElement(/*</ListEntry>*/); } _writer.WriteEndElement(/*</ListEntries>*/); _writer.WriteEndElement(/*</ListControl>*/); }