Ejemplo n.º 1
0
 /// <summary>Group instances by the script block expression with an optional label.</summary>
 public TableControlBuilder GroupByScriptBlock(string scriptBlock, CustomControl customControl = null, string label = null)
 {
     _table.GroupBy = new PSControlGroupBy
     {
         Expression = new DisplayEntry(scriptBlock, DisplayEntryValueType.ScriptBlock),
         CustomControl = customControl,
         Label = label
     };
     return this;
 }
Ejemplo n.º 2
0
        private ComplexControlBody LoadCustomControlFromObjectModel(CustomControl custom, int viewIndex, string typeName)
        {
            if (custom._cachedBody != null)
                return custom._cachedBody;

            var ccb = new ComplexControlBody();

            foreach (var entry in custom.Entries)
            {
                var cced = LoadComplexControlEntryDefinitionFromObjectModel(entry, viewIndex, typeName);
                if (cced.appliesTo == null)
                {
                    ccb.defaultEntry = cced;
                }
                else
                {
                    ccb.optionalEntryList.Add(cced);
                }
            }

            Interlocked.CompareExchange(ref custom._cachedBody, ccb, null);
            return ccb;
        }
 /// <summary/>
 public static CustomControlBuilder Create(bool outOfBand = false)
 {
     var customControl = new CustomControl { OutOfBand = outOfBand };
     return new CustomControlBuilder(customControl);
 }
Ejemplo n.º 4
0
 /// <summary>Group instances by the property name with an optional label.</summary>
 public TableControlBuilder GroupByProperty(string property, CustomControl customControl = null, string label = null)
 {
     _table.GroupBy = new PSControlGroupBy
     {
         Expression = new DisplayEntry(property, DisplayEntryValueType.Property),
         CustomControl = customControl,
         Label = label
     };
     return this;
 }
        /// <summary/>
        public CustomEntryBuilder AddCustomControlExpressionBinding(
            CustomControl customControl,
            bool enumerateCollection = false,
            string selectedByType = null,
            string selectedByScript = null)
        {
            _entryStack.Peek().Add(new CustomItemExpression()
            {
                ItemSelectionCondition = selectedByScript != null
                    ? new DisplayEntry(selectedByScript, DisplayEntryValueType.ScriptBlock)
                    : selectedByType != null
                        ? new DisplayEntry(selectedByType, DisplayEntryValueType.Property)
                        : null,
                EnumerateCollection = enumerateCollection,
                CustomControl = customControl
            });

            return this;
        }
 internal CustomControlBuilder(CustomControl control)
 {
     _control = control;
 }
 /// <summary/>
 public CustomEntryBuilder AddScriptBlockExpressionBinding(
     string scriptBlock,
     bool enumerateCollection = false,
     string selectedByType = null,
     string selectedByScript = null,
     CustomControl customControl = null)
 {
     AddDisplayExpressionBinding(scriptBlock, DisplayEntryValueType.ScriptBlock, enumerateCollection, selectedByType, selectedByScript, customControl);
     return this;
 }
 private void AddDisplayExpressionBinding(
     string value,
     DisplayEntryValueType valueType,
     bool enumerateCollection = false,
     string selectedByType = null,
     string selectedByScript = null,
     CustomControl customControl = null)
 {
     _entryStack.Peek().Add(new CustomItemExpression()
     {
         ItemSelectionCondition = selectedByScript != null
             ? new DisplayEntry(selectedByScript, DisplayEntryValueType.ScriptBlock)
             : selectedByType != null
                 ? new DisplayEntry(selectedByType, DisplayEntryValueType.Property)
                 : null,
         EnumerateCollection = enumerateCollection,
         Expression = new DisplayEntry(value, valueType),
         CustomControl = customControl
     });
 }
Ejemplo n.º 9
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.º 10
0
 internal CustomControlBuilder(CustomControl control)
 {
     _control = control;
 }
Ejemplo n.º 11
0
        internal void WriteCustomControl(CustomControl customControl)
        {
            _writer.WriteStartElement("CustomControl");

            _writer.WriteStartElement("CustomEntries");
            foreach (var entry in customControl.Entries)
            {
                _writer.WriteStartElement("CustomEntry");
                WriteEntrySelectedBy(entry.SelectedBy);
                _writer.WriteStartElement("CustomItem");
                foreach (var item in entry.CustomItems)
                {
                    WriteCustomItem(item);
                }
                _writer.WriteEndElement(/*</CustomItem>*/);
                _writer.WriteEndElement(/*</CustomEntry>*/);
            }
            _writer.WriteEndElement(/*</CustomEntries>*/);
            _writer.WriteEndElement(/*</CustomControl>*/);
        }