/// <summary> /// <para> /// Base on parametersetName to retrieve ciminstances /// </para> /// </summary> /// <param name="cmdlet"><see cref="GetCimInstanceCommand"/> object.</param> public void InvokeCimMethod(InvokeCimMethodCommand cmdlet) { IEnumerable <string> computerNames = ConstValue.GetComputerNames(cmdlet.ComputerName); string nameSpace; List <CimSessionProxy> proxys = new(); string action = string.Format(CultureInfo.CurrentUICulture, actionTemplate, cmdlet.MethodName); switch (cmdlet.ParameterSetName) { case CimBaseCommand.CimInstanceComputerSet: foreach (string computerName in computerNames) { proxys.Add(CreateSessionProxy(computerName, cmdlet.CimInstance, cmdlet)); } break; case CimBaseCommand.ClassNameComputerSet: case CimBaseCommand.CimClassComputerSet: case CimBaseCommand.ResourceUriComputerSet: case CimBaseCommand.QueryComputerSet: foreach (string computerName in computerNames) { proxys.Add(CreateSessionProxy(computerName, cmdlet)); } break; case CimBaseCommand.ClassNameSessionSet: case CimBaseCommand.CimClassSessionSet: case CimBaseCommand.QuerySessionSet: case CimBaseCommand.CimInstanceSessionSet: case CimBaseCommand.ResourceUriSessionSet: foreach (CimSession session in cmdlet.CimSession) { CimSessionProxy proxy = CreateSessionProxy(session, cmdlet); proxys.Add(proxy); } break; default: break; } CimMethodParametersCollection paramsCollection = CreateParametersCollection(cmdlet.Arguments, cmdlet.CimClass, cmdlet.CimInstance, cmdlet.MethodName); // Invoke methods switch (cmdlet.ParameterSetName) { case CimBaseCommand.ClassNameComputerSet: case CimBaseCommand.ClassNameSessionSet: case CimBaseCommand.ResourceUriSessionSet: case CimBaseCommand.ResourceUriComputerSet: { string target = string.Format(CultureInfo.CurrentUICulture, targetClass, cmdlet.ClassName); if (cmdlet.ResourceUri != null) { nameSpace = cmdlet.Namespace; } else { nameSpace = ConstValue.GetNamespace(cmdlet.Namespace); } foreach (CimSessionProxy proxy in proxys) { if (!cmdlet.ShouldProcess(target, action)) { return; } proxy.InvokeMethodAsync( nameSpace, cmdlet.ClassName, cmdlet.MethodName, paramsCollection); } } break; case CimBaseCommand.CimClassComputerSet: case CimBaseCommand.CimClassSessionSet: { string target = string.Format(CultureInfo.CurrentUICulture, targetClass, cmdlet.CimClass.CimSystemProperties.ClassName); nameSpace = ConstValue.GetNamespace(cmdlet.CimClass.CimSystemProperties.Namespace); foreach (CimSessionProxy proxy in proxys) { if (!cmdlet.ShouldProcess(target, action)) { return; } proxy.InvokeMethodAsync( nameSpace, cmdlet.CimClass.CimSystemProperties.ClassName, cmdlet.MethodName, paramsCollection); } } break; case CimBaseCommand.QueryComputerSet: case CimBaseCommand.QuerySessionSet: nameSpace = ConstValue.GetNamespace(cmdlet.Namespace); foreach (CimSessionProxy proxy in proxys) { // create context object CimInvokeCimMethodContext context = new( nameSpace, cmdlet.MethodName, paramsCollection, proxy); proxy.ContextObject = context; // firstly query instance and then invoke method upon returned instances proxy.QueryInstancesAsync(nameSpace, ConstValue.GetQueryDialectWithDefault(cmdlet.QueryDialect), cmdlet.Query); } break; case CimBaseCommand.CimInstanceComputerSet: case CimBaseCommand.CimInstanceSessionSet: { string target = cmdlet.CimInstance.ToString(); if (cmdlet.ResourceUri != null) { nameSpace = cmdlet.Namespace; } else { nameSpace = ConstValue.GetNamespace(cmdlet.CimInstance.CimSystemProperties.Namespace); } foreach (CimSessionProxy proxy in proxys) { if (!cmdlet.ShouldProcess(target, action)) { return; } proxy.InvokeMethodAsync( nameSpace, cmdlet.CimInstance, cmdlet.MethodName, paramsCollection); } } break; default: break; } }
public void InvokeCimMethod(InvokeCimMethodCommand cmdlet) { string @namespace; IEnumerable <string> computerNames = ConstValue.GetComputerNames(cmdlet.ComputerName); List <CimSessionProxy> cimSessionProxies = new List <CimSessionProxy>(); object[] methodName = new object[1]; methodName[0] = cmdlet.MethodName; string str = string.Format(CultureInfo.CurrentUICulture, "Invoke-CimMethod: {0}", methodName); string parameterSetName = cmdlet.ParameterSetName; string str1 = parameterSetName; if (parameterSetName != null) { switch (str1) { case "CimInstanceComputerSet": { IEnumerator <string> enumerator = computerNames.GetEnumerator(); using (enumerator) { while (enumerator.MoveNext()) { string current = enumerator.Current; cimSessionProxies.Add(this.CreateSessionProxy(current, cmdlet.CimInstance, cmdlet)); } } } break; case "ClassNameComputerSet": case "CimClassComputerSet": case "ResourceUriComputerSet": case "QueryComputerSet": { IEnumerator <string> enumerator1 = computerNames.GetEnumerator(); using (enumerator1) { while (enumerator1.MoveNext()) { string current1 = enumerator1.Current; cimSessionProxies.Add(this.CreateSessionProxy(current1, cmdlet)); } } } break; case "ClassNameSessionSet": case "CimClassSessionSet": case "QuerySessionSet": case "CimInstanceSessionSet": case "ResourceUriSessionSet": { CimSession[] cimSession = cmdlet.CimSession; for (int i = 0; i < (int)cimSession.Length; i++) { CimSession cimSession1 = cimSession[i]; CimSessionProxy cimSessionProxy = this.CreateSessionProxy(cimSession1, cmdlet); cimSessionProxies.Add(cimSessionProxy); } } break; } } CimMethodParametersCollection cimMethodParametersCollection = this.CreateParametersCollection(cmdlet.Arguments, cmdlet.CimClass, cmdlet.CimInstance, cmdlet.MethodName); string parameterSetName1 = cmdlet.ParameterSetName; string str2 = parameterSetName1; if (parameterSetName1 != null) { if (str2 == "ClassNameComputerSet" || str2 == "ClassNameSessionSet" || str2 == "ResourceUriSessionSet" || str2 == "ResourceUriComputerSet") { object[] className = new object[1]; className[0] = cmdlet.ClassName; string str3 = string.Format(CultureInfo.CurrentUICulture, "{0}", className); if (cmdlet.ResourceUri == null) { @namespace = ConstValue.GetNamespace(cmdlet.Namespace); } else { @namespace = cmdlet.Namespace; } List <CimSessionProxy> .Enumerator enumerator2 = cimSessionProxies.GetEnumerator(); try { while (enumerator2.MoveNext()) { CimSessionProxy cimSessionProxy1 = enumerator2.Current; if (cmdlet.ShouldProcess(str3, str)) { cimSessionProxy1.InvokeMethodAsync(@namespace, cmdlet.ClassName, cmdlet.MethodName, cimMethodParametersCollection); } else { return; } } return; } finally { enumerator2.Dispose(); } } else if (str2 == "CimClassComputerSet" || str2 == "CimClassSessionSet") { object[] objArray = new object[1]; objArray[0] = cmdlet.CimClass.CimSystemProperties.ClassName; string str4 = string.Format(CultureInfo.CurrentUICulture, "{0}", objArray); @namespace = ConstValue.GetNamespace(cmdlet.CimClass.CimSystemProperties.Namespace); List <CimSessionProxy> .Enumerator enumerator3 = cimSessionProxies.GetEnumerator(); try { while (enumerator3.MoveNext()) { CimSessionProxy current2 = enumerator3.Current; if (cmdlet.ShouldProcess(str4, str)) { current2.InvokeMethodAsync(@namespace, cmdlet.CimClass.CimSystemProperties.ClassName, cmdlet.MethodName, cimMethodParametersCollection); } else { return; } } return; } finally { enumerator3.Dispose(); } } else if (str2 == "QueryComputerSet" || str2 == "QuerySessionSet") { @namespace = ConstValue.GetNamespace(cmdlet.Namespace); List <CimSessionProxy> .Enumerator enumerator4 = cimSessionProxies.GetEnumerator(); try { while (enumerator4.MoveNext()) { CimSessionProxy cimSessionProxy2 = enumerator4.Current; CimInvokeCimMethod.CimInvokeCimMethodContext cimInvokeCimMethodContext = new CimInvokeCimMethod.CimInvokeCimMethodContext(@namespace, cmdlet.MethodName, cimMethodParametersCollection, cimSessionProxy2); cimSessionProxy2.ContextObject = cimInvokeCimMethodContext; cimSessionProxy2.QueryInstancesAsync(@namespace, ConstValue.GetQueryDialectWithDefault(cmdlet.QueryDialect), cmdlet.Query); } return; } finally { enumerator4.Dispose(); } } else if (str2 == "CimInstanceComputerSet" || str2 == "CimInstanceSessionSet") { string str5 = cmdlet.CimInstance.ToString(); if (cmdlet.ResourceUri == null) { @namespace = ConstValue.GetNamespace(cmdlet.CimInstance.CimSystemProperties.Namespace); } else { @namespace = cmdlet.Namespace; } List <CimSessionProxy> .Enumerator enumerator5 = cimSessionProxies.GetEnumerator(); try { while (enumerator5.MoveNext()) { CimSessionProxy current3 = enumerator5.Current; if (cmdlet.ShouldProcess(str5, str)) { current3.InvokeMethodAsync(@namespace, cmdlet.CimInstance, cmdlet.MethodName, cimMethodParametersCollection); } else { return; } } return; } finally { enumerator5.Dispose(); } } return; } }
/// <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; } }
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; } }