示例#1
0
        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);
            }
        }
示例#2
0
 public void SetClient(MyTcpSocketClient client)
 {
     Client = client;
 }
示例#3
0
 public DeviceItem(Device device, MyTcpSocketClient client)
 {
     this.Device = device;
     this.Client = client;
 }