public override Task OnStartAsync(StartKind startKind, IActivatedEventArgs args)
        {
            // long-running startup tasks go here
            db = new DataService();

            db.createDB();

            foreach (var device in db.DevicesTable)
            {
                IDevice dev = DeviceTypeFactory.MakeDevice(device.FirmwareName, device);

                dev.DeviceDetails.Status = DeviceStatus.Missing;

                devices.Add(dev);
            }

            NavigationService.Navigate(typeof(Views.MainPage));

            ssdpClient.Search();
            wifiClient.Search();

            searchTimer.Tick    += SearchTimer_Tick;
            searchTimer.Interval = new TimeSpan(0, 1, 0);
            searchTimer.Start();


            return(Task.CompletedTask);
        }
        private async void WifiClient_DeviceFound(object sender, WiFiClient.DeviceFoundEventArgs e)
        {
            var device = devices.FirstOrDefault(D => D.GivenName == e.Device.GivenName);

            await CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.High, () =>
            {
                if (device == null)
                {
                    devices.Add(DeviceTypeFactory.MakeDevice(e.Device.FirmwareName, e.Device));
                    db.InsertNewDevice(e.Device);
                }
                else
                {
                    device.DeviceDetails.Status = DeviceStatus.UnProvisioned;
                }
            });
        }
        private async void SsdpClient_DeviceFound(object sender, DeviceFoundEventArgs e)
        {
            if (e.Device.DeviceType.manufacturer == "IOESPT")
            {
                var foundDevice = devices.FirstOrDefault(D => D.DeviceDetails.ChipId == e.Device.DeviceType.serialNumber);

                Uri uri = new Uri(e.Device.URLBase);


                if (foundDevice != null)
                {
                    await CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.High, () => {
                        foundDevice.DeviceDetails.Status = DeviceStatus.Online;

                        foundDevice.DeviceDetails.Ip = uri.Host;
                    });
                }
                else
                {
                    //We have a new device online
                    var newDevice = new RegisteredDevice();

                    newDevice.ChipId          = e.Device.DeviceType.serialNumber;
                    newDevice.FirmwareName    = e.Device.DeviceType.modelName;
                    newDevice.ModuleType      = e.Device.DeviceType.modelName;
                    newDevice.FirmwareVersion = e.Device.DeviceType.modelNumber;
                    newDevice.GivenName       = e.Device.DeviceType.friendlyName;
                    newDevice.Status          = DeviceStatus.Online;
                    newDevice.ConnectedTo     = "None";
                    newDevice.Ip = uri.Host;

                    db.InsertNewDevice(newDevice);

                    await CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.High, () => {
                        devices.Add(DeviceTypeFactory.MakeDevice(newDevice.FirmwareName, newDevice));
                    });
                }
            }
        }