internal static CimInstance EnumerateAssociatedInstanceCore( CimSession cimSession, string cimNamespace, string cimClassName, out string associationClassName, out string resultClassName) { associationClassName = null; resultClassName = null; CimInstance associatedInstance = null; ArrayList list = GetAndPrintInstances(cimSession, cimNamespace, cimClassName); if (list == null) { Console.WriteLine("EnumerateAssociatedInstance operation not performed"); return(associatedInstance); } while (true) { Console.WriteLine("On which instance do you want to perform association"); string instanceId = Console.ReadLine(); int result; if (String.IsNullOrEmpty(instanceId) || int.TryParse(instanceId, out result) == false || result >= list.Count) { Console.WriteLine("Please type the instance Id in the range {0} to {1}", 0, list.Count - 1); } else { associatedInstance = (CimInstance)list[result]; break; } } associationClassName = DotNetSample.GetName("Association Class Name"); if (string.IsNullOrEmpty(associationClassName)) { associationClassName = null; } resultClassName = DotNetSample.GetName("Result Class Name"); if (string.IsNullOrEmpty(resultClassName)) { resultClassName = null; } return(associatedInstance); }
internal static CimMethodParametersCollection InvokeMethodCore( CimSession cimSession, string cimNamespace, string cimClassName, out string cimMethodName, out CimInstance inputInstance) { CimMethodParametersCollection methodParameters = new CimMethodParametersCollection(); inputInstance = null; cimMethodName = null; bool isStaticMethod = false; try { CimClass cimClass = cimSession.GetClass(cimNamespace, cimClassName); // Print Methods foreach (CimMethodDeclaration methodDecl in cimClass.CimClassMethods) { Console.WriteLine("Method Name = " + methodDecl.Name); } cimMethodName = DotNetSample.GetName("Method Name"); if (cimClass.CimClassMethods[cimMethodName].Qualifiers["static"] != null) { isStaticMethod = true; } foreach (CimMethodParameterDeclaration methodParameter in cimClass.CimClassMethods[cimMethodName].Parameters) { bool bInQualifier = true; try { CimQualifier inQualifier = methodParameter.Qualifiers["In"]; } catch (CimException) { //Ignore the exception bInQualifier = false; } if (bInQualifier) { Console.Write("Please type value for Parameter '" + methodParameter.Name + "' of Type:({0}) ", methodParameter.CimType); string parameterValue = Console.ReadLine(); if (!String.IsNullOrEmpty(parameterValue)) { methodParameters.Add(CimMethodParameter.Create(methodParameter.Name, parameterValue, methodParameter.CimType, 0)); } } } // Get the instance if method is not static if (!isStaticMethod) { // Get the instances for this class. ArrayList list = GetAndPrintInstances(cimSession, cimNamespace, cimClassName); if (list == null || list.Count == 0) { Console.WriteLine("InvokeMethodCore operation not performed"); return(null); } while (true) { Console.WriteLine("On which instance do you want to invoke the method"); string instanceId = Console.ReadLine(); int result; if (String.IsNullOrEmpty(instanceId) || int.TryParse(instanceId, out result) == false || result >= list.Count) { Console.WriteLine("Please type the instance Id in the range {0} to {1}", 0, list.Count - 1); } else { inputInstance = (CimInstance)list[result]; break; } } } } catch (CimException exception) { Console.WriteLine("Unable to get schema for class '" + cimClassName + "' in namespace " + cimNamespace); PrintCimException(exception); return(null); } return(methodParameters); }