Exemplo n.º 1
0
        private static Hashtable SimplifyProperties(Hashtable properties)
        {
            if (properties == null)
            {
                return((Hashtable)null);
            }
            Hashtable             hashtable  = new Hashtable((IEqualityComparer)StringComparer.OrdinalIgnoreCase);
            IDictionaryEnumerator enumerator = properties.GetEnumerator();

            while (enumerator.MoveNext())
            {
                ArrayList arrayList = (ArrayList)enumerator.Value;
                if (arrayList != null && arrayList.Count != 0)
                {
                    if (arrayList.Count == 1 && !MamlNode.IsMamlFormattingPSObject((PSObject)arrayList[0]))
                    {
                        PSObject psObject = (PSObject)arrayList[0];
                        hashtable[enumerator.Key] = (object)psObject;
                    }
                    else
                    {
                        hashtable[enumerator.Key] = (object)arrayList.ToArray(typeof(PSObject));
                    }
                }
            }
            return(hashtable);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Constructor for MamlCommandHelpInfo. This constructor will call the corresponding
        /// constructor in CommandHelpInfo so that xmlNode will be converted a mamlNode.
        /// </summary>
        /// <remarks>
        /// This constructor is intentionally made private so that the only way to create
        /// MamlCommandHelpInfo is through static function
        ///     Load(XmlNode node)
        /// where some sanity check is done.
        /// </remarks>
        private MamlCommandHelpInfo(XmlNode xmlNode, HelpCategory helpCategory) : base(helpCategory)
        {
            MamlNode mamlNode = new MamlNode(xmlNode);

            _fullHelpObject = mamlNode.PSObject;

            this.Errors = mamlNode.Errors;

            // The type name hierarchy for mshObject doesn't necessary
            // reflect the hierarchy in source code. From display's point of
            // view MamlCommandHelpInfo is derived from HelpInfo.

            _fullHelpObject.TypeNames.Clear();
            if (helpCategory == HelpCategory.DscResource)
            {
                _fullHelpObject.TypeNames.Add("DscResourceHelpInfo");
            }
            else
            {
                _fullHelpObject.TypeNames.Add("MamlCommandHelpInfo");
                _fullHelpObject.TypeNames.Add("HelpInfo");
            }

            this.ForwardHelpCategory = HelpCategory.Provider;
        }
Exemplo n.º 3
0
        private ArrayList GetListPSObjects(XmlNode xmlNode)
        {
            ArrayList arrayList = new ArrayList();

            if (xmlNode == null || !xmlNode.LocalName.Equals("list", StringComparison.OrdinalIgnoreCase) || (xmlNode.ChildNodes == null || xmlNode.ChildNodes.Count == 0))
            {
                return(arrayList);
            }
            bool ordered = MamlNode.IsOrderedList(xmlNode);
            int  index   = 1;

            foreach (XmlNode childNode in xmlNode.ChildNodes)
            {
                if (childNode.LocalName.Equals("listItem", StringComparison.OrdinalIgnoreCase))
                {
                    PSObject listItemPsObject = this.GetListItemPSObject(childNode, ordered, ref index);
                    if (listItemPsObject != null)
                    {
                        arrayList.Add((object)listItemPsObject);
                    }
                }
                else
                {
                    this.WriteMamlInvalidChildNodeError(xmlNode, childNode);
                }
            }
            return(arrayList);
        }
Exemplo n.º 4
0
        private static string[] TrimLines(string[] lines)
        {
            if (lines == null || lines.Length == 0)
            {
                return((string[])null);
            }
            int index1 = 0;

            while (index1 < lines.Length && MamlNode.IsEmptyLine(lines[index1]))
            {
                ++index1;
            }
            int num1 = index1;

            if (num1 == lines.Length)
            {
                return((string[])null);
            }
            int index2 = lines.Length - 1;

            while (index2 >= num1 && MamlNode.IsEmptyLine(lines[index2]))
            {
                --index2;
            }
            int num2 = index2;

            string[] strArray = new string[num2 - num1 + 1];
            for (int index3 = num1; index3 <= num2; ++index3)
            {
                strArray[index3 - num1] = lines[index3];
            }
            return(strArray);
        }
Exemplo n.º 5
0
        private PSObject GetPSObject(XmlNode xmlNode)
        {
            if (xmlNode == null)
            {
                return(new PSObject());
            }
            PSObject psObject;

            if (MamlNode.IsAtomic(xmlNode))
            {
                psObject = new PSObject((object)xmlNode.InnerText.Trim());
            }
            else if (MamlNode.IncludeMamlFormatting(xmlNode))
            {
                psObject = new PSObject((object)this.GetMamlFormattingPSObjects(xmlNode));
            }
            else
            {
                psObject = new PSObject((object)this.GetInsidePSObject(xmlNode));
                psObject.TypeNames.Clear();
                psObject.TypeNames.Add("MamlCommandHelpInfo#" + xmlNode.LocalName);
            }
            if (xmlNode.Attributes != null)
            {
                foreach (XmlNode attribute in (XmlNamedNodeMap)xmlNode.Attributes)
                {
                    psObject.Properties.Add((PSPropertyInfo) new PSNoteProperty(attribute.Name, (object)attribute.Value));
                }
            }
            return(psObject);
        }
Exemplo n.º 6
0
 private static string GetNodePath(XmlNode xmlNode)
 {
     if (xmlNode == null)
     {
         return("");
     }
     return(xmlNode.ParentNode == null ? "\\" + xmlNode.LocalName : MamlNode.GetNodePath(xmlNode.ParentNode) + "\\" + xmlNode.LocalName + MamlNode.GetNodeIndex(xmlNode));
 }
Exemplo n.º 7
0
 private ProviderHelpInfo(System.Xml.XmlNode xmlNode)
 {
     MamlNode node = new MamlNode(xmlNode);
     this._fullHelpObject = node.PSObject;
     base.Errors = node.Errors;
     this._fullHelpObject.TypeNames.Clear();
     this._fullHelpObject.TypeNames.Add("ProviderHelpInfo");
     this._fullHelpObject.TypeNames.Add("HelpInfo");
 }
Exemplo n.º 8
0
 private void WriteMamlInvalidChildNodeError(XmlNode node, XmlNode childNode) => this.Errors.Add(new ErrorRecord((Exception) new ParentContainsErrorRecordException("MamlInvalidChildNodeError"), "MamlInvalidChildNodeError", ErrorCategory.SyntaxError, (object)null)
 {
     ErrorDetails = new ErrorDetails(Assembly.GetExecutingAssembly(), "HelpErrors", "MamlInvalidChildNodeError", new object[3]
     {
         (object)node.LocalName,
         (object)childNode.LocalName,
         (object)MamlNode.GetNodePath(node)
     })
 });
Exemplo n.º 9
0
        private ProviderHelpInfo(System.Xml.XmlNode xmlNode)
        {
            MamlNode node = new MamlNode(xmlNode);

            this._fullHelpObject = node.PSObject;
            base.Errors          = node.Errors;
            this._fullHelpObject.TypeNames.Clear();
            this._fullHelpObject.TypeNames.Add("ProviderHelpInfo");
            this._fullHelpObject.TypeNames.Add("HelpInfo");
        }
Exemplo n.º 10
0
        /// <summary>
        /// Constructor for HelpProvider
        /// </summary>
        private ProviderHelpInfo(XmlNode xmlNode)
        {
            MamlNode mamlNode = new MamlNode(xmlNode);
            _fullHelpObject = mamlNode.PSObject;
            this.Errors = mamlNode.Errors;

            _fullHelpObject.TypeNames.Clear();
            _fullHelpObject.TypeNames.Add("ProviderHelpInfo");
            _fullHelpObject.TypeNames.Add("HelpInfo");
        }
Exemplo n.º 11
0
        private static int GetIndentation(string line)
        {
            if (MamlNode.IsEmptyLine(line))
            {
                return(0);
            }
            string str = line.TrimStart(' ');

            return(line.Length - str.Length);
        }
Exemplo n.º 12
0
 protected GeneralHelpInfo(System.Xml.XmlNode xmlNode)
 {
     MamlNode node = new MamlNode(xmlNode);
     this._fullHelpObject = node.PSObject;
     base.Errors = node.Errors;
     this._fullHelpObject.TypeNames.Clear();
     this._fullHelpObject.TypeNames.Add(string.Format(CultureInfo.InvariantCulture, "GeneralHelpInfo#{0}", new object[] { this.Name }));
     this._fullHelpObject.TypeNames.Add("GeneralHelpInfo");
     this._fullHelpObject.TypeNames.Add("HelpInfo");
 }
Exemplo n.º 13
0
 private MamlCommandHelpInfo(System.Xml.XmlNode xmlNode, HelpCategory helpCategory) : base(helpCategory)
 {
     MamlNode node = new MamlNode(xmlNode);
     this._fullHelpObject = node.PSObject;
     base.Errors = node.Errors;
     this._fullHelpObject.TypeNames.Clear();
     this._fullHelpObject.TypeNames.Add("MamlCommandHelpInfo");
     this._fullHelpObject.TypeNames.Add("HelpInfo");
     base.ForwardHelpCategory = HelpCategory.Provider;
 }
Exemplo n.º 14
0
        /// <summary>
        /// Convert a XMLNode to HelpInfo object.
        /// </summary>
        /// <param name="xmlNode"></param>
        /// <param name="helpCategory"></param>
        private MamlClassHelpInfo(XmlNode xmlNode, HelpCategory helpCategory)
        {
            HelpCategory = helpCategory;

            MamlNode mamlNode = new MamlNode(xmlNode);
            _fullHelpObject = mamlNode.PSObject;

            this.Errors = mamlNode.Errors;
            _fullHelpObject.TypeNames.Clear();
            _fullHelpObject.TypeNames.Add("PSClassHelpInfo");
        }
Exemplo n.º 15
0
        protected FaqHelpInfo(System.Xml.XmlNode xmlNode)
        {
            MamlNode node = new MamlNode(xmlNode);

            this._fullHelpObject = node.PSObject;
            base.Errors          = node.Errors;
            this._fullHelpObject.TypeNames.Clear();
            this._fullHelpObject.TypeNames.Add(string.Format(CultureInfo.InvariantCulture, "FaqHelpInfo#{0}", new object[] { this.Name }));
            this._fullHelpObject.TypeNames.Add("FaqHelpInfo");
            this._fullHelpObject.TypeNames.Add("HelpInfo");
        }
Exemplo n.º 16
0
        private MamlCommandHelpInfo(System.Xml.XmlNode xmlNode, HelpCategory helpCategory) : base(helpCategory)
        {
            MamlNode node = new MamlNode(xmlNode);

            this._fullHelpObject = node.PSObject;
            base.Errors          = node.Errors;
            this._fullHelpObject.TypeNames.Clear();
            this._fullHelpObject.TypeNames.Add("MamlCommandHelpInfo");
            this._fullHelpObject.TypeNames.Add("HelpInfo");
            base.ForwardHelpCategory = HelpCategory.Provider;
        }
Exemplo n.º 17
0
        /// <summary>
        /// Constructor for HelpProvider
        /// </summary>
        private ProviderHelpInfo(XmlNode xmlNode)
        {
            MamlNode mamlNode = new MamlNode(xmlNode);

            _fullHelpObject = mamlNode.PSObject;
            this.Errors     = mamlNode.Errors;

            _fullHelpObject.TypeNames.Clear();
            _fullHelpObject.TypeNames.Add("ProviderHelpInfo");
            _fullHelpObject.TypeNames.Add("HelpInfo");
        }
Exemplo n.º 18
0
        private MamlCommandHelpInfo(XmlNode xmlNode, HelpCategory helpCategory)
            : base(helpCategory)
        {
            MamlNode mamlNode = new MamlNode(xmlNode);

            this._fullHelpObject = mamlNode.PSObject;
            this.Errors          = mamlNode.Errors;
            this._fullHelpObject.TypeNames.Clear();
            this._fullHelpObject.TypeNames.Add(nameof(MamlCommandHelpInfo));
            this._fullHelpObject.TypeNames.Add("HelpInfo");
            this.ForwardHelpCategory = HelpCategory.Provider;
        }
Exemplo n.º 19
0
        protected GeneralHelpInfo(XmlNode xmlNode)
        {
            MamlNode mamlNode = new MamlNode(xmlNode);
            _fullHelpObject = mamlNode.PSObject;
            this.Errors = mamlNode.Errors;

            _fullHelpObject.TypeNames.Clear();
            _fullHelpObject.TypeNames.Add(string.Format(Globalization.CultureInfo.InvariantCulture,
                "GeneralHelpInfo#{0}", Name));
            _fullHelpObject.TypeNames.Add("GeneralHelpInfo");
            _fullHelpObject.TypeNames.Add("HelpInfo");
        }
Exemplo n.º 20
0
 private ProviderHelpInfo(XmlNode xmlNode)
 {
     using (ProviderHelpInfo.tracer.TraceConstructor((object) this))
       {
     MamlNode mamlNode = new MamlNode(xmlNode);
     this._fullHelpObject = mamlNode.PSObject;
     this.Errors = mamlNode.Errors;
     this._fullHelpObject.TypeNames.Clear();
     this._fullHelpObject.TypeNames.Add(nameof (ProviderHelpInfo));
     this._fullHelpObject.TypeNames.Add("HelpInfo");
       }
 }
        /// <summary>
        /// Convert a XMLNode to HelpInfo object.
        /// </summary>
        /// <param name="xmlNode"></param>
        /// <param name="helpCategory"></param>
        private MamlClassHelpInfo(XmlNode xmlNode, HelpCategory helpCategory)
        {
            HelpCategory = helpCategory;

            MamlNode mamlNode = new MamlNode(xmlNode);

            _fullHelpObject = mamlNode.PSObject;

            this.Errors = mamlNode.Errors;
            _fullHelpObject.TypeNames.Clear();
            _fullHelpObject.TypeNames.Add("PSClassHelpInfo");
        }
Exemplo n.º 22
0
        protected FaqHelpInfo(XmlNode xmlNode)
        {
            MamlNode mamlNode = new MamlNode(xmlNode);

            _fullHelpObject = mamlNode.PSObject;
            this.Errors     = mamlNode.Errors;

            _fullHelpObject.TypeNames.Clear();
            _fullHelpObject.TypeNames.Add(string.Format(Globalization.CultureInfo.InvariantCulture,
                                                        "FaqHelpInfo#{0}", Name));
            _fullHelpObject.TypeNames.Add("FaqHelpInfo");
            _fullHelpObject.TypeNames.Add("HelpInfo");
        }
Exemplo n.º 23
0
 protected FaqHelpInfo(XmlNode xmlNode)
 {
     using (FaqHelpInfo.tracer.TraceConstructor((object)this))
     {
         MamlNode mamlNode = new MamlNode(xmlNode);
         this._fullHelpObject = mamlNode.PSObject;
         this.Errors          = mamlNode.Errors;
         this._fullHelpObject.TypeNames.Clear();
         this._fullHelpObject.TypeNames.Add(string.Format((IFormatProvider)CultureInfo.InvariantCulture, "FaqHelpInfo#{0}", (object)this.Name));
         this._fullHelpObject.TypeNames.Add(nameof(FaqHelpInfo));
         this._fullHelpObject.TypeNames.Add("HelpInfo");
     }
 }
Exemplo n.º 24
0
 private static bool IncludeMamlFormatting(XmlNode xmlNode)
 {
     if (xmlNode == null || xmlNode.ChildNodes == null || xmlNode.ChildNodes.Count == 0)
     {
         return(false);
     }
     foreach (XmlNode childNode in xmlNode.ChildNodes)
     {
         if (MamlNode.IsMamlFormattingNode(childNode))
         {
             return(true);
         }
     }
     return(false);
 }
Exemplo n.º 25
0
        private static int GetMinIndentation(string[] lines)
        {
            int num = -1;

            for (int index = 0; index < lines.Length; ++index)
            {
                if (!MamlNode.IsEmptyLine(lines[index]))
                {
                    int indentation = MamlNode.GetIndentation(lines[index]);
                    if (num < 0 || indentation < num)
                    {
                        num = indentation;
                    }
                }
            }
            return(num);
        }
Exemplo n.º 26
0
        private Hashtable GetInsideProperties(XmlNode xmlNode)
        {
            Hashtable properties = new Hashtable((IEqualityComparer)StringComparer.OrdinalIgnoreCase);

            if (xmlNode == null)
            {
                return(properties);
            }
            if (xmlNode.ChildNodes != null)
            {
                foreach (XmlNode childNode in xmlNode.ChildNodes)
                {
                    MamlNode.AddProperty(properties, childNode.LocalName, this.GetPSObject(childNode));
                }
            }
            return(MamlNode.SimplifyProperties(properties));
        }
Exemplo n.º 27
0
        private static string GetPreformattedText(string text)
        {
            string[] lines = MamlNode.TrimLines(text.Replace("\t", "    ").Split('\n'));
            if (lines == null || lines.Length == 0)
            {
                return("");
            }
            int minIndentation = MamlNode.GetMinIndentation(lines);

            string[] strArray = new string[lines.Length];
            for (int index = 0; index < lines.Length; ++index)
            {
                strArray[index] = !MamlNode.IsEmptyLine(lines[index]) ? lines[index].Remove(0, minIndentation) : lines[index];
            }
            StringBuilder stringBuilder = new StringBuilder();

            for (int index = 0; index < strArray.Length; ++index)
            {
                stringBuilder.AppendLine(strArray[index]);
            }
            return(stringBuilder.ToString());
        }
Exemplo n.º 28
0
        private PSObject[] GetMamlFormattingPSObjects(XmlNode xmlNode)
        {
            ArrayList arrayList = new ArrayList();

            foreach (XmlNode childNode in xmlNode.ChildNodes)
            {
                if (childNode.LocalName.Equals("para", StringComparison.OrdinalIgnoreCase))
                {
                    PSObject paraPsObject = MamlNode.GetParaPSObject(childNode);
                    if (paraPsObject != null)
                    {
                        arrayList.Add((object)paraPsObject);
                    }
                }
                else if (childNode.LocalName.Equals("list", StringComparison.OrdinalIgnoreCase))
                {
                    ArrayList listPsObjects = this.GetListPSObjects(childNode);
                    for (int index = 0; index < listPsObjects.Count; ++index)
                    {
                        arrayList.Add(listPsObjects[index]);
                    }
                }
                else if (childNode.LocalName.Equals("definitionList", StringComparison.OrdinalIgnoreCase))
                {
                    ArrayList definitionListPsObjects = this.GetDefinitionListPSObjects(childNode);
                    for (int index = 0; index < definitionListPsObjects.Count; ++index)
                    {
                        arrayList.Add(definitionListPsObjects[index]);
                    }
                }
                else
                {
                    this.WriteMamlInvalidChildNodeError(xmlNode, childNode);
                }
            }
            return((PSObject[])arrayList.ToArray(typeof(PSObject)));
        }
Exemplo n.º 29
0
        /// <summary>
        /// Constructor for MamlCommandHelpInfo. This constructor will call the corresponding
        /// constructor in CommandHelpInfo so that xmlNode will be converted a mamlNode. 
        /// </summary>
        /// <remarks>
        /// This constructor is intentionally made private so that the only way to create
        /// MamlCommandHelpInfo is through static function
        ///     Load(XmlNode node)
        /// where some sanity check is done.
        /// </remarks>
        private MamlCommandHelpInfo(XmlNode xmlNode, HelpCategory helpCategory) : base(helpCategory)
        {
            MamlNode mamlNode = new MamlNode(xmlNode);
            _fullHelpObject = mamlNode.PSObject;

            this.Errors = mamlNode.Errors;

            // The type name hierarchy for mshObject doesn't necessary
            // reflect the hierarchy in source code. From display's point of 
            // view MamlCommandHelpInfo is derived from HelpInfo.

            _fullHelpObject.TypeNames.Clear();
            if (helpCategory == HelpCategory.DscResource)
            {
                _fullHelpObject.TypeNames.Add("DscResourceHelpInfo");
            }
            else
            {
                _fullHelpObject.TypeNames.Add("MamlCommandHelpInfo");
                _fullHelpObject.TypeNames.Add("HelpInfo");
            }

            this.ForwardHelpCategory = HelpCategory.Provider;
        }