Changed config type of Whitelist to use custom class

This commit is contained in:
Brett Hewitson 2021-12-19 11:46:09 +10:00
parent a74bc2dc78
commit 197fd1a811
11 changed files with 34 additions and 52 deletions

View file

@ -849,11 +849,6 @@
<setting name="ServerMonitorWindow_Top" serializeAs="String"> <setting name="ServerMonitorWindow_Top" serializeAs="String">
<value>50</value> <value>50</value>
</setting> </setting>
<setting name="DiscordBotWhitelist" serializeAs="Xml">
<value>
<ArrayOfString xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" />
</value>
</setting>
<setting name="DiscordBotPrefixFixed" serializeAs="String"> <setting name="DiscordBotPrefixFixed" serializeAs="String">
<value>False</value> <value>False</value>
</setting> </setting>

View file

@ -623,7 +623,7 @@ namespace ServerManagerTool
}; };
if (Config.Default.DiscordBotWhitelist != null) if (Config.Default.DiscordBotWhitelist != null)
{ {
config.DiscordBotWhitelist.AddRange(Config.Default.DiscordBotWhitelist.Cast<string>()); config.DiscordBotWhitelist.AddRange(Config.Default.DiscordBotWhitelist);
} }
await ServerManagerBotFactory.GetServerManagerBot().RunAsync(config, DiscordBotHelper.HandleDiscordCommand, DiscordBotHelper.HandleTranslation, _tokenSourceDiscordBot.Token); await ServerManagerBotFactory.GetServerManagerBot().RunAsync(config, DiscordBotHelper.HandleDiscordCommand, DiscordBotHelper.HandleTranslation, _tokenSourceDiscordBot.Token);

View file

@ -2977,11 +2977,9 @@ namespace ServerManagerTool {
[global::System.Configuration.UserScopedSettingAttribute()] [global::System.Configuration.UserScopedSettingAttribute()]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()] [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
[global::System.Configuration.DefaultSettingValueAttribute("<?xml version=\"1.0\" encoding=\"utf-16\"?>\r\n<ArrayOfString xmlns:xsd=\"http://www.w3." + public global::ServerManagerTool.DiscordBot.Models.DiscordBotWhitelist DiscordBotWhitelist {
"org/2001/XMLSchema\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" />")]
public global::System.Collections.Specialized.StringCollection DiscordBotWhitelist {
get { get {
return ((global::System.Collections.Specialized.StringCollection)(this["DiscordBotWhitelist"])); return ((global::ServerManagerTool.DiscordBot.Models.DiscordBotWhitelist)(this["DiscordBotWhitelist"]));
} }
set { set {
this["DiscordBotWhitelist"] = value; this["DiscordBotWhitelist"] = value;

View file

@ -821,9 +821,8 @@
<Setting Name="ServerMonitorWindow_Top" Type="System.Double" Scope="User"> <Setting Name="ServerMonitorWindow_Top" Type="System.Double" Scope="User">
<Value Profile="(Default)">50</Value> <Value Profile="(Default)">50</Value>
</Setting> </Setting>
<Setting Name="DiscordBotWhitelist" Type="System.Collections.Specialized.StringCollection" Scope="User"> <Setting Name="DiscordBotWhitelist" Type="ServerManagerTool.DiscordBot.Models.DiscordBotWhitelist" Scope="User">
<Value Profile="(Default)">&lt;?xml version="1.0" encoding="utf-16"?&gt; <Value Profile="(Default)" />
&lt;ArrayOfString xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" /&gt;</Value>
</Setting> </Setting>
<Setting Name="DiscordBotPrefixFixed" Type="System.Boolean" Scope="User"> <Setting Name="DiscordBotPrefixFixed" Type="System.Boolean" Scope="User">
<Value Profile="(Default)">False</Value> <Value Profile="(Default)">False</Value>

View file

@ -35,7 +35,7 @@ namespace ServerManagerTool
public static readonly DependencyProperty CommonConfigProperty = DependencyProperty.Register(nameof(CommonConfig), typeof(CommonConfig), typeof(GlobalSettingsControl), new PropertyMetadata(null)); public static readonly DependencyProperty CommonConfigProperty = DependencyProperty.Register(nameof(CommonConfig), typeof(CommonConfig), typeof(GlobalSettingsControl), new PropertyMetadata(null));
public static readonly DependencyProperty WindowStatesProperty = DependencyProperty.Register(nameof(WindowStates), typeof(ComboBoxItemList), typeof(GlobalSettingsControl), new PropertyMetadata(null)); public static readonly DependencyProperty WindowStatesProperty = DependencyProperty.Register(nameof(WindowStates), typeof(ComboBoxItemList), typeof(GlobalSettingsControl), new PropertyMetadata(null));
public static readonly DependencyProperty DiscordBotLogLevelsProperty = DependencyProperty.Register(nameof(DiscordBotLogLevels), typeof(ComboBoxItemList), typeof(GlobalSettingsControl), new PropertyMetadata(null)); public static readonly DependencyProperty DiscordBotLogLevelsProperty = DependencyProperty.Register(nameof(DiscordBotLogLevels), typeof(ComboBoxItemList), typeof(GlobalSettingsControl), new PropertyMetadata(null));
public static readonly DependencyProperty DiscordBotWhitelistProperty = DependencyProperty.Register(nameof(DiscordBotWhitelist), typeof(List<DiscordBotWhitelist>), typeof(GlobalSettingsControl), new PropertyMetadata(null)); public static readonly DependencyProperty DiscordBotWhitelistProperty = DependencyProperty.Register(nameof(DiscordBotWhitelist), typeof(List<DiscordBotWhitelistItem>), typeof(GlobalSettingsControl), new PropertyMetadata(null));
public GlobalSettingsControl() public GlobalSettingsControl()
{ {
@ -51,13 +51,10 @@ namespace ServerManagerTool
PopulateWindowsStatesComboBox(); PopulateWindowsStatesComboBox();
PopulateDiscordBotLogLevelsComboBox(); PopulateDiscordBotLogLevelsComboBox();
DiscordBotWhitelist = new List<DiscordBotWhitelist>(); DiscordBotWhitelist = new List<DiscordBotWhitelistItem>();
if (Config.DiscordBotWhitelist != null) if (Config.DiscordBotWhitelist != null)
{ {
foreach (var item in Config.DiscordBotWhitelist) DiscordBotWhitelist.AddRange(Config.DiscordBotWhitelist.Select(i => new DiscordBotWhitelistItem() { BotId = i }));
{
DiscordBotWhitelist.Add(new DiscordBotWhitelist() { BotId = item });
}
} }
this.DataContext = this; this.DataContext = this;
@ -105,19 +102,21 @@ namespace ServerManagerTool
set { SetValue(DiscordBotLogLevelsProperty, value); } set { SetValue(DiscordBotLogLevelsProperty, value); }
} }
public List<DiscordBotWhitelist> DiscordBotWhitelist public List<DiscordBotWhitelistItem> DiscordBotWhitelist
{ {
get { return (List<DiscordBotWhitelist>)GetValue(DiscordBotWhitelistProperty); } get { return (List<DiscordBotWhitelistItem>)GetValue(DiscordBotWhitelistProperty); }
set { SetValue(DiscordBotWhitelistProperty, value); } set { SetValue(DiscordBotWhitelistProperty, value); }
} }
public void ApplyChangesToConfig() public void ApplyChangesToConfig()
{ {
if (Config.DiscordBotWhitelist is null) if (Config.DiscordBotWhitelist is null)
Config.DiscordBotWhitelist = new System.Collections.Specialized.StringCollection(); {
Config.DiscordBotWhitelist = new DiscordBot.Models.DiscordBotWhitelist();
}
Config.DiscordBotWhitelist.Clear(); Config.DiscordBotWhitelist.Clear();
Config.DiscordBotWhitelist.AddRange(DiscordBotWhitelist.Select(i => i.BotId).ToArray()); Config.DiscordBotWhitelist.AddRange(DiscordBotWhitelist.Select(i => i.BotId));
App.ReconfigureLogging(); App.ReconfigureLogging();
} }
@ -529,7 +528,7 @@ namespace ServerManagerTool
#region Discord Bot Whitelist #region Discord Bot Whitelist
private void AddDiscordBotWhitelist_Click(object sender, RoutedEventArgs e) private void AddDiscordBotWhitelist_Click(object sender, RoutedEventArgs e)
{ {
DiscordBotWhitelist.Add(new DiscordBotWhitelist()); DiscordBotWhitelist.Add(new DiscordBotWhitelistItem());
CollectionViewSource.GetDefaultView(DiscordBotWhitelistGrid.ItemsSource).Refresh(); CollectionViewSource.GetDefaultView(DiscordBotWhitelistGrid.ItemsSource).Refresh();
} }
@ -549,7 +548,7 @@ namespace ServerManagerTool
if (MessageBox.Show(_globalizer.GetResourceString("ServerSettings_DeleteLabel"), _globalizer.GetResourceString("ServerSettings_DeleteTitle"), MessageBoxButton.YesNo, MessageBoxImage.Question) != MessageBoxResult.Yes) if (MessageBox.Show(_globalizer.GetResourceString("ServerSettings_DeleteLabel"), _globalizer.GetResourceString("ServerSettings_DeleteTitle"), MessageBoxButton.YesNo, MessageBoxImage.Question) != MessageBoxResult.Yes)
return; return;
var item = ((DiscordBotWhitelist)((Button)e.Source).DataContext); var item = ((DiscordBotWhitelistItem)((Button)e.Source).DataContext);
DiscordBotWhitelist.Remove(item); DiscordBotWhitelist.Remove(item);
CollectionViewSource.GetDefaultView(DiscordBotWhitelistGrid.ItemsSource).Refresh(); CollectionViewSource.GetDefaultView(DiscordBotWhitelistGrid.ItemsSource).Refresh();

View file

@ -618,11 +618,6 @@
<setting name="ServerMonitorWindow_Top" serializeAs="String"> <setting name="ServerMonitorWindow_Top" serializeAs="String">
<value>50</value> <value>50</value>
</setting> </setting>
<setting name="DiscordBotWhitelist" serializeAs="Xml">
<value>
<ArrayOfString xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" />
</value>
</setting>
<setting name="DiscordBotPrefixFixed" serializeAs="String"> <setting name="DiscordBotPrefixFixed" serializeAs="String">
<value>False</value> <value>False</value>
</setting> </setting>

View file

@ -612,7 +612,7 @@ namespace ServerManagerTool
}; };
if (Config.Default.DiscordBotWhitelist != null) if (Config.Default.DiscordBotWhitelist != null)
{ {
config.DiscordBotWhitelist.AddRange(Config.Default.DiscordBotWhitelist.Cast<string>()); config.DiscordBotWhitelist.AddRange(Config.Default.DiscordBotWhitelist);
} }
await ServerManagerBotFactory.GetServerManagerBot().RunAsync(config, DiscordBotHelper.HandleDiscordCommand, DiscordBotHelper.HandleTranslation, _tokenSourceDiscordBot.Token); await ServerManagerBotFactory.GetServerManagerBot().RunAsync(config, DiscordBotHelper.HandleDiscordCommand, DiscordBotHelper.HandleTranslation, _tokenSourceDiscordBot.Token);

View file

@ -2142,11 +2142,9 @@ namespace ServerManagerTool {
[global::System.Configuration.UserScopedSettingAttribute()] [global::System.Configuration.UserScopedSettingAttribute()]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()] [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
[global::System.Configuration.DefaultSettingValueAttribute("<?xml version=\"1.0\" encoding=\"utf-16\"?>\r\n<ArrayOfString xmlns:xsd=\"http://www.w3." + public global::ServerManagerTool.DiscordBot.Models.DiscordBotWhitelist DiscordBotWhitelist {
"org/2001/XMLSchema\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" />")]
public global::System.Collections.Specialized.StringCollection DiscordBotWhitelist {
get { get {
return ((global::System.Collections.Specialized.StringCollection)(this["DiscordBotWhitelist"])); return ((global::ServerManagerTool.DiscordBot.Models.DiscordBotWhitelist)(this["DiscordBotWhitelist"]));
} }
set { set {
this["DiscordBotWhitelist"] = value; this["DiscordBotWhitelist"] = value;

View file

@ -590,9 +590,8 @@
<Setting Name="ServerMonitorWindow_Top" Type="System.Double" Scope="User"> <Setting Name="ServerMonitorWindow_Top" Type="System.Double" Scope="User">
<Value Profile="(Default)">50</Value> <Value Profile="(Default)">50</Value>
</Setting> </Setting>
<Setting Name="DiscordBotWhitelist" Type="System.Collections.Specialized.StringCollection" Scope="User"> <Setting Name="DiscordBotWhitelist" Type="ServerManagerTool.DiscordBot.Models.DiscordBotWhitelist" Scope="User">
<Value Profile="(Default)">&lt;?xml version="1.0" encoding="utf-16"?&gt; <Value Profile="(Default)" />
&lt;ArrayOfString xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" /&gt;</Value>
</Setting> </Setting>
<Setting Name="DiscordBotPrefixFixed" Type="System.Boolean" Scope="User"> <Setting Name="DiscordBotPrefixFixed" Type="System.Boolean" Scope="User">
<Value Profile="(Default)">False</Value> <Value Profile="(Default)">False</Value>

View file

@ -33,7 +33,7 @@ namespace ServerManagerTool
public static readonly DependencyProperty IsAdministratorProperty = DependencyProperty.Register(nameof(IsAdministrator), typeof(bool), typeof(GlobalSettingsControl), new PropertyMetadata(false)); public static readonly DependencyProperty IsAdministratorProperty = DependencyProperty.Register(nameof(IsAdministrator), typeof(bool), typeof(GlobalSettingsControl), new PropertyMetadata(false));
public static readonly DependencyProperty WindowStatesProperty = DependencyProperty.Register(nameof(WindowStates), typeof(ComboBoxItemList), typeof(GlobalSettingsControl), new PropertyMetadata(null)); public static readonly DependencyProperty WindowStatesProperty = DependencyProperty.Register(nameof(WindowStates), typeof(ComboBoxItemList), typeof(GlobalSettingsControl), new PropertyMetadata(null));
public static readonly DependencyProperty DiscordBotLogLevelsProperty = DependencyProperty.Register(nameof(DiscordBotLogLevels), typeof(ComboBoxItemList), typeof(GlobalSettingsControl), new PropertyMetadata(null)); public static readonly DependencyProperty DiscordBotLogLevelsProperty = DependencyProperty.Register(nameof(DiscordBotLogLevels), typeof(ComboBoxItemList), typeof(GlobalSettingsControl), new PropertyMetadata(null));
public static readonly DependencyProperty DiscordBotWhitelistProperty = DependencyProperty.Register(nameof(DiscordBotWhitelist), typeof(List<DiscordBotWhitelist>), typeof(GlobalSettingsControl), new PropertyMetadata(null)); public static readonly DependencyProperty DiscordBotWhitelistProperty = DependencyProperty.Register(nameof(DiscordBotWhitelist), typeof(List<DiscordBotWhitelistItem>), typeof(GlobalSettingsControl), new PropertyMetadata(null));
public GlobalSettingsControl() public GlobalSettingsControl()
{ {
@ -49,13 +49,10 @@ namespace ServerManagerTool
PopulateWindowsStatesComboBox(); PopulateWindowsStatesComboBox();
PopulateDiscordBotLogLevelsComboBox(); PopulateDiscordBotLogLevelsComboBox();
DiscordBotWhitelist = new List<DiscordBotWhitelist>(); DiscordBotWhitelist = new List<DiscordBotWhitelistItem>();
if (Config.DiscordBotWhitelist != null) if (Config.DiscordBotWhitelist != null)
{ {
foreach (var item in Config.DiscordBotWhitelist) DiscordBotWhitelist.AddRange(Config.DiscordBotWhitelist.Select(i => new DiscordBotWhitelistItem() { BotId = i }));
{
DiscordBotWhitelist.Add(new DiscordBotWhitelist() { BotId = item });
}
} }
this.DataContext = this; this.DataContext = this;
@ -103,19 +100,21 @@ namespace ServerManagerTool
set { SetValue(DiscordBotLogLevelsProperty, value); } set { SetValue(DiscordBotLogLevelsProperty, value); }
} }
public List<DiscordBotWhitelist> DiscordBotWhitelist public List<DiscordBotWhitelistItem> DiscordBotWhitelist
{ {
get { return (List<DiscordBotWhitelist>)GetValue(DiscordBotWhitelistProperty); } get { return (List<DiscordBotWhitelistItem>)GetValue(DiscordBotWhitelistProperty); }
set { SetValue(DiscordBotWhitelistProperty, value); } set { SetValue(DiscordBotWhitelistProperty, value); }
} }
public void ApplyChangesToConfig() public void ApplyChangesToConfig()
{ {
if (Config.DiscordBotWhitelist is null) if (Config.DiscordBotWhitelist is null)
Config.DiscordBotWhitelist = new System.Collections.Specialized.StringCollection(); {
Config.DiscordBotWhitelist = new DiscordBot.Models.DiscordBotWhitelist();
}
Config.DiscordBotWhitelist.Clear(); Config.DiscordBotWhitelist.Clear();
Config.DiscordBotWhitelist.AddRange(DiscordBotWhitelist.Select(i => i.BotId).ToArray()); Config.DiscordBotWhitelist.AddRange(DiscordBotWhitelist.Select(i => i.BotId));
App.ReconfigureLogging(); App.ReconfigureLogging();
} }
@ -531,7 +530,7 @@ namespace ServerManagerTool
#region Discord Bot Whitelist #region Discord Bot Whitelist
private void AddDiscordBotWhitelist_Click(object sender, RoutedEventArgs e) private void AddDiscordBotWhitelist_Click(object sender, RoutedEventArgs e)
{ {
DiscordBotWhitelist.Add(new DiscordBotWhitelist()); DiscordBotWhitelist.Add(new DiscordBotWhitelistItem());
CollectionViewSource.GetDefaultView(DiscordBotWhitelistGrid.ItemsSource).Refresh(); CollectionViewSource.GetDefaultView(DiscordBotWhitelistGrid.ItemsSource).Refresh();
} }
@ -551,7 +550,7 @@ namespace ServerManagerTool
if (MessageBox.Show(_globalizer.GetResourceString("ServerSettings_DeleteLabel"), _globalizer.GetResourceString("ServerSettings_DeleteTitle"), MessageBoxButton.YesNo, MessageBoxImage.Question) != MessageBoxResult.Yes) if (MessageBox.Show(_globalizer.GetResourceString("ServerSettings_DeleteLabel"), _globalizer.GetResourceString("ServerSettings_DeleteTitle"), MessageBoxButton.YesNo, MessageBoxImage.Question) != MessageBoxResult.Yes)
return; return;
var item = ((DiscordBotWhitelist)((Button)e.Source).DataContext); var item = ((DiscordBotWhitelistItem)((Button)e.Source).DataContext);
DiscordBotWhitelist.Remove(item); DiscordBotWhitelist.Remove(item);
CollectionViewSource.GetDefaultView(DiscordBotWhitelistGrid.ItemsSource).Refresh(); CollectionViewSource.GetDefaultView(DiscordBotWhitelistGrid.ItemsSource).Refresh();

View file

@ -2,9 +2,9 @@
namespace ServerManagerTool.Common.Model namespace ServerManagerTool.Common.Model
{ {
public class DiscordBotWhitelist : DependencyObject public class DiscordBotWhitelistItem : DependencyObject
{ {
public static readonly DependencyProperty BotIdProperty = DependencyProperty.Register(nameof(BotId), typeof(string), typeof(DiscordBotWhitelist), new PropertyMetadata("")); public static readonly DependencyProperty BotIdProperty = DependencyProperty.Register(nameof(BotId), typeof(string), typeof(DiscordBotWhitelistItem), new PropertyMetadata(""));
public string BotId public string BotId
{ {