mirror of
https://github.com/Artemis-RGB/Artemis
synced 2026-11-12 03:48:56 +00:00
Data model - Improved encapsulation
Conditions - Renamed from DisplayConditions to DataModelConditions to better match their nature Core - More documentation
This commit is contained in:
1 parent
6b93b1c878
commit
a646ff95ed
39 files changed
+581
-355
No files matched your search
+19
-15
@@ -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);
|
||||
+43
-24
@@ -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
|
||||
}
|
||||
}
|
||||
+100
-55
@@ -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
|
||||
}
|
||||
}
|
||||
+153
-86
@@ -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
|
||||
}
|
||||
}
|
||||
+6
-11
@@ -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;
|
||||
|
||||
|
||||
Reference in new issue
Block a user