示例#1
0
 protected static CacheTable GetInstanceMethodTable(
     ManagementBaseObject wmiObject,
     bool staticBinding)
 {
     lock (BaseWMIAdapter.instanceMethodCacheTable)
     {
         string     str         = string.Format((IFormatProvider)CultureInfo.InvariantCulture, "{0}#{1}", (object)wmiObject.ClassPath.Path, (object)staticBinding.ToString());
         CacheTable methodTable = (CacheTable)BaseWMIAdapter.instanceMethodCacheTable[(object)str];
         if (methodTable != null)
         {
             Adapter.tracer.WriteLine("Returning method information from internal cache", new object[0]);
             return(methodTable);
         }
         Adapter.tracer.WriteLine("Method information not found in internal cache. Constructing one", new object[0]);
         try
         {
             methodTable = new CacheTable();
             if (!(wmiObject is ManagementClass mgmtClass))
             {
                 mgmtClass = BaseWMIAdapter.CreateClassFrmObject(wmiObject);
             }
             BaseWMIAdapter.PopulateMethodTable(mgmtClass, methodTable, staticBinding);
             BaseWMIAdapter.instanceMethodCacheTable[(object)str] = (object)methodTable;
         }
         catch (ManagementException ex)
         {
             Adapter.tracer.TraceException((Exception)ex);
         }
         catch (UnauthorizedAccessException ex)
         {
             Adapter.tracer.TraceException((Exception)ex);
         }
         return(methodTable);
     }
 }
示例#2
0
 internal WMIMethodCacheEntry(string n, string cPath, MethodData mData)
 {
     this.name                = n;
     this.classPath           = cPath;
     this.methodInfoStructure = BaseWMIAdapter.GetMethodInformation(mData);
     this.methodDefinition    = BaseWMIAdapter.GetMethodDefinition(mData);
 }
示例#3
0
        private object AuxillaryInvokeMethod(
            ManagementObject obj,
            BaseWMIAdapter.WMIMethodCacheEntry mdata,
            object[] arguments)
        {
            MethodInformation[] methods = new MethodInformation[1]
            {
                mdata.MethodInfoStructure
            };
            object[] newArguments;
            Adapter.GetBestMethodAndArguments(mdata.Name, methods, arguments, out newArguments);
            ParameterInformation[] parameters = mdata.MethodInfoStructure.parameters;
            Adapter.tracer.WriteLine("Parameters found {0}. Arguments supplied {0}", (object)parameters.Length, (object)newArguments.Length);
            ManagementBaseObject methodParameters = BaseWMIAdapter.CreateClassFrmObject((ManagementBaseObject)obj).GetMethodParameters(mdata.Name);

            for (int index = 0; index < parameters.Length; ++index)
            {
                BaseWMIAdapter.WMIParameterInformation parameterInformation = (BaseWMIAdapter.WMIParameterInformation)parameters[index];
                if (index < arguments.Length && arguments[index] == null)
                {
                    newArguments[index] = (object)null;
                }
                methodParameters[parameterInformation.Name] = newArguments[index];
            }
            return(this.InvokeManagementMethod(obj, mdata.Name, methodParameters));
        }
示例#4
0
        protected override void PropertySet(
            PSProperty property,
            object setValue,
            bool convertIfPossible)
        {
            if (!(property.baseObject is ManagementBaseObject))
            {
                throw new SetValueInvocationException("CannotSetNonManagementObjectMsg", (Exception)null, "ExtendedTypeSystem", "CannotSetNonManagementObject", new object[3]
                {
                    (object)property.Name,
                    (object)property.baseObject.GetType().FullName,
                    (object)typeof(ManagementBaseObject).FullName
                });
            }
            PropertyData pData = this.PropertyIsSettable(property) ? property.adapterData as PropertyData : throw new SetValueException("ReadOnlyWMIProperty", (Exception)null, "ExtendedTypeSystem", "ReadOnlyProperty", new object[1]
            {
                (object)property.Name
            });

            if (convertIfPossible && setValue != null)
            {
                Type dotNetType = BaseWMIAdapter.GetDotNetType(pData);
                setValue = Adapter.PropertySetAndMethodArgumentConvertTo(setValue, dotNetType, (IFormatProvider)CultureInfo.InvariantCulture);
            }
            pData.Value = setValue;
        }
示例#5
0
        internal static MethodInformation GetMethodInformation(MethodData mData)
        {
            SortedList parametersList = new SortedList();

            BaseWMIAdapter.UpdateParameters(mData.InParameters, parametersList);
            BaseWMIAdapter.WMIParameterInformation[] parameterInformationArray = new BaseWMIAdapter.WMIParameterInformation[parametersList.Count];
            if (parametersList.Count > 0)
            {
                parametersList.Values.CopyTo((Array)parameterInformationArray, 0);
            }
            return(new MethodInformation(false, true, (ParameterInformation[])parameterInformationArray));
        }
示例#6
0
 protected override void AddAllMethods <T>(ManagementBaseObject wmiObject, PSMemberInfoInternalCollection <T> members)
 {
     if (typeof(T).IsAssignableFrom(typeof(PSMethod)))
     {
         foreach (BaseWMIAdapter.WMIMethodCacheEntry entry in BaseWMIAdapter.GetInstanceMethodTable(wmiObject, false).memberCollection)
         {
             if (members[entry.Name] == null)
             {
                 Adapter.tracer.WriteLine("Adding method {0}", new object[] { entry.Name });
                 members.Add(new PSMethod(entry.Name, this, wmiObject, entry) as T);
             }
         }
     }
 }
示例#7
0
        protected override string PropertyType(PSProperty property)
        {
            PropertyData adapterData            = property.adapterData as PropertyData;
            string       embeddedObjectTypeName = BaseWMIAdapter.GetDotNetType(adapterData).ToString();

            if (adapterData.Type == CimType.Object)
            {
                embeddedObjectTypeName = BaseWMIAdapter.GetEmbeddedObjectTypeName(adapterData);
                if (adapterData.IsArray)
                {
                    embeddedObjectTypeName += "[]";
                }
            }
            return(embeddedObjectTypeName);
        }
示例#8
0
        internal static string GetMethodDefinition(MethodData mData)
        {
            SortedList parametersList = new SortedList();

            BaseWMIAdapter.UpdateParameters(mData.InParameters, parametersList);
            StringBuilder stringBuilder1 = new StringBuilder();

            if (parametersList.Count > 0)
            {
                foreach (BaseWMIAdapter.WMIParameterInformation parameterInformation in (IEnumerable)parametersList.Values)
                {
                    string       embeddedObjectTypeName = parameterInformation.parameterType.ToString();
                    PropertyData property = mData.InParameters.Properties[parameterInformation.Name];
                    if (property.Type == CimType.Object)
                    {
                        embeddedObjectTypeName = BaseWMIAdapter.GetEmbeddedObjectTypeName(property);
                        if (property.IsArray)
                        {
                            embeddedObjectTypeName += "[]";
                        }
                    }
                    stringBuilder1.Append(embeddedObjectTypeName);
                    stringBuilder1.Append(" ");
                    stringBuilder1.Append(parameterInformation.Name);
                    stringBuilder1.Append(", ");
                }
            }
            if (stringBuilder1.Length > 2)
            {
                stringBuilder1.Remove(stringBuilder1.Length - 2, 2);
            }
            Adapter.tracer.WriteLine("Constructing method definition for method {0}", (object)mData.Name);
            StringBuilder stringBuilder2 = new StringBuilder();

            stringBuilder2.Append("System.Management.ManagementBaseObject ");
            stringBuilder2.Append(mData.Name);
            stringBuilder2.Append("(");
            stringBuilder2.Append(stringBuilder1.ToString());
            stringBuilder2.Append(")");
            string str = stringBuilder2.ToString();

            Adapter.tracer.WriteLine("Definition constructed: {0}", (object)str);
            return(str);
        }
示例#9
0
        protected override bool PropertyIsSettable(PSProperty property)
        {
            ManagementBaseObject baseObject = property.baseObject as ManagementBaseObject;

            try
            {
                return((bool)BaseWMIAdapter.CreateClassFrmObject(baseObject).GetPropertyQualifierValue(property.Name, "Write"));
            }
            catch (ManagementException ex)
            {
                Adapter.tracer.TraceException((Exception)ex);
                return(true);
            }
            catch (UnauthorizedAccessException ex)
            {
                Adapter.tracer.TraceException((Exception)ex);
                return(true);
            }
        }
示例#10
0
        private static void PopulateMethodTable(
            ManagementClass mgmtClass,
            CacheTable methodTable,
            bool staticBinding)
        {
            MethodDataCollection methods = mgmtClass.Methods;

            if (methods == null)
            {
                return;
            }
            ManagementPath classPath = mgmtClass.ClassPath;

            foreach (MethodData methodData in methods)
            {
                if (BaseWMIAdapter.IsStaticMethod(methodData) == staticBinding)
                {
                    string name = methodData.Name;
                    BaseWMIAdapter.WMIMethodCacheEntry methodCacheEntry = new BaseWMIAdapter.WMIMethodCacheEntry(name, classPath.Path, methodData);
                    methodTable.Add(name, (object)methodCacheEntry);
                }
            }
        }
示例#11
0
 internal static void UpdateParameters(
     ManagementBaseObject parameters,
     SortedList parametersList)
 {
     if (parameters == null)
     {
         return;
     }
     foreach (PropertyData property in parameters.Properties)
     {
         int num = -1;
         BaseWMIAdapter.WMIParameterInformation parameterInformation = new BaseWMIAdapter.WMIParameterInformation(property.Name, BaseWMIAdapter.GetDotNetType(property));
         try
         {
             num = (int)property.Qualifiers["ID"].Value;
         }
         catch (ManagementException ex)
         {
             Adapter.tracer.TraceException((Exception)ex);
         }
         if (num < 0)
         {
             num = parametersList.Count;
         }
         parametersList[(object)num] = (object)parameterInformation;
     }
 }
示例#12
0
 protected override T GetManagementObjectMethod <T>(ManagementBaseObject wmiObject, string methodName)
 {
     if (!typeof(T).IsAssignableFrom(typeof(PSMethod)))
     {
         return(default(T));
     }
     BaseWMIAdapter.WMIMethodCacheEntry adapterData = (BaseWMIAdapter.WMIMethodCacheEntry)BaseWMIAdapter.GetInstanceMethodTable(wmiObject, false)[methodName];
     if (adapterData == null)
     {
         return(default(T));
     }
     return(new PSMethod(adapterData.Name, this, wmiObject, adapterData) as T);
 }