private void InstallAdapter(DeviceInfo deviceInfo)
        {
            Cursor = System.Windows.Input.Cursors.Wait;

            try
            {
                var adapterInfos = ReadAgentAdapters();

                string id         = GetAvailableId();
                string deviceName = GetAvailableName(deviceInfo.Adapter);
                int    port       = GetAvailablePort();

                deviceInfo.DeviceName  = deviceName;
                deviceInfo.DeviceId    = id;
                deviceInfo.Uuid        = id;
                deviceInfo.AdapterPort = port;

                usedIds.Add(id);
                usedNames.Add(deviceName);
                usedPorts.Add(port);

                var adapterInfo = new AgentAdapterInfo();
                adapterInfo.DeviceName = deviceInfo.DeviceName;
                adapterInfo.Port       = port;

                adapterInfos.Add(adapterInfo);

                AgentConfigurationFile.WriteAdapters(adapterInfos);

                var node = AgentDevicesFile.CreateDeviceNode(deviceInfo);
                if (node != null)
                {
                    AgentDevicesFile.WriteDeviceNode(node);
                }

                CreateAdapterFiles(deviceInfo);

                ReadAdapters();
            }
            catch (Exception ex) { Console.WriteLine(ex.Message); }

            Cursor = System.Windows.Input.Cursors.Arrow;
        }
        private void UninstallAdapter(AdapterInfo info)
        {
            Cursor = System.Windows.Input.Cursors.Wait;

            try
            {
                AdapterManagement.Stop(info.ServiceName);
                AdapterManagement.Uninstall(info.ServiceName);

                // Remove adapter from Agent Configuration File (agent.cfg);
                var adapterInfos = ReadAgentAdapters();
                var match1       = adapterInfos.Find(x => x.DeviceName == info.DeviceName);
                if (match1 != null)
                {
                    adapterInfos.Remove(match1);
                }

                AgentConfigurationFile.WriteAdapters(adapterInfos);

                // Remove Device node from Agent's devices.xml file
                var deviceInfos = AgentDevicesFile.ReadDeviceInfos();
                var match2      = deviceInfos.Find(x => x.DeviceName == info.DeviceName);
                if (match2 != null)
                {
                    string id = match2.DeviceId;

                    AgentDevicesFile.DeleteDeviceNode("//Device[@id=\"" + id + "\"]");
                }

                // Delete adapter folder in "Adapters"
                string path = Path.GetDirectoryName(info.Path);
                Directory.Delete(path, true);
            }
            catch (Exception ex) { Console.WriteLine(ex.Message); }

            Cursor = System.Windows.Input.Cursors.Arrow;
        }