private void CreateAdapterFiles(DeviceInfo deviceInfo) { string path = Paths.ADAPTERS; if (!Directory.Exists(path)) { Directory.CreateDirectory(path); } string newPath = Path.Combine(path, deviceInfo.DeviceName); Directory.CreateDirectory(newPath); foreach (var file in Directory.GetFiles(deviceInfo.AdapterPath)) { string filename = Path.GetFileName(file); File.Copy(file, Path.Combine(newPath, filename), true); } string iniPath = Path.Combine(newPath, "adapter.ini"); string serviceName = deviceInfo.DeviceName + "-Adapter"; AdapterPort.Set(iniPath, deviceInfo.AdapterPort); AdapterFocusHost.Set(iniPath, deviceInfo.AdapterFocasIp); AdapterSeviceName.Set(iniPath, serviceName); string exePath = Path.Combine(newPath, "adapter.exe"); AdapterManagement.Install(exePath); AdapterManagement.Start(serviceName); }
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; }