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;
        }
        public static List <AgentAdapterInfo> GetAdapters()
        {
            var result = new List <AgentAdapterInfo>();

            string path = Paths.AGENT_CONFIG;

            if (File.Exists(path))
            {
                using (var reader = new StreamReader(path))
                {
                    string cfg = "";

                    // Remove All Whitespace and linebreaks
                    string line;
                    while ((line = reader.ReadLine()) != null)
                    {
                        if (line.Trim().Length > 0)
                        {
                            cfg += line.Trim();
                        }
                    }

                    // Find start of 'Adapters' section
                    int i = cfg.IndexOf("Adapters");
                    i = cfg.IndexOf('{', i);
                    int z = cfg.IndexOf("}", i + 1);

                    // Check if empty
                    if (z > i + 1)
                    {
                        z = cfg.IndexOf("}}", i + 1) + 2;

                        // Get only 'Adapters' section text
                        cfg = cfg.Substring(i, z - i);

                        i = cfg.IndexOf('{');

                        int x = 0;
                        while (x < cfg.Length - 1)
                        {
                            int j = cfg.IndexOf('{', i + 1);

                            string deviceName = cfg.Substring(i + 1, j - i - 1).Trim();

                            i = cfg.IndexOf("Port", j);
                            i = cfg.IndexOf('=', i);
                            j = cfg.IndexOf('}', i + 1);

                            string p    = cfg.Substring(i + 1, j - i - 1).Trim();
                            int    port = -1;
                            int.TryParse(p, out port);

                            if (!string.IsNullOrEmpty(deviceName) && port >= 0)
                            {
                                var info = new AgentAdapterInfo();
                                info.DeviceName = deviceName;
                                info.Port       = port;
                                result.Add(info);
                            }

                            x = j + 1;
                            i = j;
                        }
                    }
                }
            }

            return(result);
        }