Ejemplo n.º 1
0
        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);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Saves changes made in the application by the user back to the Connection Monitor configuration file.
        /// </summary>
        private bool saveChanges()
        {
            bool success = false;
            MonitoredDevicesSection mds = new MonitoredDevicesSection();

            foreach (Device monitoredDevice in this.MonitoredDevicesListBox.Items)
            {
                MonitoredDeviceElement monitoredDeviceElement = new MonitoredDeviceElement();
                monitoredDeviceElement.Device     = monitoredDevice.DeviceName;
                monitoredDeviceElement.DeviceType = monitoredDevice.DeviceType;
                monitoredDeviceElement.PnPDevice  = monitoredDevice.PnPDeviceName;
                mds.Items.Add(monitoredDeviceElement);
            }

            success = MonitoredDevicesSection.SaveConfiguration(
                this.conMonServiceConfigFileLocation, mds);
            return(success);
        }