Skip to content

Commit

Permalink
Removed Serilog Nuget
Browse files Browse the repository at this point in the history
Fixed TriggerDetailWindow Service Injection
Fixed DI Container Distribution
Added DeviceService for further developing with other devices
  • Loading branch information
Locxion committed Jan 30, 2024
1 parent 7456c8a commit 392327e
Show file tree
Hide file tree
Showing 12 changed files with 97 additions and 48 deletions.
9 changes: 7 additions & 2 deletions DependencyConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<AppInfoWindow>()
.AddTransient<BlacklistWindow>()
Expand Down Expand Up @@ -46,6 +52,5 @@ public static ServiceProvider ConfigureServices()
// Hier füge deine Abhängigkeiten hinzu
// .AddTransient<Interface, Implementierung>()
.BuildServiceProvider();
return serviceProvider;
}
}
48 changes: 48 additions & 0 deletions Interfaces/IDeviceService.cs
Original file line number Diff line number Diff line change
@@ -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();
}
}
3 changes: 1 addition & 2 deletions Main.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
using NanoTwitchLeafs.Services;
using NanoTwitchLeafs.Windows;
using Newtonsoft.Json;
using Serilog.Events;

namespace NanoTwitchLeafs;

Expand All @@ -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<ISettingsService>();
// attach property change event to configuration object and its subsequent elements if any derived NotifyObject
Expand Down
7 changes: 1 addition & 6 deletions NanoTwitchLeafs.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -201,12 +201,6 @@
<Reference Include="Renci.SshNet, Version=2023.0.1.0, Culture=neutral, PublicKeyToken=1cee9f8bde3db106, processorArchitecture=MSIL">
<HintPath>packages\SSH.NET.2023.0.1\lib\net462\Renci.SshNet.dll</HintPath>
</Reference>
<Reference Include="Serilog, Version=2.0.0.0, Culture=neutral, PublicKeyToken=24c2f752a8e58a10, processorArchitecture=MSIL">
<HintPath>packages\Serilog.3.1.1\lib\net471\Serilog.dll</HintPath>
</Reference>
<Reference Include="Serilog.Extensions.Logging, Version=7.0.0.0, Culture=neutral, PublicKeyToken=24c2f752a8e58a10, processorArchitecture=MSIL">
<HintPath>packages\Serilog.Extensions.Logging.8.0.0\lib\net462\Serilog.Extensions.Logging.dll</HintPath>
</Reference>
<Reference Include="SQLite-net, Version=1.8.116.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>packages\sqlite-net-pcl.1.8.116\lib\netstandard2.0\SQLite-net.dll</HintPath>
</Reference>
Expand Down Expand Up @@ -448,6 +442,7 @@
<SubType>Designer</SubType>
</ApplicationDefinition>
<Compile Include="Enums\StreamingPlatformEnum.cs" />
<Compile Include="Interfaces\IDeviceService.cs" />
<Compile Include="Interfaces\IStreamingPlatformService.cs" />
<Compile Include="Main.cs" />
<Compile Include="Colors\ColorConverting.cs" />
Expand Down
3 changes: 1 addition & 2 deletions Properties/Resources.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Properties/Resources.resx
Original file line number Diff line number Diff line change
Expand Up @@ -879,7 +879,7 @@ and then Click the Button below.</value>
<value>Broadcaster Username</value>
</data>
<data name="Window_TwitchLink_Tab_Bot" xml:space="preserve">
<value>Bot</value>
<value>Bot Account</value>
</data>
<data name="Window_TwitchLink_Label_ClickNext" xml:space="preserve">
<value>Link successful! Click Next &gt;&gt;&gt;</value>
Expand Down
4 changes: 2 additions & 2 deletions Windows/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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<TriggerWindow>();
var triggerWindow = _serviceProvider.GetRequiredService<TriggerWindow>();
triggerWindow.Owner = this;


Expand Down
47 changes: 23 additions & 24 deletions Windows/TriggerDetailWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand All @@ -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();

Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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;
}
Expand All @@ -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();
Expand All @@ -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;
Expand Down Expand Up @@ -412,12 +411,12 @@ private void Save_Button_Click(object sender, RoutedEventArgs e)
List<TriggerSetting> 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;
Expand Down
12 changes: 6 additions & 6 deletions Windows/TriggerWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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>();
triggerDetailWindow.TriggerSetting = triggerSetting;
triggerDetailWindow.Owner = this;
triggerDetailWindow.Closed += TriggerDetailWindow_Closed;
triggerDetailWindow.Show();
}
Expand Down
2 changes: 1 addition & 1 deletion Windows/TwitchLinkWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
<TextBlock x:Name="Double_TextBlock" Grid.Column="1" HorizontalAlignment="Left" Margin="10,115,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Height="246" Width="363" TextAlignment="Center" MouseEnter="TextBlock_MouseEnter" MouseLeave="TextBlock_MouseLeave" MouseDown="Double_TextBlock_MouseDown" Text="{x:Static p:Resources.Window_TwitchLink_Double_Help}" />
</Grid>
</TabItem>
<TabItem x:Name="ConnectBroadcaster_TabItem" Header="{x:Static p:Resources.Window_TwitchLink_Tab_Broadcaster}" IsEnabled="False">
<TabItem x:Name="ConnectBroadcaster_TabItem" Header="{x:Static p:Resources.Window_TwitchLink_Tab_Broadcaster}" IsEnabled="False">
<Grid x:Name="Broadcaster_Picture" Background="#FFE5E5E5">
<TextBlock HorizontalAlignment="Left" Margin="10,10,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Height="234" Width="440" Text="{x:Static p:Resources.Window_TwitchLink_Broadcaster_Permissions_Text}" />
<Button x:Name="LinkBroadcaster_Button" Content="{x:Static p:Resources.Window_TwitchLink_Button_Link}" HorizontalAlignment="Left" Margin="105,277,0,0" VerticalAlignment="Top" Width="180" Click="LinkBroadcaster_Button_Click" />
Expand Down
6 changes: 6 additions & 0 deletions Windows/TwitchLinkWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,9 @@ private void Single_TextBlock_MouseDown(object sender, MouseButtonEventArgs e)
{
_doubleAccount = false;
ConnectBroadcaster_TabItem.IsSelected = true;
BroadcasterAccount_Textbox.Focusable = true;
BroadcasterAccount_Textbox.SelectAll();
BroadcasterAccount_Textbox.Focus();
}

private void BCBack_Button_Click(object sender, RoutedEventArgs e)
Expand All @@ -80,6 +83,9 @@ private void BCNext_Button_Click(object sender, RoutedEventArgs e)
if (_doubleAccount)
{
ConnectBot_TabItem.IsSelected = true;
BotAccount_Textbox.Focusable = true;
BotAccount_Textbox.SelectAll();
BotAccount_Textbox.Focus();
}
else
{
Expand Down
2 changes: 0 additions & 2 deletions packages.config
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@
<package id="SQLitePCLRaw.core" version="2.0.4" targetFramework="net472" />
<package id="SQLitePCLRaw.lib.e_sqlite3" version="2.0.4" targetFramework="net472" />
<package id="SQLitePCLRaw.provider.dynamic_cdecl" version="2.0.4" targetFramework="net472" />
<package id="Serilog" version="3.1.1" targetFramework="net48" />
<package id="SuperSocket.ClientEngine.Core" version="0.10.0" targetFramework="net472" />
<package id="System.Buffers" version="4.5.1" targetFramework="net472" />
<package id="System.Collections.Specialized" version="4.3.0" targetFramework="net472" />
Expand Down Expand Up @@ -103,7 +102,6 @@
<package id="Portable.BouncyCastle" version="1.9.0" targetFramework="net472" />
<package id="Microsoft.CSharp" version="4.7.0" targetFramework="net472" />
<package id="Pastebin.API.CSharp" version="1.1.0" targetFramework="net472" />
<package id="Serilog.Extensions.Logging" version="8.0.0" targetFramework="net48" />
<package id="SimpleThreadMonitor" version="1.0.2.1" targetFramework="net472" />
<package id="SocketIoClientDotNet" version="0.9.13" targetFramework="net472" />
<package id="System.ComponentModel.Annotations" version="5.0.0" targetFramework="net472" />
Expand Down

0 comments on commit 392327e

Please sign in to comment.