Example #1
0
        private void connectToDevice(Device device)
        {
            if (device.officeCode.Equals(config) && PingDevice(device))
            {
                ZkemClient objZkeeper = null;
                try
                {
                    string ipAddress  = device.IP;
                    string port       = device.Port;
                    int    portNumber = 4370;

                    objZkeeper    = new ZkemClient(RaiseDeviceEvent);
                    device.status = objZkeeper.Connect_Net(ipAddress, portNumber);

                    if (device.status)
                    {
                        string deviceInfo = manipulator.FetchDeviceInfo(objZkeeper, int.Parse(device.DeviceId));
                        Console.WriteLine("Device at: " + ipAddress + " is now Connected");
                    }

                    Combination combination = new Combination();
                    combination.device     = device;
                    combination.objZkeeper = objZkeeper;
                    devices.Add(combination);
                    devices2.Add(device);
                    Boolean status  = GetLogsToMySql(combination);
                    Boolean status2 = GetUsersToMySql(combination);

                    if (!status && !status2)
                    {
                        Console.WriteLine("---------------------------->Restart required. Device Restarting..." + device.DeviceId);
                        Boolean returned = objZkeeper.RestartDevice(Int32.Parse(device.DeviceId.Trim()));
                        Console.WriteLine(returned);
                        objZkeeper.RestartDevice(Int32.Parse(device.DeviceId));
                    }
                    objZkeeper.Disconnect();
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                }
            }
        }