private static ObjectQuery GetChildQuery(string className, ManagementBaseObject config) { var parent = (string)WmiUtil.GetPropertyValue(config, Constants.Wmi.ParentProperty); var name = (string)WmiUtil.GetPropertyValue(config, Constants.Wmi.NameProperty); return(GetChildQuery(className, CatalogueName.GetFullName(parent, name))); }
private static EventType CreateEventType(Catalogue catalogue, ManagementBaseObject config) { // Get the properties. var name = (string)WmiUtil.GetPropertyValue(config, Constants.Wmi.NameProperty); var isEnabled = (bool)WmiUtil.GetPropertyValue(config, Constants.Wmi.EventType.IsEnabledProperty); return(catalogue.CreateEventType(catalogue, name, isEnabled)); }
private static Source CreateSource(ISourceParent parent, ManagementBaseObject config) { // Get the properties. var name = (string)WmiUtil.GetPropertyValue(config, Constants.Wmi.NameProperty); var enabledEvents = (string)WmiUtil.GetPropertyValue(config, Constants.Wmi.Source.EnabledEventsProperty); string[] enabledEventsArray = SplitString(enabledEvents, Constants.Module.ListSeparator); return(parent.Catalogue.CreateSource(parent, name, enabledEventsArray)); }
private static string GetSourceFullyQualifiedReference(EventArrivedEventArgs e) { var config = (ManagementBaseObject)WmiUtil.GetPropertyValue(e.NewEvent, "TargetInstance"); Debug.Assert(config != null, "config != null"); var name = (string)WmiUtil.GetPropertyValue(config, Constants.Wmi.NameProperty); var parent = (string)WmiUtil.GetPropertyValue(config, Constants.Wmi.ParentProperty); return(CatalogueName.GetQualifiedReferenceUnchecked(parent, name)); }
private void HandleEventModification(object sender, EventArrivedEventArgs e) { string name; bool isEnabled; try { // Read the details of the change. var config = (ManagementBaseObject)WmiUtil.GetPropertyValue( e.NewEvent, "TargetInstance"); Debug.Assert(config != null, "config != null"); name = (string)WmiUtil.GetPropertyValue(config, Constants.Wmi.NameProperty); isEnabled = (bool)WmiUtil.GetPropertyValue(config, Constants.Wmi.EventType.IsEnabledProperty); } catch (System.Exception ex) { HandleNotificationException(ex); return; } // Work through the callbacks. _lock.AcquireReaderLock(Timeout.Infinite); try { foreach (IRepositoryCallback callback in _callbacks) { try { callback.EventChanged(name, isEnabled); } catch { } } } finally { _lock.ReleaseReaderLock(); } }
private void HandleEventStatusChange(object sender, EventArrivedEventArgs e) { string fullName; CatalogueElements elementType; try { // Read the details of the change. var config = (ManagementBaseObject)WmiUtil.GetPropertyValue( e.NewEvent, "TargetClass"); Debug.Assert(config != null, "config != null"); fullName = (string)WmiUtil.GetPropertyValue(config, Constants.Wmi.EventStatusChange.FullNameProperty); elementType = (CatalogueElements)WmiUtil.GetPropertyValue(config, Constants.Wmi.EventStatusChange.ElementTypeProperty); } catch (System.Exception ex) { HandleNotificationException(ex); return; } // Work through the callbacks. _lock.AcquireReaderLock(Timeout.Infinite); try { foreach (IRepositoryCallback callback in _callbacks) { try { callback.EventStatusChanged(elementType, fullName); } catch { } } } finally { _lock.ReleaseReaderLock(); } }
public Namespace GetNamespace(INamespaceParent parent, string relativeName, bool ignoreCase) { // WMI is very slow, so do everything possible to minimise WMI access. We need to load all the // namespaces in the hierarchy (from the parent to the one being sought), because any of them // may have enabled events. Get them all in one query. // Build a query that gets all the namespaces we need (if they exist). string[] nsParts = relativeName.Split('.'); string parentFullName = parent.FullName; string queryString = BuildQueryStringForNamespaces(nsParts, parentFullName); // WQL is case-insensitive, so if ignoreCase is false use the Hashtable created below to filter. Hashtable namespaces = ignoreCase ? new Hashtable(StringComparer.InvariantCultureIgnoreCase) : new Hashtable(); var searcher = new ManagementObjectSearcher(_scope, new ObjectQuery(queryString)); // Read the namespaces returned and store them temporarily in a Hasthable. We cannot create // Namespace objects as we go, because they may be returned out of order (ie. children before parents). using (ManagementObjectCollection configs = searcher.Get()) { foreach (ManagementObject config in configs) { var details = new NamespaceDetails(); var nsName = (string)WmiUtil.GetPropertyValue(config, Constants.Wmi.NameProperty); var nsParentName = (string)WmiUtil.GetPropertyValue(config, Constants.Wmi.ParentProperty); var enabledEvents = (string)WmiUtil.GetPropertyValue(config, Constants.Wmi.Namespace.EnabledEventsProperty); var mixedEvents = (string)WmiUtil.GetPropertyValue(config, Constants.Wmi.Namespace.MixedEventsProperty); details._enabledEvents = SplitString(enabledEvents, Constants.Module.ListSeparator); details._mixedEvents = SplitString(mixedEvents, Constants.Module.ListSeparator); namespaces.Add(CatalogueName.GetFullNameUnchecked(nsParentName, nsName), details); } } // Now that we have all the details create the hierarchy of Namespace objects. Catalogue catalogue = parent.Catalogue; Namespace ns = null; foreach (string nsName in nsParts) { string nsFullName = CatalogueName.GetFullNameUnchecked(parentFullName, nsName); var details = (NamespaceDetails)namespaces[nsFullName]; if (details == null) { return(null); // One of the namespaces in the path was not found in WMI. } ns = catalogue.CreateNamespace(parent, nsName, details._enabledEvents, details._mixedEvents); parent.AddIfNotLoaded(ns); parentFullName = nsFullName; parent = ns; } return(ns); }