示例#1
0
        private async void OnAddClick(object sender, RoutedEventArgs e)
        {
            try
            {
                foreach (var i in App.Devices)
                {
                    if (i.Identifier == sID.Text)
                    {
                        Logger.Log(LogType.Warning, $"Unable to add device \"{i.Name}\" with ID \"{i.Identifier}\" because it already exists");
                        await Dialog.ShowDialogAsync("Warning", $"A device with the name \"{i.Name}\" already exists with the same ID!", "OK");

                        return;
                    }
                }

                ContentDialogResult result = await Dialog.ShowDialogAsync(
                    "Add Device",
                    $"Are you sure you want to add the following device?\n\nName: {sName.Text}\n\nID: {sID.Text}",
                    "No",
                    "Yes");

                if (result == ContentDialogResult.Primary)
                {
                    try
                    {
                        Logger.Log(LogType.Information, $"Attempting to add device \"{sName.Text}\" with ID \"{sID.Text}\"");
                        Device dev = new Device
                        {
                            DarkMode   = true,
                            Identifier = sID.Text,
                            Name       = sName.Text,
                            ToastType  = Toast.Pencil
                        };

                        App.Devices.Add(dev);
                        DevicesJson.SaveDevices(App.Devices);

                        App.InvokeDeviceChange(this);

                        Logger.Log(LogType.Information, $"Successfully saved device \"{sName.Text}\" with ID \"{sID.Text}\"");
                        await Dialog.ShowDialogAsync("Success", $"Device \"{sName.Text}\" added successfully!", "OK");
                    }
                    catch (Exception ex)
                    {
                        Logger.Log(LogType.Warning, $"Was unable to add device \"{sName.Text}\" with ID \"{sID.Text}\"", ex);
                        await Dialog.ShowDialogAsync("Error", $"Unable to add device \"{sName.Text}\"", "OK");
                    }
                }
            }
            catch (Exception ex)
            {
                Logger.Log(LogType.Warning, $"Was unable to add device \"{sName.Text}\" with ID \"{sID.Text}\" because an unknown error occured", ex);
                await Dialog.ShowDialogAsync("Error", "An unknown error occured trying to add the device", "OK");
            }
        }
示例#2
0
        private void OnDeleteClicked(object sender, RoutedEventArgs e)
        {
            Logger.Log("Deleting current device");

            try
            {
                sDeleteFlyout.Hide();

                App.Devices.Remove(selectedDevice);
                DevicesJson.SaveDevices(App.Devices);

                App.InvokeDeviceChange(this);

                this.NavigationService.Navigate(null);
            }
            catch (Exception ex)
            {
                Logger.Log("Unable to delete device/an error occured deleting the device", ex);
            }
        }
示例#3
0
        private async void OnApplyClicked(object sender, RoutedEventArgs e)
        {
            selectedDevice.Name       = sName.Text;
            selectedDevice.Identifier = sID.Text;

            Logger.Log(LogType.Information, "Saving device information");

            try
            {
                int index = App.Devices.FindIndex((e) =>
                {
                    return(e == selectedDevice);
                });

                if (index < 0)
                {
                    await Dialog.ShowDialogAsync("Error", "Unable to save changes!", "OK");
                }
                else
                {
                    if (sToastType.SelectedIndex != 0)
                    {
                        await Dialog.ShowDialogAsync("Notice", "More toast types are coming soon!", "Great!");

                        return;
                    }

                    App.Devices[index].Name       = sName.Text;
                    sNameTitle.Content            = sName.Text;
                    App.Devices[index].Identifier = sID.Text;
                    App.Devices[index].DarkMode   = sDarkMode.IsOn;
                    DevicesJson.SaveDevices(App.Devices);
                    App.InvokeDeviceChange(this);
                    await Dialog.ShowDialogAsync("Success", "Successfully applied changed to device!", "OK");
                }
            }
            catch (Exception ex)
            {
                Logger.Log("Unable to save device changes", ex);
            }
        }
示例#4
0
        private void OnDoneClicked(object sender, RoutedEventArgs e)
        {
            try
            {
                Device dev = new Device
                {
                    DarkMode   = true,
                    Identifier = sID.Text,
                    Name       = sName.Text,
                    ToastType  = Toast.Pencil
                };

                App.Devices.Add(dev);
                DevicesJson.SaveDevices(App.Devices);
                App.InvokeDeviceChange(this);
            }
            catch (Exception ex)
            {
                Logger.Log("Unable to save the device from the pairing wizard", ex);
            }

            Window.GetWindow(this).Close();
        }