Esempio n. 1
0
 private void DeviceList_RemoveClicked(DeviceListItem item)
 {
     if (MessageBox.Show("Are you sure you want to remove this device?", "Remove Device", MessageBoxButton.YesNo) == MessageBoxResult.Yes)
     {
         RemoveServerDevice(item.DeviceId);
         DeviceListItems.Remove(item);
         overviewPage.RemoveDevice(item.DeviceId);
     }
 }
Esempio n. 2
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);
            }
        }
Esempio n. 4
0
        private void SearchForDevices()
        {
            FindDevicesLoading = true;

            ThreadPool.QueueUserWorkItem(new WaitCallback((o) =>
            {
                var baseUrl = "http://localhost:8479/";

                var client  = new RestClient(baseUrl);
                var request = new RestRequest("devices", Method.GET);

                var deviceItems = new List <TempServer.MTConnect.MTConnectConnection>();

                var response = client.Execute(request);
                if (response != null && response.StatusCode == HttpStatusCode.OK)
                {
                    var json = response.Content;
                    if (!string.IsNullOrEmpty(json))
                    {
                        var obj = Json.Convert.FromJson <List <TempServer.MTConnect.MTConnectConnection> >(json);
                        if (obj != null)
                        {
                            deviceItems.AddRange(obj);
                        }
                    }

                    firstFindDevices = false;
                }

                Dispatcher.BeginInvoke(new Action(() =>
                {
                    MTConnectDeviceItems.Clear();

                    foreach (var deviceItem in deviceItems)
                    {
                        if (!DeviceListItems.ToList().Exists(x => x.DeviceId == deviceItem.DeviceId))
                        {
                            MTConnectDeviceItems.Add(deviceItem);
                        }
                    }

                    FindDevicesLoading = false;
                }));
            }));
        }
Esempio n. 5
0
        private void LoadDevices()
        {
            Loading = true;

            // Clear Lists
            DeviceListItems.Clear();
            overviewPage.ClearDevices();

            // Get the Connections URL to use
            var url = _apiUrl;

            // Get a list of all Connections available from TrakHound Api
            var connectionsRequest = new Task <List <ConnectionDefinition> >(() => Connections.Get(url, _apiToken).ToList());

            connectionsRequest.ContinueWith(x =>
            {
                var connections = x.Result;
                if (!connections.IsNullOrEmpty())
                {
                    // Add each Device to SavedDeviceList
                    foreach (var connection in x.Result)
                    {
                        LoadDevice(connection.DeviceId);
                    }
                }
                else
                {
                    Dispatcher.BeginInvoke(new Action(() =>
                    {
                        Loading = false;
                        if (!IsOptionsShown)
                        {
                            OpenOptionsPage();
                        }
                    }), System.Windows.Threading.DispatcherPriority.Background, null);
                }
            });
            connectionsRequest.Start();
        }