// ***********************************************************************
// Author : Elektro
// Modified : 16-March-2017
// ***********************************************************************
using System;
using System.ComponentModel;
using System.Diagnostics;
using System.Management;
#region " Public Members Summary "
#region " Constructors "
// New(String)
// New(String, Single)
// New(String, String, Single)
// New(String, String, String(), UInteger)
// New(SelectQuery)
// New(SelectQuery, Single)
// New(SelectQuery, UInteger)
#endregion
#region " Events "
// EventArrived As EventArrivedEventHandler
#endregion
#region " Methods "
// Start()
// Stop()
// Dispose()
#endregion
#endregion
#region " WMI Event Watcher "
namespace Types {
/// ----------------------------------------------------------------------------------------------------
/// <summary>
/// A WMI event monitor that notifies about event arrivals for the subscribed event class.
/// </summary>
/// ----------------------------------------------------------------------------------------------------
[DesignerCategory("Code")]
[ImmutableObject(false)]
public class WMIEventWatcher : ManagementEventWatcher {
#region " Constructors "
/// ----------------------------------------------------------------------------------------------------
/// <summary>
/// Prevents a default instance of the <see cref="WMIEventWatcher"/> class from being created.
/// </summary>
/// ----------------------------------------------------------------------------------------------------
[DebuggerNonUserCode()]
private WMIEventWatcher() {}
/// ----------------------------------------------------------------------------------------------------
/// <summary>
/// Initializes a new instance of the <see cref="WMIEventWatcher"/> class.
/// </summary>
/// ----------------------------------------------------------------------------------------------------
/// <param name="eventClassName">
/// The name of the WMI event class to subscribe for.
/// </param>
/// ----------------------------------------------------------------------------------------------------
[DebuggerStepThrough()]
public WMIEventWatcher(string eventClassName) :
this(eventClassName, string.Empty, withinInterval: 1f) {}
/// ----------------------------------------------------------------------------------------------------
/// <summary>
/// Initializes a new instance of the <see cref="WMIEventWatcher"/> class.
/// </summary>
/// ----------------------------------------------------------------------------------------------------
/// <param name="eventClassName">
/// The name of the WMI event class to subscribe for.
/// </param>
///
/// <param name="withinInterval">
/// The interval, in seconds, that WMI will check for changes that occur to instances of the events of the
/// specified class in the <paramref name="eventClassName"/> parameter.
/// </param>
/// ----------------------------------------------------------------------------------------------------
[DebuggerStepThrough()]
public WMIEventWatcher(string eventClassName, float withinInterval) :
this(eventClassName, condition: string.Empty, withinInterval: withinInterval) {}
/// ----------------------------------------------------------------------------------------------------
/// <summary>
/// Initializes a new instance of the <see cref="WMIEventWatcher"/> class.
/// </summary>
/// ----------------------------------------------------------------------------------------------------
/// <param name="eventClassName">
/// The name of the WMI event class to subscribe for.
/// </param>
///
/// <param name="condition">
/// The condition to be applied to events of the specified class in the
/// <paramref name="eventClassName"/> parameter.
/// </param>
///
/// <param name="withinInterval">
/// The interval, in seconds, that WMI will check for changes that occur to instances of the events of the
/// specified class in the <paramref name="eventClassName"/> parameter.
/// </param>
/// ----------------------------------------------------------------------------------------------------
[DebuggerStepThrough()]
public WMIEventWatcher(string eventClassName, string condition, float withinInterval) {
base.Query = new WqlEventQuery
(eventClassName
: eventClassName,
condition: condition,
withinInterval: TimeSpan.FromSeconds(withinInterval));
}
/// ----------------------------------------------------------------------------------------------------
/// <summary>
/// Initializes a new instance of the <see cref="WMIEventWatcher"/> class.
/// </summary>
/// ----------------------------------------------------------------------------------------------------
/// <param name="eventClassName">
/// The name of the WMI event class to subscribe for.
/// </param>
///
/// <param name="condition">
/// The condition to be applied to events of the specified class in the
/// <paramref name="eventClassName"/> parameter.
/// </param>
///
/// <param name="groupByPropertyList">
/// The properties in the event class by which the events should be grouped.
/// </param>
///
/// <param name="groupWithinInterval">
/// The interval, in seconds, of the specified interval at which WMI sends one aggregate event,
/// rather than many events.
/// </param>
/// ----------------------------------------------------------------------------------------------------
[DebuggerStepThrough()]
public WMIEventWatcher(string eventClassName, string condition, string[] groupByPropertyList, uint groupWithinInterval) {
base.Query = new WqlEventQuery
(eventClassName
: eventClassName,
condition: condition,
groupWithinInterval: TimeSpan.FromSeconds(groupWithinInterval),
groupByPropertyList: groupByPropertyList);
}
/// ----------------------------------------------------------------------------------------------------
/// <summary>
/// Initializes a new instance of the <see cref="WMIEventWatcher"/> class.
/// </summary>
/// ----------------------------------------------------------------------------------------------------
/// <param name="query">
/// The WMI select query of the event class to subscribe for.
/// </param>
/// ----------------------------------------------------------------------------------------------------
[DebuggerStepThrough()]
public WMIEventWatcher(SelectQuery query) :
this(query.ClassName, condition: query.Condition, withinInterval: 1f) {}
/// ----------------------------------------------------------------------------------------------------
/// <summary>
/// Initializes a new instance of the <see cref="WMIEventWatcher"/> class.
/// </summary>
/// ----------------------------------------------------------------------------------------------------
/// <param name="query">
/// The WMI select query of the event class to subscribe for.
/// </param>
///
/// <param name="withinInterval">
/// The interval, in seconds, that WMI will check for changes that occur to instances of the events of the
/// specified class in the <paramref name="query"/> parameter.
/// </param>
/// ----------------------------------------------------------------------------------------------------
[DebuggerStepThrough()]
public WMIEventWatcher(SelectQuery query, float withinInterval) :
this(query.ClassName, condition: query.Condition, withinInterval: withinInterval) {}
/// ----------------------------------------------------------------------------------------------------
/// <summary>
/// Initializes a new instance of the <see cref="WMIEventWatcher"/> class.
/// </summary>
/// ----------------------------------------------------------------------------------------------------
/// <param name="query">
/// The WMI select query of the event class to subscribe for and its selected properties.
/// </param>
///
/// <param name="groupWithinInterval">
/// The interval, in seconds, of the specified interval at which WMI sends one aggregate event,
/// rather than many events.
/// </param>
/// ----------------------------------------------------------------------------------------------------
[DebuggerStepThrough()]
public WMIEventWatcher(SelectQuery query, uint groupWithinInterval) {
string[] strArray
= new string[query
.SelectedProperties.Count]; query.SelectedProperties.CopyTo(strArray, index: 0);
base.Query = new WqlEventQuery
(eventClassName
: query
.ClassName,
condition: query.Condition,
groupWithinInterval: TimeSpan.FromSeconds(groupWithinInterval),
groupByPropertyList: strArray);
}
#endregion
}
}
#endregion