internal static void UpdateParameters(ManagementBaseObject parameters, SortedList parametersList) { if (parameters != null) { foreach (PropertyData data in parameters.Properties) { int count = -1; WMIParameterInformation information = new WMIParameterInformation(data.Name, GetDotNetType(data)); try { count = (int)data.Qualifiers["ID"].Value; } catch (ManagementException) { } catch (COMException) { } if (count < 0) { count = parametersList.Count; } parametersList[count] = information; } } }
internal static MethodInformation GetMethodInformation(MethodData mData) { SortedList parametersList = new SortedList(); UpdateParameters(mData.InParameters, parametersList); WMIParameterInformation[] array = new WMIParameterInformation[parametersList.Count]; if (parametersList.Count > 0) { parametersList.Values.CopyTo(array, 0); } return(new MethodInformation(false, true, array)); }
private Object AuxillaryInvokeMethod(ManagementObject obj, WMIMethodCacheEntry mdata, object[] arguments) { // Evaluate method and arguments object[] verifiedArguments; MethodInformation[] methods = new MethodInformation[1]; methods[0] = mdata.MethodInfoStructure; // This will convert Null Strings to Empty Strings GetBestMethodAndArguments(mdata.Name, methods, arguments, out verifiedArguments); ParameterInformation[] parameterList = mdata.MethodInfoStructure.parameters; // GetBestMethodAndArguments should fill verifiedArguments with // correct values (even if some values are not specified) tracer.WriteLine("Parameters found {0}. Arguments supplied {0}", parameterList.Length, verifiedArguments.Length); Diagnostics.Assert(parameterList.Length == verifiedArguments.Length, "The number of parameters and arguments should match"); // we should not cache inParameters as we are updating // inParameters object with argument values..Caching will // have side effects in this scenario like we have to clear // the values once the method is invoked. // Also caching MethodData occupies lot of memory compared to // caching string. ManagementClass mClass = CreateClassFrmObject(obj); ManagementBaseObject inParameters = mClass.GetMethodParameters(mdata.Name); for (int i = 0; i < parameterList.Length; i++) { // this cast should always succeed WMIParameterInformation pInfo = (WMIParameterInformation)parameterList[i]; // Should not convert null input arguments // GetBestMethodAndArguments converts null strings to empty strings // and also null ints to 0. But WMI providers do not like these // conversions. So dont convert input arguments if they are null. // We could have done this in the base adapter but the change would be // costly for other adpaters which dont mind the conversion. if ((i < arguments.Length) && (arguments[i] == null)) { verifiedArguments[i] = null; } inParameters[pInfo.Name] = verifiedArguments[i]; } return(InvokeManagementMethod(obj, mdata.Name, inParameters)); }
/// <summary> /// Gets WMI method information. /// </summary> /// <param name="mData"></param> /// <returns></returns> /// <remarks> /// Decodes only input parameters. /// </remarks> internal static MethodInformation GetMethodInformation(MethodData mData) { Diagnostics.Assert(mData != null, "MethodData should not be null"); // Get Method parameters SortedList parameters = new SortedList(); UpdateParameters(mData.InParameters, parameters); // parameters is never null WMIParameterInformation[] pInfos = new WMIParameterInformation[parameters.Count]; if (parameters.Count > 0) { parameters.Values.CopyTo(pInfos, 0); } MethodInformation returnValue = new MethodInformation(false, true, pInfos); return(returnValue); }
private object AuxillaryInvokeMethod(ManagementObject obj, WMIMethodCacheEntry mdata, object[] arguments) { object[] objArray; MethodInformation[] methods = new MethodInformation[] { mdata.MethodInfoStructure }; Adapter.GetBestMethodAndArguments(mdata.Name, methods, arguments, out objArray); ParameterInformation[] parameters = mdata.MethodInfoStructure.parameters; Adapter.tracer.WriteLine("Parameters found {0}. Arguments supplied {0}", new object[] { parameters.Length, objArray.Length }); ManagementBaseObject methodParameters = CreateClassFrmObject(obj).GetMethodParameters(mdata.Name); for (int i = 0; i < parameters.Length; i++) { WMIParameterInformation information = (WMIParameterInformation)parameters[i]; if ((i < arguments.Length) && (arguments[i] == null)) { objArray[i] = null; } methodParameters[information.Name] = objArray[i]; } return(this.InvokeManagementMethod(obj, mdata.Name, methodParameters)); }
/// <summary> /// Decode parameter information from the supplied object. /// </summary> /// <param name="parameters">A ManagementBaseObject describing the parameters.</param> /// <param name="parametersList">A sorted list to store parameter information.</param> /// <remarks> /// Should not throw exceptions /// </remarks> internal static void UpdateParameters(ManagementBaseObject parameters, SortedList parametersList) { // ManagementObject class do not populate parameters when there are none. if (parameters == null) { return; } foreach (PropertyData data in parameters.Properties) { // parameter position.. int location = -1; WMIParameterInformation pInfo = new WMIParameterInformation(data.Name, GetDotNetType(data)); try { location = (int)data.Qualifiers["ID"].Value; } catch (ManagementException) { // If there is an exception accessing location // add the parameter to the end. } catch (System.Runtime.InteropServices.COMException) { // If there is an exception accessing location // add the parameter to the end. } if (location < 0) { location = parametersList.Count; } parametersList[location] = pInfo; } }