示例#1
0
        private void OnPageLoaded(object sender, RoutedEventArgs e)
        {
            Logger.Log("Starting connection thread");
            tTimer = new Timer(OnTick, null, 1000, 500);

            lastTick = PNP.GetPNPDevices();
        }
示例#2
0
        public void Setup()
        {
            try
            {
                devices = DevicesJson.GetDevices();

                if (devices.Count <= 0)
                {
                    MessageBox.Show("There are no devices added, please run the configurator to add devices.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    Environment.Exit(-1);
                }

                Settings settings = new Settings();

                lastTick = PNP.GetPNPDevices();

                timer  = new System.Threading.Timer(OnTick, null, 0, settings.RefreshRate);
                offset = settings.Offset;

                settings.Dispose();

                TrayService.Visible = true;
            }
            catch (Exception e)
            {
                Logger.Log("An error occured trying to setup the tray service", e);
                MessageBox.Show("An error occured trying to setup the tray service", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
示例#3
0
        public void OnTick(object stateInfo)
        {
            if (!busy)
            {
                busy    = true;
                curTick = PNP.GetPNPDevices();

                List <PnPDevice> differences = curTick.Where((i) =>
                {
                    return(!(lastTick.Contains(i)));
                }).ToList();

                if (differences.Count > 0)
                {
                    Logger.Log($"Found {differences.Count} new devices");
                }

                foreach (var i in differences)
                {
                    foreach (var j in devices)
                    {
                        if (j.Identifier == i.PNPDeviceID)
                        {
                            ShowToast(j);
                        }
                    }
                }

                lastTick = new List <PnPDevice>(curTick);
                busy     = false;
            }
        }
示例#4
0
        private void OnTick(object s)
        {
            try
            {
                if (!busy)
                {
                    busy = true;

                    curTick = PNP.GetPNPDevices();

                    List <PnPDevice> diffs = curTick.Where((i) =>
                    {
                        return(!(lastTick.Contains(i)));
                    }).ToList();

                    foreach (var i in diffs)
                    {
                        if (!newDevices.Contains(i))
                        {
                            newDevices.Add(i);
                        }
                    }

                    this.Dispatcher.Invoke(() =>
                    {
                        PnPDevice selected = sDevices.SelectedItem as PnPDevice;

                        sDevices.ItemsSource = null;
                        sDevices.ItemsSource = newDevices;
                        sDevices.Items.Refresh();

                        if (selected != null)
                        {
                            if (sDevices.Items.Contains(selected))
                            {
                                sDevices.SelectedItem = selected;
                            }
                        }
                    });

                    busy = false;
                }
            }
            catch (Exception ex)
            {
                Logger.Log("Unable to successfully scan for devices", ex);
                tTimer.Dispose();
            }
        }
示例#5
0
 private async Task RefreshDevices()
 {
     await Task.Run(() =>
     {
         try
         {
             devices     = PNP.GetPNPDevices();
             listDevices = new List <PnPDevice>(devices);
         }
         catch (Exception e)
         {
             listDevices = new List <PnPDevice>();
             Logger.Log(LogType.Warning, "Unable to scan for devices!", e);
         }
     });
 }
示例#6
0
        public void Refresh()
        {
            busy    = true;
            devices = DevicesJson.GetDevices();
            if (devices.Count <= 0)
            {
                MessageBox.Show("There are no devices added, please run the configurator to add devices.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                Environment.Exit(-1);
            }

            Settings settings = new Settings();

            lastTick = PNP.GetPNPDevices();

            offset = settings.Offset;

            settings.Dispose();
            busy = false;
        }