Ejemplo n.º 1
0
        public static void ReadAll(string strCustomer, BackgroundWorker _bw)
        {
            worker   = _bw;
            Customer = strCustomer;

            try
            {
                connectTimeout = int.Parse(ParamService.getParameterValue("ConnectTimeout"));
            }
            catch
            {
                connectTimeout = 200;
            }

            while (true)
            {
                //break;
                ReadAll();
                Thread.Sleep(3000);
            }
        }
Ejemplo n.º 2
0
        private static void ReadAll()
        {
            if (IsRunning)
            {
                ServiceResult <DataTable> devices = null;
                bool isPeriorityDevice            = !String.IsNullOrEmpty(ParamService.getParameterValue("PeriorityDevice"));
                try
                {
                    if (isPeriorityDevice)
                    {
                        devices = DeviceService.getPeriorityDevice();
                        ParamService.updateParameter("PeriorityDevice", null);
                    }
                    else
                    {
                        devices = DeviceService.getActiveDevices();
                    }
                }
                catch (Exception e)
                {
                    string message = "Error getting devices list: " + e.Message;
                    SystemContext.LogWithParams(SystemContext.RootLogger, LogLevel.ERROR, message, null, true);
                    worker.ReportProgress(0, new ProgressRecord(DateTime.Now, false, message));
                    return;
                }
                int totalCount = 0;
                if (devices.IsSuccess())
                {
                    foreach (DataRow row in devices.Result.Rows)
                    {
                        //Thread.Sleep(5000);
                        if (!IsRunning)
                        {
                            return;
                        }
                        int      count  = 0;
                        ZKDevice device = new ZKDevice();
                        if (!String.IsNullOrEmpty(ParamService.getParameterValue("PeriorityDevice")))
                        {
                            break;
                        }
                        try
                        {
                            device.DeviceID   = row["ID"].ToString();
                            device.DeviceName = row["DEVICE_NAME"].ToString();
                            device.DeviceIP   = row["DEVICE_IP"].ToString();
                            device.DevicePort = row["DEVICE_PORT"].ToString();
                            worker.ReportProgress(0, new ProgressRecord(DateTime.Now, true,
                                                                        "Pooling Data From:  " + device.DeviceFullName));
                            if (!isPeriorityDevice)
                            {
                                if (device.DeviceID != devices.Result.Rows[devices.Result.Rows.Count - 1]["ID"].ToString())
                                {
                                    ParamService.updateParameter("CurrentDevice", device.DeviceID);
                                }
                                else
                                {
                                    ParamService.updateParameter("CurrentDevice", "0");
                                }
                            }
                            count       = device.GetGeneralLogData();
                            totalCount += count;
                        }
                        catch (Exception e)
                        {
                            string message = "Error reading from device  " + device.DeviceFullName + "  " + e.Message;
                            SystemContext.LogWithParams(SystemContext.RootLogger, LogLevel.ERROR, message, null, true);
                            worker.ReportProgress(0, new ProgressRecord(DateTime.Now, false, message));
                        }
                    }
                }

                /*worker.ReportProgress(0, new ProgressRecord(DateTime.Now, true,
                 *              "Coping Log Data ..."));
                 * TransactionService.moveToRemoteTable(Customer);*/
            }
        }