Data model - Improved encapsulation

Conditions - Renamed from DisplayConditions to DataModelConditions to better match their nature
Core - More documentation
This commit is contained in:
SpoinkyNL committed 2020-09-19 11:43:49 +02:00
1 parent 6b93b1c878
commit a646ff95ed
39 files changed
+581 -355

No files matched your search

@@ -2,9 +2,16 @@
namespace Artemis.Core.DefaultTypes
{
/// <inheritdoc />
/// <summary>
/// Represents a generic data binding converter that acts as the bridge between a
/// <see cref="DataBinding{TLayerProperty, TProperty}" /> and a <see cref="LayerProperty{T}" /> and does not support
/// sum or interpolation
/// </summary>
public class GeneralDataBindingConverter<T> : DataBindingConverter<T, object> where T : ILayerProperty
{
/// <summary>
/// Creates a new instance of the <see cref="GeneralDataBindingConverter{T}" /> class
/// </summary>
public GeneralDataBindingConverter()
{
SupportsSum = false;
@@ -8,43 +8,43 @@ namespace Artemis.Core
/// <summary>
/// An abstract class for display condition parts
/// </summary>
public abstract class DisplayConditionPart : IDisposable
public abstract class DataModelConditionPart : IDisposable
{
private readonly List<DisplayConditionPart> _children = new List<DisplayConditionPart>();
private readonly List<DataModelConditionPart> _children = new List<DataModelConditionPart>();
/// <summary>
/// Gets the parent of this part
/// </summary>
public DisplayConditionPart Parent { get; internal set; }
public DataModelConditionPart Parent { get; internal set; }
/// <summary>
/// Gets the children of this part
/// </summary>
public IReadOnlyList<DisplayConditionPart> Children => _children.AsReadOnly();
public IReadOnlyList<DataModelConditionPart> Children => _children.AsReadOnly();
/// <summary>
/// Adds a child to the display condition part's <see cref="Children" /> collection
/// </summary>
/// <param name="displayConditionPart"></param>
public void AddChild(DisplayConditionPart displayConditionPart)
/// <param name="dataModelConditionPart"></param>
public void AddChild(DataModelConditionPart dataModelConditionPart)
{
if (!_children.Contains(displayConditionPart))
if (!_children.Contains(dataModelConditionPart))
{
displayConditionPart.Parent = this;
_children.Add(displayConditionPart);
dataModelConditionPart.Parent = this;
_children.Add(dataModelConditionPart);
}
}
/// <summary>
/// Removes a child from the display condition part's <see cref="Children" /> collection
/// </summary>
/// <param name="displayConditionPart">The child to remove</param>
public void RemoveChild(DisplayConditionPart displayConditionPart)
/// <param name="dataModelConditionPart">The child to remove</param>
public void RemoveChild(DataModelConditionPart dataModelConditionPart)
{
if (_children.Contains(displayConditionPart))
if (_children.Contains(dataModelConditionPart))
{
displayConditionPart.Parent = null;
_children.Remove(displayConditionPart);
dataModelConditionPart.Parent = null;
_children.Remove(dataModelConditionPart);
}
}
@@ -59,13 +59,16 @@ namespace Artemis.Core
/// </summary>
/// <param name="target"></param>
/// <returns></returns>
public abstract bool EvaluateObject(object target);
internal abstract bool EvaluateObject(object target);
internal abstract void Save();
internal abstract DisplayConditionPartEntity GetEntity();
#region IDisposable
/// <summary>
/// Disposed the condition part
/// </summary>
protected virtual void Dispose(bool disposing)
{
if (disposing)
@@ -73,6 +76,7 @@ namespace Artemis.Core
}
}
/// <inheritdoc />
public void Dispose()
{
Dispose(true);
@@ -6,29 +6,29 @@ using Artemis.Storage.Entities.Profile.Conditions;
namespace Artemis.Core
{
/// <summary>
/// A group containing zero to many <see cref="DisplayConditionPart" />s which it evaluates using a boolean specific
/// A group containing zero to many <see cref="DataModelConditionPart" />s which it evaluates using a boolean specific
/// operator
/// </summary>
public class DisplayConditionGroup : DisplayConditionPart
public class DataModelConditionGroup : DataModelConditionPart
{
private bool _disposed;
/// <summary>
/// Creates a new instance of the <see cref="DisplayConditionGroup" /> class
/// Creates a new instance of the <see cref="DataModelConditionGroup" /> class
/// </summary>
/// <param name="parent"></param>
public DisplayConditionGroup(DisplayConditionPart parent)
public DataModelConditionGroup(DataModelConditionPart parent)
{
Parent = parent;
Entity = new DisplayConditionGroupEntity();
}
/// <summary>
/// Creates a new instance of the <see cref="DisplayConditionGroup" /> class
/// Creates a new instance of the <see cref="DataModelConditionGroup" /> class
/// </summary>
/// <param name="parent"></param>
/// <param name="entity"></param>
public DisplayConditionGroup(DisplayConditionPart parent, DisplayConditionGroupEntity entity)
public DataModelConditionGroup(DataModelConditionPart parent, DisplayConditionGroupEntity entity)
{
Parent = parent;
Entity = entity;
@@ -37,13 +37,13 @@ namespace Artemis.Core
foreach (var childEntity in Entity.Children)
{
if (childEntity is DisplayConditionGroupEntity groupEntity)
AddChild(new DisplayConditionGroup(this, groupEntity));
AddChild(new DataModelConditionGroup(this, groupEntity));
else if (childEntity is DisplayConditionListEntity listEntity)
AddChild(new DisplayConditionList(this, listEntity));
AddChild(new DataModelConditionList(this, listEntity));
else if (childEntity is DisplayConditionPredicateEntity predicateEntity)
AddChild(new DisplayConditionPredicate(this, predicateEntity));
AddChild(new DataModelConditionPredicate(this, predicateEntity));
else if (childEntity is DisplayConditionListPredicateEntity listPredicateEntity)
AddChild(new DisplayConditionListPredicate(this, listPredicateEntity));
AddChild(new DataModelConditionListPredicate(this, listPredicateEntity));
}
}
@@ -82,8 +82,22 @@ namespace Artemis.Core
}
}
#region IDisposable
/// <inheritdoc />
public override bool EvaluateObject(object target)
protected override void Dispose(bool disposing)
{
_disposed = true;
foreach (var child in Children)
child.Dispose();
base.Dispose(disposing);
}
#endregion
/// <inheritdoc />
internal override bool EvaluateObject(object target)
{
if (_disposed)
throw new ObjectDisposedException("DisplayConditionGroup");
@@ -119,26 +133,31 @@ namespace Artemis.Core
{
return Entity;
}
#region IDisposable
protected override void Dispose(bool disposing)
{
_disposed = true;
foreach (var child in Children)
child.Dispose();
base.Dispose(disposing);
}
#endregion
}
/// <summary>
/// Represents a boolean operator
/// </summary>
public enum BooleanOperator
{
/// <summary>
/// All the conditions in the group should evaluate to true
/// </summary>
And,
/// <summary>
/// Any of the conditions in the group should evaluate to true
/// </summary>
Or,
/// <summary>
/// All the conditions in the group should evaluate to false
/// </summary>
AndNot,
/// <summary>
/// Any of the conditions in the group should evaluate to false
/// </summary>
OrNot
}
}
@@ -8,11 +8,18 @@ using Artemis.Storage.Entities.Profile.Conditions;
namespace Artemis.Core
{
public class DisplayConditionList : DisplayConditionPart
/// <summary>
/// A condition that evaluates one or more predicates inside a list
/// </summary>
public class DataModelConditionList : DataModelConditionPart
{
private bool _disposed;
public DisplayConditionList(DisplayConditionPart parent)
/// <summary>
/// Creates a new instance of the <see cref="DataModelConditionList" /> class
/// </summary>
/// <param name="parent"></param>
public DataModelConditionList(DataModelConditionPart parent)
{
Parent = parent;
Entity = new DisplayConditionListEntity();
@@ -20,7 +27,7 @@ namespace Artemis.Core
Initialize();
}
public DisplayConditionList(DisplayConditionPart parent, DisplayConditionListEntity entity)
internal DataModelConditionList(DataModelConditionPart parent, DisplayConditionListEntity entity)
{
Parent = parent;
Entity = entity;
@@ -29,14 +36,29 @@ namespace Artemis.Core
Initialize();
}
public DisplayConditionListEntity Entity { get; set; }
internal DisplayConditionListEntity Entity { get; set; }
/// <summary>
/// Gets or sets the list operator
/// </summary>
public ListOperator ListOperator { get; set; }
/// <summary>
/// Gets the currently used instance of the list data model
/// </summary>
public DataModel ListDataModel { get; private set; }
/// <summary>
/// Gets the path of the list property in the <see cref="ListDataModel" />
/// </summary>
public string ListPropertyPath { get; private set; }
public Func<object, IList> CompiledListAccessor { get; set; }
/// <summary>
/// Gets the compiled function that accesses the list this condition evaluates on
/// </summary>
public Func<object, IList> CompiledListAccessor { get; private set; }
/// <inheritdoc />
public override bool Evaluate()
{
if (_disposed)
@@ -48,27 +70,11 @@ namespace Artemis.Core
return EvaluateObject(CompiledListAccessor(ListDataModel));
}
public override bool EvaluateObject(object target)
{
if (_disposed)
throw new ObjectDisposedException("DisplayConditionList");
if (!Children.Any())
return false;
if (!(target is IList list))
return false;
var objectList = list.Cast<object>();
return ListOperator switch
{
ListOperator.Any => objectList.Any(o => Children[0].EvaluateObject(o)),
ListOperator.All => objectList.All(o => Children[0].EvaluateObject(o)),
ListOperator.None => objectList.Any(o => !Children[0].EvaluateObject(o)),
ListOperator.Count => false,
_ => throw new ArgumentOutOfRangeException()
};
}
/// <summary>
/// Updates the list the predicate is evaluated on
/// </summary>
/// <param name="dataModel">The data model of the list</param>
/// <param name="path">The path pointing to the list inside the list</param>
public void UpdateList(DataModel dataModel, string path)
{
if (_disposed)
@@ -98,24 +104,49 @@ namespace Artemis.Core
return;
// Create a new root group
AddChild(new DisplayConditionGroup(this));
AddChild(new DataModelConditionGroup(this));
CreateExpression();
}
public void CreateExpression()
#region IDisposable
/// <inheritdoc />
protected override void Dispose(bool disposing)
{
_disposed = true;
DataModelStore.DataModelAdded -= DataModelStoreOnDataModelAdded;
DataModelStore.DataModelRemoved -= DataModelStoreOnDataModelRemoved;
foreach (var child in Children)
child.Dispose();
base.Dispose(disposing);
}
#endregion
internal override bool EvaluateObject(object target)
{
if (_disposed)
throw new ObjectDisposedException("DisplayConditionList");
var parameter = Expression.Parameter(typeof(object), "listDataModel");
var accessor = ListPropertyPath.Split('.').Aggregate<string, Expression>(
Expression.Convert(parameter, ListDataModel.GetType()),
(expression, s) => Expression.Convert(Expression.Property(expression, s), typeof(IList)));
if (!Children.Any())
return false;
if (!(target is IList list))
return false;
var lambda = Expression.Lambda<Func<object, IList>>(accessor, parameter);
CompiledListAccessor = lambda.Compile();
var objectList = list.Cast<object>();
return ListOperator switch
{
ListOperator.Any => objectList.Any(o => Children[0].EvaluateObject(o)),
ListOperator.All => objectList.All(o => Children[0].EvaluateObject(o)),
ListOperator.None => objectList.Any(o => !Children[0].EvaluateObject(o)),
ListOperator.Count => false,
_ => throw new ArgumentOutOfRangeException()
};
}
internal override void Save()
{
// Target list
@@ -159,14 +190,28 @@ namespace Artemis.Core
// There should only be one child and it should be a group
if (Entity.Children.SingleOrDefault() is DisplayConditionGroupEntity rootGroup)
AddChild(new DisplayConditionGroup(this, rootGroup));
AddChild(new DataModelConditionGroup(this, rootGroup));
else
{
Entity.Children.Clear();
AddChild(new DisplayConditionGroup(this));
AddChild(new DataModelConditionGroup(this));
}
}
private void CreateExpression()
{
if (_disposed)
throw new ObjectDisposedException("DisplayConditionList");
var parameter = Expression.Parameter(typeof(object), "listDataModel");
var accessor = ListPropertyPath.Split('.').Aggregate<string, Expression>(
Expression.Convert(parameter, ListDataModel.GetType()),
(expression, s) => Expression.Convert(Expression.Property(expression, s), typeof(IList)));
var lambda = Expression.Lambda<Func<object, IList>>(accessor, parameter);
CompiledListAccessor = lambda.Compile();
}
#region Event handlers
@@ -191,31 +236,31 @@ namespace Artemis.Core
}
#endregion
#region IDisposable
/// <inheritdoc />
protected override void Dispose(bool disposing)
{
_disposed = true;
DataModelStore.DataModelAdded -= DataModelStoreOnDataModelAdded;
DataModelStore.DataModelRemoved -= DataModelStoreOnDataModelRemoved;
foreach (var child in Children)
child.Dispose();
base.Dispose(disposing);
}
#endregion
}
/// <summary>
/// Represents a list operator
/// </summary>
public enum ListOperator
{
/// <summary>
/// Any of the list items should evaluate to true
/// </summary>
Any,
/// <summary>
/// All of the list items should evaluate to true
/// </summary>
All,
/// <summary>
/// None of the list items should evaluate to true
/// </summary>
None,
/// <summary>
/// A specific amount of the list items should evaluate to true
/// </summary>
Count
}
}
@@ -8,9 +8,17 @@ using Newtonsoft.Json;
namespace Artemis.Core
{
public class DisplayConditionListPredicate : DisplayConditionPart
/// <summary>
/// A predicate like evaluated inside a <see cref="DataModelConditionList" />
/// </summary>
public class DataModelConditionListPredicate : DataModelConditionPart
{
public DisplayConditionListPredicate(DisplayConditionPart parent, ProfileRightSideType predicateType)
/// <summary>
/// Creates a new instance of the <see cref="DataModelConditionListPredicate" /> class
/// </summary>
/// <param name="parent"></param>
/// <param name="predicateType"></param>
public DataModelConditionListPredicate(DataModelConditionPart parent, ProfileRightSideType predicateType)
{
Parent = parent;
PredicateType = predicateType;
@@ -20,7 +28,7 @@ namespace Artemis.Core
Initialize();
}
public DisplayConditionListPredicate(DisplayConditionPart parent, DisplayConditionListPredicateEntity entity)
internal DataModelConditionListPredicate(DataModelConditionPart parent, DisplayConditionListPredicateEntity entity)
{
Parent = parent;
Entity = entity;
@@ -30,27 +38,150 @@ namespace Artemis.Core
Initialize();
}
public DisplayConditionListPredicateEntity Entity { get; set; }
internal DisplayConditionListPredicateEntity Entity { get; set; }
/// <summary>
/// Gets or sets the predicate type
/// </summary>
public ProfileRightSideType PredicateType { get; set; }
/// <summary>
/// Gets the operator
/// </summary>
public ConditionOperator Operator { get; private set; }
/// <summary>
/// Gets the type of the content of the list this predicate is evaluated on
/// </summary>
public Type ListType { get; private set; }
/// <summary>
/// Gets the currently used instance of the list data model
/// </summary>
public DataModel ListDataModel { get; private set; }
/// <summary>
/// Gets the path of the list property in the <see cref="ListDataModel" />
/// </summary>
public string ListPropertyPath { get; private set; }
/// <summary>
/// Gets the path of the left property in the <see cref="ListType" />
/// </summary>
public string LeftPropertyPath { get; private set; }
/// <summary>
/// Gets the path of the right property in the <see cref="ListType" />
/// </summary>
public string RightPropertyPath { get; private set; }
/// <summary>
/// Gets the right static value, only used it <see cref="PredicateType" /> is
/// <see cref="ProfileRightSideType.Static" />
/// </summary>
public object RightStaticValue { get; private set; }
/// <summary>
/// Gets the compiled function that evaluates this predicate
/// </summary>
public Func<object, bool> CompiledListPredicate { get; private set; }
public void ApplyParentList()
/// <summary>
/// Updates the left side of the predicate
/// </summary>
/// <param name="path">The path pointing to the left side value inside the list</param>
public void UpdateLeftSide(string path)
{
if (!ListContainsInnerPath(path))
throw new ArtemisCoreException($"List type {ListType.Name} does not contain path {path}");
LeftPropertyPath = path;
ValidateOperator();
ValidateRightSide();
CreateExpression();
}
/// <summary>
/// Updates the right side of the predicate, makes the predicate dynamic and re-compiles the expression
/// </summary>
/// <param name="path">The path pointing to the right side value inside the list</param>
public void UpdateRightSideDynamic(string path)
{
if (!ListContainsInnerPath(path))
throw new ArtemisCoreException($"List type {ListType.Name} does not contain path {path}");
PredicateType = ProfileRightSideType.Dynamic;
RightPropertyPath = path;
CreateExpression();
}
/// <summary>
/// Updates the right side of the predicate, makes the predicate static and re-compiles the expression
/// </summary>
/// <param name="staticValue">The right side value to use</param>
public void UpdateRightSideStatic(object staticValue)
{
PredicateType = ProfileRightSideType.Static;
RightPropertyPath = null;
SetStaticValue(staticValue);
CreateExpression();
}
/// <summary>
/// Updates the operator of the predicate and re-compiles the expression
/// </summary>
/// <param name="conditionOperator"></param>
public void UpdateOperator(ConditionOperator conditionOperator)
{
if (conditionOperator == null)
{
Operator = null;
return;
}
if (LeftPropertyPath == null)
{
Operator = conditionOperator;
return;
}
var leftType = GetTypeAtInnerPath(LeftPropertyPath);
if (conditionOperator.SupportsType(leftType))
Operator = conditionOperator;
CreateExpression();
}
/// <summary>
/// Not supported for list predicates, always returns <c>false</c>
/// </summary>
public override bool Evaluate()
{
return false;
}
#region IDisposable
/// <inheritdoc />
protected override void Dispose(bool disposing)
{
ConditionOperatorStore.ConditionOperatorAdded -= ConditionOperatorStoreOnConditionOperatorAdded;
ConditionOperatorStore.ConditionOperatorRemoved -= ConditionOperatorStoreOnConditionOperatorRemoved;
base.Dispose(disposing);
}
#endregion
internal void ApplyParentList()
{
var current = Parent;
while (current != null)
{
if (current is DisplayConditionList parentList)
if (current is DataModelConditionList parentList)
{
UpdateList(parentList.ListDataModel, parentList.ListPropertyPath);
return;
@@ -60,7 +191,7 @@ namespace Artemis.Core
}
}
public void UpdateList(DataModel dataModel, string path)
internal void UpdateList(DataModel dataModel, string path)
{
if (dataModel != null && path == null)
throw new ArtemisCoreException("If a data model is provided, a path is also required");
@@ -89,70 +220,19 @@ namespace Artemis.Core
CreateExpression();
}
public void UpdateLeftSide(string path)
{
if (!ListContainsInnerPath(path))
throw new ArtemisCoreException($"List type {ListType.Name} does not contain path {path}");
LeftPropertyPath = path;
ValidateOperator();
ValidateRightSide();
CreateExpression();
}
public void UpdateRightSideDynamic(string path)
{
if (!ListContainsInnerPath(path))
throw new ArtemisCoreException($"List type {ListType.Name} does not contain path {path}");
PredicateType = ProfileRightSideType.Dynamic;
RightPropertyPath = path;
CreateExpression();
}
public void UpdateRightSideStatic(object staticValue)
{
PredicateType = ProfileRightSideType.Static;
RightPropertyPath = null;
SetStaticValue(staticValue);
CreateExpression();
}
public void UpdateOperator(ConditionOperator conditionOperator)
{
if (conditionOperator == null)
{
Operator = null;
return;
}
if (LeftPropertyPath == null)
{
Operator = conditionOperator;
return;
}
var leftType = GetTypeAtInnerPath(LeftPropertyPath);
if (conditionOperator.SupportsType(leftType))
Operator = conditionOperator;
CreateExpression();
}
public override bool Evaluate()
{
return false;
}
public override bool EvaluateObject(object target)
/// <summary>
/// Evaluates the condition part on the given target
/// </summary>
/// <param name="target">
/// An instance of the list described in <see cref="ListDataModel" /> and
/// <see cref="ListPropertyPath" />
/// </param>
internal override bool EvaluateObject(object target)
{
return CompiledListPredicate != null && CompiledListPredicate(target);
}
public bool ListContainsInnerPath(string path)
internal bool ListContainsInnerPath(string path)
{
if (ListType == null)
return false;
@@ -171,7 +251,7 @@ namespace Artemis.Core
return true;
}
public Type GetTypeAtInnerPath(string path)
internal Type GetTypeAtInnerPath(string path)
{
if (!ListContainsInnerPath(path))
return null;
@@ -210,6 +290,11 @@ namespace Artemis.Core
}
}
internal override DisplayConditionPartEntity GetEntity()
{
return Entity;
}
private void Initialize()
{
ConditionOperatorStore.ConditionOperatorAdded += ConditionOperatorStoreOnConditionOperatorAdded;
@@ -270,11 +355,6 @@ namespace Artemis.Core
}
}
internal override DisplayConditionPartEntity GetEntity()
{
return Entity;
}
private void CreateExpression()
{
CompiledListPredicate = null;
@@ -412,18 +492,5 @@ namespace Artemis.Core
}
#endregion
#region IDisposable
/// <inheritdoc />
protected override void Dispose(bool disposing)
{
ConditionOperatorStore.ConditionOperatorAdded -= ConditionOperatorStoreOnConditionOperatorAdded;
ConditionOperatorStore.ConditionOperatorRemoved -= ConditionOperatorStoreOnConditionOperatorRemoved;
base.Dispose(disposing);
}
#endregion
}
}
@@ -9,17 +9,17 @@ using Newtonsoft.Json;
namespace Artemis.Core
{
/// <summary>
/// A predicate in a display condition using either two data model values or one data model value and a
/// A predicate in a data model condition using either two data model values or one data model value and a
/// static value
/// </summary>
public class DisplayConditionPredicate : DisplayConditionPart
public class DataModelConditionPredicate : DataModelConditionPart
{
/// <summary>
/// Creates a new instance of the <see cref="DisplayConditionPredicate" /> class
/// Creates a new instance of the <see cref="DataModelConditionPredicate" /> class
/// </summary>
/// <param name="parent"></param>
/// <param name="predicateType"></param>
public DisplayConditionPredicate(DisplayConditionPart parent, ProfileRightSideType predicateType)
public DataModelConditionPredicate(DataModelConditionPart parent, ProfileRightSideType predicateType)
{
Parent = parent;
PredicateType = predicateType;
@@ -28,12 +28,7 @@ namespace Artemis.Core
Initialize();
}
/// <summary>
/// Creates a new instance of the <see cref="DisplayConditionPredicate" /> class
/// </summary>
/// <param name="parent"></param>
/// <param name="entity"></param>
public DisplayConditionPredicate(DisplayConditionPart parent, DisplayConditionPredicateEntity entity)
internal DataModelConditionPredicate(DataModelConditionPart parent, DisplayConditionPredicateEntity entity)
{
Parent = parent;
Entity = entity;
@@ -219,7 +214,7 @@ namespace Artemis.Core
}
/// <inheritdoc />
public override bool EvaluateObject(object target)
internal override bool EvaluateObject(object target)
{
return false;
}
@@ -11,15 +11,18 @@ namespace Artemis.Core
public abstract class DataBindingConverter<TLayerProperty, TProperty> : IDataBindingConverter
{
/// <summary>
/// A dynamically compiled getter pointing to the data bound property
/// Gets a dynamically compiled getter pointing to the data bound property
/// </summary>
public Func<TLayerProperty, TProperty> GetExpression { get; private set; }
/// <summary>
/// A dynamically compiled setter pointing to the data bound property
/// Gets a dynamically compiled setter pointing to the data bound property used for value types
/// </summary>
public Action<TProperty> ValueTypeSetExpression { get; private set; }
/// <summary>
/// Gets a dynamically compiled setter pointing to the data bound property used for reference types
/// </summary>
public Action<TLayerProperty, TProperty> ReferenceTypeSetExpression { get; private set; }
/// <summary>
@@ -49,9 +49,9 @@ namespace Artemis.Core
DisplayContinuously = RenderElementEntity.DisplayContinuously;
AlwaysFinishTimeline = RenderElementEntity.AlwaysFinishTimeline;
DisplayConditionGroup = RenderElementEntity.RootDisplayCondition != null
? new DisplayConditionGroup(null, RenderElementEntity.RootDisplayCondition)
: new DisplayConditionGroup(null);
DataModelConditionGroup = RenderElementEntity.RootDisplayCondition != null
? new DataModelConditionGroup(null, RenderElementEntity.RootDisplayCondition)
: new DataModelConditionGroup(null);
ActivateEffects();
}
@@ -82,8 +82,8 @@ namespace Artemis.Core
}
// Conditions
RenderElementEntity.RootDisplayCondition = DisplayConditionGroup?.Entity;
DisplayConditionGroup?.Save();
RenderElementEntity.RootDisplayCondition = DataModelConditionGroup?.Entity;
DataModelConditionGroup?.Save();
}
#region Properties
@@ -392,22 +392,22 @@ namespace Artemis.Core
private set => SetAndNotify(ref _displayConditionMet, value);
}
private DisplayConditionGroup _displayConditionGroup;
private DataModelConditionGroup _dataModelConditionGroup;
private TimeSpan _timelinePosition;
private bool _displayConditionMet;
/// <summary>
/// Gets or sets the root display condition group
/// </summary>
public DisplayConditionGroup DisplayConditionGroup
public DataModelConditionGroup DataModelConditionGroup
{
get => _displayConditionGroup;
set => SetAndNotify(ref _displayConditionGroup, value);
get => _dataModelConditionGroup;
set => SetAndNotify(ref _dataModelConditionGroup, value);
}
public void UpdateDisplayCondition()
{
var conditionMet = DisplayConditionGroup == null || DisplayConditionGroup.Evaluate();
var conditionMet = DataModelConditionGroup == null || DataModelConditionGroup.Evaluate();
if (conditionMet && !DisplayConditionMet)
TimelinePosition = TimeSpan.Zero;
@@ -2,6 +2,9 @@
namespace Artemis.Core.DataModelExpansions
{
/// <summary>
/// Represents an attribute that marks a data model property to be ignored by the UI
/// </summary>
public class DataModelIgnoreAttribute : Attribute
{
}
@@ -2,6 +2,9 @@
namespace Artemis.Core.DataModelExpansions
{
/// <summary>
/// Represents an attribute that describes a data model property
/// </summary>
[AttributeUsage(AttributeTargets.Property)]
public class DataModelPropertyAttribute : Attribute
{
@@ -28,7 +28,7 @@ namespace Artemis.Core.DataModelExpansions
[DataModelIgnore]
public bool IsExpansion { get; internal set; }
public bool ContainsPath(string path)
internal bool ContainsPath(string path)
{
var parts = path.Split('.');
var current = GetType();
@@ -43,7 +43,7 @@ namespace Artemis.Core.DataModelExpansions
return true;
}
public Type GetTypeAtPath(string path)
internal Type GetTypeAtPath(string path)
{
if (!ContainsPath(path))
return null;
@@ -62,7 +62,7 @@ namespace Artemis.Core.DataModelExpansions
return result;
}
public Type GetListTypeInPath(string path)
internal Type GetListTypeInPath(string path)
{
if (!ContainsPath(path))
return null;
@@ -90,7 +90,7 @@ namespace Artemis.Core.DataModelExpansions
return null;
}
public Type GetListTypeAtPath(string path)
internal Type GetListTypeAtPath(string path)
{
if (!ContainsPath(path))
return null;
@@ -98,29 +98,7 @@ namespace Artemis.Core.DataModelExpansions
var child = GetTypeAtPath(path);
return child.GenericTypeArguments.Length > 0 ? child.GenericTypeArguments[0] : null;
}
public string GetListInnerPath(string path)
{
if (GetListTypeInPath(path) == null)
throw new ArtemisCoreException($"Cannot determine inner list path at {path} because it does not contain a list");
var parts = path.Split('.');
var current = GetType();
for (var index = 0; index < parts.Length; index++)
{
var part = parts[index];
var property = current.GetProperty(part);
if (typeof(IList).IsAssignableFrom(property.PropertyType))
return string.Join('.', parts.Skip(index + 1).ToList());
current = property.PropertyType;
}
return null;
}
/// <summary>
/// Returns a read-only list of all properties in this datamodel that are to be ignored
/// </summary>
@@ -10,14 +10,22 @@ namespace Artemis.Core.DataModelExpansions
/// </summary>
public abstract class BaseDataModelExpansion : Plugin
{
protected readonly List<PropertyInfo> HiddenPropertiesList = new List<PropertyInfo>();
/// <summary>
/// Gets a list of all properties ignored at runtime using <c>IgnoreProperty(x => x.y)</c>
/// </summary>
protected internal readonly List<PropertyInfo> HiddenPropertiesList = new List<PropertyInfo>();
/// <summary>
/// Gets a list of all properties ignored at runtime using IgnoreProperty(x => x.y)
/// Gets a list of all properties ignored at runtime using <c>IgnoreProperty(x => x.y)</c>
/// </summary>
public ReadOnlyCollection<PropertyInfo> HiddenProperties => HiddenPropertiesList.AsReadOnly();
internal DataModel InternalDataModel { get; set; }
/// <summary>
/// Called each frame when the data model should update
/// </summary>
/// <param name="deltaTime">Time in seconds since the last update</param>
public abstract void Update(double deltaTime);
/// <summary>
@@ -2,13 +2,23 @@
namespace Artemis.Core.LayerBrushes
{
/// <summary>
/// Represents a view model for a brush configuration window
/// </summary>
public abstract class BrushConfigurationViewModel : Screen
{
/// <summary>
/// Creates a new instance of the <see cref="BrushConfigurationViewModel" /> class
/// </summary>
/// <param name="layerBrush"></param>
protected BrushConfigurationViewModel(BaseLayerBrush layerBrush)
{
LayerBrush = layerBrush;
}
/// <summary>
/// Gets the layer brush this view model is associated with
/// </summary>
public BaseLayerBrush LayerBrush { get; }
}
}
@@ -1,10 +1,16 @@
using Artemis.Core.Services;
using SkiaSharp;
using SkiaSharp;
namespace Artemis.Core.LayerBrushes
{
/// <summary>
/// Represents a brush that renders on a layer
/// </summary>
/// <typeparam name="T">The type of brush properties</typeparam>
public abstract class LayerBrush<T> : PropertiesLayerBrush<T> where T : LayerPropertyGroup
{
/// <summary>
/// Creates a new instance of the <see cref="LayerBrush{T}" /> class
/// </summary>
protected LayerBrush()
{
BrushType = LayerBrushType.Regular;
@@ -44,6 +44,16 @@ namespace Artemis.Core.LayerBrushes
/// </summary>
public LayerBrushProvider LayerBrushProvider { get; }
/// <summary>
/// Determines whether the provided <paramref name="reference" /> references to a brush provided by this descriptor
/// </summary>
public bool MatchesLayerBrushReference(LayerBrushReference reference)
{
if (reference == null)
return false;
return LayerBrushProvider.PluginInfo.Guid == reference.BrushPluginGuid && LayerBrushType.Name == reference.BrushType;
}
/// <summary>
/// Creates an instance of the described brush and applies it to the layer
/// </summary>
@@ -61,12 +71,5 @@ namespace Artemis.Core.LayerBrushes
layer.LayerBrush = brush;
layer.OnLayerBrushUpdated();
}
public bool MatchesLayerBrushReference(LayerBrushReference reference)
{
if (reference == null)
return false;
return LayerBrushProvider.PluginInfo.Guid == reference.BrushPluginGuid && LayerBrushType.Name == reference.BrushType;
}
}
}
@@ -1,16 +1,21 @@
using Artemis.Core.Services;
using SkiaSharp;
using SkiaSharp;
namespace Artemis.Core.LayerBrushes
{
/// <summary>
/// Represents a brush that renders on a per-layer basis
/// </summary>
/// <typeparam name="T">The type of brush properties</typeparam>
public abstract class PerLedLayerBrush<T> : PropertiesLayerBrush<T> where T : LayerPropertyGroup
{
/// <summary>
/// Creates a new instance of the <see cref="PerLedLayerBrush{T}" /> class
/// </summary>
protected PerLedLayerBrush()
{
BrushType = LayerBrushType.Regular;
}
/// <summary>
/// The main method of rendering for this type of brush. Called once per frame for each LED in the layer
/// <para>
@@ -2,13 +2,23 @@
namespace Artemis.Core.LayerEffects
{
/// <summary>
/// Represents a view model for an effect configuration window
/// </summary>
public abstract class EffectConfigurationViewModel : Screen
{
/// <summary>
/// Creates a new instance of the <see cref="EffectConfigurationViewModel" /> class
/// </summary>
/// <param name="layerEffect"></param>
protected EffectConfigurationViewModel(BaseLayerEffect layerEffect)
{
LayerEffect = layerEffect;
}
/// <summary>
/// Gets the layer effect this view model is associated with
/// </summary>
public BaseLayerEffect LayerEffect { get; }
}
}
@@ -1,8 +1,11 @@
using System;
using Artemis.Core.Services;
namespace Artemis.Core.LayerEffects
{
/// <summary>
/// Represents an effect that applies preprocessing and/or postprocessing to a layer
/// </summary>
/// <typeparam name="T"></typeparam>
public abstract class LayerEffect<T> : BaseLayerEffect where T : LayerPropertyGroup
{
private T _properties;
@@ -16,6 +16,7 @@
return ActivationMet;
}
/// <inheritdoc />
public string GetUserFriendlyDescription()
{
return "No description available";
@@ -43,6 +43,7 @@ namespace Artemis.Core.Modules
: processes.Any();
}
/// <inheritdoc />
public string GetUserFriendlyDescription()
{
var description = $"Requirement met when \"{ProcessName}.exe\" is running";
+2 -2
View File
@@ -144,13 +144,13 @@ namespace Artemis.Core.Modules
public bool IsUpdateAllowed => IsActivated && (UpdateDuringActivationOverride || !IsActivatedOverride);
/// <summary>
/// Called each frame when the module must update
/// Called each frame when the module should update
/// </summary>
/// <param name="deltaTime">Time in seconds since the last update</param>
public abstract void Update(double deltaTime);
/// <summary>
/// Called each frame when the module must render
/// Called each frame when the module should render
/// </summary>
/// <param name="deltaTime">Time since the last render</param>
/// <param name="surface">The RGB Surface to render to</param>
@@ -91,18 +91,27 @@ namespace Artemis.Core.Modules
/// </summary>
public abstract class ProfileModule : Module
{
protected readonly List<PropertyInfo> HiddenPropertiesList = new List<PropertyInfo>();
/// <summary>
/// Gets a list of all properties ignored at runtime using <c>IgnoreProperty(x => x.y)</c>
/// </summary>
protected internal readonly List<PropertyInfo> HiddenPropertiesList = new List<PropertyInfo>();
/// <summary>
/// Creates a new instance of the <see cref="ProfileModule" /> class
/// </summary>
protected ProfileModule()
{
OpacityOverride = 1;
}
/// <summary>
/// Gets a list of all properties ignored at runtime using IgnoreProperty(x => x.y)
/// Gets a list of all properties ignored at runtime using <c>IgnoreProperty(x => x.y)</c>
/// </summary>
public ReadOnlyCollection<PropertyInfo> HiddenProperties => HiddenPropertiesList.AsReadOnly();
/// <summary>
/// Gets the currently active profile
/// </summary>
public Profile ActiveProfile { get; private set; }
/// <summary>
@@ -225,8 +234,14 @@ namespace Artemis.Core.Modules
#region Events
/// <summary>
/// Occurs when the <see cref="ActiveProfile" /> has changed
/// </summary>
public event EventHandler ActiveProfileChanged;
/// <summary>
/// Invokes the <see cref="ActiveProfileChanged" /> event
/// </summary>
protected virtual void OnActiveProfileChanged()
{
ActiveProfileChanged?.Invoke(this, EventArgs.Empty);
@@ -2,13 +2,23 @@
namespace Artemis.Core
{
/// <summary>
/// Represents a view model for a plugin configuration window
/// </summary>
public abstract class PluginConfigurationViewModel : Screen
{
/// <summary>
/// Creates a new instance of the <see cref="PluginConfigurationViewModel" /> class
/// </summary>
/// <param name="plugin"></param>
protected PluginConfigurationViewModel(Plugin plugin)
{
Plugin = plugin;
}
/// <summary>
/// Gets the plugin this configuration view model is associated with
/// </summary>
public Plugin Plugin { get; }
}
}
+4 -1
View File
@@ -8,6 +8,9 @@ using Stylet;
namespace Artemis.Core
{
/// <summary>
/// Represents basic info about a plugin and contains a reference to the instance of said plugin
/// </summary>
[JsonObject(MemberSerialization.OptIn)]
public class PluginInfo : PropertyChangedBase
{
@@ -17,7 +20,6 @@ namespace Artemis.Core
private Guid _guid;
private string _icon;
private Plugin _instance;
private bool _lastEnableSuccessful;
private Exception _loadException;
private string _main;
private string _name;
@@ -140,6 +142,7 @@ namespace Artemis.Core
/// </summary>
internal PluginEntity PluginEntity { get; set; }
/// <inheritdoc />
public override string ToString()
{
return $"{Name} v{Version} - {Guid}";
@@ -93,12 +93,12 @@ namespace Artemis.Core
Action(interval.TotalSeconds);
}
private void InstanceOnPluginEnabled(object? sender, EventArgs e)
private void InstanceOnPluginEnabled(object sender, EventArgs e)
{
Start();
}
private void InstanceOnPluginDisabled(object? sender, EventArgs e)
private void InstanceOnPluginDisabled(object sender, EventArgs e)
{
Stop();
}
@@ -6,6 +6,10 @@ using Stylet;
namespace Artemis.Core
{
/// <summary>
/// Represents a setting tied to a plugin of type <typeparamref name="T" />
/// </summary>
/// <typeparam name="T">The value type of the setting</typeparam>
public class PluginSetting<T> : PropertyChangedBase
{
// ReSharper disable once NotAccessedField.Local
@@ -78,14 +82,21 @@ namespace Artemis.Core
_pluginRepository.SaveSetting(_pluginSettingEntity);
}
/// <summary>
/// Occurs when the value of the setting has been changed
/// </summary>
public event EventHandler<EventArgs> SettingChanged;
/// <inheritdoc />
public override string ToString()
{
return $"{nameof(Name)}: {Name}, {nameof(Value)}: {Value}, {nameof(HasChanged)}: {HasChanged}";
}
protected virtual void OnSettingChanged()
/// <summary>
/// Invokes the <see cref="SettingChanged" /> event
/// </summary>
protected internal virtual void OnSettingChanged()
{
SettingChanged?.Invoke(this, EventArgs.Empty);
}
+13 -1
View File
@@ -47,8 +47,19 @@ namespace Artemis.Core
/// <inheritdoc />
public Dictionary<BrushRenderTarget, Color> RenderedTargets { get; } = new Dictionary<BrushRenderTarget, Color>();
/// <summary>
/// Gets or sets the desired scale of the bitmap brush
/// </summary>
public Scale Scale { get; set; }
/// <summary>
/// Gets the last rendered scale of the bitmap brush
/// </summary>
public Scale RenderedScale { get; private set; }
/// <summary>
/// Gets the bitmap used to sample the brush
/// </summary>
public SKBitmap Bitmap { get; private set; }
#endregion
@@ -148,6 +159,7 @@ namespace Artemis.Core
{
}
/// <inheritdoc />
public void Dispose()
{
lock (_disposeLock)
@@ -157,7 +169,7 @@ namespace Artemis.Core
}
}
public bool IsDisposed { get; set; }
internal bool IsDisposed { get; set; }
#endregion
}
@@ -70,10 +70,10 @@ namespace Artemis.Core.Services
List<PluginInfo> GetAllPluginInfo();
/// <summary>
/// Finds all enabled <see cref="Plugin" /> instances of type T
/// Finds all enabled <see cref="Plugin" /> instances of <typeparamref name="T"/>
/// </summary>
/// <typeparam name="T">Either <see cref="Plugin" /> or a plugin type implementing <see cref="Plugin" /></typeparam>
/// <returns>Returns a list of plug instances of type T
/// <returns>Returns a list of plugin instances of <typeparamref name="T"/></returns>
List<T> GetPluginsOfType<T>() where T : Plugin;
/// <summary>
@@ -3,6 +3,9 @@ using System.Collections.ObjectModel;
namespace Artemis.Core.Services
{
/// <summary>
/// Provides access to the device surface and its configuration
/// </summary>
public interface ISurfaceService : IArtemisService
{
/// <summary>
@@ -13,26 +13,26 @@ namespace Artemis.Core
_logger = kernel.Get<ILogger>();
}
public static void LogPredicateDeserializationFailure(DisplayConditionPredicate displayConditionPredicate, JsonException exception)
public static void LogPredicateDeserializationFailure(DataModelConditionPredicate dataModelConditionPredicate, JsonException exception)
{
_logger.Warning(
exception,
"Failed to deserialize display condition predicate {left} {operator} {right}",
displayConditionPredicate.Entity.LeftPropertyPath,
displayConditionPredicate.Entity.OperatorType,
displayConditionPredicate.Entity.RightPropertyPath
dataModelConditionPredicate.Entity.LeftPropertyPath,
dataModelConditionPredicate.Entity.OperatorType,
dataModelConditionPredicate.Entity.RightPropertyPath
);
}
public static void LogListPredicateDeserializationFailure(DisplayConditionListPredicate displayConditionPredicate, JsonException exception)
public static void LogListPredicateDeserializationFailure(DataModelConditionListPredicate dataModelConditionPredicate, JsonException exception)
{
_logger.Warning(
exception,
"Failed to deserialize display condition list predicate {list} => {left} {operator} {right}",
displayConditionPredicate.Entity.ListPropertyPath,
displayConditionPredicate.Entity.LeftPropertyPath,
displayConditionPredicate.Entity.OperatorType,
displayConditionPredicate.Entity.RightPropertyPath
dataModelConditionPredicate.Entity.ListPropertyPath,
dataModelConditionPredicate.Entity.LeftPropertyPath,
dataModelConditionPredicate.Entity.OperatorType,
dataModelConditionPredicate.Entity.RightPropertyPath
);
}
+2 -1
View File
@@ -1,4 +1,5 @@
using System;
#pragma warning disable 1591
using System;
namespace Artemis.Core
{