public IProfile GenerateEmptyProfile(string newName = "")
        {
            Log.Information("=> DelcomConfiguration.GenerateEmptyProfile");
            var defaultProfile = new MonitoringProfile
            {
                Id = Guid.NewGuid(),
                Name = newName,
                HasRestrictedHours = false,
                StartTime = 0,
                EndTime = 24
            };

            foreach (BuildState buildState in Enum.GetValues(typeof(BuildState)))
                defaultProfile.States.Add(new ProfileState { BuildState = buildState });

            return defaultProfile;
        }
        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;
            }
        }