Exemple #1
0
 void _logger_InfoLogged(object sender, LoggedDataArgs e)
 {
     _actionQueue.Add(new Action(() =>
     {
         DeviceMonitor deviceMonitor = AddOrGetDevice(e.Device);
         deviceMonitor.UpdateControl(e.Control, e.State, e.PreviousState);
         OnDataLoggedToFile(e);
     }));
 }
Exemple #2
0
        void _logger_DeviceChanged(object sender, DeviceInfo e)
        {
            Action action = null;

            switch (e.InfoAction)
            {
            case DeviceInfo.InfoType.Added:
                action = () =>
                {
                    AddMessage(new StatusMessage(e.Device, "Added"));
                    AddOrGetDevice(e.Device);
                };
                break;

            case DeviceInfo.InfoType.Checked:
                action = () =>
                {
                    AddMessage(new StatusMessage(e.Device, "Checked"));
                    AddOrGetDevice(e.Device);
                };
                break;

            case DeviceInfo.InfoType.Error:
                action = () =>
                {
                    AddMessage(new StatusMessage(e.Device, "Error"));
                    if (e is DeviceInfoError)
                    {
                        AddMessage(new StatusMessage(e.Device, ((DeviceInfoError)e).ErrorMessage));
                    }
                };
                break;

            case DeviceInfo.InfoType.Removed:
                action = () =>
                {
                    AddMessage(new StatusMessage(e.Device, "Removed"));
                    DeviceMonitor deviceMonitor = null;
                    if (_nameToDeviceMonitor.TryGetValue(e.Device, out deviceMonitor))
                    {
                        _nameToDeviceMonitor.Remove(e.Device);
                        _devices.Remove(deviceMonitor);
                    }
                };
                break;

            case DeviceInfo.InfoType.Updated:
                action = () => AddMessage(new StatusMessage(e.Device, "Updated"));
                break;
            }
            if (action != null)
            {
                _actionQueue.Add(action);
            }
        }
Exemple #3
0
        private DeviceMonitor AddOrGetDevice(string deviceName)
        {
            DeviceMonitor deviceMonitor = null;

            if (!_nameToDeviceMonitor.TryGetValue(deviceName, out deviceMonitor))
            {
                deviceMonitor = new DeviceMonitor(deviceName);
                _nameToDeviceMonitor.Add(deviceName, deviceMonitor);
                _devices.Add(deviceMonitor);
            }
            return(deviceMonitor);
        }