diff --git a/GroundStation.cs b/GroundStation.cs index d2b672f..b026c09 100644 --- a/GroundStation.cs +++ b/GroundStation.cs @@ -10,6 +10,7 @@ This Source Code Form is subject to the terms of the Mozilla Public #endregion "copyright" +using CommunityToolkit.Mvvm.Input; using DaleGhent.NINA.GroundStation.Mqtt; using DaleGhent.NINA.GroundStation.TTS; using DaleGhent.NINA.GroundStation.Utilities; @@ -30,12 +31,11 @@ This Source Code Form is subject to the terms of the Mozilla Public using System.Security; using System.Threading; using System.Threading.Tasks; -using System.Windows.Input; namespace DaleGhent.NINA.GroundStation { [Export(typeof(IPluginManifest))] - public class GroundStation : PluginBase, ISettings, INotifyPropertyChanged { + public partial class GroundStation : PluginBase, ISettings, INotifyPropertyChanged { private MqttClient mqttClient; [ImportingConstructor] @@ -45,16 +45,6 @@ public GroundStation() { Properties.Settings.Default.UpgradeSettings = false; CoreUtil.SaveSettings(Properties.Settings.Default); } - - PushoverTestCommand = new AsyncCommand(PushoverTest); - EmailTestCommand = new AsyncCommand(EmailTest); - TelegramTestCommand = new AsyncCommand(TelegramTest); - MQTTTestCommand = new AsyncCommand(MQTTTest); - IFTTTTestCommand = new AsyncCommand(IFTTTTest); - TtsTestCommand = new AsyncCommand(TtsTest); - - SelectDefaultSoundFileCommand = new RelayCommand(OpenSelectDefaultSoundFileDialog); - SelectDefaultFailureSoundFileCommand = new RelayCommand(OpenSelectDefaultFailureSoundFileDialog); } public override Task Initialize() { @@ -75,6 +65,7 @@ public override async Task Teardown() { return; } + [RelayCommand] private async Task PushoverTest(object arg) { var send = new SendToPushover.SendToPushover() { Message = "Test Message", @@ -93,6 +84,7 @@ private async Task PushoverTest(object arg) { } } + [RelayCommand] private async Task EmailTest(object arg) { var send = new SendToEmail.SendToEmail() { Subject = "Test Subject", @@ -116,6 +108,7 @@ private async Task EmailTest(object arg) { } } + [RelayCommand] private async Task TelegramTest(object arg) { var send = new SendToTelegram.SendToTelegram() { Message = "Test Message", @@ -133,6 +126,7 @@ private async Task TelegramTest(object arg) { } } + [RelayCommand] private async Task MQTTTest(object arg) { var send = new SendToMqtt.SendToMqtt() { Topic = "Test Topic", @@ -151,6 +145,7 @@ private async Task MQTTTest(object arg) { } } + [RelayCommand] private async Task IFTTTTest(object arg) { var send = new SendToIftttWebhook.SendToIftttWebhook() { Value1 = "Test Value1", @@ -170,6 +165,7 @@ private async Task IFTTTTest(object arg) { } } + [RelayCommand] private async Task TtsTest(object arg) { var send = new SendToTTS() { Message = TtsTestMessage, @@ -217,13 +213,6 @@ private async Task LwtStopWorker() { return; } - public IAsyncCommand PushoverTestCommand { get; } - public IAsyncCommand EmailTestCommand { get; } - public IAsyncCommand IFTTTTestCommand { get; } - public IAsyncCommand TelegramTestCommand { get; } - public IAsyncCommand MQTTTestCommand { get; } - public IAsyncCommand TtsTestCommand { get; } - public string IFTTTWebhookKey { get => Security.Decrypt(Properties.Settings.Default.IFTTTWebhookKey); set { @@ -680,6 +669,7 @@ protected void RaisePropertyChanged([CallerMemberName] string propertyName = nul PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName)); } + [RelayCommand] internal void OpenSelectDefaultSoundFileDialog(object obj) { Microsoft.Win32.OpenFileDialog dialog = new() { FileName = string.Empty, @@ -691,6 +681,7 @@ internal void OpenSelectDefaultSoundFileDialog(object obj) { } } + [RelayCommand] internal void OpenSelectDefaultFailureSoundFileDialog(object obj) { Microsoft.Win32.OpenFileDialog dialog = new() { FileName = string.Empty, @@ -701,8 +692,5 @@ internal void OpenSelectDefaultFailureSoundFileDialog(object obj) { PlaySoundDefaultFailureFile = dialog.FileName; } } - - public ICommand SelectDefaultSoundFileCommand { get; private set; } - public ICommand SelectDefaultFailureSoundFileCommand { get; private set; } } } \ No newline at end of file diff --git a/Options.xaml b/Options.xaml index 0ec2f30..222215c 100644 --- a/Options.xaml +++ b/Options.xaml @@ -958,7 +958,7 @@ Margin="5" HorizontalAlignment="Left" VerticalAlignment="Center" - Command="{Binding SelectDefaultSoundFileCommand}"> + Command="{Binding OpenSelectDefaultSoundFileDialogCommand}"> @@ -988,7 +988,7 @@ Margin="5" HorizontalAlignment="Left" VerticalAlignment="Center" - Command="{Binding SelectDefaultFailureSoundFileCommand}"> + Command="{Binding OpenSelectDefaultFailureSoundFileDialogCommand}"> diff --git a/PlaySound/PlaySound.cs b/PlaySound/PlaySound.cs index 6b9045d..815acd2 100644 --- a/PlaySound/PlaySound.cs +++ b/PlaySound/PlaySound.cs @@ -10,6 +10,7 @@ This Source Code Form is subject to the terms of the Mozilla Public #endregion "copyright" +using CommunityToolkit.Mvvm.Input; using NetCoreAudio; using Newtonsoft.Json; using NINA.Core.Model; @@ -22,7 +23,6 @@ This Source Code Form is subject to the terms of the Mozilla Public using System.IO; using System.Threading; using System.Threading.Tasks; -using System.Windows.Input; namespace DaleGhent.NINA.GroundStation.PlaySound { @@ -32,14 +32,13 @@ namespace DaleGhent.NINA.GroundStation.PlaySound { [ExportMetadata("Category", "Ground Station")] [Export(typeof(ISequenceItem))] [JsonObject(MemberSerialization.OptIn)] - public class PlaySound : SequenceItem, IValidatable { + public partial class PlaySound : SequenceItem, IValidatable { private string soundFile = string.Empty; private bool waitUntilFinished = true; [ImportingConstructor] public PlaySound() { SoundFile = Properties.Settings.Default.PlaySoundDefaultFile; - SelectSoundFileCommand = new RelayCommand(OpenSelectSoundFileDialog); Validate(); } @@ -118,6 +117,7 @@ public override string ToString() { return $"Category: {Category}, Item: {nameof(PlaySound)}, SoundFile: {soundFile}, WaitUntilFinished: {WaitUntilFinished}"; } + [RelayCommand] internal void OpenSelectSoundFileDialog(object obj) { Microsoft.Win32.OpenFileDialog dialog = new() { FileName = string.Empty, @@ -128,7 +128,5 @@ internal void OpenSelectSoundFileDialog(object obj) { SoundFile = dialog.FileName; } } - - public ICommand SelectSoundFileCommand { get; private set; } } } \ No newline at end of file diff --git a/PlaySound/PlaySoundOnFailureTrigger.cs b/PlaySound/PlaySoundOnFailureTrigger.cs index 3dd39a5..436440f 100644 --- a/PlaySound/PlaySoundOnFailureTrigger.cs +++ b/PlaySound/PlaySoundOnFailureTrigger.cs @@ -10,6 +10,7 @@ This Source Code Form is subject to the terms of the Mozilla Public #endregion "copyright" +using CommunityToolkit.Mvvm.Input; using NetCoreAudio; using Newtonsoft.Json; using NINA.Core.Enum; @@ -37,14 +38,13 @@ namespace DaleGhent.NINA.GroundStation.PlaySoundOnFailureTrigger { [ExportMetadata("Category", "Ground Station")] [Export(typeof(ISequenceTrigger))] [JsonObject(MemberSerialization.OptIn)] - public class PlaySoundOnFailureTrigger : SequenceTrigger, IValidatable { + public partial class PlaySoundOnFailureTrigger : SequenceTrigger, IValidatable { private string soundFile = string.Empty; private ISequenceRootContainer failureHook; [ImportingConstructor] public PlaySoundOnFailureTrigger() { SoundFile = Properties.Settings.Default.PlaySoundDefaultFailureFile; - SelectSoundFileCommand = new RelayCommand(OpenSelectSoundFileDialog); Validate(); } @@ -157,6 +157,7 @@ public override string ToString() { return $"Category: {Category}, Item: {nameof(PlaySoundOnFailureTrigger)}, SoundFile: {soundFile}"; } + [RelayCommand] internal void OpenSelectSoundFileDialog(object obj) { Microsoft.Win32.OpenFileDialog dialog = new() { FileName = string.Empty, @@ -167,7 +168,5 @@ internal void OpenSelectSoundFileDialog(object obj) { SoundFile = dialog.FileName; } } - - public ICommand SelectSoundFileCommand { get; private set; } } } \ No newline at end of file diff --git a/PlaySound/PlaySoundOnFailureTriggerTemplate.xaml b/PlaySound/PlaySoundOnFailureTriggerTemplate.xaml index 9fafddd..3041fb9 100644 --- a/PlaySound/PlaySoundOnFailureTriggerTemplate.xaml +++ b/PlaySound/PlaySoundOnFailureTriggerTemplate.xaml @@ -37,7 +37,7 @@ Margin="5" HorizontalAlignment="Left" VerticalAlignment="Center" - Command="{Binding SelectSoundFileCommand}"> + Command="{Binding OpenSelectSoundFileDialogCommand}"> diff --git a/PlaySound/PlaySoundTemplate.xaml b/PlaySound/PlaySoundTemplate.xaml index 173e3e3..d85878e 100644 --- a/PlaySound/PlaySoundTemplate.xaml +++ b/PlaySound/PlaySoundTemplate.xaml @@ -44,7 +44,7 @@ Margin="5" HorizontalAlignment="Left" VerticalAlignment="Center" - Command="{Binding SelectSoundFileCommand}"> + Command="{Binding OpenSelectSoundFileDialogCommand}">