protected override ManagementEventWatcher CreateEventWatcher()
 {
     return(WqlHelper.GetEventWatcher(WqlEventType.Operation,
                                      WqlTableName.EthernetSwitchExtension,
                                      string.Format("TargetInstance.{0} = '{1}'",
                                                    WqlColumnNames.ElementName, OvsExtentionName)));
 }
 protected override ManagementObjectCollection QueryItems()
 {
     return(WqlHelper.QueryAll(WqlTableName.EthernetSwitchExtension,
                               string.Format("{0} = '{1}' AND {2} = {3}",
                                             WqlColumnNames.ElementName, OvsExtentionName,
                                             WqlColumnNames.EnabledState, (int)EnabledState.Enabled),
                               new string[] { WqlColumnNames.SystemName }));
 }
Example #3
0
 protected override ManagementObjectCollection QueryItems()
 {
     return(WqlHelper.QueryAll(WqlTableName.EthernetPortAllocationSettingData,
                               string.Format("{0} = '{1}' AND {2} = {3}", WqlColumnNames.Caption,
                                             VirtualAdapterCaption, WqlColumnNames.EnabledState, (int)EnabledState.Enabled),
                               new string[] { WqlColumnNames.ElementName, WqlColumnNames.InstanceID,
                                              WqlColumnNames.HostResource }));
 }
        private void EventWatcher_EventArrived(object sender, EventArrivedEventArgs e)
        {
            var changed = WqlHelper.ParseEventArrivedEventArgs(e);
            T   oldItem = default(T), newItem = default(T);

            if (changed.Item1 != null)
            {
                oldItem = ConvertItem(changed.Item1);
            }
            if (changed.Item2 != null)
            {
                newItem = ConvertItem(changed.Item2);
            }
            if (IsSameItem(oldItem, newItem))
            {
                //Nothing relevant is changed.
                return;
            }
            var  args = new WmiMonitorEventArgs <T>();
            bool updateResult;

            args.NewEvent = e.NewEvent;
            args.OldValue = oldItem;
            args.NewValue = newItem;
            cacheLock.EnterWriteLock();
            if (IsSameItem(oldItem, null) && !IsSameItem(newItem, null))
            {
                args.Operation = ItemOperation.Remove;
                updateResult   = AddOrDeleteItem(changed.Item1, false);
            }
            else if (!IsSameItem(oldItem, null) && IsSameItem(newItem, null))
            {
                args.Operation = ItemOperation.Add;
                updateResult   = AddOrDeleteItem(changed.Item2, true);
            }
            else
            {
                args.Operation = ItemOperation.Modify;
                updateResult   = AddOrDeleteItem(changed.Item1, false) && AddOrDeleteItem(changed.Item2, true);
            }
            cacheLock.ExitWriteLock();
            if (updateResult)
            {
                cacheLock.EnterReadLock();
                ItemUpdated?.Invoke(this, args);
                cacheLock.ExitReadLock();
            }
        }
Example #5
0
 protected override ManagementEventWatcher CreateEventWatcher()
 {
     return(WqlHelper.GetEventWatcher(
                WqlEventType.Operation, WqlTableName.EthernetPortAllocationSettingData,
                string.Format("TargetInstance.{0} = '{1}'", WqlColumnNames.Caption, VirtualAdapterCaption)));
 }