mirror of
https://github.com/Artemis-RGB/Artemis
synced 2026-11-11 19:36:28 +00:00
Data models - Added ClearDynamicChildren method
Plugins - Added async support for timed updates Plugins - Added dialog host to plugin settings window Data model visualization - Fixed some null references Data model visualization - Added check to ensure parameterless getters are present
This commit is contained in:
1 parent
c095f329c4
commit
17d41647b6
8 files changed
+96
-26
No files matched your search
@@ -67,10 +67,8 @@ namespace Artemis.Core.DataModelExpansions
|
||||
if (key.Contains('.'))
|
||||
throw new ArtemisCoreException("The provided key contains an illegal character (.)");
|
||||
if (_dynamicDataModels.ContainsKey(key))
|
||||
{
|
||||
throw new ArtemisCoreException($"Cannot add a dynamic data model with key '{key}' " +
|
||||
"because the key is already in use on by another dynamic property this data model.");
|
||||
}
|
||||
|
||||
if (_dynamicDataModels.ContainsValue(dynamicDataModel))
|
||||
{
|
||||
@@ -80,10 +78,8 @@ namespace Artemis.Core.DataModelExpansions
|
||||
}
|
||||
|
||||
if (GetType().GetProperty(key) != null)
|
||||
{
|
||||
throw new ArtemisCoreException($"Cannot add a dynamic data model with key '{key}' " +
|
||||
"because the key is already in use by a static property on this data model.");
|
||||
}
|
||||
|
||||
dynamicDataModel.PluginInfo = PluginInfo;
|
||||
dynamicDataModel.DataModelDescription = new DataModelPropertyAttribute
|
||||
@@ -125,6 +121,15 @@ namespace Artemis.Core.DataModelExpansions
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Removes all dynamic data models from this data model
|
||||
/// </summary>
|
||||
public void ClearDynamicChildren()
|
||||
{
|
||||
while (_dynamicDataModels.Any())
|
||||
RemoveDynamicChildByKey(_dynamicDataModels.First().Key);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets a dynamic data model of type <typeparamref name="T" /> by its key
|
||||
/// </summary>
|
||||
|
||||
@@ -23,12 +23,6 @@ namespace Artemis.Core
|
||||
/// </summary>
|
||||
public PluginConfigurationDialog ConfigurationDialog { get; protected set; }
|
||||
|
||||
/// <inheritdoc />
|
||||
public void Dispose()
|
||||
{
|
||||
DisablePlugin();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Called when the plugin is activated
|
||||
/// </summary>
|
||||
@@ -40,11 +34,15 @@ namespace Artemis.Core
|
||||
public abstract void DisablePlugin();
|
||||
|
||||
/// <summary>
|
||||
/// Registers a timed update that whenever the plugin is enabled calls the provided <paramref name="action" /> at the provided
|
||||
/// Registers a timed update that whenever the plugin is enabled calls the provided <paramref name="action" /> at the
|
||||
/// provided
|
||||
/// <paramref name="interval" />
|
||||
/// </summary>
|
||||
/// <param name="interval">The interval at which the update should occur</param>
|
||||
/// <param name="action">The action to call every time the interval has passed. The delta time parameter represents the time passed since the last update in seconds</param>
|
||||
/// <param name="action">
|
||||
/// The action to call every time the interval has passed. The delta time parameter represents the
|
||||
/// time passed since the last update in seconds
|
||||
/// </param>
|
||||
/// <returns>The resulting plugin update registration</returns>
|
||||
public PluginUpdateRegistration AddTimedUpdate(TimeSpan interval, Action<double> action)
|
||||
{
|
||||
@@ -53,6 +51,24 @@ namespace Artemis.Core
|
||||
return new PluginUpdateRegistration(PluginInfo, interval, action);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Registers a timed update that whenever the plugin is enabled calls the provided <paramref name="action" /> at the
|
||||
/// provided
|
||||
/// <paramref name="interval" />
|
||||
/// </summary>
|
||||
/// <param name="interval">The interval at which the update should occur</param>
|
||||
/// <param name="asyncAction">
|
||||
/// The async action to call every time the interval has passed. The delta time parameter
|
||||
/// represents the time passed since the last update in seconds
|
||||
/// </param>
|
||||
/// <returns>The resulting plugin update registration</returns>
|
||||
public PluginUpdateRegistration AddTimedUpdate(TimeSpan interval, Func<double, Task> asyncAction)
|
||||
{
|
||||
if (asyncAction == null)
|
||||
throw new ArgumentNullException(nameof(asyncAction));
|
||||
return new PluginUpdateRegistration(PluginInfo, interval, asyncAction);
|
||||
}
|
||||
|
||||
internal void SetEnabled(bool enable, bool isAutoEnable = false)
|
||||
{
|
||||
if (enable && !Enabled)
|
||||
@@ -123,6 +139,12 @@ namespace Artemis.Core
|
||||
DisablePlugin();
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public void Dispose()
|
||||
{
|
||||
DisablePlugin();
|
||||
}
|
||||
|
||||
#region Events
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using System;
|
||||
using System.Threading.Tasks;
|
||||
using System.Timers;
|
||||
using Artemis.Core.Modules;
|
||||
|
||||
@@ -24,6 +25,19 @@ namespace Artemis.Core
|
||||
Start();
|
||||
}
|
||||
|
||||
internal PluginUpdateRegistration(PluginInfo pluginInfo, TimeSpan interval, Func<double, Task> asyncAction)
|
||||
{
|
||||
PluginInfo = pluginInfo;
|
||||
Interval = interval;
|
||||
AsyncAction = asyncAction;
|
||||
|
||||
PluginInfo.Instance.PluginEnabled += InstanceOnPluginEnabled;
|
||||
PluginInfo.Instance.PluginDisabled += InstanceOnPluginDisabled;
|
||||
if (PluginInfo.Instance.Enabled)
|
||||
Start();
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Gets the plugin info of the plugin this registration is associated with
|
||||
/// </summary>
|
||||
@@ -40,7 +54,12 @@ namespace Artemis.Core
|
||||
public Action<double> Action { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Starts calling the <see cref="Action" /> at the configured <see cref="Interval" />
|
||||
/// Gets the task that gets called each time the update event fires
|
||||
/// </summary>
|
||||
public Func<double, Task> AsyncAction { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Starts calling the <see cref="Action" /> or <see cref="AsyncAction"/> at the configured <see cref="Interval" />
|
||||
/// <para>Note: Called automatically when the plugin enables</para>
|
||||
/// </summary>
|
||||
public void Start()
|
||||
@@ -61,7 +80,7 @@ namespace Artemis.Core
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Stops calling the <see cref="Action" /> at the configured <see cref="Interval" />
|
||||
/// Stops calling the <see cref="Action" /> or <see cref="AsyncAction"/> at the configured <see cref="Interval" />
|
||||
/// <para>Note: Called automatically when the plugin disables</para>
|
||||
/// </summary>
|
||||
public void Stop()
|
||||
@@ -90,7 +109,13 @@ namespace Artemis.Core
|
||||
if (PluginInfo.Instance is Module module && !module.IsUpdateAllowed)
|
||||
return;
|
||||
|
||||
Action(interval.TotalSeconds);
|
||||
if (Action != null)
|
||||
Action(interval.TotalSeconds);
|
||||
else if (AsyncAction != null)
|
||||
{
|
||||
Task task = AsyncAction(interval.TotalSeconds);
|
||||
task.Wait();
|
||||
}
|
||||
}
|
||||
|
||||
private void InstanceOnPluginEnabled(object sender, EventArgs e)
|
||||
|
||||
Reference in new issue
Block a user