Пример #1
0
        protected override object MethodInvoke(PSMethod method, object[] arguments)
        {
            ManagementObject    baseObject  = method.baseObject as ManagementObject;
            WMIMethodCacheEntry adapterData = (WMIMethodCacheEntry)method.adapterData;

            return(this.AuxillaryInvokeMethod(baseObject, adapterData, arguments));
        }
Пример #2
0
        protected override Collection <string> MethodDefinitions(PSMethod method)
        {
            WMIMethodCacheEntry adapterData = (WMIMethodCacheEntry)method.adapterData;

            return(new Collection <string> {
                adapterData.MethodDefinition
            });
        }
Пример #3
0
        /// <summary>
        /// Called after a non null return from GetMember to return the overloads
        /// </summary>
        /// <param name="method">the return of GetMember</param>
        /// <returns></returns>
        protected override Collection <String> MethodDefinitions(PSMethod method)
        {
            WMIMethodCacheEntry methodEntry = (WMIMethodCacheEntry)method.adapterData;
            Collection <string> returnValue = new Collection <string>();

            returnValue.Add(methodEntry.MethodDefinition);

            return(returnValue);
        }
Пример #4
0
        /// <summary>
        /// Called after a non null return from GetMember to try to call
        /// the method with the arguments
        /// </summary>
        /// <param name="method">the non empty return from GetMethods</param>
        /// <param name="arguments">the arguments to use</param>
        /// <returns>the return value for the method</returns>
        protected override object MethodInvoke(PSMethod method, object[] arguments)
        {
            ManagementObject mgmtObject = method.baseObject as ManagementObject;

            Diagnostics.Assert(mgmtObject != null,
                               "Object is not of ManagementObject type");

            WMIMethodCacheEntry methodEntry = (WMIMethodCacheEntry)method.adapterData;

            return(AuxillaryInvokeMethod(mgmtObject, methodEntry, arguments));
        }
Пример #5
0
        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));
        }
Пример #6
0
        private static void PopulateMethodTable(ManagementClass mgmtClass, CacheTable methodTable, bool staticBinding)
        {
            MethodDataCollection methods = mgmtClass.Methods;

            if (methods != null)
            {
                ManagementPath classPath = mgmtClass.ClassPath;
                foreach (MethodData data in methods)
                {
                    if (IsStaticMethod(data) == staticBinding)
                    {
                        string name = data.Name;
                        WMIMethodCacheEntry member = new WMIMethodCacheEntry(name, classPath.Path, data);
                        methodTable.Add(name, member);
                    }
                }
            }
        }
Пример #7
0
        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));
        }
Пример #8
0
        /// <summary>
        /// Populates methods of a ManagementClass in a CacheTable
        /// </summary>
        /// <param name="mgmtClass">Class to get the method info from.</param>
        /// <param name="methodTable">Cachetable to update.</param>
        /// <param name="staticBinding">controls what methods are adapted.</param>
        /// <exception cref="UnauthorizedAccessException"></exception>
        /// <exception cref="ManagementException"></exception>
        private static void PopulateMethodTable(ManagementClass mgmtClass, CacheTable methodTable, bool staticBinding)
        {
            Dbg.Assert(null != mgmtClass, "ManagementClass cannot be null in this method");
            MethodDataCollection mgmtMethods = mgmtClass.Methods;

            if (null != mgmtMethods)
            {
                ManagementPath classPath = mgmtClass.ClassPath;
                // new operation will never fail
                foreach (MethodData mdata in mgmtMethods)
                {
                    // is method static
                    bool isStatic = IsStaticMethod(mdata);
                    if (isStatic == staticBinding)
                    {
                        // a method is added depending on
                        // whether staticBinding is requested or not.
                        string methodName          = mdata.Name;
                        WMIMethodCacheEntry mCache = new WMIMethodCacheEntry(methodName, classPath.Path, mdata);
                        methodTable.Add(methodName, mCache);
                    }
                }
            }
        }