From 392327e24dc63630b85ea3c5fa586092b47aaeb6 Mon Sep 17 00:00:00 2001 From: Locxion Date: Tue, 30 Jan 2024 12:47:00 +0100 Subject: [PATCH] Removed Serilog Nuget Fixed TriggerDetailWindow Service Injection Fixed DI Container Distribution Added DeviceService for further developing with other devices --- DependencyConfig.cs | 9 ++++-- Interfaces/IDeviceService.cs | 48 +++++++++++++++++++++++++++++ Main.cs | 3 +- NanoTwitchLeafs.csproj | 7 +---- Properties/Resources.Designer.cs | 3 +- Properties/Resources.resx | 2 +- Windows/MainWindow.xaml.cs | 4 +-- Windows/TriggerDetailWindow.xaml.cs | 47 ++++++++++++++-------------- Windows/TriggerWindow.xaml.cs | 12 ++++---- Windows/TwitchLinkWindow.xaml | 2 +- Windows/TwitchLinkWindow.xaml.cs | 6 ++++ packages.config | 2 -- 12 files changed, 97 insertions(+), 48 deletions(-) create mode 100644 Interfaces/IDeviceService.cs diff --git a/DependencyConfig.cs b/DependencyConfig.cs index ef2143d..86b9621 100644 --- a/DependencyConfig.cs +++ b/DependencyConfig.cs @@ -10,9 +10,15 @@ namespace NanoTwitchLeafs; public static class DependencyConfig { + public static ServiceProvider ServiceProvider; + static DependencyConfig() + { + ServiceProvider = ConfigureServices(); + } + public static ServiceProvider ConfigureServices() { - var serviceProvider = new ServiceCollection() + return new ServiceCollection() //Windows .AddTransient() .AddTransient() @@ -46,6 +52,5 @@ public static ServiceProvider ConfigureServices() // Hier füge deine Abhängigkeiten hinzu // .AddTransient() .BuildServiceProvider(); - return serviceProvider; } } \ No newline at end of file diff --git a/Interfaces/IDeviceService.cs b/Interfaces/IDeviceService.cs new file mode 100644 index 0000000..afc109a --- /dev/null +++ b/Interfaces/IDeviceService.cs @@ -0,0 +1,48 @@ +using System; +using System.Threading.Tasks; + +namespace NanoTwitchLeafs.Interfaces; + +public interface IDeviceService +{ + Task DiscoverDevice(); + Task PairDevice(); + Task SendEffectToDevice(); + Task SendColorToDevice(); + Task SendColorToPart(); +} + +public class DeviceService : IDeviceService +{ + private readonly ISettingsService _settingsService; + + public DeviceService(ISettingsService settingsService) + { + _settingsService = settingsService ?? throw new ArgumentNullException(nameof(settingsService)); + } + + public async Task DiscoverDevice() + { + throw new NotImplementedException(); + } + + public async Task PairDevice() + { + throw new System.NotImplementedException(); + } + + public async Task SendEffectToDevice() + { + throw new System.NotImplementedException(); + } + + public async Task SendColorToDevice() + { + throw new System.NotImplementedException(); + } + + public async Task SendColorToPart() + { + throw new System.NotImplementedException(); + } +} \ No newline at end of file diff --git a/Main.cs b/Main.cs index c033201..0a99cc1 100644 --- a/Main.cs +++ b/Main.cs @@ -13,7 +13,6 @@ using NanoTwitchLeafs.Services; using NanoTwitchLeafs.Windows; using Newtonsoft.Json; -using Serilog.Events; namespace NanoTwitchLeafs; @@ -24,7 +23,7 @@ public static class Main public static async void Run() { - var serviceProvider = DependencyConfig.ConfigureServices(); + var serviceProvider = DependencyConfig.ServiceProvider; var settingsService = serviceProvider.GetService(); // attach property change event to configuration object and its subsequent elements if any derived NotifyObject diff --git a/NanoTwitchLeafs.csproj b/NanoTwitchLeafs.csproj index 797a963..23b23f2 100644 --- a/NanoTwitchLeafs.csproj +++ b/NanoTwitchLeafs.csproj @@ -201,12 +201,6 @@ packages\SSH.NET.2023.0.1\lib\net462\Renci.SshNet.dll - - packages\Serilog.3.1.1\lib\net471\Serilog.dll - - - packages\Serilog.Extensions.Logging.8.0.0\lib\net462\Serilog.Extensions.Logging.dll - packages\sqlite-net-pcl.1.8.116\lib\netstandard2.0\SQLite-net.dll @@ -448,6 +442,7 @@ Designer + diff --git a/Properties/Resources.Designer.cs b/Properties/Resources.Designer.cs index cad51ca..78e7b0b 100644 --- a/Properties/Resources.Designer.cs +++ b/Properties/Resources.Designer.cs @@ -1,7 +1,6 @@ //------------------------------------------------------------------------------ // // This code was generated by a tool. -// Runtime Version:4.0.30319.42000 // // Changes to this file may cause incorrect behavior and will be lost if // the code is regenerated. @@ -2448,7 +2447,7 @@ public static string Window_TwitchLink_Single_Help { } /// - /// Looks up a localized string similar to Bot. + /// Looks up a localized string similar to Bot Account. /// public static string Window_TwitchLink_Tab_Bot { get { diff --git a/Properties/Resources.resx b/Properties/Resources.resx index ece1c37..23a4a39 100644 --- a/Properties/Resources.resx +++ b/Properties/Resources.resx @@ -879,7 +879,7 @@ and then Click the Button below. Broadcaster Username - Bot + Bot Account Link successful! Click Next >>> diff --git a/Windows/MainWindow.xaml.cs b/Windows/MainWindow.xaml.cs index 5412f30..e416e28 100644 --- a/Windows/MainWindow.xaml.cs +++ b/Windows/MainWindow.xaml.cs @@ -44,7 +44,7 @@ public partial class MainWindow : Window private readonly ITriggerService _triggerService; private readonly IStreamingPlatformService _streamingPlatformService; private readonly TaskbarIcon _tbi = new TaskbarIcon(); - private readonly ServiceProvider _serviceProvider = DependencyConfig.ConfigureServices(); + private readonly ServiceProvider _serviceProvider = DependencyConfig.ServiceProvider; #region Init public MainWindow(ISettingsService settingsService, IAnalyticsService analyticsService, IHypeRateService hypeRateService, @@ -663,7 +663,7 @@ private void SendMessage_TextBox_TouchEnter(object sender, System.Windows.Input. private void NanoCmd_Button_Click(object sender, RoutedEventArgs e) { - TriggerWindow triggerWindow = _serviceProvider.GetRequiredService(); + var triggerWindow = _serviceProvider.GetRequiredService(); triggerWindow.Owner = this; diff --git a/Windows/TriggerDetailWindow.xaml.cs b/Windows/TriggerDetailWindow.xaml.cs index 8445aac..e0695fc 100644 --- a/Windows/TriggerDetailWindow.xaml.cs +++ b/Windows/TriggerDetailWindow.xaml.cs @@ -30,7 +30,7 @@ public partial class TriggerDetailWindow : Window private readonly ILog _logger = LogManager.GetLogger(typeof(TriggerWindow)); private string _channelPointsGuid; - public TriggerSetting _triggerSetting { get; set; } + public TriggerSetting TriggerSetting; public TriggerDetailWindow(ISettingsService settingsService, INanoService nanoService, IHypeRateService hypeRateService,IStreamLabsService streamLabsService, ITwitchPubSubService twitchPubSubService, ITriggerRepositoryService triggerRepositoryService) { @@ -41,7 +41,6 @@ public TriggerDetailWindow(ISettingsService settingsService, INanoService nanoSe _twitchPubSubService = twitchPubSubService ?? throw new ArgumentNullException(nameof(twitchPubSubService)); _triggerRepositoryService = triggerRepositoryService ?? throw new ArgumentNullException(nameof(triggerRepositoryService)); - Constants.SetCultureInfo(_settingsService.CurrentSettings.Language); InitializeComponent(); @@ -85,11 +84,11 @@ private async Task InitData() Effect_ComboBox.Items.Add(effect); } - if (_triggerSetting == null) + if (TriggerSetting == null) return; // Set On/Off Slider State - if (_triggerSetting.IsActive == true) + if (TriggerSetting.IsActive == true) { OnOff_Slider.Value = 0; OnOff_Slider.Background = Brushes.LimeGreen; @@ -103,14 +102,14 @@ private async Task InitData() // Set Selected Item in Effect Dropdown foreach (string effect in Effect_ComboBox.Items) { - if (effect == _triggerSetting.Effect) + if (effect == TriggerSetting.Effect) { Effect_ComboBox.SelectedItem = effect; } } // Set Radio Button for Effect or Color - if (_triggerSetting.IsColor) + if (TriggerSetting.IsColor) { Effect_RadioButton.IsChecked = false; Effect_ComboBox.IsEnabled = false; @@ -120,15 +119,15 @@ private async Task InitData() } // Set Color Picker to saved Color - Color color = new Color { R = _triggerSetting.R, G = _triggerSetting.G, B = _triggerSetting.B, A = 255 }; + Color color = new Color { R = TriggerSetting.R, G = TriggerSetting.G, B = TriggerSetting.B, A = 255 }; ColorPicker.SelectedColor = color; // Fill Command/Keyword Textbox - CommandKeyword_Textbox.Text = _triggerSetting.CMD; + CommandKeyword_Textbox.Text = TriggerSetting.CMD; // Fill SoundeffectPath Textbox - SoundFilePath_Textbox.Text = _triggerSetting.SoundFilePath; - if (!string.IsNullOrWhiteSpace(_triggerSetting.SoundFilePath)) + SoundFilePath_Textbox.Text = TriggerSetting.SoundFilePath; + if (!string.IsNullOrWhiteSpace(TriggerSetting.SoundFilePath)) { SoundFilePath_Textbox.IsEnabled = true; } @@ -146,21 +145,21 @@ private async Task InitData() } // Fill Options Texboxes and Checkboxes - Duration_Textbox.Text = _triggerSetting.Duration.ToString(); - Brightness_Textbox.Text = _triggerSetting.Brightness.ToString(); - Amount_Textbox.Text = _triggerSetting.Amount.ToString(); - Cooldown_Textbox.Text = _triggerSetting.Cooldown.ToString(); - Volume_Textbox.Text = _triggerSetting.Volume.ToString(); - _channelPointsGuid = _triggerSetting.ChannelPointsGuid; + Duration_Textbox.Text = TriggerSetting.Duration.ToString(); + Brightness_Textbox.Text = TriggerSetting.Brightness.ToString(); + Amount_Textbox.Text = TriggerSetting.Amount.ToString(); + Cooldown_Textbox.Text = TriggerSetting.Cooldown.ToString(); + Volume_Textbox.Text = TriggerSetting.Volume.ToString(); + _channelPointsGuid = TriggerSetting.ChannelPointsGuid; - Viponly_Checkbox.IsChecked = _triggerSetting.VipOnly; - Subonly_Checkbox.IsChecked = _triggerSetting.SubscriberOnly; - Modonly_Checkbox.IsChecked = _triggerSetting.ModeratorOnly; + Viponly_Checkbox.IsChecked = TriggerSetting.VipOnly; + Subonly_Checkbox.IsChecked = TriggerSetting.SubscriberOnly; + Modonly_Checkbox.IsChecked = TriggerSetting.ModeratorOnly; - if (_triggerSetting.ChannelPointsGuid != null && _triggerSetting.ChannelPointsGuid != "{00000000-0000-0000-0000-000000000000}") + if (TriggerSetting.ChannelPointsGuid != null && TriggerSetting.ChannelPointsGuid != "{00000000-0000-0000-0000-000000000000}") { Dispatcher.BeginInvoke(new Action(() => channelPointsDetection_Label.Foreground = Brushes.Green)); - Dispatcher.BeginInvoke(new Action(() => channelPointsDetection_Label.Content = string.Format(Properties.Resources.Code_TriggerDetail_Label_CPGuidSet, _triggerSetting.ChannelPointsGuid))); + Dispatcher.BeginInvoke(new Action(() => channelPointsDetection_Label.Content = string.Format(Properties.Resources.Code_TriggerDetail_Label_CPGuidSet, TriggerSetting.ChannelPointsGuid))); } SetControlsEnabled(); @@ -171,7 +170,7 @@ private async Task InitData() private void SetControlsEnabled() { // Set Controls Enabled State && Radio Buttons - switch (_triggerSetting.Trigger) + switch (TriggerSetting.Trigger) { case "Command": Cmd_RadioButton.IsChecked = true; @@ -412,12 +411,12 @@ private void Save_Button_Click(object sender, RoutedEventArgs e) List triggerSettings = _triggerRepositoryService.GetList().ToList(); // If Trigger already exists - if (_triggerSetting != null) + if (TriggerSetting != null) { // Search for existing Trigger and Remove it from List foreach (TriggerSetting setting in triggerSettings) { - if (setting.ID == _triggerSetting.ID) + if (setting.ID == TriggerSetting.ID) { triggerSettings.Remove(setting); break; diff --git a/Windows/TriggerWindow.xaml.cs b/Windows/TriggerWindow.xaml.cs index deaeafa..f254f2e 100644 --- a/Windows/TriggerWindow.xaml.cs +++ b/Windows/TriggerWindow.xaml.cs @@ -8,6 +8,7 @@ using System.Windows; using System.Windows.Controls; using System.Windows.Media; +using Microsoft.Extensions.DependencyInjection; using NanoTwitchLeafs.Interfaces; namespace NanoTwitchLeafs.Windows @@ -215,13 +216,12 @@ private async void OpenTriggerDetails(TriggerSetting triggerSetting = null) _logger.Error("Connection failed! Couldn't get Effect List!"); MessageBox.Show(Properties.Resources.Code_Trigger_MessageBox_EffectList, Properties.Resources.General_MessageBox_Error_Title); return; - } + } + var serviceProvider = DependencyConfig.ServiceProvider; - Window triggerDetailWindow = new TriggerDetailWindow() - { - _triggerSetting = triggerSetting, - Owner = this - }; + var triggerDetailWindow = serviceProvider.GetRequiredService(); + triggerDetailWindow.TriggerSetting = triggerSetting; + triggerDetailWindow.Owner = this; triggerDetailWindow.Closed += TriggerDetailWindow_Closed; triggerDetailWindow.Show(); } diff --git a/Windows/TwitchLinkWindow.xaml b/Windows/TwitchLinkWindow.xaml index 63ed66d..1a605a4 100644 --- a/Windows/TwitchLinkWindow.xaml +++ b/Windows/TwitchLinkWindow.xaml @@ -25,7 +25,7 @@ - +