Пример #1
0
 public void RemoveOutputDevice(DelcomDevice outputDevice)
 {
     Log.Information("=> DelcomConfiguration.RemoveOutputDevice");
     outputDevices.Remove(outputDevice);
 }
Пример #2
0
        public void SetMemento(Memento memento)
        {
            Log.Information("=> DelcomConfiguration.SetMemento");
            if (memento.Key != key)
                Log.Warning("Possible attempt to load non-Delcom configuration");

            var element = memento.Element;
            var profilesElement = element.Element("profiles");
            if (profilesElement != null)
            {
                foreach (var profileElement in profilesElement.Elements("profile"))
                {
                    var profile = new MonitoringProfile();
                    profile.SetMemento(profileElement);
                    profiles.Add(profile);
                }
            }
            else
                Log.Warning("Missing element: profiles");

            var devicesElement = element.Element("devices");
            if (devicesElement != null)
            {
                foreach (var deviceElement in devicesElement.Elements("device"))
                {
                    var device = new DelcomDevice();
                    device.SetMemento(deviceElement);
                    device.Profile = Profiles.Single(p => p.Id == device.ProfileId);
                    AddOutputDevice(device);
                }
            }
            else
                Log.Warning("Missing element: devices");

            for (uint i = 1; ; i++)
            {
                var delcom = new DelcomHid();
                if (delcom.OpenNthDevice(i) != 0)
                    break;

                var physicalDevice = new PhysicalDevice(delcom);
                var deviceId = physicalDevice.Id;

                var delcomDevice = outputDevices.OfType<DelcomDevice>().SingleOrDefault(d => d.PhysicalDeviceId == deviceId);
                if (delcomDevice != null)
                    delcomDevice.PhysicalDevice = physicalDevice;
            }
        }