Ejemplo n.º 1
0
        private void GetChildItemsOrNames(string path, ProviderMethods methodname, bool recurse)
        {
            Dictionary<string, object> sessionObjCache = WSManHelper.GetSessionObjCache();
            if (path.Length == 0)
            {
                switch (methodname)
                {
                    case ProviderMethods.GetChildItems:
                    {
                        PSObject psobject = this.BuildHostLevelPSObjectArrayList(null, "", true);
                        this.WritePSObjectPropertiesAsWSManElementObjects(psobject, "WSMan", null, "ComputerLevel", WsManElementObjectTypes.WSManConfigContainerElement, recurse);
                        return;
                    }
                    case ProviderMethods.GetChildNames:
                        foreach (string str in sessionObjCache.Keys)
                        {
                            base.WriteItemObject(str, "WSMan", true);
                        }
                        return;
                }
            }
            else
            {
                char ch = '\\';
                if (path.EndsWith(ch.ToString(), StringComparison.OrdinalIgnoreCase))
                {
                    path = path.Remove(path.LastIndexOf('\\'));
                }
                string hostName = this.GetHostName(path);
                if (string.IsNullOrEmpty(hostName))
                {
                    throw new InvalidOperationException("InvalidPath");
                }
                if (this.IsPathLocalMachine(hostName) && !this.IsWSManServiceRunning())
                {
                    if (methodname.Equals(ProviderMethods.GetChildItems))
                    {
                        WSManHelper.ThrowIfNotAdministrator();
                        this.StartWSManService((bool) base.Force);
                    }
                    else if (methodname.Equals(ProviderMethods.GetChildNames))
                    {
                        this.AssertError("WinRMServiceError", false);
                    }
                }
                lock (WSManHelper.AutoSession)
                {
                    object obj3;
                    XmlDocument document;
                    string str5;
                    string str6;
                    sessionObjCache.TryGetValue(hostName, out obj3);
                    string uri = this.NormalizePath(path, hostName);
                    string str4 = hostName + '\\';
                    if (path.EndsWith(hostName, StringComparison.OrdinalIgnoreCase))
                    {
                        PSObject obj4 = this.BuildHostLevelPSObjectArrayList(obj3, uri, false);
                        switch (methodname)
                        {
                            case ProviderMethods.GetChildItems:
                                this.WritePSObjectPropertiesAsWSManElementObjects(obj4, path, null, null, WsManElementObjectTypes.WSManConfigLeafElement, recurse);
                                break;

                            case ProviderMethods.GetChildNames:
                                this.WritePSObjectPropertyNames(obj4, path);
                                break;
                        }
                    }
                    else
                    {
                        document = this.FindResourceValue(obj3, uri, null);
                        if ((document != null) && document.HasChildNodes)
                        {
                            if (path.Contains(str4 + "Listener"))
                            {
                                this.GetChildItemOrNamesForListenerOrCertMapping(document, "Listener", path, hostName, methodname, recurse);
                            }
                            else if (path.Contains(str4 + "ClientCertificate"))
                            {
                                this.GetChildItemOrNamesForListenerOrCertMapping(document, "ClientCertificate", path, hostName, methodname, recurse);
                            }
                            else
                            {
                                if (!path.Contains(str4 + "Plugin"))
                                {
                                    goto Label_0A51;
                                }
                                str5 = string.Empty;
                                this.GetPluginNames(document, out this.objPluginNames, out str5, path);
                                if (!path.EndsWith(str4 + "Plugin", StringComparison.OrdinalIgnoreCase))
                                {
                                    goto Label_0302;
                                }
                                switch (methodname)
                                {
                                    case ProviderMethods.GetChildItems:
                                        foreach (PSPropertyInfo info in this.objPluginNames.Properties)
                                        {
                                            PSObject obj5 = new PSObject();
                                            obj5.Properties.Add(new PSNoteProperty(info.Name, info.Value));
                                            this.WritePSObjectPropertiesAsWSManElementObjects(obj5, path, new string[] { "Name=" + info.Name }, null, WsManElementObjectTypes.WSManConfigContainerElement, recurse);
                                        }
                                        break;

                                    case ProviderMethods.GetChildNames:
                                        goto Label_02F0;
                                }
                            }
                        }
                    }
                    goto Label_0B27;
                Label_02F0:
                    this.WritePSObjectPropertyNames(this.objPluginNames, path);
                    goto Label_0B27;
                Label_0302:
                    str6 = uri + "?Name=" + str5;
                    XmlDocument xmldoc = this.GetResourceValue(obj3, str6, null);
                    if (xmldoc != null)
                    {
                        PSObject obj6 = this.ProcessPluginConfigurationLevel(xmldoc, true);
                        ArrayList arrSecurity = null;
                        ArrayList list2 = this.ProcessPluginResourceLevel(xmldoc, out arrSecurity);
                        ArrayList list3 = this.ProcessPluginInitParamLevel(xmldoc);
                        str4 = str4 + "Plugin" + '\\';
                        if (path.EndsWith(str4 + str5, StringComparison.OrdinalIgnoreCase))
                        {
                            switch (methodname)
                            {
                                case ProviderMethods.GetChildItems:
                                    this.WritePSObjectPropertiesAsWSManElementObjects(obj6, path, null, null, WsManElementObjectTypes.WSManConfigLeafElement, recurse);
                                    break;

                                case ProviderMethods.GetChildNames:
                                    this.WritePSObjectPropertyNames(obj6, path);
                                    break;
                            }
                        }
                        else if (path.EndsWith("Quotas", StringComparison.OrdinalIgnoreCase))
                        {
                            XmlNodeList elementsByTagName = xmldoc.GetElementsByTagName("Quotas");
                            if (elementsByTagName.Count > 0)
                            {
                                XmlNode node = elementsByTagName[0];
                                foreach (XmlAttribute attribute in node.Attributes)
                                {
                                    string str7 = string.Format(CultureInfo.InvariantCulture, "{0}{1}{2}", new object[] { path, '\\', attribute.Name });
                                    if (methodname == ProviderMethods.GetChildNames)
                                    {
                                        base.WriteItemObject(attribute.Name, str7, false);
                                    }
                                    else
                                    {
                                        PSObject item = this.GetItemPSObjectWithTypeName(attribute.Name, attribute.Value.GetType().ToString(), attribute.Value, null, null, WsManElementObjectTypes.WSManConfigLeafElement, null);
                                        base.WriteItemObject(item, str7, false);
                                    }
                                }
                            }
                        }
                        else if (path.Contains(string.Concat(new object[] { str4, str5, '\\', "Resources" })))
                        {
                            str4 = str4 + str5 + '\\';
                            if (path.EndsWith(str4 + "Resources", StringComparison.OrdinalIgnoreCase) && (list2 != null))
                            {
                                foreach (PSObject obj8 in list2)
                                {
                                    switch (methodname)
                                    {
                                        case ProviderMethods.GetChildItems:
                                        {
                                            string[] keys = new string[] { "Uri" + '=' + obj8.Properties["ResourceURI"].Value.ToString() };
                                            PSObject obj9 = new PSObject();
                                            obj9.Properties.Add(new PSNoteProperty(obj8.Properties["ResourceDir"].Value.ToString(), "Container"));
                                            this.WritePSObjectPropertiesAsWSManElementObjects(obj9, path, keys, null, WsManElementObjectTypes.WSManConfigContainerElement, recurse);
                                            break;
                                        }
                                        case ProviderMethods.GetChildNames:
                                            base.WriteItemObject(obj8.Properties["ResourceDir"].Value.ToString(), path, true);
                                            break;
                                    }
                                }
                            }
                            else
                            {
                                str4 = str4 + "Resources" + '\\';
                                int index = path.IndexOf('\\', str4.Length);
                                string str8 = string.Empty;
                                if (index == -1)
                                {
                                    str8 = path.Substring(str4.Length);
                                }
                                else
                                {
                                    str8 = path.Substring(str4.Length, path.IndexOf('\\', str4.Length) - str4.Length);
                                }
                                if ((list2 != null) && path.Contains(str4 + str8))
                                {
                                    if (path.EndsWith(str4 + str8, StringComparison.OrdinalIgnoreCase))
                                    {
                                        foreach (PSObject obj10 in list2)
                                        {
                                            if (str8.Equals(obj10.Properties["ResourceDir"].Value.ToString()))
                                            {
                                                obj10.Properties.Remove("ResourceDir");
                                                switch (methodname)
                                                {
                                                    case ProviderMethods.GetChildItems:
                                                        this.WritePSObjectPropertiesAsWSManElementObjects(obj10, path, null, null, WsManElementObjectTypes.WSManConfigLeafElement, recurse);
                                                        break;

                                                    case ProviderMethods.GetChildNames:
                                                        this.WritePSObjectPropertyNames(obj10, path);
                                                        break;
                                                }
                                            }
                                        }
                                    }
                                    else
                                    {
                                        str4 = str4 + str8 + '\\';
                                        if ((path.EndsWith(str4 + "Security", StringComparison.OrdinalIgnoreCase) || path.Contains('\\' + "Security_")) && (arrSecurity != null))
                                        {
                                            foreach (PSObject obj11 in arrSecurity)
                                            {
                                                if (str8.Equals(obj11.Properties["ResourceDir"].Value.ToString(), StringComparison.OrdinalIgnoreCase))
                                                {
                                                    if (path.EndsWith(str4 + "Security", StringComparison.OrdinalIgnoreCase))
                                                    {
                                                        obj11.Properties.Remove("ResourceDir");
                                                        switch (methodname)
                                                        {
                                                            case ProviderMethods.GetChildItems:
                                                            {
                                                                string str9 = "Uri" + '=' + obj11.Properties["Uri"].Value.ToString();
                                                                PSObject obj12 = new PSObject();
                                                                obj12.Properties.Add(new PSNoteProperty(obj11.Properties["SecurityDIR"].Value.ToString(), "Container"));
                                                                this.WritePSObjectPropertiesAsWSManElementObjects(obj12, path, new string[] { str9 }, null, WsManElementObjectTypes.WSManConfigContainerElement, recurse);
                                                                break;
                                                            }
                                                            case ProviderMethods.GetChildNames:
                                                                base.WriteItemObject(obj11.Properties["SecurityDIR"].Value.ToString(), path, true);
                                                                break;
                                                        }
                                                    }
                                                    else if (path.Substring(path.LastIndexOf('\\') + 1, path.Length - (path.LastIndexOf('\\') + 1)).Equals(obj11.Properties["SecurityDIR"].Value.ToString(), StringComparison.OrdinalIgnoreCase))
                                                    {
                                                        obj11.Properties.Remove("ResourceDir");
                                                        obj11.Properties.Remove("SecurityDIR");
                                                        switch (methodname)
                                                        {
                                                            case ProviderMethods.GetChildItems:
                                                                this.WritePSObjectPropertiesAsWSManElementObjects(obj11, path, null, null, WsManElementObjectTypes.WSManConfigLeafElement, recurse);
                                                                break;

                                                            case ProviderMethods.GetChildNames:
                                                                this.WritePSObjectPropertyNames(obj11, path);
                                                                break;
                                                        }
                                                    }
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                        else if (path.EndsWith(string.Concat(new object[] { hostName, '\\', "Plugin", '\\', str5, '\\', "InitializationParameters" }), StringComparison.OrdinalIgnoreCase) && (list3 != null))
                        {
                            foreach (PSObject obj13 in list3)
                            {
                                switch (methodname)
                                {
                                    case ProviderMethods.GetChildItems:
                                        this.WritePSObjectPropertiesAsWSManElementObjects(obj13, path, null, "InitParams", WsManElementObjectTypes.WSManConfigLeafElement, recurse);
                                        break;

                                    case ProviderMethods.GetChildNames:
                                        this.WritePSObjectPropertyNames(obj13, path);
                                        break;
                                }
                            }
                        }
                    }
                    goto Label_0B27;
                Label_0A51:
                    if (((path.EndsWith("Service", StringComparison.OrdinalIgnoreCase) || path.EndsWith("TrustedHosts", StringComparison.OrdinalIgnoreCase)) || (path.EndsWith("Client", StringComparison.OrdinalIgnoreCase) || path.EndsWith("DefaultPorts", StringComparison.OrdinalIgnoreCase))) || (path.EndsWith("Auth", StringComparison.OrdinalIgnoreCase) || path.EndsWith("Shell", StringComparison.OrdinalIgnoreCase)))
                    {
                        foreach (XmlNode node2 in document.ChildNodes)
                        {
                            PSObject obj14 = this.ConvertToPSObject(node2);
                            switch (methodname)
                            {
                                case ProviderMethods.GetChildItems:
                                    this.WritePSObjectPropertiesAsWSManElementObjects(obj14, path, null, null, WsManElementObjectTypes.WSManConfigLeafElement, recurse);
                                    break;

                                case ProviderMethods.GetChildNames:
                                    this.WritePSObjectPropertyNames(obj14, path);
                                    break;
                            }
                        }
                    }
                Label_0B27:;
                }
            }
        }
Ejemplo n.º 2
0
 private void GetChildItemOrNamesForListenerOrCertMapping(XmlDocument xmlResource, string ListenerOrCerMapping, string path, string host, ProviderMethods methodname, bool recurse)
 {
     Hashtable hashtable;
     Hashtable hashtable2;
     if (ListenerOrCerMapping.Equals("ClientCertificate"))
     {
         this.ProcessCertMappingObjects(xmlResource, out hashtable, out hashtable2);
     }
     else if (ListenerOrCerMapping.Equals("Listener"))
     {
         this.ProcessListernerObjects(xmlResource, out hashtable, out hashtable2);
     }
     else
     {
         return;
     }
     if ((hashtable != null) && (hashtable2 != null))
     {
         if (path.EndsWith(host + '\\' + ListenerOrCerMapping, StringComparison.OrdinalIgnoreCase))
         {
             foreach (string str in hashtable2.Keys)
             {
                 switch (methodname)
                 {
                     case ProviderMethods.GetChildItems:
                     {
                         PSObject psobject = new PSObject();
                         psobject.Properties.Add(new PSNoteProperty(str, "Container"));
                         this.WritePSObjectPropertiesAsWSManElementObjects(psobject, path, (string[]) hashtable2[str], null, WsManElementObjectTypes.WSManConfigContainerElement, recurse);
                         break;
                     }
                     case ProviderMethods.GetChildNames:
                         base.WriteItemObject(str, path, true);
                         break;
                 }
             }
         }
         else
         {
             string str2 = path.Substring(path.LastIndexOf('\\') + 1);
             if (methodname.Equals(ProviderMethods.GetChildItems))
             {
                 this.WritePSObjectPropertiesAsWSManElementObjects((PSObject) hashtable[str2], path, null, null, WsManElementObjectTypes.WSManConfigLeafElement, recurse);
             }
             else if (methodname.Equals(ProviderMethods.GetChildNames))
             {
                 foreach (PSPropertyInfo info in ((PSObject) hashtable[str2]).Properties)
                 {
                     base.WriteItemObject(info.Name, path + '\\' + info.Name, false);
                 }
             }
         }
     }
 }
Ejemplo n.º 3
0
 private void GetChildItemsRecurse(string path, string childname, ProviderMethods methodname, bool recurse)
 {
     if (path.Equals("WSMan"))
     {
         path = childname;
     }
     else
     {
         path = path + '\\' + childname;
     }
     if (this.HasChildItems(path))
     {
         this.GetChildItemsOrNames(path, ProviderMethods.GetChildItems, recurse);
     }
 }
Ejemplo n.º 4
0
        private void GetChildItemsOrNames(string path, ProviderMethods methodname, bool recurse)
        {
            Dictionary<string, object> SessionObjCache = WSManHelper.GetSessionObjCache();
            if (path.Length == 0)
            {
                switch (methodname)
                {
                    case ProviderMethods.GetChildItems:
                        PSObject obj = BuildHostLevelPSObjectArrayList(null, "", true);
                        WritePSObjectPropertiesAsWSManElementObjects(obj, WSManStringLiterals.rootpath, null,
                            "ComputerLevel", WsManElementObjectTypes.WSManConfigContainerElement, recurse);
                        break;
                    case ProviderMethods.GetChildNames:
                        foreach (string hostname in SessionObjCache.Keys)
                        {
                            WriteItemObject(hostname, WSManStringLiterals.rootpath, true);
                        }
                        break;
                }
                return;
            }

            //if endswith '\', removes it.
            if (path.EndsWith(WSManStringLiterals.DefaultPathSeparator.ToString(), StringComparison.OrdinalIgnoreCase))
            {
                path = path.Remove(path.LastIndexOf(WSManStringLiterals.DefaultPathSeparator));
            }

            //Get the wsman host name to find the session object
            string host = GetHostName(path);
            if (String.IsNullOrEmpty(host))
            {
                throw new InvalidOperationException("InvalidPath");
            }


            //Checks the WinRM Service
            if (IsPathLocalMachine(host))
            {
                if (!IsWSManServiceRunning())
                {
                    if (methodname.Equals(ProviderMethods.GetChildItems))
                    {
                        WSManHelper.ThrowIfNotAdministrator();
                        StartWSManService(Force);
                    }
                    else if (methodname.Equals(ProviderMethods.GetChildNames))
                    {
                        AssertError("WinRMServiceError", false);
                    }
                }
            }
            lock(WSManHelper.AutoSession)
            {
                object sessionobj;
                //gets the sessionobject
                SessionObjCache.TryGetValue(host, out sessionobj);

                //Normalize to the required uri
                string uri = NormalizePath(path, host);

                string strPathchk = host + WSManStringLiterals.DefaultPathSeparator;

                if (path.EndsWith(host, StringComparison.OrdinalIgnoreCase))
                {
                    PSObject obj = BuildHostLevelPSObjectArrayList(sessionobj, uri, false);
                    switch (methodname)
                    {
                        //Get the items at Config level
                        case ProviderMethods.GetChildItems:
                            WritePSObjectPropertiesAsWSManElementObjects(obj, path, null, null, WsManElementObjectTypes.WSManConfigLeafElement, recurse);
                            break;
                        //Get the names of container at config level
                        case ProviderMethods.GetChildNames:
                            WritePSObjectPropertyNames(obj, path);
                            break;
                    }
                    return;
                }
                XmlDocument outxml = FindResourceValue(sessionobj, uri, null);
                if (outxml == null || !outxml.HasChildNodes)
                {
                    return;
                }
                if (path.Contains(strPathchk + WSManStringLiterals.containerListener))
                {
                    GetChildItemOrNamesForListenerOrCertMapping(outxml, WSManStringLiterals.containerListener, path, host, methodname, recurse);
                }
                else if (path.Contains(strPathchk + WSManStringLiterals.containerClientCertificate))
                {
                    GetChildItemOrNamesForListenerOrCertMapping(outxml, WSManStringLiterals.containerClientCertificate, path, host, methodname, recurse);
                }
                else if (path.Contains(strPathchk + WSManStringLiterals.containerPlugin))
                {
                    string currentpluginname = String.Empty;
                    GetPluginNames(outxml, out objPluginNames, out currentpluginname, path);
                    if (path.EndsWith(strPathchk + WSManStringLiterals.containerPlugin, StringComparison.OrdinalIgnoreCase))
                    {
                        switch (methodname)
                        {
                            //Get the items at Plugin level
                            case ProviderMethods.GetChildItems:
                                foreach (PSPropertyInfo p in objPluginNames.Properties)
                                {
                                    PSObject obj = new PSObject();
                                    obj.Properties.Add(new PSNoteProperty(p.Name, p.Value));
                                    WritePSObjectPropertiesAsWSManElementObjects(obj, path, new string[] { "Name=" + p.Name }, null, WsManElementObjectTypes.WSManConfigContainerElement, recurse);
                                    //WriteItemObject(new PSObject(new WSManConfigContainerElement(p.Name, p.Value.ToString(), new string[] { "Name=" + p.Name })), path + WSManStringLiterals.DefaultPathSeparator + p.Name, true);
                                }
                                break;
                            //Get the names of container at Plugin level
                            case ProviderMethods.GetChildNames:
                                WritePSObjectPropertyNames(objPluginNames, path);
                                break;
                        }
                        return;
                    }
                    else
                    {
                        string filter = uri + "?Name=" + currentpluginname;
                        XmlDocument CurrentPluginXML = GetResourceValue(sessionobj, filter, null);
                        if (null == CurrentPluginXML)
                        {
                            return;
                        }
                        PSObject objPluginlevel = ProcessPluginConfigurationLevel(CurrentPluginXML, true);
                        ArrayList arrSecurity = null;
                        ArrayList arrResources = ProcessPluginResourceLevel(CurrentPluginXML, out arrSecurity);
                        ArrayList arrInitParams = ProcessPluginInitParamLevel(CurrentPluginXML);
                        strPathchk = strPathchk + WSManStringLiterals.containerPlugin + WSManStringLiterals.DefaultPathSeparator;
                        if (path.EndsWith(strPathchk + currentpluginname, StringComparison.OrdinalIgnoreCase))
                        {
                            switch (methodname)
                            {
                                //Get the items at Plugin level
                                case ProviderMethods.GetChildItems:
                                    WritePSObjectPropertiesAsWSManElementObjects(objPluginlevel, path, null, null, WsManElementObjectTypes.WSManConfigLeafElement, recurse);
                                    break;
                                //Get the names of container at Plugin level
                                case ProviderMethods.GetChildNames:
                                    WritePSObjectPropertyNames(objPluginlevel, path);
                                    break;
                            }
                            return;

                        }
                        else if(path.EndsWith(WSManStringLiterals.containerQuotasParameters, StringComparison.OrdinalIgnoreCase))
                        {
                            // Get the Quotas element from the config XML.
                            XmlNodeList nodeListForQuotas = CurrentPluginXML.GetElementsByTagName(WSManStringLiterals.containerQuotasParameters);
                            if (nodeListForQuotas.Count > 0)
                            {
                                XmlNode pluginQuotas = nodeListForQuotas[0];
                                foreach (XmlAttribute attrOfQuotas in pluginQuotas.Attributes)
                                {
                                    String pathToAdd =
                                        String.Format(
                                                  CultureInfo.InvariantCulture,
                                                  "{0}{1}{2}",
                                                  path,
                                                  WSManStringLiterals.DefaultPathSeparator,
                                                  attrOfQuotas.Name);
                                    if (methodname == ProviderMethods.GetChildNames)
                                    {
                                        WriteItemObject(attrOfQuotas.Name, pathToAdd, false);
                                    }
                                    else
                                    {
                                        PSObject objectToAdd =
                                        GetItemPSObjectWithTypeName(
                                            attrOfQuotas.Name,
                                            attrOfQuotas.Value.GetType().ToString(),
                                            attrOfQuotas.Value,
                                            null,
                                            null,
                                            WsManElementObjectTypes.WSManConfigLeafElement);

                                        WriteItemObject(objectToAdd, pathToAdd, false);
                                    }                                    
                                }
                            }
                        }
                        else if (path.Contains(strPathchk + currentpluginname + WSManStringLiterals.DefaultPathSeparator + WSManStringLiterals.containerResources))
                        {
                            strPathchk = strPathchk + currentpluginname + WSManStringLiterals.DefaultPathSeparator;
                            if (path.EndsWith(strPathchk + WSManStringLiterals.containerResources, StringComparison.OrdinalIgnoreCase))
                            {
                                if (null != arrResources)
                                {
                                    foreach (PSObject p in arrResources)
                                    {
                                        switch (methodname)
                                        {
                                            //Get the items at Plugin level
                                            case ProviderMethods.GetChildItems:
                                                string[] key = new string[] { "Uri" + WSManStringLiterals.Equalto + p.Properties["ResourceURI"].Value.ToString() };
                                                PSObject obj = new PSObject();
                                                obj.Properties.Add(new PSNoteProperty(p.Properties["ResourceDir"].Value.ToString(), WSManStringLiterals.ContainerChildValue));
                                                WritePSObjectPropertiesAsWSManElementObjects(obj, path, key, null, WsManElementObjectTypes.WSManConfigContainerElement, recurse);



                                                //WriteItemObject(new WSManConfigContainerElement(p.Properties["ResourceDir"].Value.ToString(), WSManStringLiterals.ContainerChildValue, key), path + WSManStringLiterals.DefaultPathSeparator + p.Properties["ResourceDir"].Value.ToString(), true);
                                                break;
                                            case ProviderMethods.GetChildNames:
                                                WriteItemObject(p.Properties["ResourceDir"].Value.ToString(), path, true);
                                                break;
                                        }
                                    }
                                    return;
                                }
                            }
                            strPathchk = strPathchk + WSManStringLiterals.containerResources + WSManStringLiterals.DefaultPathSeparator;
                            int Sepindex = path.IndexOf(WSManStringLiterals.DefaultPathSeparator, strPathchk.Length);
                            string sResourceDirName = String.Empty;
                            if (Sepindex == -1)
                            {
                                sResourceDirName = path.Substring(strPathchk.Length);
                            }
                            else
                            {
                                sResourceDirName = path.Substring(strPathchk.Length, path.IndexOf(WSManStringLiterals.DefaultPathSeparator, strPathchk.Length) - (strPathchk.Length));
                            }

                            if (null == arrResources)
                            {
                                return;
                            }
                            if (path.Contains(strPathchk + sResourceDirName))
                            {
                                if (path.EndsWith(strPathchk + sResourceDirName, StringComparison.OrdinalIgnoreCase))
                                {
                                    foreach (PSObject p in arrResources)
                                    {
                                        if (sResourceDirName.Equals(p.Properties["ResourceDir"].Value.ToString()))
                                        {
                                            p.Properties.Remove("ResourceDir");
                                            switch (methodname)
                                            {
                                                //Get the items at Initparams level
                                                case ProviderMethods.GetChildItems:
                                                    WritePSObjectPropertiesAsWSManElementObjects(p, path, null, null, WsManElementObjectTypes.WSManConfigLeafElement, recurse);
                                                    break;
                                                case ProviderMethods.GetChildNames:
                                                    WritePSObjectPropertyNames(p, path);
                                                    break;
                                            }
                                        }
                                    }
                                    return;
                                }
                                strPathchk = strPathchk + sResourceDirName + WSManStringLiterals.DefaultPathSeparator;
                                if (path.EndsWith(strPathchk + WSManStringLiterals.containerSecurity, StringComparison.OrdinalIgnoreCase) || path.Contains(WSManStringLiterals.DefaultPathSeparator + WSManStringLiterals.containerSecurity + "_"))
                                {
                                    if (null != arrSecurity)
                                    {
                                        foreach (PSObject objsecurity in arrSecurity)
                                        {
                                            if (sResourceDirName.Equals(objsecurity.Properties["ResourceDir"].Value.ToString(), StringComparison.OrdinalIgnoreCase))
                                            {
                                                if (path.EndsWith(strPathchk + WSManStringLiterals.containerSecurity, StringComparison.OrdinalIgnoreCase))
                                                {
                                                    objsecurity.Properties.Remove("ResourceDir");
                                                    switch (methodname)
                                                    {
                                                        //Get the items at Security level
                                                        case ProviderMethods.GetChildItems:
                                                            string key = "Uri" + WSManStringLiterals.Equalto + objsecurity.Properties["Uri"].Value.ToString();
                                                            PSObject obj = new PSObject();
                                                            obj.Properties.Add(new PSNoteProperty(objsecurity.Properties["SecurityDIR"].Value.ToString(), WSManStringLiterals.ContainerChildValue));
                                                            WritePSObjectPropertiesAsWSManElementObjects(obj, path, new string[] { key }, null, WsManElementObjectTypes.WSManConfigContainerElement, recurse);
                                                            //WriteItemObject(new WSManConfigContainerElement(objsecurity.Properties["SecurityDIR"].Value.ToString(), WSManStringLiterals.ContainerChildValue, new string[] { key }), path + WSManStringLiterals.DefaultPathSeparator + objsecurity.Properties["SecurityDIR"].Value.ToString(), true);

                                                            break;
                                                        case ProviderMethods.GetChildNames:
                                                            WriteItemObject(objsecurity.Properties["SecurityDIR"].Value.ToString(), path, true);
                                                            break;
                                                    }
                                                }
                                                else
                                                {
                                                    string sSecurityDirName = path.Substring(path.LastIndexOf(WSManStringLiterals.DefaultPathSeparator) + 1, path.Length - (path.LastIndexOf(WSManStringLiterals.DefaultPathSeparator) + 1));
                                                    if (sSecurityDirName.Equals(objsecurity.Properties["SecurityDIR"].Value.ToString(), StringComparison.OrdinalIgnoreCase))
                                                    {
                                                        objsecurity.Properties.Remove("ResourceDir");
                                                        objsecurity.Properties.Remove("SecurityDIR");
                                                        switch (methodname)
                                                        {
                                                            //Get the items at Security level
                                                            case ProviderMethods.GetChildItems:
                                                                WritePSObjectPropertiesAsWSManElementObjects(objsecurity, path, null, null, WsManElementObjectTypes.WSManConfigLeafElement, recurse);
                                                                break;
                                                            case ProviderMethods.GetChildNames:
                                                                WritePSObjectPropertyNames(objsecurity, path);
                                                                break;
                                                        }
                                                    }
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                        else if (path.EndsWith(host + WSManStringLiterals.DefaultPathSeparator + WSManStringLiterals.containerPlugin + WSManStringLiterals.DefaultPathSeparator + currentpluginname + WSManStringLiterals.DefaultPathSeparator + WSManStringLiterals.containerInitParameters, StringComparison.OrdinalIgnoreCase))
                        {
                            if (null == arrInitParams)
                            {
                                return;
                            }
                            foreach (PSObject p in arrInitParams)
                            {
                                switch (methodname)
                                {
                                    //Get the items at Initparams level
                                    case ProviderMethods.GetChildItems:
                                        WritePSObjectPropertiesAsWSManElementObjects(p, path, null, "InitParams", WsManElementObjectTypes.WSManConfigLeafElement, recurse);
                                        break;
                                    case ProviderMethods.GetChildNames:
                                        WritePSObjectPropertyNames(p, path);
                                        break;
                                }
                            }
                        }

                    }
                }
                else
                {
                    if ((path.EndsWith(WSManStringLiterals.containerService, StringComparison.OrdinalIgnoreCase) || path.EndsWith(WSManStringLiterals.containerTrustedHosts, StringComparison.OrdinalIgnoreCase)
                           || path.EndsWith(WSManStringLiterals.containerClient, StringComparison.OrdinalIgnoreCase) || path.EndsWith(WSManStringLiterals.containerDefaultPorts, StringComparison.OrdinalIgnoreCase)
                              || path.EndsWith(WSManStringLiterals.containerAuth, StringComparison.OrdinalIgnoreCase) || path.EndsWith(WSManStringLiterals.containerShell, StringComparison.OrdinalIgnoreCase)))
                    {
                        foreach (XmlNode node in outxml.ChildNodes)
                        {
                            PSObject mshObject = ConvertToPSObject(node);
                            switch (methodname)
                            {
                                case ProviderMethods.GetChildItems:
                                    WritePSObjectPropertiesAsWSManElementObjects(mshObject, path, null, null, WsManElementObjectTypes.WSManConfigLeafElement, recurse);
                                    break;
                                case ProviderMethods.GetChildNames:
                                    WritePSObjectPropertyNames(mshObject, path);
                                    break;
                            }
                        }
                    }
                }
            }
        }
Ejemplo n.º 5
0
        /// <summary>
        /// for the recurse operation of Get-ChildItems.
        /// </summary>
        /// <param name="path"></param>
        /// <param name="childname"></param>
        /// <param name="methodname"></param>
        /// <param name="recurse"></param>
        private void GetChildItemsRecurse(string path, string childname, ProviderMethods methodname, bool recurse)
        {
            if (path.Equals(WSManStringLiterals.rootpath))
            {
                path = childname;
            }
            else
            {
                path = path + WSManStringLiterals.DefaultPathSeparator + childname;
            }
            if (HasChildItems(path))
            {
                GetChildItemsOrNames(path, ProviderMethods.GetChildItems, recurse);
            }

        }
Ejemplo n.º 6
0
        /// <summary>
        /// Get Child Items of Listener and Client Certificate. Used by Getchilditem or getchildname.
        /// </summary>
        /// <param name="xmlResource"></param>
        /// <param name="ListenerOrCerMapping"></param>
        /// <param name="path"></param>
        /// <param name="host"></param>
        /// <param name="methodname"></param>
        /// <param name="recurse"></param>
        private void GetChildItemOrNamesForListenerOrCertMapping(XmlDocument xmlResource, string ListenerOrCerMapping, string path, string host, ProviderMethods methodname, bool recurse)
        {
            Hashtable Objcache, Keyscache;
            string PathEnd = String.Empty;
            if (ListenerOrCerMapping.Equals(WSManStringLiterals.containerClientCertificate))
            {
                ProcessCertMappingObjects(xmlResource, out Objcache, out Keyscache);
            }
            else if (ListenerOrCerMapping.Equals(WSManStringLiterals.containerListener))
            {
                ProcessListernerObjects(xmlResource, out Objcache, out Keyscache);
            }
            else
            { return; }
            if (null == Objcache || null == Keyscache)
            {
                return;
            }
            if (path.EndsWith(host + WSManStringLiterals.DefaultPathSeparator + ListenerOrCerMapping, StringComparison.OrdinalIgnoreCase))
            {
                foreach (string key in Keyscache.Keys)
                {
                    switch (methodname)
                    {
                        //Get the items at Config level
                        case ProviderMethods.GetChildItems:
                            PSObject obj = new PSObject();
                            obj.Properties.Add(new PSNoteProperty(key, WSManStringLiterals.ContainerChildValue));
                            WritePSObjectPropertiesAsWSManElementObjects(obj, path, (string[])Keyscache[key], null, WsManElementObjectTypes.WSManConfigContainerElement, recurse);
                            //WriteItemObject(new WSManConfigContainerElement(key, WSManStringLiterals.ContainerChildValue, (string[])Keyscache[key]), path, true);
                            break;
                        //Get the names of container at config level
                        case ProviderMethods.GetChildNames:
                            WriteItemObject(key, path, true);
                            break;
                    }
                }
                return;
            }
            else
            {
                string item = path.Substring(path.LastIndexOf(WSManStringLiterals.DefaultPathSeparator) + 1);
                if (methodname.Equals(ProviderMethods.GetChildItems))
                {
                    WritePSObjectPropertiesAsWSManElementObjects((PSObject)Objcache[item], path, null, null, WsManElementObjectTypes.WSManConfigLeafElement, recurse);
                }
                else if (methodname.Equals(ProviderMethods.GetChildNames))
                {
                    foreach (PSPropertyInfo prop in ((PSObject)Objcache[item]).Properties)
                    {
                        WriteItemObject(prop.Name, path + WSManStringLiterals.DefaultPathSeparator + prop.Name, false);
                    }
                }
                return;
            }

        }