public static void Start() { var alldevices = DeviceService.GetAllDevices(); var getwayAddresses = alldevices.Select(o => new { o.IPAddress, o.Port }).Distinct(); foreach (var getwayItem in getwayAddresses) { var client = new MyTcpSocketClient(getwayItem.IPAddress, getwayItem.Port); bool success = false; do { try { client.ConnectToServer(); success = true; } catch (Exception ex) { Console.WriteLine(ex.ToString()); } } while (success == false); Clients.Add(client); foreach (var device in alldevices.Where(o => o.Port == getwayItem.Port && o.IPAddress == getwayItem.IPAddress)) { DeviceItems.Add(new DeviceItem(device, client)); } } if (StartCompleted != null) { StartCompleted(Clients); } }
public void SetClient(MyTcpSocketClient client) { Client = client; }
public DeviceItem(Device device, MyTcpSocketClient client) { this.Device = device; this.Client = client; }