Example #1
0
 public bool AddDevice(dtDevice checkDevice)
 {
     foreach (dtDevice item in listDevices)
     {
         if (item.deviceId == checkDevice.deviceId)
         {
             return(false);
         }
     }
     listDevices.Add(checkDevice);
     return(true);
 }
Example #2
0
        private void WorkerLoadDevice_DoWork(object sender, DoWorkEventArgs e)
        {
            Application.Current.Dispatcher.BeginInvoke(new ThreadStart(() =>
            {
                //planControl.btn_importPlan.IsEnabled = false;
                planControl.Btn_Accept.IsEnabled = false;
                planControl.Btn_Delete.IsEnabled = false;
                planControl.RefreshBtn.IsEnabled = false;
            }));
            Stopwatch stopwatch = Stopwatch.StartNew();

            listDevices.Clear();
            HttpWebRequest request = (HttpWebRequest)WebRequest.Create(@"http://" + Properties.Settings.Default.serverIp + ":" + Properties.Settings.Default.serverPort + @"/robot/rest/" + "device/getListDevice");

            request.Method      = "GET";
            request.ContentType = @"application/json";
            HttpWebResponse response = request.GetResponse() as HttpWebResponse;

            using (Stream responseStream = response.GetResponseStream())
            {
                StreamReader reader = new StreamReader(responseStream, Encoding.UTF8);
                string       result = reader.ReadToEnd();

                DataTable devices = JsonConvert.DeserializeObject <DataTable>(result);
                for (int i = 0; i < devices.Rows.Count; i++)
                {
                    dtDevice tempDevice = new dtDevice
                    {
                        creUsrId = int.Parse(devices.Rows[i]["creUsrId"].ToString()),
                        creDt    = devices.Rows[i]["creDt"].ToString(),
                        updUsrId = int.Parse(devices.Rows[i]["updUsrId"].ToString()),
                        updDt    = devices.Rows[i]["updDt"].ToString(),

                        deviceId   = int.Parse(devices.Rows[i]["deviceId"].ToString()),
                        deviceName = devices.Rows[i]["deviceName"].ToString()
                    };
                    if (AddDevice(tempDevice))
                    {
                        tempDevice.GetDeviceProductsList();
                    }
                    (sender as BackgroundWorker).ReportProgress((i * 100) / devices.Rows.Count);
                }
            }
            stopwatch.Stop();
            Console.WriteLine(stopwatch.ElapsedMilliseconds);
        }