/// <summary> /// Retrieves the list of monitored devices from the Connection Monitor Configuration file. /// </summary> /// <param name="deviceToReplace">OPTIONAL - If an instance of Device is passed, will replace what is read from the configuration with the instance data passed and returns the list. NOTE: this method does not save the configuration file so passing this instance does not write it out to the configuration, this is only reflected in memory, not persisted!</param> /// <returns>List of Device instances build from the configuration file</returns> private List <Device> getMonitoredDeviceList(Device deviceToReplace = null) { List <Device> devices = new List <Device>(); MonitoredDevicesSection mds = MonitoredDevicesSection.LoadConfiguration(this.conMonServiceConfigFileLocation); List <string> deviceTypeOrderList = this.getDeviceTypeOrderList(); foreach (string deviceTypeOrder in deviceTypeOrderList) { foreach (MonitoredDeviceElement monitoredDeviceConfigElement in mds.Items) { if (string.Compare(monitoredDeviceConfigElement.DeviceType, deviceTypeOrder) == 0 || (deviceToReplace != null && string.Compare(deviceToReplace.DeviceType, deviceTypeOrder) == 0)) { Device deviceItem = null; if (deviceToReplace != null && deviceToReplace.DeviceName == monitoredDeviceConfigElement.Device) { deviceItem = deviceToReplace; } else { deviceItem = new Device(monitoredDeviceConfigElement); } deviceItem.MouseDoubleClick += new MouseButtonEventHandler(monitoredDeviceItem_MouseDoubleClick); devices.Add(deviceItem); } } } return(devices); }
private bool updateMonitoredDevicesConfigurationSection(string configFilename) { bool success = false; try { TryEnableWireless(); List <string> wirelessAdapters = GetWirelessAdapterList(); if (wirelessAdapters == null) { throw new InstallException("Connection Monitor could not find any wireless adapters to manage."); } bool saveMonitoredDevicesSection = false; MonitoredDevicesSection mds = MonitoredDevicesSection.LoadConfiguration(configFilename); if (mds == null) { throw new InstallException("MonitoredDevices section not found."); } List <string> monitoredDevices = mds.Items.GetAllMonitoredDeviceNames(); if (monitoredDevices == null) { throw new InstallException("Error occured getting all monitored devices."); } foreach (string wirelessAdapter in wirelessAdapters) { if (!monitoredDevices.Contains(wirelessAdapter)) { MonitoredDeviceElement wirelessDeviceElement = new MonitoredDeviceElement(); wirelessDeviceElement.Device = wirelessAdapter; wirelessDeviceElement.PnPDevice = wirelessAdapter; wirelessDeviceElement.DeviceType = "Wireless"; mds.Items.AddAt(mds.Items.StartingIndexForAddingWirelessMonitoredDevices(), wirelessDeviceElement); saveMonitoredDevicesSection = true; } } if (saveMonitoredDevicesSection) { if (!MonitoredDevicesSection.SaveConfiguration(configFilename, mds)) { throw new InstallException("Failed to save configuration file."); } } success = true; } catch (Exception ex) { throw new InstallException("Failed to update MonitoredDevices section of the configuration file.", ex); } return(success); }
/// <summary> /// Retrieve the device type ordering list from the configuration file. /// </summary> /// <returns>List of device types in order as they appear in the configuration file</returns> private List <string> getDeviceOrderListFromConfig() { List <string> deviceTypes = new List <string>(); MonitoredDevicesSection mds = MonitoredDevicesSection.LoadConfiguration(this.conMonServiceConfigFileLocation); foreach (MonitoredDeviceElement monitoredDeviceConfigElement in mds.Items) { if (!deviceTypes.Contains(monitoredDeviceConfigElement.DeviceType)) { deviceTypes.Add(monitoredDeviceConfigElement.DeviceType); } } return(deviceTypes); }