Exemplo n.º 1
0
        /// <summary>Create a default WideControl</summary>
        public static WideControlBuilder Create(bool outOfBand = false, bool autoSize = false, uint columns = 0)
        {
            var control = new WideControl {
                OutOfBand = false, AutoSize = autoSize, Columns = columns
            };

            return(new WideControlBuilder(control));
        }
Exemplo 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]));
     }
 }
Exemplo n.º 3
0
 internal WideControlBuilder(WideControl control)
 {
     _control = control;
 }
Exemplo n.º 4
0
 private WideControlBody LoadWideControlFromObjectModel(WideControl wide, int viewIndex, string typeName)
 {
     WideControlBody wideBody = new WideControlBody {
         columns = (int) wide.Columns
     };
     this.LoadWideControlEntriesFromObjectModel(wideBody, wide.Entries, viewIndex, typeName);
     if (wideBody.defaultEntryDefinition == null)
     {
         return null;
     }
     return wideBody;
 }
Exemplo n.º 5
0
        /// <summary>
        /// Load the WideControl into the WideControlBody
        /// </summary>
        /// <param name="wide"></param>
        /// <param name="viewIndex"></param>
        /// <param name="typeName"></param>
        /// <returns></returns>
        private WideControlBody LoadWideControlFromObjectModel(WideControl wide, int viewIndex, string typeName)
        {
            WideControlBody wideBody = new WideControlBody();

            // Contains:
            //   Columns --- ColumnNumbers  cardinality 0..1
            //   Entries --- WideEntries    cardinality 1
            wideBody.columns = (int)wide.Columns;

            if (wide.AutoSize)
                wideBody.autosize = true;

            LoadWideControlEntriesFromObjectModel(wideBody, wide.Entries, viewIndex, typeName);
            if (wideBody.defaultEntryDefinition == null)
            {
                // if we have no default entry definition, it means there was a failure
                return null;
            }
            return wideBody;
        }
Exemplo n.º 6
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);
                }
            }
        }
Exemplo n.º 7
0
 /// <summary>Create a default WideControl</summary>
 public static WideControlBuilder Create(bool outOfBand = false, bool autoSize = false, uint columns = 0)
 {
     var control = new WideControl { OutOfBand = false, AutoSize = autoSize, Columns = columns };
     return new WideControlBuilder(control);
 }
Exemplo n.º 8
0
 internal WideControlBuilder(WideControl control)
 {
     _control = control;
 }
Exemplo n.º 9
0
        internal void WriteWideControl(WideControl wideControl)
        {
            _writer.WriteStartElement("WideControl");

            if (wideControl.Columns > 0)
            {
                _writer.WriteElementString("ColumnNumber", wideControl.Columns.ToString(CultureInfo.InvariantCulture));
            }

            if (wideControl.AutoSize)
            {
                _writer.WriteElementString("AutoSize", "");
            }

            _writer.WriteStartElement("WideEntries");
            foreach (WideControlEntryItem entry in wideControl.Entries)
            {
                _writer.WriteStartElement("WideEntry");

                WriteEntrySelectedBy(entry.EntrySelectedBy);

                _writer.WriteStartElement("WideItem");
                WriteDisplayEntry(entry.DisplayEntry);
                if (!string.IsNullOrEmpty(entry.FormatString))
                {
                    _writer.WriteElementString("FormatString", entry.FormatString);
                }
                _writer.WriteEndElement(/*</WideItem>*/);

                _writer.WriteEndElement(/*</WideEntry>*/);
            }
            _writer.WriteEndElement(/*</WideEntries>*/);

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