source code checkin

This commit is contained in:
Brett Hewitson 2021-01-07 16:23:23 +10:00
parent 5f8fb2c825
commit 7e57b72e35
675 changed files with 168433 additions and 0 deletions

View file

@ -0,0 +1,55 @@
using ServerManagerTool.Plugin.Common;
using System.Runtime.Serialization;
namespace ServerManagerTool.Plugin.Discord
{
[DataContract]
internal class AlertTypeValue : Bindable
{
public AlertTypeValue()
: base()
{
Value = AlertType.Error;
OriginalValue = Value;
HasChanges = false;
}
public AlertTypeValue(AlertType value)
: base()
{
Value = value;
OriginalValue = Value;
HasChanges = !Value.Equals(OriginalValue);
}
public AlertTypeValue(AlertType value, AlertType originalValue)
: base()
{
Value = value;
OriginalValue = originalValue;
HasChanges = !Value.Equals(OriginalValue);
}
[DataMember]
public AlertType Value
{
get { return Get<AlertType>(); }
set { Set(value); }
}
public AlertType OriginalValue
{
get;
set;
}
public override bool HasAnyChanges => base.HasChanges && !Value.Equals(OriginalValue);
public override void CommitChanges()
{
base.CommitChanges();
OriginalValue = Value;
}
}
}

View file

@ -0,0 +1,69 @@
using System.Collections.Generic;
using System.Collections.Specialized;
using System.ComponentModel;
using System.Linq;
using System.Runtime.CompilerServices;
namespace ServerManagerTool.Plugin.Discord
{
internal class AlertTypeValueList : List<AlertTypeValue>, IBindable, INotifyCollectionChanged
{
private bool _hasChanges = false;
public bool HasChanges
{
get => _hasChanges;
set => _hasChanges = value;
}
public bool HasAnyChanges => _hasChanges || this.Any(a => a?.HasAnyChanges ?? false);
public void BeginUpdate()
{
}
public void CommitChanges()
{
HasChanges = false;
foreach (var alertType in this)
{
alertType.CommitChanges();
}
}
public void EndUpdate()
{
}
#region INotifyCollectionChanged
public event NotifyCollectionChangedEventHandler CollectionChanged;
#endregion
protected void OnCollectionChanged(NotifyCollectionChangedEventArgs e)
{
CollectionChanged?.Invoke(this, e);
}
public void NotifyAdd(AlertTypeValue item, bool setChanged = true)
{
OnCollectionChanged(new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Add, item));
if (setChanged)
HasChanges = true;
}
public void NotifyClear(bool setChanged = true)
{
OnCollectionChanged(new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Reset));
if (setChanged)
HasChanges = true;
}
public void NotifyRemove(AlertTypeValue item, int index, bool setChanged = true)
{
OnCollectionChanged(new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Remove, item, index));
if (setChanged)
HasChanges = true;
}
}
}

View file

@ -0,0 +1,85 @@
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Runtime.Serialization;
namespace ServerManagerTool.Plugin.Discord
{
[DataContract]
internal class Bindable : INotifyPropertyChanged, IBindable
{
private Dictionary<string, object> _properties = new Dictionary<string, object>();
protected bool _isUpdating = false;
public Bindable()
{
_properties = new Dictionary<string, object>();
}
protected T Get<T>([CallerMemberName] string name = null)
{
object value = null;
if (_properties?.TryGetValue(name, out value) ?? false)
return value == null ? default(T) : (T)value;
return default(T);
}
protected void Set<T>(T value, bool setChanged = true, [CallerMemberName] string name = null)
{
if (Equals(value, Get<T>(name)))
return;
if (_properties == null)
_properties = new Dictionary<string, object>();
_properties[name] = value;
OnPropertyChanged(name);
if (!_isUpdating && setChanged)
HasChanges = true;
}
protected virtual void OnPropertyChanged([CallerMemberName] string propertyName = null)
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
}
#region INotifyPropertyChanged
public event PropertyChangedEventHandler PropertyChanged;
#endregion
#region IBindable
public bool HasChanges
{
get { return Get<bool>(); }
set { Set(value, false); }
}
public virtual bool HasAnyChanges => HasChanges || (_properties?.Any(p => (p.Value as IBindable)?.HasAnyChanges ?? false) ?? false);
public virtual void CommitChanges()
{
HasChanges = false;
if (_properties == null)
return;
foreach (var property in _properties)
{
var bindable = property.Value as IBindable;
if (bindable != null)
bindable.CommitChanges();
}
}
public void BeginUpdate()
{
_isUpdating = true;
}
public void EndUpdate()
{
_isUpdating = false;
}
#endregion
}
}

View file

@ -0,0 +1,56 @@
using System.Windows;
namespace ServerManagerTool.Plugin.Discord
{
public class ComboBoxItem : DependencyObject
{
public static readonly DependencyProperty ValueMemberProperty = DependencyProperty.Register(nameof(ValueMember), typeof(string), typeof(ComboBoxItem), new PropertyMetadata(string.Empty));
public static readonly DependencyProperty DisplayMemberProperty = DependencyProperty.Register(nameof(DisplayMember), typeof(string), typeof(ComboBoxItem), new PropertyMetadata(string.Empty));
public static readonly DependencyProperty GroupMemberProperty = DependencyProperty.Register(nameof(GroupMember), typeof(string), typeof(ComboBoxItem), new PropertyMetadata(string.Empty));
public ComboBoxItem()
{
}
public ComboBoxItem(string valueMember, string displayMember)
{
ValueMember = valueMember;
DisplayMember = displayMember;
}
public ComboBoxItem(string valueMember, string displayMember, string groupMember)
{
ValueMember = valueMember;
DisplayMember = displayMember;
GroupMember = groupMember;
}
public string ValueMember
{
get { return (string)GetValue(ValueMemberProperty); }
set { SetValue(ValueMemberProperty, value); }
}
public string DisplayMember
{
get { return (string)GetValue(DisplayMemberProperty); }
set { SetValue(DisplayMemberProperty, value); }
}
public string GroupMember
{
get { return (string)GetValue(GroupMemberProperty); }
set { SetValue(GroupMemberProperty, value); }
}
public ComboBoxItem Duplicate()
{
return new ComboBoxItem
{
DisplayMember = this.DisplayMember,
ValueMember = this.ValueMember,
GroupMember = this.GroupMember,
};
}
}
}

View file

@ -0,0 +1,11 @@
using System.Collections.ObjectModel;
namespace ServerManagerTool.Plugin.Discord
{
public class ComboBoxItemList : ObservableCollection<ComboBoxItem>
{
public ComboBoxItemList()
{
}
}
}

View file

@ -0,0 +1,188 @@
using System.Runtime.Serialization;
namespace ServerManagerTool.Plugin.Discord
{
[DataContract]
internal sealed class ConfigProfile : Bindable
{
public ConfigProfile()
: base()
{
Name = "New Discord Profile";
ProfileNames = new ProfileNameValueList();
AlertTypes = new AlertTypeValueList();
DiscordWebhookUrl = string.Empty;
DiscordBotName = string.Empty;
DiscordUseTTS = false;
PrefixMessageWithProfileName = false;
MessageBold = false;
MessageUnderlined = false;
MessageItalic = false;
MessageCodeBlock = false;
IsEnabled = true;
}
[DataMember]
public string Name
{
get { return Get<string>(); }
set { Set(value); }
}
[DataMember]
public ProfileNameValueList ProfileNames
{
get { return Get<ProfileNameValueList>(); }
set { Set(value); }
}
[DataMember]
public AlertTypeValueList AlertTypes
{
get { return Get<AlertTypeValueList>(); }
set { Set(value); }
}
[DataMember]
public string DiscordWebhookUrl
{
get { return Get<string>(); }
set { Set(value); }
}
[DataMember]
public string DiscordBotName
{
get { return Get<string>(); }
set { Set(value); }
}
[DataMember]
public bool DiscordUseTTS
{
get { return Get<bool>(); }
set { Set(value); }
}
[DataMember]
public bool PrefixMessageWithProfileName
{
get { return Get<bool>(); }
set { Set(value); }
}
[DataMember]
public bool IsEnabled
{
get { return Get<bool>(); }
set { Set(value); }
}
[DataMember]
public bool MessageBold
{
get { return Get<bool>(); }
set { Set(value); }
}
[DataMember]
public bool MessageUnderlined
{
get { return Get<bool>(); }
set { Set(value); }
}
[DataMember]
public bool MessageItalic
{
get { return Get<bool>(); }
set { Set(value); }
}
[DataMember]
public bool MessageCodeBlock
{
get { return Get<bool>(); }
set { Set(value); }
}
public ConfigProfile Clone()
{
var clone = new ConfigProfile();
clone.Name = this.Name;
foreach (var profileName in this.ProfileNames)
{
clone.ProfileNames.Add(new ProfileNameValue(profileName.Value, profileName.OriginalValue) { HasChanges = profileName.HasChanges });
}
clone.ProfileNames.HasChanges = this.ProfileNames.HasChanges;
foreach (var alertType in this.AlertTypes)
{
clone.AlertTypes.Add(new AlertTypeValue(alertType.Value, alertType.OriginalValue) { HasChanges = alertType.HasChanges });
}
clone.AlertTypes.HasChanges = this.AlertTypes.HasChanges;
clone.DiscordWebhookUrl = this.DiscordWebhookUrl;
clone.DiscordBotName = this.DiscordBotName;
clone.DiscordUseTTS = this.DiscordUseTTS;
clone.PrefixMessageWithProfileName = this.PrefixMessageWithProfileName;
clone.MessageBold = this.MessageBold;
clone.MessageUnderlined = this.MessageUnderlined;
clone.MessageItalic = this.MessageItalic;
clone.MessageCodeBlock = this.MessageCodeBlock;
clone.IsEnabled = this.IsEnabled;
clone.HasChanges = this.HasChanges;
return clone;
}
public void CopyFrom(ConfigProfile source)
{
if (source == null)
return;
try
{
this.BeginUpdate();
this.Name = source.Name;
this.ProfileNames.BeginUpdate();
this.ProfileNames.Clear();
foreach (var profileName in source.ProfileNames)
{
this.ProfileNames.Add(new ProfileNameValue(profileName.Value, profileName.OriginalValue));
}
if (source.ProfileNames.HasChanges)
this.ProfileNames.HasChanges = true;
this.ProfileNames.EndUpdate();
this.AlertTypes.BeginUpdate();
this.AlertTypes.Clear();
foreach (var alertType in source.AlertTypes)
{
this.AlertTypes.Add(new AlertTypeValue(alertType.Value, alertType.OriginalValue));
}
if (source.AlertTypes.HasChanges)
this.AlertTypes.HasChanges = true;
this.AlertTypes.EndUpdate();
this.DiscordWebhookUrl = source.DiscordWebhookUrl;
this.DiscordBotName = source.DiscordBotName;
this.DiscordUseTTS = source.DiscordUseTTS;
this.PrefixMessageWithProfileName = source.PrefixMessageWithProfileName;
this.MessageBold = source.MessageBold;
this.MessageUnderlined = source.MessageUnderlined;
this.MessageItalic = source.MessageItalic;
this.MessageCodeBlock = source.MessageCodeBlock;
this.IsEnabled = source.IsEnabled;
if (source.HasChanges)
this.HasChanges = true;
}
finally
{
this.EndUpdate();
}
}
}
}

View file

@ -0,0 +1,35 @@
using System;
using System.Runtime.Serialization;
namespace ServerManagerTool.Plugin.Discord
{
[DataContract]
internal sealed class DiscordPluginConfig : Bindable
{
public DiscordPluginConfig()
: base()
{
LastCallHome = DateTime.MinValue;
ConfigProfiles = new ObservableList<ConfigProfile>();
}
[DataMember]
public DateTime LastCallHome
{
get;
set;
}
[DataMember]
public ObservableList<ConfigProfile> ConfigProfiles
{
get { return Get<ObservableList<ConfigProfile>>(); }
set { Set(value); }
}
public override bool HasAnyChanges
{
get => base.HasChanges || (ConfigProfiles?.HasAnyChanges ?? false);
}
}
}

View file

@ -0,0 +1,142 @@
using System.Collections;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Linq;
using System.Runtime.Serialization;
namespace ServerManagerTool.Plugin.Discord
{
[DataContract]
internal class ObservableList<T> : Bindable, IList<T>, INotifyCollectionChanged
{
private List<T> _listObject = null;
public ObservableList()
: base()
{
_listObject = new List<T>();
CommitChanges();
}
public override bool HasAnyChanges => base.HasChanges || (_listObject?.Any(i => (i as IBindable)?.HasAnyChanges ?? false) ?? false);
public override void CommitChanges()
{
base.CommitChanges();
if (_listObject == null)
return;
foreach (T item in _listObject)
{
var bindable = item as IBindable;
if (bindable != null)
bindable.CommitChanges();
}
}
[DataMember]
internal List<T> List
{
get => _listObject;
set => _listObject = value;
}
#region IList<T>
public T this[int index]
{
get => _listObject[index];
set
{
T oldValue = _listObject[index];
_listObject[index] = value;
OnCollectionChanged(new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Replace, value, oldValue));
}
}
public int Count => _listObject.Count;
public bool IsReadOnly => false;
public void Add(T item)
{
_listObject.Add(item);
OnCollectionChanged(new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Add, item));
}
public void Clear()
{
_listObject.Clear();
OnCollectionChanged(new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Reset));
}
public bool Contains(T item)
{
return _listObject.Contains(item);
}
public void CopyTo(T[] array, int arrayIndex)
{
_listObject.CopyTo(array, arrayIndex);
}
public IEnumerator<T> GetEnumerator()
{
return _listObject.GetEnumerator();
}
public int IndexOf(T item)
{
return _listObject.IndexOf(item);
}
public void Insert(int index, T item)
{
_listObject.Insert(index, item);
OnCollectionChanged(new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Add, item));
}
public void Move(int oldIndex, int newIndex)
{
var item = _listObject.ElementAt(oldIndex);
if (item != null)
{
_listObject.Remove(item);
_listObject.Insert(newIndex, item);
OnCollectionChanged(new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Move, item, newIndex, oldIndex));
}
}
public bool Remove(T item)
{
int index = _listObject.IndexOf(item);
var result = _listObject.Remove(item);
OnCollectionChanged(new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Remove, item, index));
return result;
}
public void RemoveAt(int index)
{
T item = _listObject[index];
_listObject.RemoveAt(index);
OnCollectionChanged(new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Remove, item, index));
}
IEnumerator IEnumerable.GetEnumerator()
{
return _listObject.GetEnumerator();
}
#endregion
#region INotifyCollectionChanged
public event NotifyCollectionChangedEventHandler CollectionChanged;
protected void OnCollectionChanged(NotifyCollectionChangedEventArgs e)
{
CollectionChanged?.Invoke(this, e);
if (!_isUpdating)
HasChanges = true;
}
#endregion
}
}

View file

@ -0,0 +1,54 @@
using System.Runtime.Serialization;
namespace ServerManagerTool.Plugin.Discord
{
[DataContract]
internal class ProfileNameValue : Bindable
{
public ProfileNameValue()
: base()
{
Value = string.Empty;
OriginalValue = Value;
HasChanges = false;
}
public ProfileNameValue(string value)
: base()
{
Value = value;
OriginalValue = Value;
HasChanges = !Value.Equals(OriginalValue);
}
public ProfileNameValue(string value, string originalValue)
: base()
{
Value = value;
OriginalValue = originalValue;
HasChanges = !Value.Equals(OriginalValue);
}
[DataMember]
public string Value
{
get { return Get<string>(); }
set { Set(value); }
}
public string OriginalValue
{
get;
set;
}
public override bool HasAnyChanges => base.HasChanges && !Value.Equals(OriginalValue);
public override void CommitChanges()
{
base.CommitChanges();
OriginalValue = Value;
}
}
}

View file

@ -0,0 +1,67 @@
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Linq;
namespace ServerManagerTool.Plugin.Discord
{
internal class ProfileNameValueList : List<ProfileNameValue>, IBindable, INotifyCollectionChanged
{
private bool _hasChanges = false;
public bool HasChanges
{
get => _hasChanges;
set => _hasChanges = value;
}
public bool HasAnyChanges => _hasChanges || this.Any(p => p?.HasAnyChanges ?? false);
public void BeginUpdate()
{
}
public void CommitChanges()
{
HasChanges = false;
foreach (var profileName in this)
{
profileName.CommitChanges();
}
}
public void EndUpdate()
{
}
#region INotifyCollectionChanged
public event NotifyCollectionChangedEventHandler CollectionChanged;
#endregion
protected void OnCollectionChanged(NotifyCollectionChangedEventArgs e)
{
CollectionChanged?.Invoke(this, e);
}
public void NotifyAdd(ProfileNameValue item, bool setChanged = true)
{
OnCollectionChanged(new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Add, item));
if (setChanged)
HasChanges = true;
}
public void NotifyClear(bool setChanged = true)
{
OnCollectionChanged(new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Reset));
if (setChanged)
HasChanges = true;
}
public void NotifyRemove(ProfileNameValue item, int index, bool setChanged = true)
{
OnCollectionChanged(new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Remove, item, index));
if (setChanged)
HasChanges = true;
}
}
}

View file

@ -0,0 +1,16 @@
using System;
using System.Collections.Generic;
namespace ServerManagerTool.Plugin.Discord
{
public class VersionFeed
{
public string Id { get; set; } = string.Empty;
public string Title { get; set; } = string.Empty;
public string SubTitle { get; set; } = string.Empty;
public Uri Link { get; set; } = null;
public DateTimeOffset Updated { get; set; } = DateTimeOffset.Now;
public List<VersionFeedEntry> Entries { get; set; } = new List<VersionFeedEntry>();
}
}

View file

@ -0,0 +1,17 @@
using System;
namespace ServerManagerTool.Plugin.Discord
{
public class VersionFeedEntry
{
public string Id { get; set; } = string.Empty;
public string Title { get; set; } = string.Empty;
public string Summary { get; set; } = string.Empty;
public Uri Link { get; set; } = null;
public DateTimeOffset Updated { get; set; } = DateTimeOffset.Now;
public string Content { get; set; } = string.Empty;
public string Author { get; set; } = string.Empty;
public bool IsCurrent { get; set; } = false;
}
}