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

@@ -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)
{