private void AddDevices(ContextMenuStrip menu, AutoSwitchConfiguration configuration) { var deviceIds = configuration.DeviceConfigurations .GroupBy(x => x.PlaybackDeviceId) .Select(x => x.First()) .Select(x => x.PlaybackDeviceId) .ToList(); deviceIds.AddRange(configuration.FavoriteDevices.Where(x => !deviceIds.Contains(x.PlaybackDeviceId)).Select(x => x.PlaybackDeviceId)); foreach (var deviceId in deviceIds) { //var deviceId = config.PlaybackDeviceId; var deviceName = _playbackDeviceProvider.GetPlaybackDeviceName(deviceId); var item = new ToolStripMenuItem(deviceName); item.Tag = deviceId; Action<int> setCheckedDevice = (id) => item.Checked = id == _playbackDeviceProvider.GetDefaultDeviceId(); item.Click += (sender, e) => { _playbackDeviceProvider.SetPlaybackDevice(deviceId); setCheckedDevice(deviceId); }; setCheckedDevice(deviceId); menu.Items.Add(item); } if (configuration.DeviceConfigurations.Count > 0) { menu.Items.Add(new ToolStripSeparator()); } }
public ProcessEventContainer(IPlaybackDeviceProvider playbackDeviceProvider, AutoSwitchConfiguration configuration) { _playbackDeviceProvider = playbackDeviceProvider; _configuration = configuration; _defaultPlaybackDevice = _playbackDeviceProvider.GetDefaultDeviceId(); _configuration.IsEnabledChanged += (sender, args) => ReconfigureListeners(); _configuration.DeviceConfigurationsChanged += (sender, args) => ReconfigureListeners(); }
public void Load() { if (!File.Exists(ConfigurationFile)) { Configuration = new AutoSwitchConfiguration(); } else { try { using (var fs = new FileStream(ConfigurationFile, FileMode.Open, FileAccess.Read)) { var serializer = CreateSerializer(); Configuration = (AutoSwitchConfiguration) serializer.ReadObject(fs); } } catch(Exception ex) { Console.WriteLine("Load failed: {0}", ex); Configuration = new AutoSwitchConfiguration(); } } }