Esempio n. 1
0
        private void LoadDevice(string deviceId)
        {
            var deviceConfigurations = Properties.Settings.Default.DeviceList;

            ThreadPool.QueueUserWorkItem(new WaitCallback((o) => {
                var model = Model.Get(_apiUrl, deviceId, _apiToken);
                if (model != null)
                {
                    Dispatcher.BeginInvoke(new Action(() =>
                    {
                        var listItem            = new DeviceListItem(model);
                        listItem.RemoveClicked += DeviceList_RemoveClicked;
                        int index = -1;

                        var config = deviceConfigurations.Find(x => x.DeviceId == model.DeviceId);
                        if (config != null)
                        {
                            listItem.Enabled            = config.Enabled;
                            listItem.PerformanceEnabled = config.PerformanceEnabled;
                            listItem.QualityEnabled     = config.QualityEnabled;
                            listItem.Configuration      = config;
                            index = config.Index;
                        }
                        else
                        {
                            config          = new DeviceConfiguration();
                            config.DeviceId = model.DeviceId;
                            config.Enabled  = true;

                            listItem.Enabled            = true;
                            listItem.PerformanceEnabled = true;
                            listItem.QualityEnabled     = false;
                            listItem.Configuration      = config;
                        }

                        listItem.CheckedChanged += DeviceListItem_CheckedChanged;
                        DeviceListItems.Add(listItem);

                        if (listItem.Enabled)
                        {
                            overviewPage.AddDevice(model, index);
                        }

                        if (loadDeviceCompletedTimer != null)
                        {
                            loadDeviceCompletedTimer.Stop();
                        }
                        loadDeviceCompletedTimer          = new System.Timers.Timer();
                        loadDeviceCompletedTimer.Interval = 2000;
                        loadDeviceCompletedTimer.Elapsed += LoadDeviceCompletedTimer_Elapsed;
                        loadDeviceCompletedTimer.Start();
                    }), System.Windows.Threading.DispatcherPriority.Background, null);
                }
            }));
        }
        private async Task LookUpSerialNumber(string sn)
        {
            var toastConfig = new ToastConfig("Tag gescand");

            toastConfig.SetDuration(1500);
            toastConfig.SetBackgroundColor(System.Drawing.Color.Green);
            toastConfig.SetMessageTextColor(System.Drawing.Color.White);

            UserDialogs.Instance.Toast(toastConfig);

            try
            {
                var foundDevice = await deviceService.GetDeviceAsync(sn);

                if (IsUnique(foundDevice.sn))
                {
                    DeviceListItems.Add(new DeviceListItem
                    {
                        DeviceName   = foundDevice.name,
                        SerialNumber = foundDevice.sn,
                        DeviceType   = foundDevice.type,
                        DeviceId     = foundDevice._id
                    });
                }
                else
                {
                    toastConfig = new ToastConfig("Dit apparaat is al een keer gescand");
                    toastConfig.SetDuration(1500);
                    toastConfig.SetBackgroundColor(System.Drawing.Color.Firebrick);
                    toastConfig.SetMessageTextColor(System.Drawing.Color.White);

                    UserDialogs.Instance.Toast(toastConfig);
                }
            }
            catch (ArgumentOutOfRangeException ex)
            {
                toastConfig = new ToastConfig("Er is iets misgegaan. Mogelijk is dit geen geldige tag.");
                toastConfig.SetDuration(5000);
                toastConfig.SetBackgroundColor(System.Drawing.Color.Firebrick);
                toastConfig.SetMessageTextColor(System.Drawing.Color.White);

                UserDialogs.Instance.Toast(toastConfig);

                Console.WriteLine(ex.Message);
            }
        }