public void RevokeInformer(WmiReadynessInformer obj, bool force = false) { if (!ContainsInformer(obj)) { throw new ArgumentException("Informer with specified ApplicationName 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.ApplicationName); }
protected override void OnStart(string[] args) { //string[] uninstallArgs = new string[] { "/u", @"C:\Program Files\WindowsServer2012WMIService\UserBusinessObject.dll" }; //ManagedInstallerClass.InstallHelper(uninstallArgs); //try //{ // string[] installArgs = new string[] { @"C:\Program Files\WindowsServer2012WMIService\SBSBusinessObject.dll" }; // ManagedInstallerClass.InstallHelper(installArgs); // string[] installArgs2 = new string[] { @"C:\Program Files\WindowsServer2012WMIService\SBSWMINotifications.dll" }; // ManagedInstallerClass.InstallHelper(installArgs2); //} //catch (Exception e) //{ // Logger.WriteLine(e.ToString()); //} //Assembly a = Assembly.Load(@"C:\Program Files\WindowsServer2012WMIService\SBSBusinessObject.dll"); //InstrumentationManager.RegisterAssembly(a); //InstrumentationManager.RegisterAssembly( /*System.Configuration.Install.AssemblyInstaller myAssemblyInstaller = new System.Configuration.Install.AssemblyInstaller(); * myAssemblyInstaller.Path = "UserBusinessObject.dll"; * myAssemblyInstaller.Install(null); * myAssemblyInstaller.Dispose();*/ //SBSWMIInstaller installer = new SBSWMIInstaller(); // ManagedInstallerClass.InstallHelper(new string[]{"UserBusinessObject.dll"}); InstrumentationManager.RegisterType(typeof(SBSUser)); // Logger.WriteLine("we started"); }
/// <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); }
private void ComputerHardwareAdded(IHardware hardware) { if (!Exists(hardware.Identifier.ToString())) { foreach (ISensor sensor in hardware.Sensors) { HardwareSensorAdded(sensor); } hardware.SensorAdded += HardwareSensorAdded; hardware.SensorRemoved += HardwareSensorRemoved; Hardware hw = new Hardware(hardware); activeInstances.Add(hw); try { InstrumentationManager.Publish(hw); } catch (Exception) { } } foreach (IHardware subHardware in hardware.SubHardware) { ComputerHardwareAdded(subHardware); } }
private static void DoUnregisterType(Type type) { try { InstrumentationManager.UnregisterType(type); } catch (NullReferenceException) { } }
public void Dispose() { foreach (IWmiObject instance in activeInstances) { try { InstrumentationManager.Revoke(instance); } catch (Exception) { } } activeInstances = null; }
/// <summary> /// Initializes an Event Message with the passed parameters /// </summary> internal EventMessage(InstrumentationSource source, Event instrumentationEvent, System.Type type, string method, string message, Exception exception, IErrorHandler errorHandler, EventParameter[] parameters) { try { // Set members. _source = source == null ? string.Empty : source.FullyQualifiedReference; _event = instrumentationEvent == null ? string.Empty : instrumentationEvent.Name; _type = type == null ? string.Empty : type.AssemblyQualifiedName; _method = method ?? string.Empty; _message = message ?? string.Empty; _parameters = parameters; _exception = (exception == null ? null : new ExceptionInfo(exception, errorHandler)); // Store the time in UTC. _time = System.DateTime.UtcNow; if (instrumentationEvent != null) { _details = instrumentationEvent.CreateEventDetails(); } } catch (Exception ex) { // Don't propagate anything outside Instrumentation. If an exception is thrown send a // message to the internal message handler, but only up to a maximum of 10 times. if (_errorCount < Constants.Errors.MaximumErrorsToLog) { _errorCount++; string errorMessage = "The following error occurred while trying to create an EventMessage:" + Environment.NewLine + ex; if (_errorCount >= Constants.Errors.MaximumErrorsToLog) { errorMessage += Environment.NewLine + Environment.NewLine + "No further EventMessage constructor errors will be logged."; } // Use the simplest (private) EventMessage constructor to minimise the chance of // another exception occurring and avoid a loop. InstrumentationManager.GetInternalMessageHandler().HandleEventMessage( new EventMessage(Constants.Events.Warning, typeof(EventMessage).Name, typeof(EventMessage).AssemblyQualifiedName, ".ctor", errorMessage, System.DateTime.UtcNow, new ExceptionInfo(ex, null))); } } }
public void PublishInformer(WmiReadynessInformer obj) { if (ContainsInformer(obj)) { throw new ArgumentException("This informer has already been already published.", "obj.ApplicationName = " + obj.ApplicationName); } if (obj.GetType().GetCustomAttributes(typeof(ManagementEntityAttribute), false).Any()) { InstrumentationManager.Publish(obj); } else { Instrumentation.Publish(obj); } _inform.Add(obj.ApplicationName, obj); }
/// <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); }
private void RevokeInstance(string identifier) { int instanceIndex = activeInstances.FindIndex( item => item.Identifier == identifier.ToString() ); if (instanceIndex == -1) { return; } try { InstrumentationManager.Revoke(activeInstances[instanceIndex]); } catch (Exception) { } activeInstances.RemoveAt(instanceIndex); }
private void HardwareSensorAdded(ISensor data) { IWmiObject sensor; if (data.SensorType == SensorType.Control) { sensor = new Control(data); } else { sensor = new Sensor(data); } activeInstances.Add(sensor); try { InstrumentationManager.Publish(sensor); } catch (Exception) { } }
protected override void OnStop() { //try //{ // string[] installArgs = new string[] { "/u", @"C:\Program Files\WindowsServer2012WMIService\SBSBusinessObject.dll" }; // ManagedInstallerClass.InstallHelper(installArgs); // string[] installArgs2 = new string[] { "/u", @"C:\Program Files\WindowsServer2012WMIService\SBSWMINotifications.dll" }; // ManagedInstallerClass.InstallHelper(installArgs2); //} //catch (Exception e) //{ // Logger.WriteLine(e.ToString()); //} //Assembly a = Assembly.Load(@"C:\Program Files\WindowsServer2012WMIService\SBSBusinessObject.dll"); //InstrumentationManager.UnregisterAssembly(a); InstrumentationManager.UnregisterType(typeof(SBSUser)); }
private void ReadDetails(XmlReadAdaptor adaptor) { _details = new EventDetails(); if (adaptor.ReadElement(Constants.Xml.DetailsElement)) { while (adaptor.ReadElement()) { string name = adaptor.Name; IEventDetailFactory factory = InstrumentationManager.GetEventDetailFactory(name); if (factory != null) { IEventDetail detail = factory.CreateInstance(); ((IXmlSerializable)detail).ReadXml(adaptor.XmlReader); _details.Add(detail); } adaptor.ReadEndElement(); } adaptor.ReadEndElement(); } }
/// <summary> /// Instruments <paramref name="message"/>. /// </summary> /// <param name="severity"></param> /// <param name="message"></param> public void Instrument(MessageSeverity severity, string message) { InstrumentationManager.Instrument(new TextMessage(severity, DefaultSource, DateTime.Now, message)); }