예제 #1
0
 /// <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);
 }
예제 #2
0
 /// <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);
 }