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); } }
/// <summary> /// Retrieves the table for instance methods /// </summary> /// <param name="wmiObject">object containing methods to load in typeTable.</param> /// <param name="staticBinding">controls what methods are adapted.</param> protected static CacheTable GetInstanceMethodTable(ManagementBaseObject wmiObject, bool staticBinding) { lock (s_instanceMethodCacheTable) { CacheTable typeTable = null; // unique identifier for identifying this ManagementObject's type ManagementPath classPath = wmiObject.ClassPath; string key = string.Format(CultureInfo.InvariantCulture, "{0}#{1}", classPath.Path, staticBinding.ToString()); typeTable = (CacheTable)s_instanceMethodCacheTable[key]; if (typeTable != null) { tracer.WriteLine("Returning method information from internal cache"); return(typeTable); } tracer.WriteLine("Method information not found in internal cache. Constructing one"); try { // try to populate method table..if there is any exception // generating the method metadata..suppress the exception // but dont store the info in the cache. This is to allow // for method look up again in future (after the wmi object // is fixed) typeTable = new CacheTable(); // Construct a ManagementClass object for this object to get the member metadata ManagementClass mgmtClass = wmiObject as ManagementClass ?? CreateClassFrmObject(wmiObject); PopulateMethodTable(mgmtClass, typeTable, staticBinding); s_instanceMethodCacheTable[key] = typeTable; } catch (ManagementException) { } catch (UnauthorizedAccessException) { } catch (System.Runtime.InteropServices.COMException) { } return(typeTable); } }
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); } } } }
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); } } }
protected static CacheTable GetInstanceMethodTable(ManagementBaseObject wmiObject, bool staticBinding) { lock (instanceMethodCacheTable) { CacheTable methodTable = null; ManagementPath classPath = wmiObject.ClassPath; string str = string.Format(CultureInfo.InvariantCulture, "{0}#{1}", new object[] { classPath.Path, staticBinding.ToString() }); methodTable = (CacheTable)instanceMethodCacheTable[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(); ManagementClass mgmtClass = wmiObject as ManagementClass; if (mgmtClass == null) { mgmtClass = CreateClassFrmObject(wmiObject); } PopulateMethodTable(mgmtClass, methodTable, staticBinding); instanceMethodCacheTable[str] = methodTable; } catch (ManagementException) { } catch (UnauthorizedAccessException) { } catch (COMException) { } return(methodTable); } }
/// <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); } } } }