Core - Fixed a lot of compiler warnings

Scripting - Added script renaming/deleting
This commit is contained in:
Robert committed 2021-06-21 19:34:34 +02:00
1 parent 4a69baebb7
commit 5367027471
36 files changed
+434 -96

No files matched your search

+2 -2
View File
@@ -46,7 +46,7 @@ namespace Artemis.Core
/// </param>
/// <returns><c>true</c> if the value was changed, <c>false</c> if the existing value matched the desired value.</returns>
[NotifyPropertyChangedInvocator]
protected virtual bool SetAndNotify<T>(ref T storage, T value, [CallerMemberName] string propertyName = null)
protected virtual bool SetAndNotify<T>(ref T storage, T value, [CallerMemberName] string? propertyName = null)
{
if (!RequiresUpdate(ref storage, value)) return false;
@@ -64,7 +64,7 @@ namespace Artemis.Core
/// and can be provided automatically when invoked from compilers that support <see cref="CallerMemberNameAttribute" />
/// .
/// </param>
protected virtual void OnPropertyChanged([CallerMemberName] string propertyName = null)
protected virtual void OnPropertyChanged([CallerMemberName] string? propertyName = null)
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
}
@@ -9,6 +9,9 @@ namespace Artemis.Core
/// </summary>
public class CategoryAdaptionHint : IAdaptionHint
{
/// <summary>
/// Creates a new instance of the <see cref="CategoryAdaptionHint" /> class
/// </summary>
public CategoryAdaptionHint()
{
}
@@ -41,6 +44,12 @@ namespace Artemis.Core
/// </summary>
public int Amount { get; set; }
/// <inheritdoc />
public override string ToString()
{
return $"Category adaption - {nameof(Category)}: {Category}, {nameof(Skip)}: {Skip}, {nameof(LimitAmount)}: {LimitAmount}, {nameof(Amount)}: {Amount}";
}
#region Implementation of IAdaptionHint
/// <inheritdoc />
@@ -65,11 +74,5 @@ namespace Artemis.Core
}
#endregion
/// <inheritdoc />
public override string ToString()
{
return $"Category adaption - {nameof(Category)}: {Category}, {nameof(Skip)}: {Skip}, {nameof(LimitAmount)}: {LimitAmount}, {nameof(Amount)}: {Amount}";
}
}
}
@@ -10,6 +10,9 @@ namespace Artemis.Core
/// </summary>
public class DeviceAdaptionHint : IAdaptionHint
{
/// <summary>
/// Creates a new instance of the <see cref="DeviceAdaptionHint" /> class
/// </summary>
public DeviceAdaptionHint()
{
}
@@ -18,6 +18,9 @@ namespace Artemis.Core
{KeyboardSection.Extra, Enum.GetValues<LedId>().Where(l => l >= LedId.Keyboard_Custom1 && l <= LedId.Keyboard_Custom64).ToList()}
};
/// <summary>
/// Creates a new instance of the <see cref="KeyboardSectionAdaptionHint" /> class
/// </summary>
public KeyboardSectionAdaptionHint()
{
}
@@ -421,7 +421,7 @@ namespace Artemis.Core
{
if (keyframeEntity.Position > ProfileElement.Timeline.Length)
return null;
T value = CoreJson.DeserializeObject<T>(keyframeEntity.Value);
T? value = CoreJson.DeserializeObject<T>(keyframeEntity.Value);
if (value == null)
return null;
@@ -28,6 +28,7 @@ namespace Artemis.Core
internal ProfileCategory(ProfileCategoryEntity entity)
{
_name = null!;
Entity = entity;
Load();
}
+1 -4
View File
@@ -1,7 +1,4 @@
using System;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.IO;
using Artemis.Core.Services;
using Artemis.Storage;
using Artemis.Storage.Migrations.Interfaces;
@@ -15,7 +15,7 @@ namespace Artemis.Core.Modules
/// <summary>
/// Gets or sets the current value of the dynamic child
/// </summary>
public new T Value { get; set; }
public T Value { get; set; }
/// <inheritdoc />
protected override object? GetValue()
+3
View File
@@ -66,6 +66,9 @@ namespace Artemis.Core
/// </summary>
public ReadOnlyCollection<PluginFeatureInfo> Features => _features.AsReadOnly();
/// <summary>
/// Gets a read-only collection of profiles running on the plugin
/// </summary>
public ReadOnlyCollection<Profiler> Profilers => _profilers.AsReadOnly();
/// <summary>
@@ -51,6 +51,7 @@ namespace Artemis.Core
if (instance == null) throw new ArgumentNullException(nameof(instance));
Plugin = plugin ?? throw new ArgumentNullException(nameof(plugin));
FeatureType = instance.GetType();
Entity = new PluginFeatureEntity();
Name = attribute?.Name ?? instance.GetType().Name.Humanize(LetterCasing.Title);
Description = attribute?.Description;
@@ -9,10 +9,10 @@ namespace Artemis.Core
{
private long _current;
private DateTime _lastReport;
private long _lastReportValue;
private double _percentage;
private double _progressPerSecond;
private long _total;
private long _lastReportValue;
/// <summary>
/// The current amount
@@ -81,6 +81,9 @@ namespace Artemis.Core
/// </summary>
public event EventHandler? ProgressReported;
/// <summary>
/// Invokes the <see cref="ProgressReported" /> event
/// </summary>
protected virtual void OnProgressReported()
{
ProgressReported?.Invoke(this, EventArgs.Empty);
@@ -1,4 +1,5 @@
using Artemis.Storage.Entities.General;
using System;
using Artemis.Storage.Entities.General;
namespace Artemis.Core.ScriptingProviders
{
@@ -7,24 +8,26 @@ namespace Artemis.Core.ScriptingProviders
/// </summary>
public class ScriptConfiguration : CorePropertyChanged, IStorageModel
{
private string _scriptingProviderId;
private bool _hasChanges;
private string _name;
private string? _pendingScriptContent;
private string? _scriptContent;
private string _scriptingProviderId;
/// <summary>
/// Creates a new instance of the <see cref="ScriptConfiguration" /> class
/// </summary>
public ScriptConfiguration(ScriptingProvider provider, string name)
{
ScriptingProviderId = provider.Id;
Name = name;
_scriptingProviderId = provider.Id;
_name = name;
Entity = new ScriptConfigurationEntity();
}
internal ScriptConfiguration(ScriptConfigurationEntity entity)
{
ScriptingProviderId = null!;
Name = null!;
_scriptingProviderId = null!;
_name = null!;
Entity = entity;
Load();
@@ -54,7 +57,36 @@ namespace Artemis.Core.ScriptingProviders
public string? ScriptContent
{
get => _scriptContent;
set => SetAndNotify(ref _scriptContent, value);
private set
{
if (!SetAndNotify(ref _scriptContent, value)) return;
OnScriptContentChanged();
}
}
/// <summary>
/// Gets or sets the pending changes to the script's content
/// </summary>
public string? PendingScriptContent
{
get => _pendingScriptContent;
set
{
if (string.IsNullOrWhiteSpace(value))
value = null;
if (!SetAndNotify(ref _pendingScriptContent, value)) return;
HasChanges = ScriptContent != PendingScriptContent;
}
}
/// <summary>
/// Gets or sets a boolean indicating whether this configuration has pending changes to it's
/// <see cref="ScriptContent" />
/// </summary>
public bool HasChanges
{
get => _hasChanges;
set => SetAndNotify(ref _hasChanges, value);
}
/// <summary>
@@ -64,6 +96,24 @@ namespace Artemis.Core.ScriptingProviders
internal ScriptConfigurationEntity Entity { get; }
/// <summary>
/// Applies the <see cref="PendingScriptContent" /> to the <see cref="ScriptContent" />
/// </summary>
public void ApplyPendingChanges()
{
ScriptContent = PendingScriptContent;
HasChanges = false;
}
/// <summary>
/// Discards the <see cref="PendingScriptContent" />
/// </summary>
public void DiscardPendingChanges()
{
PendingScriptContent = ScriptContent;
HasChanges = false;
}
#region Implementation of IStorageModel
/// <inheritdoc />
@@ -71,6 +121,7 @@ namespace Artemis.Core.ScriptingProviders
{
ScriptingProviderId = Entity.ScriptingProviderId;
ScriptContent = Entity.ScriptContent;
PendingScriptContent = Entity.ScriptContent;
Name = Entity.Name;
}
@@ -79,6 +130,24 @@ namespace Artemis.Core.ScriptingProviders
{
Entity.ScriptingProviderId = ScriptingProviderId;
Entity.ScriptContent = ScriptContent;
Entity.Name = Name;
}
#endregion
#region Events
/// <summary>
/// Occurs whenever the contents of the script have changed
/// </summary>
public event EventHandler? ScriptContentChanged;
/// <summary>
/// Invokes the <see cref="ScriptContentChanged" /> event
/// </summary>
protected virtual void OnScriptContentChanged()
{
ScriptContentChanged?.Invoke(this, EventArgs.Empty);
}
#endregion
@@ -37,6 +37,19 @@ namespace Artemis.Core.ScriptingProviders
/// <param name="script">The script the editor must edit</param>
public abstract IScriptEditorViewModel CreatePropertyScriptEditor(TPropertyScript script);
#region Overrides of PluginFeature
/// <inheritdoc />
internal override void InternalDisable()
{
base.InternalDisable();
while (Scripts.Count > 0)
Scripts[0].Dispose();
}
#endregion
#region Overrides of ScriptingProvider
/// <inheritdoc />
@@ -104,19 +117,6 @@ namespace Artemis.Core.ScriptingProviders
}
#endregion
#region Overrides of PluginFeature
/// <inheritdoc />
internal override void InternalDisable()
{
base.InternalDisable();
while (Scripts.Count > 0)
Scripts[0].Dispose();
}
#endregion
}
/// <summary>
@@ -128,17 +128,22 @@ namespace Artemis.Core.ScriptingProviders
/// </summary>
public abstract class ScriptingProvider : PluginFeature
{
internal abstract Type GlobalScriptType { get; }
internal abstract Type PropertyScriptType { get; }
internal abstract Type LayerScriptType { get; }
internal abstract Type ProfileScriptType { get; }
internal List<Script> InternalScripts { get; } = new();
/// <summary>
/// Gets the name of the scripting language this provider provides
/// </summary>
public abstract string LanguageName { get; }
/// <summary>
/// Gets a list of all active scripts belonging to this scripting provider
/// </summary>
public ReadOnlyCollection<Script> Scripts => InternalScripts.AsReadOnly();
internal abstract Type GlobalScriptType { get; }
internal abstract Type PropertyScriptType { get; }
internal abstract Type LayerScriptType { get; }
internal abstract Type ProfileScriptType { get; }
internal List<Script> InternalScripts { get; } = new();
/// <summary>
/// Called when the UI needs a script editor for a <see cref="GlobalScript" />
/// </summary>
@@ -12,7 +12,7 @@ namespace Artemis.Core.ScriptingProviders
{
}
internal ScriptingService ScriptingService { get; set; }
internal ScriptingService? ScriptingService { get; set; }
/// <summary>
/// Called whenever the Artemis Core is about to update
@@ -35,7 +35,7 @@ namespace Artemis.Core.ScriptingProviders
/// <inheritdoc />
internal override void InternalCleanup()
{
ScriptingService.InternalGlobalScripts.Remove(this);
ScriptingService?.InternalGlobalScripts.Remove(this);
}
#endregion
@@ -35,7 +35,7 @@ namespace Artemis.Core
/// <param name="name">The name of the setting</param>
/// <param name="defaultValue">The default value to use if the setting does not exist yet</param>
/// <returns></returns>
public PluginSetting<T> GetSetting<T>(string name, T defaultValue = default)
public PluginSetting<T> GetSetting<T>(string name, T? defaultValue = default)
{
lock (_settingEntities)
{
@@ -0,0 +1,64 @@
using System.Collections.ObjectModel;
using Artemis.Core.ScriptingProviders;
namespace Artemis.Core.Services
{
/// <summary>
/// A service that allows you to manage various types of <see cref="Script" /> instances
/// </summary>
public interface IScriptingService : IArtemisService
{
/// <summary>
/// Gets a list of all currently active global scripts
/// </summary>
ReadOnlyCollection<GlobalScript> GlobalScripts { get; }
/// <summary>
/// Creates a <see cref="GlobalScript" /> instance for the given <paramref name="scriptConfiguration" />
/// </summary>
/// <param name="scriptConfiguration">The script configuration of the script</param>
/// <returns>
/// If the <see cref="ScriptingProvider" /> was found an instance of the script; otherwise <see langword="null" />
/// .
/// </returns>
GlobalScript? CreateScriptInstance(ScriptConfiguration scriptConfiguration);
/// <summary>
/// Creates a <see cref="ProfileScript" /> instance for the given <paramref name="scriptConfiguration" />
/// </summary>
/// <param name="profile">The profile the script configuration is configured for</param>
/// <param name="scriptConfiguration">The script configuration of the script</param>
/// <returns>
/// If the <see cref="ScriptingProvider" /> was found an instance of the script; otherwise <see langword="null" />
/// .
/// </returns>
ProfileScript? CreateScriptInstance(Profile profile, ScriptConfiguration scriptConfiguration);
/// <summary>
/// Creates a <see cref="LayerScript" /> instance for the given <paramref name="scriptConfiguration" />
/// </summary>
/// <param name="layer">The layer the script configuration is configured fo</param>
/// <param name="scriptConfiguration">The script configuration of the script</param>
/// <returns>
/// If the <see cref="ScriptingProvider" /> was found an instance of the script; otherwise <see langword="null" />
/// .
/// </returns>
LayerScript? CreateScriptInstance(Layer layer, ScriptConfiguration scriptConfiguration);
/// <summary>
/// Creates a <see cref="PropertyScript" /> instance for the given <paramref name="scriptConfiguration" />
/// </summary>
/// <param name="layerProperty">The layer property the script configuration is configured fo</param>
/// <param name="scriptConfiguration">The script configuration of the script</param>
/// <returns>
/// If the <see cref="ScriptingProvider" /> was found an instance of the script; otherwise <see langword="null" />
/// .
/// </returns>
PropertyScript? CreateScriptInstance(ILayerProperty layerProperty, ScriptConfiguration scriptConfiguration);
/// <summary>
/// Deletes the provided global script by it's configuration
/// </summary>
void DeleteScript(ScriptConfiguration scriptConfiguration);
}
}
@@ -175,14 +175,10 @@ namespace Artemis.Core.Services
provider.InternalScripts.Add(script);
return script;
}
}
public interface IScriptingService : IArtemisService
{
ReadOnlyCollection<GlobalScript> GlobalScripts { get; }
GlobalScript? CreateScriptInstance(ScriptConfiguration scriptConfiguration);
ProfileScript? CreateScriptInstance(Profile profile, ScriptConfiguration scriptConfiguration);
LayerScript? CreateScriptInstance(Layer layer, ScriptConfiguration scriptConfiguration);
PropertyScript? CreateScriptInstance(ILayerProperty layerProperty, ScriptConfiguration scriptConfiguration);
/// <inheritdoc />
public void DeleteScript(ScriptConfiguration scriptConfiguration)
{
}
}
}
+3 -3
View File
@@ -12,9 +12,9 @@ namespace Artemis.Core.Services
_pluginSettings = new PluginSettings(Constants.CorePlugin, pluginRepository);
}
public PluginSetting<T> GetSetting<T>(string name, T defaultValue = default)
public PluginSetting<T> GetSetting<T>(string name, T? defaultValue = default)
{
return _pluginSettings.GetSetting(name, defaultValue!);
return _pluginSettings.GetSetting(name, defaultValue);
}
}
@@ -31,6 +31,6 @@ namespace Artemis.Core.Services
/// <param name="name">The name of the setting</param>
/// <param name="defaultValue">The default value to use if the setting does not exist yet</param>
/// <returns></returns>
PluginSetting<T> GetSetting<T>(string name, T defaultValue = default);
PluginSetting<T> GetSetting<T>(string name, T? defaultValue = default);
}
}
@@ -52,7 +52,9 @@ namespace Artemis.Core.Services
object? response = null;
try
{
T deserialized = JsonConvert.DeserializeObject<T>(await reader.ReadToEndAsync());
T? deserialized = JsonConvert.DeserializeObject<T>(await reader.ReadToEndAsync());
if (deserialized == null)
throw new JsonException("Deserialization returned null");
if (_requestHandler != null)
{