Profile modules - Added option to provide default profiles

Profiles - Run adaption on freshly imported profiles when activating
Profiles - Run adaption on freshly imported profiles when surface changes
This commit is contained in:
Robert committed 2021-05-15 22:41:15 +02:00
1 parent c7c78dfecc
commit 14f82284ac
7 files changed
+121 -53

No files matched your search

+28 -17
View File
@@ -14,6 +14,7 @@ namespace Artemis.Core
{
private readonly object _lock = new();
private bool _isActivated;
private bool _isFreshImport;
internal Profile(ProfileModule module, string name) : base(null!)
{
@@ -57,6 +58,20 @@ namespace Artemis.Core
private set => SetAndNotify(ref _isActivated, value);
}
/// <summary>
/// Gets or sets a boolean indicating whether this profile is freshly imported i.e. no changes have been made to it
/// since import
/// <para>
/// Note: As long as this is <see langword="true" />, profile adaption will be performed on load and any surface
/// changes
/// </para>
/// </summary>
public bool IsFreshImport
{
get => _isFreshImport;
set => SetAndNotify(ref _isFreshImport, value);
}
/// <summary>
/// Gets the profile entity this profile uses for persistent storage
/// </summary>
@@ -134,6 +149,16 @@ namespace Artemis.Core
layer.PopulateLeds(devices);
}
/// <summary>
/// Occurs when the profile has been activated.
/// </summary>
public event EventHandler? Activated;
/// <summary>
/// Occurs when the profile is being deactivated.
/// </summary>
public event EventHandler? Deactivated;
/// <inheritdoc />
protected override void Dispose(bool disposing)
{
@@ -156,6 +181,7 @@ namespace Artemis.Core
throw new ObjectDisposedException("Profile");
Name = ProfileEntity.Name;
IsFreshImport = ProfileEntity.IsFreshImport;
lock (ChildrenList)
{
@@ -171,9 +197,7 @@ namespace Artemis.Core
Folder _ = new(this, "Root folder");
}
else
{
AddChild(new Folder(this, this, rootFolder));
}
}
}
@@ -186,6 +210,7 @@ namespace Artemis.Core
ProfileEntity.ModuleId = Module.Id;
ProfileEntity.Name = Name;
ProfileEntity.IsActive = IsActivated;
ProfileEntity.IsFreshImport = IsFreshImport;
foreach (ProfileElement profileElement in Children)
profileElement.Save();
@@ -196,7 +221,7 @@ namespace Artemis.Core
ProfileEntity.Layers.Clear();
ProfileEntity.Layers.AddRange(GetAllLayers().Select(f => f.LayerEntity));
}
internal void Activate(IEnumerable<ArtemisDevice> devices)
{
lock (_lock)
@@ -212,18 +237,6 @@ namespace Artemis.Core
}
}
#region Events
/// <summary>
/// Occurs when the profile has been activated.
/// </summary>
public event EventHandler? Activated;
/// <summary>
/// Occurs when the profile is being deactivated.
/// </summary>
public event EventHandler? Deactivated;
private void OnActivated()
{
Activated?.Invoke(this, EventArgs.Empty);
@@ -233,7 +246,5 @@ namespace Artemis.Core
{
Deactivated?.Invoke(this, EventArgs.Empty);
}
#endregion
}
}
@@ -37,10 +37,5 @@ namespace Artemis.Core
/// Gets a boolean indicating whether this was the last active profile
/// </summary>
public bool IsLastActiveProfile { get; }
/// <summary>
/// Gets or sets a boolean indicating whether the profile will be adapted the next time it is activated
/// </summary>
public bool NeedsAdaption { get; set; }
}
}