Ejemplo n.º 1
0
        private static System.Management.Automation.PSObject GetParaPSObject(System.Xml.XmlNode xmlNode, bool newLine)
        {
            if (xmlNode == null)
            {
                return(null);
            }
            if (!xmlNode.LocalName.Equals("para", StringComparison.OrdinalIgnoreCase))
            {
                return(null);
            }
            System.Management.Automation.PSObject obj2 = new System.Management.Automation.PSObject();
            StringBuilder builder = new StringBuilder();

            if (newLine && !xmlNode.InnerText.Trim().Equals(string.Empty))
            {
                builder.AppendLine(xmlNode.InnerText.Trim());
            }
            else
            {
                builder.Append(xmlNode.InnerText.Trim());
            }
            obj2.Properties.Add(new PSNoteProperty("Text", builder.ToString()));
            obj2.TypeNames.Clear();
            obj2.TypeNames.Add("MamlParaTextItem");
            obj2.TypeNames.Add("MamlTextItem");
            return(obj2);
        }
Ejemplo n.º 2
0
 private System.Management.Automation.PSObject GetPSObject(System.Xml.XmlNode xmlNode)
 {
     if (xmlNode == null)
     {
         return(new System.Management.Automation.PSObject());
     }
     System.Management.Automation.PSObject obj2 = null;
     if (IsAtomic(xmlNode))
     {
         obj2 = new System.Management.Automation.PSObject(string.Copy(xmlNode.InnerText.Trim()));
     }
     else if (IncludeMamlFormatting(xmlNode))
     {
         obj2 = new System.Management.Automation.PSObject(this.GetMamlFormattingPSObjects(xmlNode));
     }
     else
     {
         obj2 = new System.Management.Automation.PSObject(this.GetInsidePSObject(xmlNode));
         obj2.TypeNames.Clear();
         obj2.TypeNames.Add("MamlCommandHelpInfo#" + xmlNode.LocalName);
     }
     if (xmlNode.Attributes != null)
     {
         foreach (System.Xml.XmlNode node in xmlNode.Attributes)
         {
             obj2.Properties.Add(new PSNoteProperty(node.Name, node.Value));
         }
     }
     return(obj2);
 }
Ejemplo n.º 3
0
 /// <summary>
 /// Helper method to set the WriteStreamType property
 /// based on note properties of a PSObject object.
 /// </summary>
 /// <param name="so">PSObject.</param>
 internal void SetStreamTypeFromPSObject(
     System.Management.Automation.PSObject so)
 {
     if (PSObjectHelper.IsWriteErrorStream(so))
     {
         writeStream = WriteStreamType.Error;
     }
     else if (PSObjectHelper.IsWriteWarningStream(so))
     {
         writeStream = WriteStreamType.Warning;
     }
     else if (PSObjectHelper.IsWriteVerboseStream(so))
     {
         writeStream = WriteStreamType.Verbose;
     }
     else if (PSObjectHelper.IsWriteDebugStream(so))
     {
         writeStream = WriteStreamType.Debug;
     }
     else if (PSObjectHelper.IsWriteInformationStream(so))
     {
         writeStream = WriteStreamType.Information;
     }
     else
     {
         writeStream = WriteStreamType.None;
     }
 }
Ejemplo n.º 4
0
        private ArrayList GetListPSObjects(System.Xml.XmlNode xmlNode)
        {
            ArrayList list = new ArrayList();

            if (xmlNode != null)
            {
                if (!xmlNode.LocalName.Equals("list", StringComparison.OrdinalIgnoreCase))
                {
                    return(list);
                }
                if ((xmlNode.ChildNodes == null) || (xmlNode.ChildNodes.Count == 0))
                {
                    return(list);
                }
                bool ordered = IsOrderedList(xmlNode);
                int  index   = 1;
                foreach (System.Xml.XmlNode node in xmlNode.ChildNodes)
                {
                    if (node.LocalName.Equals("listItem", StringComparison.OrdinalIgnoreCase))
                    {
                        System.Management.Automation.PSObject obj2 = this.GetListItemPSObject(node, ordered, ref index);
                        if (obj2 != null)
                        {
                            list.Add(obj2);
                        }
                    }
                    else
                    {
                        this.WriteMamlInvalidChildNodeError(xmlNode, node);
                    }
                }
            }
            return(list);
        }
Ejemplo n.º 5
0
        private static void AddProperty(Hashtable properties, string name, System.Management.Automation.PSObject mshObject)
        {
            ArrayList list = (ArrayList)properties[name];

            if (list == null)
            {
                list             = new ArrayList();
                properties[name] = list;
            }
            if (mshObject != null)
            {
                if ((mshObject.BaseObject is PSCustomObject) || !mshObject.BaseObject.GetType().Equals(typeof(System.Management.Automation.PSObject[])))
                {
                    list.Add(mshObject);
                }
                else
                {
                    System.Management.Automation.PSObject[] baseObject = (System.Management.Automation.PSObject[])mshObject.BaseObject;
                    for (int i = 0; i < baseObject.Length; i++)
                    {
                        list.Add(baseObject[i]);
                    }
                }
            }
        }
Ejemplo n.º 6
0
        private static Hashtable SimplifyProperties(Hashtable properties)
        {
            if (properties == null)
            {
                return(null);
            }
            Hashtable             hashtable  = new Hashtable(StringComparer.OrdinalIgnoreCase);
            IDictionaryEnumerator enumerator = properties.GetEnumerator();

            while (enumerator.MoveNext())
            {
                ArrayList list = (ArrayList)enumerator.Value;
                if ((list != null) && (list.Count != 0))
                {
                    if ((list.Count == 1) && !IsMamlFormattingPSObject((System.Management.Automation.PSObject)list[0]))
                    {
                        System.Management.Automation.PSObject obj2 = (System.Management.Automation.PSObject)list[0];
                        hashtable[enumerator.Key] = obj2;
                    }
                    else
                    {
                        hashtable[enumerator.Key] = list.ToArray(typeof(System.Management.Automation.PSObject));
                    }
                }
            }
            return(hashtable);
        }
Ejemplo n.º 7
0
        private ArrayList GetDefinitionListPSObjects(System.Xml.XmlNode xmlNode)
        {
            ArrayList list = new ArrayList();

            if (xmlNode != null)
            {
                if (!xmlNode.LocalName.Equals("definitionList", StringComparison.OrdinalIgnoreCase))
                {
                    return(list);
                }
                if ((xmlNode.ChildNodes == null) || (xmlNode.ChildNodes.Count == 0))
                {
                    return(list);
                }
                foreach (System.Xml.XmlNode node in xmlNode.ChildNodes)
                {
                    if (node.LocalName.Equals("definitionListItem", StringComparison.OrdinalIgnoreCase))
                    {
                        System.Management.Automation.PSObject definitionListItemPSObject = this.GetDefinitionListItemPSObject(node);
                        if (definitionListItemPSObject != null)
                        {
                            list.Add(definitionListItemPSObject);
                        }
                    }
                    else
                    {
                        this.WriteMamlInvalidChildNodeError(xmlNode, node);
                    }
                }
            }
            return(list);
        }
Ejemplo n.º 8
0
        private System.Management.Automation.PSObject GetListItemPSObject(System.Xml.XmlNode xmlNode, bool ordered, ref int index)
        {
            if (xmlNode == null)
            {
                return(null);
            }
            if (!xmlNode.LocalName.Equals("listItem", StringComparison.OrdinalIgnoreCase))
            {
                return(null);
            }
            string str = "";

            if (xmlNode.ChildNodes.Count > 1)
            {
                this.WriteMamlInvalidChildNodeCountError(xmlNode, "para", 1);
            }
            foreach (System.Xml.XmlNode node in xmlNode.ChildNodes)
            {
                if (node.LocalName.Equals("para", StringComparison.OrdinalIgnoreCase))
                {
                    str = node.InnerText.Trim();
                }
                else
                {
                    this.WriteMamlInvalidChildNodeError(xmlNode, node);
                }
            }
            string str2 = "";

            if (ordered)
            {
                str2 = ((int)index).ToString("d2", CultureInfo.CurrentCulture) + ". ";
                index++;
            }
            else
            {
                str2 = "* ";
            }
            System.Management.Automation.PSObject obj2 = new System.Management.Automation.PSObject();
            obj2.Properties.Add(new PSNoteProperty("Text", str));
            obj2.Properties.Add(new PSNoteProperty("Tag", str2));
            obj2.TypeNames.Clear();
            if (ordered)
            {
                obj2.TypeNames.Add("MamlOrderedListTextItem");
            }
            else
            {
                obj2.TypeNames.Add("MamlUnorderedListTextItem");
            }
            obj2.TypeNames.Add("MamlTextItem");
            return(obj2);
        }
 internal static T GetValueForProperty <T>(this System.Management.Automation.PSObject psObject, string propertyName, T defaultValue, System.Func <object, object> converter)
 {
     try
     {
         var property = System.Linq.Enumerable.FirstOrDefault(psObject.Properties, each => System.String.Equals(each.Name.ToString(), propertyName, System.StringComparison.CurrentCultureIgnoreCase));
         return(property == null ? defaultValue : (T)converter(property.Value));
     }
     catch
     {
     }
     return(defaultValue);
 }
Ejemplo n.º 10
0
        private System.Management.Automation.PSObject GetInsidePSObject(System.Xml.XmlNode xmlNode)
        {
            Hashtable insideProperties = this.GetInsideProperties(xmlNode);

            System.Management.Automation.PSObject obj2 = new System.Management.Automation.PSObject();
            IDictionaryEnumerator enumerator           = insideProperties.GetEnumerator();

            while (enumerator.MoveNext())
            {
                obj2.Properties.Add(new PSNoteProperty((string)enumerator.Key, enumerator.Value));
            }
            return(obj2);
        }
Ejemplo n.º 11
0
        internal static T GetValueForProperty <T>(this System.Management.Automation.PSObject psObject, string propertyName, T defaultValue, System.Func <object, T> converter)
        {
            try
            {
                var property = System.Linq.Enumerable.FirstOrDefault(psObject.Properties, each => System.String.Equals(each.Name.ToString(), propertyName, System.StringComparison.CurrentCultureIgnoreCase));
                return(property == null ? defaultValue : (T)converter(property.Value));
            }
#if DEBUG
            catch (System.Exception E)
            {
                System.Console.Error.WriteLine($"{E.GetType().Name}/{E.Message}/{E.StackTrace}");
            }
#else
            catch
            {
            }
#endif
            return(defaultValue);
        }
Ejemplo n.º 12
0
        internal static bool Contains(this System.Management.Automation.PSObject psObject, string propertyName)
        {
            bool result = false;

            try
            {
                var property = System.Linq.Enumerable.FirstOrDefault(psObject.Properties, each => System.String.Equals(each.Name.ToString(), propertyName, System.StringComparison.CurrentCultureIgnoreCase));
                result = property == null ? false : true;
            }
#if DEBUG
            catch (System.Exception E)
            {
                System.Console.Error.WriteLine($"{E.GetType().Name}/{E.Message}/{E.StackTrace}");
            }
#else
            catch
            {
            }
#endif
            return(result);
        }
Ejemplo n.º 13
0
        private System.Management.Automation.PSObject[] GetMamlFormattingPSObjects(System.Xml.XmlNode xmlNode)
        {
            ArrayList list = new ArrayList();
            int       paraMamlNodeCount = this.GetParaMamlNodeCount(xmlNode.ChildNodes);
            int       num2 = 0;

            foreach (System.Xml.XmlNode node in xmlNode.ChildNodes)
            {
                if (node.LocalName.Equals("para", StringComparison.OrdinalIgnoreCase))
                {
                    num2++;
                    System.Management.Automation.PSObject paraPSObject = GetParaPSObject(node, num2 != paraMamlNodeCount);
                    if (paraPSObject != null)
                    {
                        list.Add(paraPSObject);
                    }
                }
                else if (node.LocalName.Equals("list", StringComparison.OrdinalIgnoreCase))
                {
                    ArrayList listPSObjects = this.GetListPSObjects(node);
                    for (int i = 0; i < listPSObjects.Count; i++)
                    {
                        list.Add(listPSObjects[i]);
                    }
                }
                else if (node.LocalName.Equals("definitionList", StringComparison.OrdinalIgnoreCase))
                {
                    ArrayList definitionListPSObjects = this.GetDefinitionListPSObjects(node);
                    for (int j = 0; j < definitionListPSObjects.Count; j++)
                    {
                        list.Add(definitionListPSObjects[j]);
                    }
                }
                else
                {
                    this.WriteMamlInvalidChildNodeError(xmlNode, node);
                }
            }
            return((System.Management.Automation.PSObject[])list.ToArray(typeof(System.Management.Automation.PSObject)));
        }
Ejemplo n.º 14
0
        private System.Management.Automation.PSObject GetDefinitionListItemPSObject(System.Xml.XmlNode xmlNode)
        {
            if (xmlNode == null)
            {
                return(null);
            }
            if (!xmlNode.LocalName.Equals("definitionListItem", StringComparison.OrdinalIgnoreCase))
            {
                return(null);
            }
            string str            = null;
            string definitionText = null;

            foreach (System.Xml.XmlNode node in xmlNode.ChildNodes)
            {
                if (node.LocalName.Equals("term", StringComparison.OrdinalIgnoreCase))
                {
                    str = node.InnerText.Trim();
                }
                else if (node.LocalName.Equals("definition", StringComparison.OrdinalIgnoreCase))
                {
                    definitionText = this.GetDefinitionText(node);
                }
                else
                {
                    this.WriteMamlInvalidChildNodeError(xmlNode, node);
                }
            }
            if (string.IsNullOrEmpty(str))
            {
                return(null);
            }
            System.Management.Automation.PSObject obj2 = new System.Management.Automation.PSObject();
            obj2.Properties.Add(new PSNoteProperty("Term", str));
            obj2.Properties.Add(new PSNoteProperty("Definition", definitionText));
            obj2.TypeNames.Clear();
            obj2.TypeNames.Add("MamlDefinitionTextItem");
            obj2.TypeNames.Add("MamlTextItem");
            return(obj2);
        }
Ejemplo n.º 15
0
 private System.Management.Automation.PSObject GetDefinitionListItemPSObject(System.Xml.XmlNode xmlNode)
 {
     if (xmlNode == null)
     {
         return null;
     }
     if (!xmlNode.LocalName.Equals("definitionListItem", StringComparison.OrdinalIgnoreCase))
     {
         return null;
     }
     string str = null;
     string definitionText = null;
     foreach (System.Xml.XmlNode node in xmlNode.ChildNodes)
     {
         if (node.LocalName.Equals("term", StringComparison.OrdinalIgnoreCase))
         {
             str = node.InnerText.Trim();
         }
         else if (node.LocalName.Equals("definition", StringComparison.OrdinalIgnoreCase))
         {
             definitionText = this.GetDefinitionText(node);
         }
         else
         {
             this.WriteMamlInvalidChildNodeError(xmlNode, node);
         }
     }
     if (string.IsNullOrEmpty(str))
     {
         return null;
     }
     System.Management.Automation.PSObject obj2 = new System.Management.Automation.PSObject();
     obj2.Properties.Add(new PSNoteProperty("Term", str));
     obj2.Properties.Add(new PSNoteProperty("Definition", definitionText));
     obj2.TypeNames.Clear();
     obj2.TypeNames.Add("MamlDefinitionTextItem");
     obj2.TypeNames.Add("MamlTextItem");
     return obj2;
 }
Ejemplo n.º 16
0
 internal static System.Collections.Generic.IEnumerable <System.Collections.Generic.KeyValuePair <object, object> > GetFilteredProperties(this System.Management.Automation.PSObject instance, global::System.Collections.Generic.HashSet <string> exclusions = null, global::System.Collections.Generic.HashSet <string> inclusions = null)
 {
     // new global::System.Collections.Generic.HashSet<string>(System.StringComparer.InvariantCultureIgnoreCase)
     return((null == instance || !instance.Properties.Any()) ?
            Enumerable.Empty <System.Collections.Generic.KeyValuePair <object, object> >() :
            instance.Properties
            .Where(property =>
                   !(true == exclusions?.Contains(property.Name)) &&
                   (false != inclusions?.Contains(property.Name)))
            .Select(property => new System.Collections.Generic.KeyValuePair <object, object>(property.Name, property.Value)));
 }
Ejemplo n.º 17
0
 private System.Management.Automation.PSObject GetPSObject(System.Xml.XmlNode xmlNode)
 {
     if (xmlNode == null)
     {
         return new System.Management.Automation.PSObject();
     }
     System.Management.Automation.PSObject obj2 = null;
     if (IsAtomic(xmlNode))
     {
         obj2 = new System.Management.Automation.PSObject(string.Copy(xmlNode.InnerText.Trim()));
     }
     else if (IncludeMamlFormatting(xmlNode))
     {
         obj2 = new System.Management.Automation.PSObject(this.GetMamlFormattingPSObjects(xmlNode));
     }
     else
     {
         obj2 = new System.Management.Automation.PSObject(this.GetInsidePSObject(xmlNode));
         obj2.TypeNames.Clear();
         obj2.TypeNames.Add("MamlCommandHelpInfo#" + xmlNode.LocalName);
     }
     if (xmlNode.Attributes != null)
     {
         foreach (System.Xml.XmlNode node in xmlNode.Attributes)
         {
             obj2.Properties.Add(new PSNoteProperty(node.Name, node.Value));
         }
     }
     return obj2;
 }
Ejemplo n.º 18
0
 private static System.Management.Automation.PSObject GetParaPSObject(System.Xml.XmlNode xmlNode, bool newLine)
 {
     if (xmlNode == null)
     {
         return null;
     }
     if (!xmlNode.LocalName.Equals("para", StringComparison.OrdinalIgnoreCase))
     {
         return null;
     }
     System.Management.Automation.PSObject obj2 = new System.Management.Automation.PSObject();
     StringBuilder builder = new StringBuilder();
     if (newLine && !xmlNode.InnerText.Trim().Equals(string.Empty))
     {
         builder.AppendLine(xmlNode.InnerText.Trim());
     }
     else
     {
         builder.Append(xmlNode.InnerText.Trim());
     }
     obj2.Properties.Add(new PSNoteProperty("Text", builder.ToString()));
     obj2.TypeNames.Clear();
     obj2.TypeNames.Add("MamlParaTextItem");
     obj2.TypeNames.Add("MamlTextItem");
     return obj2;
 }
Ejemplo n.º 19
0
 private System.Management.Automation.PSObject GetListItemPSObject(System.Xml.XmlNode xmlNode, bool ordered, ref int index)
 {
     if (xmlNode == null)
     {
         return null;
     }
     if (!xmlNode.LocalName.Equals("listItem", StringComparison.OrdinalIgnoreCase))
     {
         return null;
     }
     string str = "";
     if (xmlNode.ChildNodes.Count > 1)
     {
         this.WriteMamlInvalidChildNodeCountError(xmlNode, "para", 1);
     }
     foreach (System.Xml.XmlNode node in xmlNode.ChildNodes)
     {
         if (node.LocalName.Equals("para", StringComparison.OrdinalIgnoreCase))
         {
             str = node.InnerText.Trim();
         }
         else
         {
             this.WriteMamlInvalidChildNodeError(xmlNode, node);
         }
     }
     string str2 = "";
     if (ordered)
     {
         str2 = ((int) index).ToString("d2", CultureInfo.CurrentCulture) + ". ";
         index++;
     }
     else
     {
         str2 = "* ";
     }
     System.Management.Automation.PSObject obj2 = new System.Management.Automation.PSObject();
     obj2.Properties.Add(new PSNoteProperty("Text", str));
     obj2.Properties.Add(new PSNoteProperty("Tag", str2));
     obj2.TypeNames.Clear();
     if (ordered)
     {
         obj2.TypeNames.Add("MamlOrderedListTextItem");
     }
     else
     {
         obj2.TypeNames.Add("MamlUnorderedListTextItem");
     }
     obj2.TypeNames.Add("MamlTextItem");
     return obj2;
 }
Ejemplo n.º 20
0
        private static bool IsMamlFormattingPSObject(System.Management.Automation.PSObject mshObject)
        {
            Collection <string> typeNames = mshObject.TypeNames;

            return(((typeNames != null) && (typeNames.Count != 0)) && typeNames[typeNames.Count - 1].Equals("MamlTextItem", StringComparison.OrdinalIgnoreCase));
        }
Ejemplo n.º 21
0
 internal static System.Collections.Generic.IEnumerable <object> GetPropertyKeys(this System.Management.Automation.PSObject instance)
 {
     if (null != instance)
     {
         foreach (var each in instance.Properties)
         {
             yield return(each);
         }
     }
 }
Ejemplo n.º 22
0
 private System.Management.Automation.PSObject GetInsidePSObject(System.Xml.XmlNode xmlNode)
 {
     Hashtable insideProperties = this.GetInsideProperties(xmlNode);
     System.Management.Automation.PSObject obj2 = new System.Management.Automation.PSObject();
     IDictionaryEnumerator enumerator = insideProperties.GetEnumerator();
     while (enumerator.MoveNext())
     {
         obj2.Properties.Add(new PSNoteProperty((string) enumerator.Key, enumerator.Value));
     }
     return obj2;
 }