1
0
mirror of https://github.com/Artemis-RGB/Artemis synced 2025-12-31 17:53:32 +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:
SpoinkyNL 2020-09-19 11:43:49 +02:00
parent 6b93b1c878
commit a646ff95ed
39 changed files with 581 additions and 355 deletions

View File

@ -2,9 +2,16 @@
namespace Artemis.Core.DefaultTypes 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 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() public GeneralDataBindingConverter()
{ {
SupportsSum = false; SupportsSum = false;

View File

@ -8,43 +8,43 @@ namespace Artemis.Core
/// <summary> /// <summary>
/// An abstract class for display condition parts /// An abstract class for display condition parts
/// </summary> /// </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> /// <summary>
/// Gets the parent of this part /// Gets the parent of this part
/// </summary> /// </summary>
public DisplayConditionPart Parent { get; internal set; } public DataModelConditionPart Parent { get; internal set; }
/// <summary> /// <summary>
/// Gets the children of this part /// Gets the children of this part
/// </summary> /// </summary>
public IReadOnlyList<DisplayConditionPart> Children => _children.AsReadOnly(); public IReadOnlyList<DataModelConditionPart> Children => _children.AsReadOnly();
/// <summary> /// <summary>
/// Adds a child to the display condition part's <see cref="Children" /> collection /// Adds a child to the display condition part's <see cref="Children" /> collection
/// </summary> /// </summary>
/// <param name="displayConditionPart"></param> /// <param name="dataModelConditionPart"></param>
public void AddChild(DisplayConditionPart displayConditionPart) public void AddChild(DataModelConditionPart dataModelConditionPart)
{ {
if (!_children.Contains(displayConditionPart)) if (!_children.Contains(dataModelConditionPart))
{ {
displayConditionPart.Parent = this; dataModelConditionPart.Parent = this;
_children.Add(displayConditionPart); _children.Add(dataModelConditionPart);
} }
} }
/// <summary> /// <summary>
/// Removes a child from the display condition part's <see cref="Children" /> collection /// Removes a child from the display condition part's <see cref="Children" /> collection
/// </summary> /// </summary>
/// <param name="displayConditionPart">The child to remove</param> /// <param name="dataModelConditionPart">The child to remove</param>
public void RemoveChild(DisplayConditionPart displayConditionPart) public void RemoveChild(DataModelConditionPart dataModelConditionPart)
{ {
if (_children.Contains(displayConditionPart)) if (_children.Contains(dataModelConditionPart))
{ {
displayConditionPart.Parent = null; dataModelConditionPart.Parent = null;
_children.Remove(displayConditionPart); _children.Remove(dataModelConditionPart);
} }
} }
@ -59,13 +59,16 @@ namespace Artemis.Core
/// </summary> /// </summary>
/// <param name="target"></param> /// <param name="target"></param>
/// <returns></returns> /// <returns></returns>
public abstract bool EvaluateObject(object target); internal abstract bool EvaluateObject(object target);
internal abstract void Save(); internal abstract void Save();
internal abstract DisplayConditionPartEntity GetEntity(); internal abstract DisplayConditionPartEntity GetEntity();
#region IDisposable #region IDisposable
/// <summary>
/// Disposed the condition part
/// </summary>
protected virtual void Dispose(bool disposing) protected virtual void Dispose(bool disposing)
{ {
if (disposing) if (disposing)
@ -73,6 +76,7 @@ namespace Artemis.Core
} }
} }
/// <inheritdoc />
public void Dispose() public void Dispose()
{ {
Dispose(true); Dispose(true);

View File

@ -6,29 +6,29 @@ using Artemis.Storage.Entities.Profile.Conditions;
namespace Artemis.Core namespace Artemis.Core
{ {
/// <summary> /// <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 /// operator
/// </summary> /// </summary>
public class DisplayConditionGroup : DisplayConditionPart public class DataModelConditionGroup : DataModelConditionPart
{ {
private bool _disposed; private bool _disposed;
/// <summary> /// <summary>
/// Creates a new instance of the <see cref="DisplayConditionGroup" /> class /// Creates a new instance of the <see cref="DataModelConditionGroup" /> class
/// </summary> /// </summary>
/// <param name="parent"></param> /// <param name="parent"></param>
public DisplayConditionGroup(DisplayConditionPart parent) public DataModelConditionGroup(DataModelConditionPart parent)
{ {
Parent = parent; Parent = parent;
Entity = new DisplayConditionGroupEntity(); Entity = new DisplayConditionGroupEntity();
} }
/// <summary> /// <summary>
/// Creates a new instance of the <see cref="DisplayConditionGroup" /> class /// Creates a new instance of the <see cref="DataModelConditionGroup" /> class
/// </summary> /// </summary>
/// <param name="parent"></param> /// <param name="parent"></param>
/// <param name="entity"></param> /// <param name="entity"></param>
public DisplayConditionGroup(DisplayConditionPart parent, DisplayConditionGroupEntity entity) public DataModelConditionGroup(DataModelConditionPart parent, DisplayConditionGroupEntity entity)
{ {
Parent = parent; Parent = parent;
Entity = entity; Entity = entity;
@ -37,13 +37,13 @@ namespace Artemis.Core
foreach (var childEntity in Entity.Children) foreach (var childEntity in Entity.Children)
{ {
if (childEntity is DisplayConditionGroupEntity groupEntity) if (childEntity is DisplayConditionGroupEntity groupEntity)
AddChild(new DisplayConditionGroup(this, groupEntity)); AddChild(new DataModelConditionGroup(this, groupEntity));
else if (childEntity is DisplayConditionListEntity listEntity) else if (childEntity is DisplayConditionListEntity listEntity)
AddChild(new DisplayConditionList(this, listEntity)); AddChild(new DataModelConditionList(this, listEntity));
else if (childEntity is DisplayConditionPredicateEntity predicateEntity) else if (childEntity is DisplayConditionPredicateEntity predicateEntity)
AddChild(new DisplayConditionPredicate(this, predicateEntity)); AddChild(new DataModelConditionPredicate(this, predicateEntity));
else if (childEntity is DisplayConditionListPredicateEntity listPredicateEntity) 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 /> /// <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) if (_disposed)
throw new ObjectDisposedException("DisplayConditionGroup"); throw new ObjectDisposedException("DisplayConditionGroup");
@ -119,26 +133,31 @@ namespace Artemis.Core
{ {
return Entity; 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 public enum BooleanOperator
{ {
/// <summary>
/// All the conditions in the group should evaluate to true
/// </summary>
And, And,
/// <summary>
/// Any of the conditions in the group should evaluate to true
/// </summary>
Or, Or,
/// <summary>
/// All the conditions in the group should evaluate to false
/// </summary>
AndNot, AndNot,
/// <summary>
/// Any of the conditions in the group should evaluate to false
/// </summary>
OrNot OrNot
} }
} }

View File

@ -8,11 +8,18 @@ using Artemis.Storage.Entities.Profile.Conditions;
namespace Artemis.Core 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; 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; Parent = parent;
Entity = new DisplayConditionListEntity(); Entity = new DisplayConditionListEntity();
@ -20,7 +27,7 @@ namespace Artemis.Core
Initialize(); Initialize();
} }
public DisplayConditionList(DisplayConditionPart parent, DisplayConditionListEntity entity) internal DataModelConditionList(DataModelConditionPart parent, DisplayConditionListEntity entity)
{ {
Parent = parent; Parent = parent;
Entity = entity; Entity = entity;
@ -29,14 +36,29 @@ namespace Artemis.Core
Initialize(); Initialize();
} }
public DisplayConditionListEntity Entity { get; set; } internal DisplayConditionListEntity Entity { get; set; }
/// <summary>
/// Gets or sets the list operator
/// </summary>
public ListOperator ListOperator { get; set; } public ListOperator ListOperator { get; set; }
/// <summary>
/// Gets the currently used instance of the list data model
/// </summary>
public DataModel ListDataModel { get; private set; } 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 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() public override bool Evaluate()
{ {
if (_disposed) if (_disposed)
@ -48,27 +70,11 @@ namespace Artemis.Core
return EvaluateObject(CompiledListAccessor(ListDataModel)); return EvaluateObject(CompiledListAccessor(ListDataModel));
} }
public override bool EvaluateObject(object target) /// <summary>
{ /// Updates the list the predicate is evaluated on
if (_disposed) /// </summary>
throw new ObjectDisposedException("DisplayConditionList"); /// <param name="dataModel">The data model of the list</param>
/// <param name="path">The path pointing to the list inside the list</param>
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()
};
}
public void UpdateList(DataModel dataModel, string path) public void UpdateList(DataModel dataModel, string path)
{ {
if (_disposed) if (_disposed)
@ -98,22 +104,47 @@ namespace Artemis.Core
return; return;
// Create a new root group // Create a new root group
AddChild(new DisplayConditionGroup(this)); AddChild(new DataModelConditionGroup(this));
CreateExpression(); 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) if (_disposed)
throw new ObjectDisposedException("DisplayConditionList"); throw new ObjectDisposedException("DisplayConditionList");
var parameter = Expression.Parameter(typeof(object), "listDataModel"); if (!Children.Any())
var accessor = ListPropertyPath.Split('.').Aggregate<string, Expression>( return false;
Expression.Convert(parameter, ListDataModel.GetType()), if (!(target is IList list))
(expression, s) => Expression.Convert(Expression.Property(expression, s), typeof(IList))); return false;
var lambda = Expression.Lambda<Func<object, IList>>(accessor, parameter); var objectList = list.Cast<object>();
CompiledListAccessor = lambda.Compile(); 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() internal override void Save()
@ -159,14 +190,28 @@ namespace Artemis.Core
// There should only be one child and it should be a group // There should only be one child and it should be a group
if (Entity.Children.SingleOrDefault() is DisplayConditionGroupEntity rootGroup) if (Entity.Children.SingleOrDefault() is DisplayConditionGroupEntity rootGroup)
AddChild(new DisplayConditionGroup(this, rootGroup)); AddChild(new DataModelConditionGroup(this, rootGroup));
else else
{ {
Entity.Children.Clear(); 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 #region Event handlers
@ -191,31 +236,31 @@ namespace Artemis.Core
} }
#endregion #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 public enum ListOperator
{ {
/// <summary>
/// Any of the list items should evaluate to true
/// </summary>
Any, Any,
/// <summary>
/// All of the list items should evaluate to true
/// </summary>
All, All,
/// <summary>
/// None of the list items should evaluate to true
/// </summary>
None, None,
/// <summary>
/// A specific amount of the list items should evaluate to true
/// </summary>
Count Count
} }
} }

View File

@ -8,9 +8,17 @@ using Newtonsoft.Json;
namespace Artemis.Core 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; Parent = parent;
PredicateType = predicateType; PredicateType = predicateType;
@ -20,7 +28,7 @@ namespace Artemis.Core
Initialize(); Initialize();
} }
public DisplayConditionListPredicate(DisplayConditionPart parent, DisplayConditionListPredicateEntity entity) internal DataModelConditionListPredicate(DataModelConditionPart parent, DisplayConditionListPredicateEntity entity)
{ {
Parent = parent; Parent = parent;
Entity = entity; Entity = entity;
@ -30,27 +38,150 @@ namespace Artemis.Core
Initialize(); Initialize();
} }
public DisplayConditionListPredicateEntity Entity { get; set; } internal DisplayConditionListPredicateEntity Entity { get; set; }
/// <summary>
/// Gets or sets the predicate type
/// </summary>
public ProfileRightSideType PredicateType { get; set; } public ProfileRightSideType PredicateType { get; set; }
/// <summary>
/// Gets the operator
/// </summary>
public ConditionOperator Operator { get; private set; } 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; } public Type ListType { get; private set; }
/// <summary>
/// Gets the currently used instance of the list data model
/// </summary>
public DataModel ListDataModel { get; private set; } 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 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; } 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; } 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; } 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 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; var current = Parent;
while (current != null) while (current != null)
{ {
if (current is DisplayConditionList parentList) if (current is DataModelConditionList parentList)
{ {
UpdateList(parentList.ListDataModel, parentList.ListPropertyPath); UpdateList(parentList.ListDataModel, parentList.ListPropertyPath);
return; 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) if (dataModel != null && path == null)
throw new ArtemisCoreException("If a data model is provided, a path is also required"); throw new ArtemisCoreException("If a data model is provided, a path is also required");
@ -89,70 +220,19 @@ namespace Artemis.Core
CreateExpression(); CreateExpression();
} }
public void UpdateLeftSide(string path) /// <summary>
{ /// Evaluates the condition part on the given target
if (!ListContainsInnerPath(path)) /// </summary>
throw new ArtemisCoreException($"List type {ListType.Name} does not contain path {path}"); /// <param name="target">
/// An instance of the list described in <see cref="ListDataModel" /> and
LeftPropertyPath = path; /// <see cref="ListPropertyPath" />
/// </param>
ValidateOperator(); internal override bool EvaluateObject(object target)
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)
{ {
return CompiledListPredicate != null && CompiledListPredicate(target); return CompiledListPredicate != null && CompiledListPredicate(target);
} }
public bool ListContainsInnerPath(string path) internal bool ListContainsInnerPath(string path)
{ {
if (ListType == null) if (ListType == null)
return false; return false;
@ -171,7 +251,7 @@ namespace Artemis.Core
return true; return true;
} }
public Type GetTypeAtInnerPath(string path) internal Type GetTypeAtInnerPath(string path)
{ {
if (!ListContainsInnerPath(path)) if (!ListContainsInnerPath(path))
return null; return null;
@ -210,6 +290,11 @@ namespace Artemis.Core
} }
} }
internal override DisplayConditionPartEntity GetEntity()
{
return Entity;
}
private void Initialize() private void Initialize()
{ {
ConditionOperatorStore.ConditionOperatorAdded += ConditionOperatorStoreOnConditionOperatorAdded; ConditionOperatorStore.ConditionOperatorAdded += ConditionOperatorStoreOnConditionOperatorAdded;
@ -270,11 +355,6 @@ namespace Artemis.Core
} }
} }
internal override DisplayConditionPartEntity GetEntity()
{
return Entity;
}
private void CreateExpression() private void CreateExpression()
{ {
CompiledListPredicate = null; CompiledListPredicate = null;
@ -412,18 +492,5 @@ namespace Artemis.Core
} }
#endregion #endregion
#region IDisposable
/// <inheritdoc />
protected override void Dispose(bool disposing)
{
ConditionOperatorStore.ConditionOperatorAdded -= ConditionOperatorStoreOnConditionOperatorAdded;
ConditionOperatorStore.ConditionOperatorRemoved -= ConditionOperatorStoreOnConditionOperatorRemoved;
base.Dispose(disposing);
}
#endregion
} }
} }

View File

@ -9,17 +9,17 @@ using Newtonsoft.Json;
namespace Artemis.Core namespace Artemis.Core
{ {
/// <summary> /// <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 /// static value
/// </summary> /// </summary>
public class DisplayConditionPredicate : DisplayConditionPart public class DataModelConditionPredicate : DataModelConditionPart
{ {
/// <summary> /// <summary>
/// Creates a new instance of the <see cref="DisplayConditionPredicate" /> class /// Creates a new instance of the <see cref="DataModelConditionPredicate" /> class
/// </summary> /// </summary>
/// <param name="parent"></param> /// <param name="parent"></param>
/// <param name="predicateType"></param> /// <param name="predicateType"></param>
public DisplayConditionPredicate(DisplayConditionPart parent, ProfileRightSideType predicateType) public DataModelConditionPredicate(DataModelConditionPart parent, ProfileRightSideType predicateType)
{ {
Parent = parent; Parent = parent;
PredicateType = predicateType; PredicateType = predicateType;
@ -28,12 +28,7 @@ namespace Artemis.Core
Initialize(); Initialize();
} }
/// <summary> internal DataModelConditionPredicate(DataModelConditionPart parent, DisplayConditionPredicateEntity entity)
/// 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)
{ {
Parent = parent; Parent = parent;
Entity = entity; Entity = entity;
@ -219,7 +214,7 @@ namespace Artemis.Core
} }
/// <inheritdoc /> /// <inheritdoc />
public override bool EvaluateObject(object target) internal override bool EvaluateObject(object target)
{ {
return false; return false;
} }

View File

@ -11,15 +11,18 @@ namespace Artemis.Core
public abstract class DataBindingConverter<TLayerProperty, TProperty> : IDataBindingConverter public abstract class DataBindingConverter<TLayerProperty, TProperty> : IDataBindingConverter
{ {
/// <summary> /// <summary>
/// A dynamically compiled getter pointing to the data bound property /// Gets a dynamically compiled getter pointing to the data bound property
/// </summary> /// </summary>
public Func<TLayerProperty, TProperty> GetExpression { get; private set; } public Func<TLayerProperty, TProperty> GetExpression { get; private set; }
/// <summary> /// <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> /// </summary>
public Action<TProperty> ValueTypeSetExpression { get; private set; } 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; } public Action<TLayerProperty, TProperty> ReferenceTypeSetExpression { get; private set; }
/// <summary> /// <summary>

View File

@ -49,9 +49,9 @@ namespace Artemis.Core
DisplayContinuously = RenderElementEntity.DisplayContinuously; DisplayContinuously = RenderElementEntity.DisplayContinuously;
AlwaysFinishTimeline = RenderElementEntity.AlwaysFinishTimeline; AlwaysFinishTimeline = RenderElementEntity.AlwaysFinishTimeline;
DisplayConditionGroup = RenderElementEntity.RootDisplayCondition != null DataModelConditionGroup = RenderElementEntity.RootDisplayCondition != null
? new DisplayConditionGroup(null, RenderElementEntity.RootDisplayCondition) ? new DataModelConditionGroup(null, RenderElementEntity.RootDisplayCondition)
: new DisplayConditionGroup(null); : new DataModelConditionGroup(null);
ActivateEffects(); ActivateEffects();
} }
@ -82,8 +82,8 @@ namespace Artemis.Core
} }
// Conditions // Conditions
RenderElementEntity.RootDisplayCondition = DisplayConditionGroup?.Entity; RenderElementEntity.RootDisplayCondition = DataModelConditionGroup?.Entity;
DisplayConditionGroup?.Save(); DataModelConditionGroup?.Save();
} }
#region Properties #region Properties
@ -392,22 +392,22 @@ namespace Artemis.Core
private set => SetAndNotify(ref _displayConditionMet, value); private set => SetAndNotify(ref _displayConditionMet, value);
} }
private DisplayConditionGroup _displayConditionGroup; private DataModelConditionGroup _dataModelConditionGroup;
private TimeSpan _timelinePosition; private TimeSpan _timelinePosition;
private bool _displayConditionMet; private bool _displayConditionMet;
/// <summary> /// <summary>
/// Gets or sets the root display condition group /// Gets or sets the root display condition group
/// </summary> /// </summary>
public DisplayConditionGroup DisplayConditionGroup public DataModelConditionGroup DataModelConditionGroup
{ {
get => _displayConditionGroup; get => _dataModelConditionGroup;
set => SetAndNotify(ref _displayConditionGroup, value); set => SetAndNotify(ref _dataModelConditionGroup, value);
} }
public void UpdateDisplayCondition() public void UpdateDisplayCondition()
{ {
var conditionMet = DisplayConditionGroup == null || DisplayConditionGroup.Evaluate(); var conditionMet = DataModelConditionGroup == null || DataModelConditionGroup.Evaluate();
if (conditionMet && !DisplayConditionMet) if (conditionMet && !DisplayConditionMet)
TimelinePosition = TimeSpan.Zero; TimelinePosition = TimeSpan.Zero;

View File

@ -2,6 +2,9 @@
namespace Artemis.Core.DataModelExpansions 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 public class DataModelIgnoreAttribute : Attribute
{ {
} }

View File

@ -2,6 +2,9 @@
namespace Artemis.Core.DataModelExpansions namespace Artemis.Core.DataModelExpansions
{ {
/// <summary>
/// Represents an attribute that describes a data model property
/// </summary>
[AttributeUsage(AttributeTargets.Property)] [AttributeUsage(AttributeTargets.Property)]
public class DataModelPropertyAttribute : Attribute public class DataModelPropertyAttribute : Attribute
{ {

View File

@ -28,7 +28,7 @@ namespace Artemis.Core.DataModelExpansions
[DataModelIgnore] [DataModelIgnore]
public bool IsExpansion { get; internal set; } public bool IsExpansion { get; internal set; }
public bool ContainsPath(string path) internal bool ContainsPath(string path)
{ {
var parts = path.Split('.'); var parts = path.Split('.');
var current = GetType(); var current = GetType();
@ -43,7 +43,7 @@ namespace Artemis.Core.DataModelExpansions
return true; return true;
} }
public Type GetTypeAtPath(string path) internal Type GetTypeAtPath(string path)
{ {
if (!ContainsPath(path)) if (!ContainsPath(path))
return null; return null;
@ -62,7 +62,7 @@ namespace Artemis.Core.DataModelExpansions
return result; return result;
} }
public Type GetListTypeInPath(string path) internal Type GetListTypeInPath(string path)
{ {
if (!ContainsPath(path)) if (!ContainsPath(path))
return null; return null;
@ -90,7 +90,7 @@ namespace Artemis.Core.DataModelExpansions
return null; return null;
} }
public Type GetListTypeAtPath(string path) internal Type GetListTypeAtPath(string path)
{ {
if (!ContainsPath(path)) if (!ContainsPath(path))
return null; return null;
@ -99,28 +99,6 @@ namespace Artemis.Core.DataModelExpansions
return child.GenericTypeArguments.Length > 0 ? child.GenericTypeArguments[0] : null; 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> /// <summary>
/// Returns a read-only list of all properties in this datamodel that are to be ignored /// Returns a read-only list of all properties in this datamodel that are to be ignored
/// </summary> /// </summary>

View File

@ -10,14 +10,22 @@ namespace Artemis.Core.DataModelExpansions
/// </summary> /// </summary>
public abstract class BaseDataModelExpansion : Plugin 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> /// <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> /// </summary>
public ReadOnlyCollection<PropertyInfo> HiddenProperties => HiddenPropertiesList.AsReadOnly(); public ReadOnlyCollection<PropertyInfo> HiddenProperties => HiddenPropertiesList.AsReadOnly();
internal DataModel InternalDataModel { get; set; } 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); public abstract void Update(double deltaTime);
/// <summary> /// <summary>

View File

@ -2,13 +2,23 @@
namespace Artemis.Core.LayerBrushes namespace Artemis.Core.LayerBrushes
{ {
/// <summary>
/// Represents a view model for a brush configuration window
/// </summary>
public abstract class BrushConfigurationViewModel : Screen 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) protected BrushConfigurationViewModel(BaseLayerBrush layerBrush)
{ {
LayerBrush = layerBrush; LayerBrush = layerBrush;
} }
/// <summary>
/// Gets the layer brush this view model is associated with
/// </summary>
public BaseLayerBrush LayerBrush { get; } public BaseLayerBrush LayerBrush { get; }
} }
} }

View File

@ -1,10 +1,16 @@
using Artemis.Core.Services; using SkiaSharp;
using SkiaSharp;
namespace Artemis.Core.LayerBrushes 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 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() protected LayerBrush()
{ {
BrushType = LayerBrushType.Regular; BrushType = LayerBrushType.Regular;

View File

@ -44,6 +44,16 @@ namespace Artemis.Core.LayerBrushes
/// </summary> /// </summary>
public LayerBrushProvider LayerBrushProvider { get; } 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> /// <summary>
/// Creates an instance of the described brush and applies it to the layer /// Creates an instance of the described brush and applies it to the layer
/// </summary> /// </summary>
@ -61,12 +71,5 @@ namespace Artemis.Core.LayerBrushes
layer.LayerBrush = brush; layer.LayerBrush = brush;
layer.OnLayerBrushUpdated(); layer.OnLayerBrushUpdated();
} }
public bool MatchesLayerBrushReference(LayerBrushReference reference)
{
if (reference == null)
return false;
return LayerBrushProvider.PluginInfo.Guid == reference.BrushPluginGuid && LayerBrushType.Name == reference.BrushType;
}
} }
} }

View File

@ -1,16 +1,21 @@
using Artemis.Core.Services; using SkiaSharp;
using SkiaSharp;
namespace Artemis.Core.LayerBrushes 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 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() protected PerLedLayerBrush()
{ {
BrushType = LayerBrushType.Regular; BrushType = LayerBrushType.Regular;
} }
/// <summary> /// <summary>
/// The main method of rendering for this type of brush. Called once per frame for each LED in the layer /// The main method of rendering for this type of brush. Called once per frame for each LED in the layer
/// <para> /// <para>

View File

@ -2,13 +2,23 @@
namespace Artemis.Core.LayerEffects namespace Artemis.Core.LayerEffects
{ {
/// <summary>
/// Represents a view model for an effect configuration window
/// </summary>
public abstract class EffectConfigurationViewModel : Screen 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) protected EffectConfigurationViewModel(BaseLayerEffect layerEffect)
{ {
LayerEffect = layerEffect; LayerEffect = layerEffect;
} }
/// <summary>
/// Gets the layer effect this view model is associated with
/// </summary>
public BaseLayerEffect LayerEffect { get; } public BaseLayerEffect LayerEffect { get; }
} }
} }

View File

@ -1,8 +1,11 @@
using System; using System;
using Artemis.Core.Services;
namespace Artemis.Core.LayerEffects 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 public abstract class LayerEffect<T> : BaseLayerEffect where T : LayerPropertyGroup
{ {
private T _properties; private T _properties;

View File

@ -16,6 +16,7 @@
return ActivationMet; return ActivationMet;
} }
/// <inheritdoc />
public string GetUserFriendlyDescription() public string GetUserFriendlyDescription()
{ {
return "No description available"; return "No description available";

View File

@ -43,6 +43,7 @@ namespace Artemis.Core.Modules
: processes.Any(); : processes.Any();
} }
/// <inheritdoc />
public string GetUserFriendlyDescription() public string GetUserFriendlyDescription()
{ {
var description = $"Requirement met when \"{ProcessName}.exe\" is running"; var description = $"Requirement met when \"{ProcessName}.exe\" is running";

View File

@ -144,13 +144,13 @@ namespace Artemis.Core.Modules
public bool IsUpdateAllowed => IsActivated && (UpdateDuringActivationOverride || !IsActivatedOverride); public bool IsUpdateAllowed => IsActivated && (UpdateDuringActivationOverride || !IsActivatedOverride);
/// <summary> /// <summary>
/// Called each frame when the module must update /// Called each frame when the module should update
/// </summary> /// </summary>
/// <param name="deltaTime">Time in seconds since the last update</param> /// <param name="deltaTime">Time in seconds since the last update</param>
public abstract void Update(double deltaTime); public abstract void Update(double deltaTime);
/// <summary> /// <summary>
/// Called each frame when the module must render /// Called each frame when the module should render
/// </summary> /// </summary>
/// <param name="deltaTime">Time since the last render</param> /// <param name="deltaTime">Time since the last render</param>
/// <param name="surface">The RGB Surface to render to</param> /// <param name="surface">The RGB Surface to render to</param>

View File

@ -91,18 +91,27 @@ namespace Artemis.Core.Modules
/// </summary> /// </summary>
public abstract class ProfileModule : Module 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() protected ProfileModule()
{ {
OpacityOverride = 1; OpacityOverride = 1;
} }
/// <summary> /// <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> /// </summary>
public ReadOnlyCollection<PropertyInfo> HiddenProperties => HiddenPropertiesList.AsReadOnly(); public ReadOnlyCollection<PropertyInfo> HiddenProperties => HiddenPropertiesList.AsReadOnly();
/// <summary>
/// Gets the currently active profile
/// </summary>
public Profile ActiveProfile { get; private set; } public Profile ActiveProfile { get; private set; }
/// <summary> /// <summary>
@ -225,8 +234,14 @@ namespace Artemis.Core.Modules
#region Events #region Events
/// <summary>
/// Occurs when the <see cref="ActiveProfile" /> has changed
/// </summary>
public event EventHandler ActiveProfileChanged; public event EventHandler ActiveProfileChanged;
/// <summary>
/// Invokes the <see cref="ActiveProfileChanged" /> event
/// </summary>
protected virtual void OnActiveProfileChanged() protected virtual void OnActiveProfileChanged()
{ {
ActiveProfileChanged?.Invoke(this, EventArgs.Empty); ActiveProfileChanged?.Invoke(this, EventArgs.Empty);

View File

@ -2,13 +2,23 @@
namespace Artemis.Core namespace Artemis.Core
{ {
/// <summary>
/// Represents a view model for a plugin configuration window
/// </summary>
public abstract class PluginConfigurationViewModel : Screen 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) protected PluginConfigurationViewModel(Plugin plugin)
{ {
Plugin = plugin; Plugin = plugin;
} }
/// <summary>
/// Gets the plugin this configuration view model is associated with
/// </summary>
public Plugin Plugin { get; } public Plugin Plugin { get; }
} }
} }

View File

@ -8,6 +8,9 @@ using Stylet;
namespace Artemis.Core namespace Artemis.Core
{ {
/// <summary>
/// Represents basic info about a plugin and contains a reference to the instance of said plugin
/// </summary>
[JsonObject(MemberSerialization.OptIn)] [JsonObject(MemberSerialization.OptIn)]
public class PluginInfo : PropertyChangedBase public class PluginInfo : PropertyChangedBase
{ {
@ -17,7 +20,6 @@ namespace Artemis.Core
private Guid _guid; private Guid _guid;
private string _icon; private string _icon;
private Plugin _instance; private Plugin _instance;
private bool _lastEnableSuccessful;
private Exception _loadException; private Exception _loadException;
private string _main; private string _main;
private string _name; private string _name;
@ -140,6 +142,7 @@ namespace Artemis.Core
/// </summary> /// </summary>
internal PluginEntity PluginEntity { get; set; } internal PluginEntity PluginEntity { get; set; }
/// <inheritdoc />
public override string ToString() public override string ToString()
{ {
return $"{Name} v{Version} - {Guid}"; return $"{Name} v{Version} - {Guid}";

View File

@ -93,12 +93,12 @@ namespace Artemis.Core
Action(interval.TotalSeconds); Action(interval.TotalSeconds);
} }
private void InstanceOnPluginEnabled(object? sender, EventArgs e) private void InstanceOnPluginEnabled(object sender, EventArgs e)
{ {
Start(); Start();
} }
private void InstanceOnPluginDisabled(object? sender, EventArgs e) private void InstanceOnPluginDisabled(object sender, EventArgs e)
{ {
Stop(); Stop();
} }

View File

@ -6,6 +6,10 @@ using Stylet;
namespace Artemis.Core 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 public class PluginSetting<T> : PropertyChangedBase
{ {
// ReSharper disable once NotAccessedField.Local // ReSharper disable once NotAccessedField.Local
@ -78,14 +82,21 @@ namespace Artemis.Core
_pluginRepository.SaveSetting(_pluginSettingEntity); _pluginRepository.SaveSetting(_pluginSettingEntity);
} }
/// <summary>
/// Occurs when the value of the setting has been changed
/// </summary>
public event EventHandler<EventArgs> SettingChanged; public event EventHandler<EventArgs> SettingChanged;
/// <inheritdoc />
public override string ToString() public override string ToString()
{ {
return $"{nameof(Name)}: {Name}, {nameof(Value)}: {Value}, {nameof(HasChanged)}: {HasChanged}"; 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); SettingChanged?.Invoke(this, EventArgs.Empty);
} }

View File

@ -47,8 +47,19 @@ namespace Artemis.Core
/// <inheritdoc /> /// <inheritdoc />
public Dictionary<BrushRenderTarget, Color> RenderedTargets { get; } = new Dictionary<BrushRenderTarget, Color>(); 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; } public Scale Scale { get; set; }
/// <summary>
/// Gets the last rendered scale of the bitmap brush
/// </summary>
public Scale RenderedScale { get; private set; } public Scale RenderedScale { get; private set; }
/// <summary>
/// Gets the bitmap used to sample the brush
/// </summary>
public SKBitmap Bitmap { get; private set; } public SKBitmap Bitmap { get; private set; }
#endregion #endregion
@ -148,6 +159,7 @@ namespace Artemis.Core
{ {
} }
/// <inheritdoc />
public void Dispose() public void Dispose()
{ {
lock (_disposeLock) lock (_disposeLock)
@ -157,7 +169,7 @@ namespace Artemis.Core
} }
} }
public bool IsDisposed { get; set; } internal bool IsDisposed { get; set; }
#endregion #endregion
} }

View File

@ -70,10 +70,10 @@ namespace Artemis.Core.Services
List<PluginInfo> GetAllPluginInfo(); List<PluginInfo> GetAllPluginInfo();
/// <summary> /// <summary>
/// Finds all enabled <see cref="Plugin" /> instances of type T /// Finds all enabled <see cref="Plugin" /> instances of <typeparamref name="T"/>
/// </summary> /// </summary>
/// <typeparam name="T">Either <see cref="Plugin" /> or a plugin type implementing <see cref="Plugin" /></typeparam> /// <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; List<T> GetPluginsOfType<T>() where T : Plugin;
/// <summary> /// <summary>

View File

@ -3,6 +3,9 @@ using System.Collections.ObjectModel;
namespace Artemis.Core.Services namespace Artemis.Core.Services
{ {
/// <summary>
/// Provides access to the device surface and its configuration
/// </summary>
public interface ISurfaceService : IArtemisService public interface ISurfaceService : IArtemisService
{ {
/// <summary> /// <summary>

View File

@ -13,26 +13,26 @@ namespace Artemis.Core
_logger = kernel.Get<ILogger>(); _logger = kernel.Get<ILogger>();
} }
public static void LogPredicateDeserializationFailure(DisplayConditionPredicate displayConditionPredicate, JsonException exception) public static void LogPredicateDeserializationFailure(DataModelConditionPredicate dataModelConditionPredicate, JsonException exception)
{ {
_logger.Warning( _logger.Warning(
exception, exception,
"Failed to deserialize display condition predicate {left} {operator} {right}", "Failed to deserialize display condition predicate {left} {operator} {right}",
displayConditionPredicate.Entity.LeftPropertyPath, dataModelConditionPredicate.Entity.LeftPropertyPath,
displayConditionPredicate.Entity.OperatorType, dataModelConditionPredicate.Entity.OperatorType,
displayConditionPredicate.Entity.RightPropertyPath dataModelConditionPredicate.Entity.RightPropertyPath
); );
} }
public static void LogListPredicateDeserializationFailure(DisplayConditionListPredicate displayConditionPredicate, JsonException exception) public static void LogListPredicateDeserializationFailure(DataModelConditionListPredicate dataModelConditionPredicate, JsonException exception)
{ {
_logger.Warning( _logger.Warning(
exception, exception,
"Failed to deserialize display condition list predicate {list} => {left} {operator} {right}", "Failed to deserialize display condition list predicate {list} => {left} {operator} {right}",
displayConditionPredicate.Entity.ListPropertyPath, dataModelConditionPredicate.Entity.ListPropertyPath,
displayConditionPredicate.Entity.LeftPropertyPath, dataModelConditionPredicate.Entity.LeftPropertyPath,
displayConditionPredicate.Entity.OperatorType, dataModelConditionPredicate.Entity.OperatorType,
displayConditionPredicate.Entity.RightPropertyPath dataModelConditionPredicate.Entity.RightPropertyPath
); );
} }

View File

@ -1,4 +1,5 @@
using System; #pragma warning disable 1591
using System;
namespace Artemis.Core namespace Artemis.Core
{ {

View File

@ -176,7 +176,7 @@ namespace Artemis.UI.Shared
IsMatchingFilteredTypes = filteredTypes.Any(t => t == PropertyInfo.PropertyType || t == typeof(Enum) && PropertyInfo.PropertyType.IsEnum); IsMatchingFilteredTypes = filteredTypes.Any(t => t == PropertyInfo.PropertyType || t == typeof(Enum) && PropertyInfo.PropertyType.IsEnum);
} }
public DataModelVisualizationViewModel GetChildForCondition(DisplayConditionPredicate predicate, DisplayConditionSide side) public DataModelVisualizationViewModel GetChildForCondition(DataModelConditionPredicate predicate, DisplayConditionSide side)
{ {
if (side == DisplayConditionSide.Left) if (side == DisplayConditionSide.Left)
{ {

View File

@ -65,10 +65,10 @@ namespace Artemis.UI.Ninject.Factories
public interface IDisplayConditionsVmFactory : IVmFactory public interface IDisplayConditionsVmFactory : IVmFactory
{ {
DisplayConditionGroupViewModel DisplayConditionGroupViewModel(DisplayConditionGroup displayConditionGroup, bool isListGroup); DisplayConditionGroupViewModel DisplayConditionGroupViewModel(DataModelConditionGroup dataModelConditionGroup, bool isListGroup);
DisplayConditionListViewModel DisplayConditionListViewModel(DisplayConditionList displayConditionList); DisplayConditionListViewModel DisplayConditionListViewModel(DataModelConditionList dataModelConditionList);
DisplayConditionPredicateViewModel DisplayConditionPredicateViewModel(DisplayConditionPredicate displayConditionPredicate); DisplayConditionPredicateViewModel DisplayConditionPredicateViewModel(DataModelConditionPredicate dataModelConditionPredicate);
DisplayConditionListPredicateViewModel DisplayConditionListPredicateViewModel(DisplayConditionListPredicate displayConditionListPredicate); DisplayConditionListPredicateViewModel DisplayConditionListPredicateViewModel(DataModelConditionListPredicate dataModelConditionListPredicate);
} }
public interface ILayerPropertyVmFactory : IVmFactory public interface ILayerPropertyVmFactory : IVmFactory

View File

@ -5,12 +5,12 @@ namespace Artemis.UI.Screens.ProfileEditor.DisplayConditions.Abstract
{ {
public abstract class DisplayConditionViewModel : Conductor<DisplayConditionViewModel>.Collection.AllActive public abstract class DisplayConditionViewModel : Conductor<DisplayConditionViewModel>.Collection.AllActive
{ {
protected DisplayConditionViewModel(DisplayConditionPart model) protected DisplayConditionViewModel(DataModelConditionPart model)
{ {
Model = model; Model = model;
} }
public DisplayConditionPart Model { get; } public DataModelConditionPart Model { get; }
public abstract void Update(); public abstract void Update();

View File

@ -17,11 +17,11 @@ namespace Artemis.UI.Screens.ProfileEditor.DisplayConditions
private bool _isInitialized; private bool _isInitialized;
private bool _isRootGroup; private bool _isRootGroup;
public DisplayConditionGroupViewModel(DisplayConditionGroup displayConditionGroup, public DisplayConditionGroupViewModel(DataModelConditionGroup dataModelConditionGroup,
bool isListGroup, bool isListGroup,
IProfileEditorService profileEditorService, IProfileEditorService profileEditorService,
IDisplayConditionsVmFactory displayConditionsVmFactory) IDisplayConditionsVmFactory displayConditionsVmFactory)
: base(displayConditionGroup) : base(dataModelConditionGroup)
{ {
IsListGroup = isListGroup; IsListGroup = isListGroup;
_profileEditorService = profileEditorService; _profileEditorService = profileEditorService;
@ -38,7 +38,7 @@ namespace Artemis.UI.Screens.ProfileEditor.DisplayConditions
public bool IsListGroup { get; } public bool IsListGroup { get; }
public DisplayConditionGroup DisplayConditionGroup => (DisplayConditionGroup) Model; public DataModelConditionGroup DataModelConditionGroup => (DataModelConditionGroup) Model;
public bool IsRootGroup public bool IsRootGroup
{ {
@ -53,12 +53,12 @@ namespace Artemis.UI.Screens.ProfileEditor.DisplayConditions
} }
public bool DisplayBooleanOperator => Items.Count > 1; public bool DisplayBooleanOperator => Items.Count > 1;
public string SelectedBooleanOperator => DisplayConditionGroup.BooleanOperator.Humanize(); public string SelectedBooleanOperator => DataModelConditionGroup.BooleanOperator.Humanize();
public void SelectBooleanOperator(string type) public void SelectBooleanOperator(string type)
{ {
var enumValue = Enum.Parse<BooleanOperator>(type); var enumValue = Enum.Parse<BooleanOperator>(type);
DisplayConditionGroup.BooleanOperator = enumValue; DataModelConditionGroup.BooleanOperator = enumValue;
NotifyOfPropertyChange(nameof(SelectedBooleanOperator)); NotifyOfPropertyChange(nameof(SelectedBooleanOperator));
_profileEditorService.UpdateSelectedProfileElement(); _profileEditorService.UpdateSelectedProfileElement();
@ -69,19 +69,19 @@ namespace Artemis.UI.Screens.ProfileEditor.DisplayConditions
if (type == "Static") if (type == "Static")
{ {
if (!IsListGroup) if (!IsListGroup)
DisplayConditionGroup.AddChild(new DisplayConditionPredicate(DisplayConditionGroup, ProfileRightSideType.Static)); DataModelConditionGroup.AddChild(new DataModelConditionPredicate(DataModelConditionGroup, ProfileRightSideType.Static));
else else
DisplayConditionGroup.AddChild(new DisplayConditionListPredicate(DisplayConditionGroup, ProfileRightSideType.Static)); DataModelConditionGroup.AddChild(new DataModelConditionListPredicate(DataModelConditionGroup, ProfileRightSideType.Static));
} }
else if (type == "Dynamic") else if (type == "Dynamic")
{ {
if (!IsListGroup) if (!IsListGroup)
DisplayConditionGroup.AddChild(new DisplayConditionPredicate(DisplayConditionGroup, ProfileRightSideType.Dynamic)); DataModelConditionGroup.AddChild(new DataModelConditionPredicate(DataModelConditionGroup, ProfileRightSideType.Dynamic));
else else
DisplayConditionGroup.AddChild(new DisplayConditionListPredicate(DisplayConditionGroup, ProfileRightSideType.Dynamic)); DataModelConditionGroup.AddChild(new DataModelConditionListPredicate(DataModelConditionGroup, ProfileRightSideType.Dynamic));
} }
else if (type == "List" && !IsListGroup) else if (type == "List" && !IsListGroup)
DisplayConditionGroup.AddChild(new DisplayConditionList(DisplayConditionGroup)); DataModelConditionGroup.AddChild(new DataModelConditionList(DataModelConditionGroup));
Update(); Update();
_profileEditorService.UpdateSelectedProfileElement(); _profileEditorService.UpdateSelectedProfileElement();
@ -89,7 +89,7 @@ namespace Artemis.UI.Screens.ProfileEditor.DisplayConditions
public void AddGroup() public void AddGroup()
{ {
DisplayConditionGroup.AddChild(new DisplayConditionGroup(DisplayConditionGroup)); DataModelConditionGroup.AddChild(new DataModelConditionGroup(DataModelConditionGroup));
Update(); Update();
_profileEditorService.UpdateSelectedProfileElement(); _profileEditorService.UpdateSelectedProfileElement();
@ -100,7 +100,7 @@ namespace Artemis.UI.Screens.ProfileEditor.DisplayConditions
NotifyOfPropertyChange(nameof(SelectedBooleanOperator)); NotifyOfPropertyChange(nameof(SelectedBooleanOperator));
// Remove VMs of effects no longer applied on the layer // Remove VMs of effects no longer applied on the layer
var toRemove = Items.Where(c => !DisplayConditionGroup.Children.Contains(c.Model)).ToList(); var toRemove = Items.Where(c => !DataModelConditionGroup.Children.Contains(c.Model)).ToList();
// Using RemoveRange breaks our lovely animations // Using RemoveRange breaks our lovely animations
foreach (var displayConditionViewModel in toRemove) foreach (var displayConditionViewModel in toRemove)
Items.Remove(displayConditionViewModel); Items.Remove(displayConditionViewModel);
@ -112,17 +112,17 @@ namespace Artemis.UI.Screens.ProfileEditor.DisplayConditions
switch (childModel) switch (childModel)
{ {
case DisplayConditionGroup displayConditionGroup: case DataModelConditionGroup displayConditionGroup:
Items.Add(_displayConditionsVmFactory.DisplayConditionGroupViewModel(displayConditionGroup, IsListGroup)); Items.Add(_displayConditionsVmFactory.DisplayConditionGroupViewModel(displayConditionGroup, IsListGroup));
break; break;
case DisplayConditionList displayConditionListPredicate: case DataModelConditionList displayConditionListPredicate:
Items.Add(_displayConditionsVmFactory.DisplayConditionListViewModel(displayConditionListPredicate)); Items.Add(_displayConditionsVmFactory.DisplayConditionListViewModel(displayConditionListPredicate));
break; break;
case DisplayConditionPredicate displayConditionPredicate: case DataModelConditionPredicate displayConditionPredicate:
if (!IsListGroup) if (!IsListGroup)
Items.Add(_displayConditionsVmFactory.DisplayConditionPredicateViewModel(displayConditionPredicate)); Items.Add(_displayConditionsVmFactory.DisplayConditionPredicateViewModel(displayConditionPredicate));
break; break;
case DisplayConditionListPredicate displayConditionListPredicate: case DataModelConditionListPredicate displayConditionListPredicate:
if (IsListGroup) if (IsListGroup)
Items.Add(_displayConditionsVmFactory.DisplayConditionListPredicateViewModel(displayConditionListPredicate)); Items.Add(_displayConditionsVmFactory.DisplayConditionListPredicateViewModel(displayConditionListPredicate));
break; break;

View File

@ -38,12 +38,12 @@ namespace Artemis.UI.Screens.ProfileEditor.DisplayConditions
private List<Type> _supportedInputTypes; private List<Type> _supportedInputTypes;
public DisplayConditionListPredicateViewModel( public DisplayConditionListPredicateViewModel(
DisplayConditionListPredicate displayConditionListPredicate, DataModelConditionListPredicate dataModelConditionListPredicate,
IProfileEditorService profileEditorService, IProfileEditorService profileEditorService,
IDataModelUIService dataModelUIService, IDataModelUIService dataModelUIService,
IConditionOperatorService conditionOperatorService, IConditionOperatorService conditionOperatorService,
ISettingsService settingsService, ISettingsService settingsService,
IEventAggregator eventAggregator) : base(displayConditionListPredicate) IEventAggregator eventAggregator) : base(dataModelConditionListPredicate)
{ {
_profileEditorService = profileEditorService; _profileEditorService = profileEditorService;
_dataModelUIService = dataModelUIService; _dataModelUIService = dataModelUIService;
@ -63,8 +63,8 @@ namespace Artemis.UI.Screens.ProfileEditor.DisplayConditions
Task.Run(Initialize); Task.Run(Initialize);
} }
public DisplayConditionListPredicate DisplayConditionListPredicate => (DisplayConditionListPredicate) Model; public DataModelConditionListPredicate DataModelConditionListPredicate => (DataModelConditionListPredicate) Model;
public bool ShowRightSidePropertySelection => DisplayConditionListPredicate.PredicateType == ProfileRightSideType.Dynamic; public bool ShowRightSidePropertySelection => DataModelConditionListPredicate.PredicateType == ProfileRightSideType.Dynamic;
public bool CanActivateRightSideInputViewModel => SelectedLeftSideProperty?.PropertyInfo != null; public bool CanActivateRightSideInputViewModel => SelectedLeftSideProperty?.PropertyInfo != null;
public PluginSetting<bool> ShowDataModelValues { get; } public PluginSetting<bool> ShowDataModelValues { get; }
@ -193,45 +193,45 @@ namespace Artemis.UI.Screens.ProfileEditor.DisplayConditions
if (LeftSideDataModel == null || RightSideDataModel == null) if (LeftSideDataModel == null || RightSideDataModel == null)
return; return;
var listDataModelGuid = DisplayConditionListPredicate.ListDataModel.PluginInfo.Guid; var listDataModelGuid = DataModelConditionListPredicate.ListDataModel.PluginInfo.Guid;
// If static, only allow selecting properties also supported by input // If static, only allow selecting properties also supported by input
if (DisplayConditionListPredicate.PredicateType == ProfileRightSideType.Static) if (DataModelConditionListPredicate.PredicateType == ProfileRightSideType.Static)
LeftSideDataModel.ApplyTypeFilter(false, _supportedInputTypes.ToArray()); LeftSideDataModel.ApplyTypeFilter(false, _supportedInputTypes.ToArray());
// Determine the left side property first // Determine the left side property first
SelectedLeftSideProperty = LeftSideDataModel.GetChildByPath(listDataModelGuid, DisplayConditionListPredicate.LeftPropertyPath); SelectedLeftSideProperty = LeftSideDataModel.GetChildByPath(listDataModelGuid, DataModelConditionListPredicate.LeftPropertyPath);
var leftSideType = SelectedLeftSideProperty?.PropertyInfo?.PropertyType; var leftSideType = SelectedLeftSideProperty?.PropertyInfo?.PropertyType;
// Get the supported operators // Get the supported operators
Operators.Clear(); Operators.Clear();
Operators.AddRange(_conditionOperatorService.GetConditionOperatorsForType(leftSideType)); Operators.AddRange(_conditionOperatorService.GetConditionOperatorsForType(leftSideType));
if (DisplayConditionListPredicate.Operator == null) if (DataModelConditionListPredicate.Operator == null)
DisplayConditionListPredicate.UpdateOperator(Operators.FirstOrDefault(o => o.SupportsType(leftSideType))); DataModelConditionListPredicate.UpdateOperator(Operators.FirstOrDefault(o => o.SupportsType(leftSideType)));
SelectedOperator = DisplayConditionListPredicate.Operator; SelectedOperator = DataModelConditionListPredicate.Operator;
// Determine the right side // Determine the right side
if (DisplayConditionListPredicate.PredicateType == ProfileRightSideType.Dynamic) if (DataModelConditionListPredicate.PredicateType == ProfileRightSideType.Dynamic)
{ {
SelectedRightSideProperty = RightSideDataModel.GetChildByPath(listDataModelGuid, DisplayConditionListPredicate.RightPropertyPath); SelectedRightSideProperty = RightSideDataModel.GetChildByPath(listDataModelGuid, DataModelConditionListPredicate.RightPropertyPath);
RightSideDataModel.ApplyTypeFilter(true, leftSideType); RightSideDataModel.ApplyTypeFilter(true, leftSideType);
} }
else else
RightStaticValue = DisplayConditionListPredicate.RightStaticValue; RightStaticValue = DataModelConditionListPredicate.RightStaticValue;
} }
public void ApplyLeftSide() public void ApplyLeftSide()
{ {
DisplayConditionListPredicate.UpdateLeftSide(SelectedLeftSideProperty.PropertyPath); DataModelConditionListPredicate.UpdateLeftSide(SelectedLeftSideProperty.PropertyPath);
_profileEditorService.UpdateSelectedProfileElement(); _profileEditorService.UpdateSelectedProfileElement();
SelectedOperator = DisplayConditionListPredicate.Operator; SelectedOperator = DataModelConditionListPredicate.Operator;
Update(); Update();
} }
public void ApplyRightSideDynamic() public void ApplyRightSideDynamic()
{ {
DisplayConditionListPredicate.UpdateRightSideDynamic(SelectedRightSideProperty.PropertyPath); DataModelConditionListPredicate.UpdateRightSideDynamic(SelectedRightSideProperty.PropertyPath);
_profileEditorService.UpdateSelectedProfileElement(); _profileEditorService.UpdateSelectedProfileElement();
Update(); Update();
@ -241,7 +241,7 @@ namespace Artemis.UI.Screens.ProfileEditor.DisplayConditions
{ {
if (isSubmitted) if (isSubmitted)
{ {
DisplayConditionListPredicate.UpdateRightSideStatic(value); DataModelConditionListPredicate.UpdateRightSideStatic(value);
_profileEditorService.UpdateSelectedProfileElement(); _profileEditorService.UpdateSelectedProfileElement();
Update(); Update();
@ -255,7 +255,7 @@ namespace Artemis.UI.Screens.ProfileEditor.DisplayConditions
public void ApplyOperator() public void ApplyOperator()
{ {
DisplayConditionListPredicate.UpdateOperator(SelectedOperator); DataModelConditionListPredicate.UpdateOperator(SelectedOperator);
_profileEditorService.UpdateSelectedProfileElement(); _profileEditorService.UpdateSelectedProfileElement();
Update(); Update();
@ -270,7 +270,7 @@ namespace Artemis.UI.Screens.ProfileEditor.DisplayConditions
RightSideInputViewModel = _dataModelUIService.GetDataModelInputViewModel( RightSideInputViewModel = _dataModelUIService.GetDataModelInputViewModel(
SelectedLeftSideProperty.PropertyInfo.PropertyType, SelectedLeftSideProperty.PropertyInfo.PropertyType,
SelectedLeftSideProperty.PropertyDescription, SelectedLeftSideProperty.PropertyDescription,
DisplayConditionListPredicate.RightStaticValue, DataModelConditionListPredicate.RightStaticValue,
ApplyRightSideStatic ApplyRightSideStatic
); );
_eventAggregator.Subscribe(this); _eventAggregator.Subscribe(this);
@ -286,12 +286,12 @@ namespace Artemis.UI.Screens.ProfileEditor.DisplayConditions
private void RightDataModelUpdateRequested(object sender, EventArgs e) private void RightDataModelUpdateRequested(object sender, EventArgs e)
{ {
var listDataModelGuid = DisplayConditionListPredicate.ListDataModel.PluginInfo.Guid; var listDataModelGuid = DataModelConditionListPredicate.ListDataModel.PluginInfo.Guid;
var leftSideType = SelectedLeftSideProperty?.PropertyInfo?.PropertyType; var leftSideType = SelectedLeftSideProperty?.PropertyInfo?.PropertyType;
// If the right side property is missing it may be available now that the data model has been updated // If the right side property is missing it may be available now that the data model has been updated
if (SelectedRightSideProperty == null && DisplayConditionListPredicate.RightPropertyPath != null) if (SelectedRightSideProperty == null && DataModelConditionListPredicate.RightPropertyPath != null)
SelectedRightSideProperty = RightSideDataModel.GetChildByPath(listDataModelGuid, DisplayConditionListPredicate.RightPropertyPath); SelectedRightSideProperty = RightSideDataModel.GetChildByPath(listDataModelGuid, DataModelConditionListPredicate.RightPropertyPath);
// With the data model updated, also reapply the filter // With the data model updated, also reapply the filter
RightSideDataModel.ApplyTypeFilter(true, leftSideType); RightSideDataModel.ApplyTypeFilter(true, leftSideType);
@ -299,19 +299,19 @@ namespace Artemis.UI.Screens.ProfileEditor.DisplayConditions
private void LeftDataModelUpdateRequested(object sender, EventArgs e) private void LeftDataModelUpdateRequested(object sender, EventArgs e)
{ {
if (DisplayConditionListPredicate.PredicateType == ProfileRightSideType.Static) if (DataModelConditionListPredicate.PredicateType == ProfileRightSideType.Static)
LeftSideDataModel.ApplyTypeFilter(false, _supportedInputTypes.ToArray()); LeftSideDataModel.ApplyTypeFilter(false, _supportedInputTypes.ToArray());
} }
private DataModelVisualizationViewModel GetListDataModel() private DataModelVisualizationViewModel GetListDataModel()
{ {
if (DisplayConditionListPredicate.ListDataModel == null || DisplayConditionListPredicate.ListPropertyPath == null) if (DataModelConditionListPredicate.ListDataModel == null || DataModelConditionListPredicate.ListPropertyPath == null)
throw new ArtemisUIException("Cannot create a list predicate without first selecting a target list"); throw new ArtemisUIException("Cannot create a list predicate without first selecting a target list");
var dataModel = _dataModelUIService.GetPluginDataModelVisualization(_profileEditorService.GetCurrentModule(), true); var dataModel = _dataModelUIService.GetPluginDataModelVisualization(_profileEditorService.GetCurrentModule(), true);
var listDataModel = (DataModelListViewModel) dataModel.GetChildByPath( var listDataModel = (DataModelListViewModel) dataModel.GetChildByPath(
DisplayConditionListPredicate.ListDataModel.PluginInfo.Guid, DataModelConditionListPredicate.ListDataModel.PluginInfo.Guid,
DisplayConditionListPredicate.ListPropertyPath DataModelConditionListPredicate.ListPropertyPath
); );
return listDataModel.GetListTypeViewModel(_dataModelUIService); return listDataModel.GetListTypeViewModel(_dataModelUIService);

View File

@ -25,12 +25,12 @@ namespace Artemis.UI.Screens.ProfileEditor.DisplayConditions
private DataModelPropertiesViewModel _targetDataModel; private DataModelPropertiesViewModel _targetDataModel;
public DisplayConditionListViewModel( public DisplayConditionListViewModel(
DisplayConditionList displayConditionList, DataModelConditionList dataModelConditionList,
DisplayConditionViewModel parent, DisplayConditionViewModel parent,
IProfileEditorService profileEditorService, IProfileEditorService profileEditorService,
IDataModelUIService dataModelUIService, IDataModelUIService dataModelUIService,
IDisplayConditionsVmFactory displayConditionsVmFactory, IDisplayConditionsVmFactory displayConditionsVmFactory,
ISettingsService settingsService) : base(displayConditionList) ISettingsService settingsService) : base(dataModelConditionList)
{ {
_profileEditorService = profileEditorService; _profileEditorService = profileEditorService;
_dataModelUIService = dataModelUIService; _dataModelUIService = dataModelUIService;
@ -48,7 +48,7 @@ namespace Artemis.UI.Screens.ProfileEditor.DisplayConditions
public DelegateCommand SelectListPropertyCommand { get; } public DelegateCommand SelectListPropertyCommand { get; }
public PluginSetting<bool> ShowDataModelValues { get; } public PluginSetting<bool> ShowDataModelValues { get; }
public DisplayConditionList DisplayConditionList => (DisplayConditionList) Model; public DataModelConditionList DataModelConditionList => (DataModelConditionList) Model;
public bool IsInitialized public bool IsInitialized
{ {
@ -70,12 +70,12 @@ namespace Artemis.UI.Screens.ProfileEditor.DisplayConditions
set => SetAndNotify(ref _selectedListProperty, value); set => SetAndNotify(ref _selectedListProperty, value);
} }
public string SelectedListOperator => DisplayConditionList.ListOperator.Humanize(); public string SelectedListOperator => DataModelConditionList.ListOperator.Humanize();
public void SelectListOperator(string type) public void SelectListOperator(string type)
{ {
var enumValue = Enum.Parse<ListOperator>(type); var enumValue = Enum.Parse<ListOperator>(type);
DisplayConditionList.ListOperator = enumValue; DataModelConditionList.ListOperator = enumValue;
NotifyOfPropertyChange(nameof(SelectedListOperator)); NotifyOfPropertyChange(nameof(SelectedListOperator));
_profileEditorService.UpdateSelectedProfileElement(); _profileEditorService.UpdateSelectedProfileElement();
@ -84,9 +84,9 @@ namespace Artemis.UI.Screens.ProfileEditor.DisplayConditions
public void AddCondition(string type) public void AddCondition(string type)
{ {
if (type == "Static") if (type == "Static")
DisplayConditionList.AddChild(new DisplayConditionPredicate(DisplayConditionList, ProfileRightSideType.Static)); DataModelConditionList.AddChild(new DataModelConditionPredicate(DataModelConditionList, ProfileRightSideType.Static));
else if (type == "Dynamic") else if (type == "Dynamic")
DisplayConditionList.AddChild(new DisplayConditionPredicate(DisplayConditionList, ProfileRightSideType.Dynamic)); DataModelConditionList.AddChild(new DataModelConditionPredicate(DataModelConditionList, ProfileRightSideType.Dynamic));
Update(); Update();
_profileEditorService.UpdateSelectedProfileElement(); _profileEditorService.UpdateSelectedProfileElement();
@ -94,7 +94,7 @@ namespace Artemis.UI.Screens.ProfileEditor.DisplayConditions
public void AddGroup() public void AddGroup()
{ {
DisplayConditionList.AddChild(new DisplayConditionGroup(DisplayConditionList)); DataModelConditionList.AddChild(new DataModelConditionGroup(DataModelConditionList));
Update(); Update();
_profileEditorService.UpdateSelectedProfileElement(); _profileEditorService.UpdateSelectedProfileElement();
@ -122,7 +122,7 @@ namespace Artemis.UI.Screens.ProfileEditor.DisplayConditions
public void ApplyList() public void ApplyList()
{ {
DisplayConditionList.UpdateList(SelectedListProperty.DataModel, SelectedListProperty.PropertyPath); DataModelConditionList.UpdateList(SelectedListProperty.DataModel, SelectedListProperty.PropertyPath);
_profileEditorService.UpdateSelectedProfileElement(); _profileEditorService.UpdateSelectedProfileElement();
Update(); Update();
@ -136,11 +136,11 @@ namespace Artemis.UI.Screens.ProfileEditor.DisplayConditions
NotifyOfPropertyChange(nameof(SelectedListOperator)); NotifyOfPropertyChange(nameof(SelectedListOperator));
// Update the selected list property // Update the selected list property
if (DisplayConditionList.ListDataModel != null && DisplayConditionList.ListPropertyPath != null) if (DataModelConditionList.ListDataModel != null && DataModelConditionList.ListPropertyPath != null)
{ {
var child = TargetDataModel.GetChildByPath( var child = TargetDataModel.GetChildByPath(
DisplayConditionList.ListDataModel.PluginInfo.Guid, DataModelConditionList.ListDataModel.PluginInfo.Guid,
DisplayConditionList.ListPropertyPath DataModelConditionList.ListPropertyPath
); );
SelectedListProperty = child as DataModelListViewModel; SelectedListProperty = child as DataModelListViewModel;
} }
@ -149,7 +149,7 @@ namespace Artemis.UI.Screens.ProfileEditor.DisplayConditions
TargetDataModel.ApplyTypeFilter(true, typeof(IList)); TargetDataModel.ApplyTypeFilter(true, typeof(IList));
// Remove VMs of effects no longer applied on the layer // Remove VMs of effects no longer applied on the layer
var toRemove = Items.Where(c => !DisplayConditionList.Children.Contains(c.Model)).ToList(); var toRemove = Items.Where(c => !DataModelConditionList.Children.Contains(c.Model)).ToList();
// Using RemoveRange breaks our lovely animations // Using RemoveRange breaks our lovely animations
foreach (var displayConditionViewModel in toRemove) foreach (var displayConditionViewModel in toRemove)
Items.Remove(displayConditionViewModel); Items.Remove(displayConditionViewModel);
@ -158,7 +158,7 @@ namespace Artemis.UI.Screens.ProfileEditor.DisplayConditions
{ {
if (Items.Any(c => c.Model == childModel)) if (Items.Any(c => c.Model == childModel))
continue; continue;
if (!(childModel is DisplayConditionGroup displayConditionGroup)) if (!(childModel is DataModelConditionGroup displayConditionGroup))
continue; continue;
var viewModel = _displayConditionsVmFactory.DisplayConditionGroupViewModel(displayConditionGroup, true); var viewModel = _displayConditionsVmFactory.DisplayConditionGroupViewModel(displayConditionGroup, true);

View File

@ -37,12 +37,12 @@ namespace Artemis.UI.Screens.ProfileEditor.DisplayConditions
private List<Type> _supportedInputTypes; private List<Type> _supportedInputTypes;
public DisplayConditionPredicateViewModel( public DisplayConditionPredicateViewModel(
DisplayConditionPredicate displayConditionPredicate, DataModelConditionPredicate dataModelConditionPredicate,
IProfileEditorService profileEditorService, IProfileEditorService profileEditorService,
IDataModelUIService dataModelUIService, IDataModelUIService dataModelUIService,
IConditionOperatorService conditionOperatorService, IConditionOperatorService conditionOperatorService,
ISettingsService settingsService, ISettingsService settingsService,
IEventAggregator eventAggregator) : base(displayConditionPredicate) IEventAggregator eventAggregator) : base(dataModelConditionPredicate)
{ {
_profileEditorService = profileEditorService; _profileEditorService = profileEditorService;
_dataModelUIService = dataModelUIService; _dataModelUIService = dataModelUIService;
@ -61,8 +61,8 @@ namespace Artemis.UI.Screens.ProfileEditor.DisplayConditions
Initialize(); Initialize();
} }
public DisplayConditionPredicate DisplayConditionPredicate => (DisplayConditionPredicate) Model; public DataModelConditionPredicate DataModelConditionPredicate => (DataModelConditionPredicate) Model;
public bool ShowRightSidePropertySelection => DisplayConditionPredicate.PredicateType == ProfileRightSideType.Dynamic; public bool ShowRightSidePropertySelection => DataModelConditionPredicate.PredicateType == ProfileRightSideType.Dynamic;
public bool CanActivateRightSideInputViewModel => SelectedLeftSideProperty?.PropertyInfo != null; public bool CanActivateRightSideInputViewModel => SelectedLeftSideProperty?.PropertyInfo != null;
public PluginSetting<bool> ShowDataModelValues { get; } public PluginSetting<bool> ShowDataModelValues { get; }
@ -188,46 +188,46 @@ namespace Artemis.UI.Screens.ProfileEditor.DisplayConditions
public override void Update() public override void Update()
{ {
if (LeftSideDataModel == null || DisplayConditionPredicate.PredicateType == ProfileRightSideType.Dynamic && RightSideDataModel == null) if (LeftSideDataModel == null || DataModelConditionPredicate.PredicateType == ProfileRightSideType.Dynamic && RightSideDataModel == null)
return; return;
// If static, only allow selecting properties also supported by input // If static, only allow selecting properties also supported by input
if (DisplayConditionPredicate.PredicateType == ProfileRightSideType.Static) if (DataModelConditionPredicate.PredicateType == ProfileRightSideType.Static)
LeftSideDataModel.ApplyTypeFilter(false, _supportedInputTypes.ToArray()); LeftSideDataModel.ApplyTypeFilter(false, _supportedInputTypes.ToArray());
// Determine the left side property first // Determine the left side property first
SelectedLeftSideProperty = LeftSideDataModel.GetChildForCondition(DisplayConditionPredicate, DisplayConditionSide.Left); SelectedLeftSideProperty = LeftSideDataModel.GetChildForCondition(DataModelConditionPredicate, DisplayConditionSide.Left);
var leftSideType = SelectedLeftSideProperty?.PropertyInfo?.PropertyType; var leftSideType = SelectedLeftSideProperty?.PropertyInfo?.PropertyType;
// Get the supported operators // Get the supported operators
Operators.Clear(); Operators.Clear();
Operators.AddRange(_conditionOperatorService.GetConditionOperatorsForType(leftSideType)); Operators.AddRange(_conditionOperatorService.GetConditionOperatorsForType(leftSideType));
if (DisplayConditionPredicate.Operator == null) if (DataModelConditionPredicate.Operator == null)
DisplayConditionPredicate.UpdateOperator(Operators.FirstOrDefault(o => o.SupportsType(leftSideType))); DataModelConditionPredicate.UpdateOperator(Operators.FirstOrDefault(o => o.SupportsType(leftSideType)));
SelectedOperator = DisplayConditionPredicate.Operator; SelectedOperator = DataModelConditionPredicate.Operator;
// Determine the right side // Determine the right side
if (DisplayConditionPredicate.PredicateType == ProfileRightSideType.Dynamic) if (DataModelConditionPredicate.PredicateType == ProfileRightSideType.Dynamic)
{ {
SelectedRightSideProperty = LeftSideDataModel.GetChildForCondition(DisplayConditionPredicate, DisplayConditionSide.Right); SelectedRightSideProperty = LeftSideDataModel.GetChildForCondition(DataModelConditionPredicate, DisplayConditionSide.Right);
RightSideDataModel.ApplyTypeFilter(true, leftSideType); RightSideDataModel.ApplyTypeFilter(true, leftSideType);
} }
else else
RightStaticValue = DisplayConditionPredicate.RightStaticValue; RightStaticValue = DataModelConditionPredicate.RightStaticValue;
} }
public void ApplyLeftSide() public void ApplyLeftSide()
{ {
DisplayConditionPredicate.UpdateLeftSide(SelectedLeftSideProperty.DataModel, SelectedLeftSideProperty.PropertyPath); DataModelConditionPredicate.UpdateLeftSide(SelectedLeftSideProperty.DataModel, SelectedLeftSideProperty.PropertyPath);
_profileEditorService.UpdateSelectedProfileElement(); _profileEditorService.UpdateSelectedProfileElement();
SelectedOperator = DisplayConditionPredicate.Operator; SelectedOperator = DataModelConditionPredicate.Operator;
Update(); Update();
} }
public void ApplyRightSideDynamic() public void ApplyRightSideDynamic()
{ {
DisplayConditionPredicate.UpdateRightSide(SelectedRightSideProperty.DataModel, SelectedRightSideProperty.PropertyPath); DataModelConditionPredicate.UpdateRightSide(SelectedRightSideProperty.DataModel, SelectedRightSideProperty.PropertyPath);
_profileEditorService.UpdateSelectedProfileElement(); _profileEditorService.UpdateSelectedProfileElement();
Update(); Update();
@ -237,7 +237,7 @@ namespace Artemis.UI.Screens.ProfileEditor.DisplayConditions
{ {
if (isSubmitted) if (isSubmitted)
{ {
DisplayConditionPredicate.UpdateRightSide(value); DataModelConditionPredicate.UpdateRightSide(value);
_profileEditorService.UpdateSelectedProfileElement(); _profileEditorService.UpdateSelectedProfileElement();
Update(); Update();
@ -251,7 +251,7 @@ namespace Artemis.UI.Screens.ProfileEditor.DisplayConditions
public void ApplyOperator() public void ApplyOperator()
{ {
DisplayConditionPredicate.UpdateOperator(SelectedOperator); DataModelConditionPredicate.UpdateOperator(SelectedOperator);
_profileEditorService.UpdateSelectedProfileElement(); _profileEditorService.UpdateSelectedProfileElement();
Update(); Update();
@ -266,7 +266,7 @@ namespace Artemis.UI.Screens.ProfileEditor.DisplayConditions
RightSideInputViewModel = _dataModelUIService.GetDataModelInputViewModel( RightSideInputViewModel = _dataModelUIService.GetDataModelInputViewModel(
SelectedLeftSideProperty.PropertyInfo.PropertyType, SelectedLeftSideProperty.PropertyInfo.PropertyType,
SelectedLeftSideProperty.PropertyDescription, SelectedLeftSideProperty.PropertyDescription,
DisplayConditionPredicate.RightStaticValue, DataModelConditionPredicate.RightStaticValue,
ApplyRightSideStatic ApplyRightSideStatic
); );
_eventAggregator.Subscribe(this); _eventAggregator.Subscribe(this);
@ -283,8 +283,8 @@ namespace Artemis.UI.Screens.ProfileEditor.DisplayConditions
private void RightDataModelUpdateRequested(object sender, EventArgs e) private void RightDataModelUpdateRequested(object sender, EventArgs e)
{ {
var leftSideType = SelectedLeftSideProperty?.PropertyInfo?.PropertyType; var leftSideType = SelectedLeftSideProperty?.PropertyInfo?.PropertyType;
if (DisplayConditionPredicate.PredicateType == ProfileRightSideType.Dynamic) if (DataModelConditionPredicate.PredicateType == ProfileRightSideType.Dynamic)
SelectedRightSideProperty = LeftSideDataModel.GetChildForCondition(DisplayConditionPredicate, DisplayConditionSide.Right); SelectedRightSideProperty = LeftSideDataModel.GetChildForCondition(DataModelConditionPredicate, DisplayConditionSide.Right);
// With the data model updated, also reapply the filter // With the data model updated, also reapply the filter
RightSideDataModel.ApplyTypeFilter(true, leftSideType); RightSideDataModel.ApplyTypeFilter(true, leftSideType);
@ -292,7 +292,7 @@ namespace Artemis.UI.Screens.ProfileEditor.DisplayConditions
private void LeftDataModelUpdateRequested(object sender, EventArgs e) private void LeftDataModelUpdateRequested(object sender, EventArgs e)
{ {
if (DisplayConditionPredicate.PredicateType == ProfileRightSideType.Static) if (DataModelConditionPredicate.PredicateType == ProfileRightSideType.Static)
LeftSideDataModel.ApplyTypeFilter(false, _supportedInputTypes.ToArray()); LeftSideDataModel.ApplyTypeFilter(false, _supportedInputTypes.ToArray());
} }

View File

@ -82,10 +82,10 @@ namespace Artemis.UI.Screens.ProfileEditor.DisplayConditions
} }
// Ensure the layer has a root display condition group // Ensure the layer has a root display condition group
if (e.RenderProfileElement.DisplayConditionGroup == null) if (e.RenderProfileElement.DataModelConditionGroup == null)
e.RenderProfileElement.DisplayConditionGroup = new DisplayConditionGroup(null); e.RenderProfileElement.DataModelConditionGroup = new DataModelConditionGroup(null);
ActiveItem = _displayConditionsVmFactory.DisplayConditionGroupViewModel(e.RenderProfileElement.DisplayConditionGroup, false); ActiveItem = _displayConditionsVmFactory.DisplayConditionGroupViewModel(e.RenderProfileElement.DataModelConditionGroup, false);
ActiveItem.IsRootGroup = true; ActiveItem.IsRootGroup = true;
ActiveItem.Update(); ActiveItem.Update();