예제 #1
0
        /// <summary>
        /// <para>
        /// Refactor to be reused by Get-CimInstance;Remove-CimInstance;Set-CimInstance
        /// </para>
        /// </summary>
        /// <param name="cmdlet"></param>
        protected void GetCimInstanceInternal(CimBaseCommand cmdlet)
        {
            IEnumerable <string> computerNames = ConstValue.GetComputerNames(
                GetComputerName(cmdlet));
            string nameSpace;
            List <CimSessionProxy> proxys       = new List <CimSessionProxy>();
            bool        isGetCimInstanceCommand = (cmdlet is GetCimInstanceCommand);
            CimInstance targetCimInstance       = null;

            switch (cmdlet.ParameterSetName)
            {
            case CimBaseCommand.CimInstanceComputerSet:
                foreach (string computerName in computerNames)
                {
                    targetCimInstance = GetCimInstanceParameter(cmdlet);
                    CimSessionProxy proxy = CreateSessionProxy(computerName, targetCimInstance, cmdlet);
                    if (isGetCimInstanceCommand)
                    {
                        this.SetPreProcess(proxy, cmdlet as GetCimInstanceCommand);
                    }
                    proxys.Add(proxy);
                }
                break;

            case CimBaseCommand.ClassNameComputerSet:
            case CimBaseCommand.QueryComputerSet:
            case CimBaseCommand.ResourceUriComputerSet:
                foreach (string computerName in computerNames)
                {
                    CimSessionProxy proxy = CreateSessionProxy(computerName, cmdlet);
                    if (isGetCimInstanceCommand)
                    {
                        this.SetPreProcess(proxy, cmdlet as GetCimInstanceCommand);
                    }
                    proxys.Add(proxy);
                }
                break;

            case CimBaseCommand.ClassNameSessionSet:
            case CimBaseCommand.CimInstanceSessionSet:
            case CimBaseCommand.QuerySessionSet:
            case CimBaseCommand.ResourceUriSessionSet:
                foreach (CimSession session in GetCimSession(cmdlet))
                {
                    CimSessionProxy proxy = CreateSessionProxy(session, cmdlet);
                    if (isGetCimInstanceCommand)
                    {
                        this.SetPreProcess(proxy, cmdlet as GetCimInstanceCommand);
                    }
                    proxys.Add(proxy);
                }
                break;

            default:
                break;
            }
            switch (cmdlet.ParameterSetName)
            {
            case CimBaseCommand.ClassNameComputerSet:
            case CimBaseCommand.ClassNameSessionSet:
                nameSpace = ConstValue.GetNamespace(GetNamespace(cmdlet));
                if (IsClassNameQuerySet(cmdlet))
                {
                    string query = CreateQuery(cmdlet);
                    DebugHelper.WriteLogEx(@"Query = {0}", 1, query);
                    foreach (CimSessionProxy proxy in proxys)
                    {
                        proxy.QueryInstancesAsync(nameSpace,
                                                  ConstValue.GetQueryDialectWithDefault(GetQueryDialect(cmdlet)),
                                                  query);
                    }
                }
                else
                {
                    foreach (CimSessionProxy proxy in proxys)
                    {
                        proxy.EnumerateInstancesAsync(nameSpace, GetClassName(cmdlet));
                    }
                }
                break;

            case CimBaseCommand.CimInstanceComputerSet:
            case CimBaseCommand.CimInstanceSessionSet:
            {
                CimInstance instance = GetCimInstanceParameter(cmdlet);
                nameSpace = ConstValue.GetNamespace(instance.CimSystemProperties.Namespace);
                foreach (CimSessionProxy proxy in proxys)
                {
                    proxy.GetInstanceAsync(nameSpace, instance);
                }
            }
            break;

            case CimBaseCommand.QueryComputerSet:
            case CimBaseCommand.QuerySessionSet:
                nameSpace = ConstValue.GetNamespace(GetNamespace(cmdlet));
                foreach (CimSessionProxy proxy in proxys)
                {
                    proxy.QueryInstancesAsync(nameSpace,
                                              ConstValue.GetQueryDialectWithDefault(GetQueryDialect(cmdlet)),
                                              GetQuery(cmdlet));
                }
                break;

            case CimBaseCommand.ResourceUriSessionSet:
            case CimBaseCommand.ResourceUriComputerSet:
                foreach (CimSessionProxy proxy in proxys)
                {
                    proxy.EnumerateInstancesAsync(GetNamespace(cmdlet), GetClassName(cmdlet));
                }
                break;

            default:
                break;
            }
        }
예제 #2
0
        protected void GetCimInstanceInternal(CimBaseCommand cmdlet)
        {
            string @namespace;
            IEnumerable <string>   computerNames     = ConstValue.GetComputerNames(CimGetInstance.GetComputerName(cmdlet));
            List <CimSessionProxy> cimSessionProxies = new List <CimSessionProxy>();
            bool   flag             = cmdlet is GetCimInstanceCommand;
            string parameterSetName = cmdlet.ParameterSetName;
            string str = parameterSetName;

            if (parameterSetName != null)
            {
                switch (str)
                {
                case "CimInstanceComputerSet":
                {
                    IEnumerator <string> enumerator = computerNames.GetEnumerator();
                    using (enumerator)
                    {
                        while (enumerator.MoveNext())
                        {
                            string          current = enumerator.Current;
                            CimInstance     cimInstanceParameter = CimGetInstance.GetCimInstanceParameter(cmdlet);
                            CimSessionProxy cimSessionProxy      = this.CreateSessionProxy(current, cimInstanceParameter, cmdlet);
                            if (flag)
                            {
                                this.SetPreProcess(cimSessionProxy, cmdlet as GetCimInstanceCommand);
                            }
                            cimSessionProxies.Add(cimSessionProxy);
                        }
                    }
                }
                break;

                case "ClassNameComputerSet":
                case "QueryComputerSet":
                case "ResourceUriComputerSet":
                {
                    IEnumerator <string> enumerator1 = computerNames.GetEnumerator();
                    using (enumerator1)
                    {
                        while (enumerator1.MoveNext())
                        {
                            string          current1         = enumerator1.Current;
                            CimSessionProxy cimSessionProxy1 = this.CreateSessionProxy(current1, cmdlet);
                            if (flag)
                            {
                                this.SetPreProcess(cimSessionProxy1, cmdlet as GetCimInstanceCommand);
                            }
                            cimSessionProxies.Add(cimSessionProxy1);
                        }
                        break;
                    }
                }

                case "ClassNameSessionSet":
                case "CimInstanceSessionSet":
                case "QuerySessionSet":
                case "ResourceUriSessionSet":
                {
                    CimSession[] cimSession = CimGetInstance.GetCimSession(cmdlet);
                    for (int i = 0; i < (int)cimSession.Length; i++)
                    {
                        CimSession      cimSession1      = cimSession[i];
                        CimSessionProxy cimSessionProxy2 = this.CreateSessionProxy(cimSession1, cmdlet);
                        if (flag)
                        {
                            this.SetPreProcess(cimSessionProxy2, cmdlet as GetCimInstanceCommand);
                        }
                        cimSessionProxies.Add(cimSessionProxy2);
                    }
                }
                break;
                }
            }
            string parameterSetName1 = cmdlet.ParameterSetName;
            string str1 = parameterSetName1;

            if (parameterSetName1 != null)
            {
                if (str1 == "ClassNameComputerSet" || str1 == "ClassNameSessionSet")
                {
                    @namespace = ConstValue.GetNamespace(CimGetInstance.GetNamespace(cmdlet));
                    if (!CimGetInstance.IsClassNameQuerySet(cmdlet))
                    {
                        List <CimSessionProxy> .Enumerator enumerator2 = cimSessionProxies.GetEnumerator();
                        try
                        {
                            while (enumerator2.MoveNext())
                            {
                                CimSessionProxy current2 = enumerator2.Current;
                                current2.EnumerateInstancesAsync(@namespace, CimGetInstance.GetClassName(cmdlet));
                            }
                            return;
                        }
                        finally
                        {
                            enumerator2.Dispose();
                        }
                    }
                    else
                    {
                        string   str2     = CimGetInstance.CreateQuery(cmdlet);
                        object[] objArray = new object[1];
                        objArray[0] = str2;
                        DebugHelper.WriteLogEx("Query = {0}", 1, objArray);
                        List <CimSessionProxy> .Enumerator enumerator3 = cimSessionProxies.GetEnumerator();
                        try
                        {
                            while (enumerator3.MoveNext())
                            {
                                CimSessionProxy current3 = enumerator3.Current;
                                current3.QueryInstancesAsync(@namespace, ConstValue.GetQueryDialectWithDefault(CimGetInstance.GetQueryDialect(cmdlet)), str2);
                            }
                            return;
                        }
                        finally
                        {
                            enumerator3.Dispose();
                        }
                    }
                }
                else if (str1 == "CimInstanceComputerSet" || str1 == "CimInstanceSessionSet")
                {
                    CimInstance cimInstance = CimGetInstance.GetCimInstanceParameter(cmdlet);
                    @namespace = ConstValue.GetNamespace(cimInstance.CimSystemProperties.Namespace);
                    List <CimSessionProxy> .Enumerator enumerator4 = cimSessionProxies.GetEnumerator();
                    try
                    {
                        while (enumerator4.MoveNext())
                        {
                            CimSessionProxy cimSessionProxy3 = enumerator4.Current;
                            cimSessionProxy3.GetInstanceAsync(@namespace, cimInstance);
                        }
                        return;
                    }
                    finally
                    {
                        enumerator4.Dispose();
                    }
                }
                else if (str1 == "QueryComputerSet" || str1 == "QuerySessionSet")
                {
                    @namespace = ConstValue.GetNamespace(CimGetInstance.GetNamespace(cmdlet));
                    List <CimSessionProxy> .Enumerator enumerator5 = cimSessionProxies.GetEnumerator();
                    try
                    {
                        while (enumerator5.MoveNext())
                        {
                            CimSessionProxy current4 = enumerator5.Current;
                            current4.QueryInstancesAsync(@namespace, ConstValue.GetQueryDialectWithDefault(CimGetInstance.GetQueryDialect(cmdlet)), CimGetInstance.GetQuery(cmdlet));
                        }
                        return;
                    }
                    finally
                    {
                        enumerator5.Dispose();
                    }
                }
                else if (str1 == "ResourceUriSessionSet" || str1 == "ResourceUriComputerSet")
                {
                    List <CimSessionProxy> .Enumerator enumerator6 = cimSessionProxies.GetEnumerator();
                    try
                    {
                        while (enumerator6.MoveNext())
                        {
                            CimSessionProxy cimSessionProxy4 = enumerator6.Current;
                            cimSessionProxy4.EnumerateInstancesAsync(CimGetInstance.GetNamespace(cmdlet), CimGetInstance.GetClassName(cmdlet));
                        }
                        return;
                    }
                    finally
                    {
                        enumerator6.Dispose();
                    }
                }
                return;
            }
        }