/// <summary> /// Revokes a published object. ArgumentException is thrown if the object has not been published by means of this provider. /// </summary> /// <param name="obj">The object has to be the one published through this provider class.</param> /// <param name="force">Suppresses WMI exceptions (but not ArgumentException) and forcefully clears internal list.</param> public void Revoke(IWmiHardwareEntity obj, bool force = false) { if (!Contains(obj)) { throw new ArgumentException("IHardware object with specified HWID has not been published through this provider."); } try { if (obj.GetType().GetCustomAttributes(typeof(ManagementEntityAttribute), false).Any()) { InstrumentationManager.Revoke(obj); } else { Instrumentation.Revoke(obj); } } catch (Exception ex) { if (!force) { throw ex; } } _pub.Remove(obj.Hwid); }
/// <summary> /// Published object to WMI. Automatically recognizes .NET 2.0 and 3.5 classes (through reflection). /// Exceptions are thrown if the object has been already published or if the assembly is not installed. /// </summary> /// <param name="obj"></param> public void Publish(IWmiHardwareEntity obj) { if (Contains(obj)) { throw new ArgumentException("This IHardware object is already published.", "obj.Hwid = " + obj.Hwid); } if (obj.GetType().GetCustomAttributes(typeof(ManagementEntityAttribute), false).Any()) { InstrumentationManager.Publish(obj); } else { Instrumentation.Publish(obj); } _pub.Add(obj.Hwid, obj); }
public static void Fire(IWmiHardwareEntity obj) { Fire(obj.Hwid); }
/// <summary> /// Utilizes HWID comparison (other properties are not required by IWmiHardwareEntity and thus are not explicitly compared, /// though HWID-generation entirely depends on them and HWID comparison implies Name/Index comparison). /// </summary> /// <param name="entity"></param> /// <returns></returns> public bool Contains(IWmiHardwareEntity entity) { return(Contains(entity.Hwid)); }