mirror of
https://github.com/Artemis-RGB/Artemis
synced 2026-11-12 03:48:56 +00:00
Core - Added stores for the different register-able types
Profiles - Refactored large parts of the profile structure to use these stores
This commit is contained in:
1 parent
4cfe71796c
commit
11de30318e
75 files changed
+1526
-934
No files matched your search
@@ -60,7 +60,6 @@ namespace Artemis.Core
|
||||
/// <returns></returns>
|
||||
public abstract bool EvaluateObject(object target);
|
||||
|
||||
internal abstract void Initialize(IDataModelService dataModelService);
|
||||
internal abstract void ApplyToEntity();
|
||||
internal abstract DisplayConditionPartEntity GetEntity();
|
||||
}
|
||||
|
||||
+2
-36
@@ -2,18 +2,14 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Linq.Expressions;
|
||||
using Artemis.Core.Services;
|
||||
|
||||
namespace Artemis.Core
|
||||
{
|
||||
/// <summary>
|
||||
/// A display condition operator is used by the conditions system to perform a specific boolean check
|
||||
/// A condition operator is used by the conditions system to perform a specific boolean check
|
||||
/// </summary>
|
||||
public abstract class DisplayConditionOperator
|
||||
public abstract class ConditionOperator
|
||||
{
|
||||
private IDataModelService _dataModelService;
|
||||
private bool _registered;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the plugin info this condition operator belongs to
|
||||
/// <para>Note: Not set until after registering</para>
|
||||
@@ -57,35 +53,5 @@ namespace Artemis.Core
|
||||
/// <param name="rightSide">The parameter on the right side of the expression</param>
|
||||
/// <returns></returns>
|
||||
public abstract BinaryExpression CreateExpression(Expression leftSide, Expression rightSide);
|
||||
|
||||
internal void Register(PluginInfo pluginInfo, IDataModelService dataModelService)
|
||||
{
|
||||
if (_registered)
|
||||
return;
|
||||
|
||||
PluginInfo = pluginInfo;
|
||||
_dataModelService = dataModelService;
|
||||
|
||||
if (PluginInfo != Constants.CorePluginInfo)
|
||||
PluginInfo.Instance.PluginDisabled += InstanceOnPluginDisabled;
|
||||
|
||||
_registered = true;
|
||||
}
|
||||
|
||||
internal void Unsubscribe()
|
||||
{
|
||||
if (!_registered)
|
||||
return;
|
||||
|
||||
if (PluginInfo != Constants.CorePluginInfo)
|
||||
PluginInfo.Instance.PluginDisabled -= InstanceOnPluginDisabled;
|
||||
_registered = false;
|
||||
}
|
||||
|
||||
private void InstanceOnPluginDisabled(object sender, EventArgs e)
|
||||
{
|
||||
// The service will call Unsubscribe
|
||||
_dataModelService.RemoveConditionOperator(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,5 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
using Artemis.Core.Services;
|
||||
using Artemis.Storage.Entities.Profile.Abstract;
|
||||
using Artemis.Storage.Entities.Profile.Conditions;
|
||||
|
||||
@@ -108,12 +107,6 @@ namespace Artemis.Core
|
||||
child.ApplyToEntity();
|
||||
}
|
||||
|
||||
internal override void Initialize(IDataModelService dataModelService)
|
||||
{
|
||||
foreach (var child in Children)
|
||||
child.Initialize(dataModelService);
|
||||
}
|
||||
|
||||
internal override DisplayConditionPartEntity GetEntity()
|
||||
{
|
||||
return Entity;
|
||||
|
||||
@@ -3,7 +3,6 @@ using System.Collections;
|
||||
using System.Linq;
|
||||
using System.Linq.Expressions;
|
||||
using Artemis.Core.DataModelExpansions;
|
||||
using Artemis.Core.Services;
|
||||
using Artemis.Storage.Entities.Profile.Abstract;
|
||||
using Artemis.Storage.Entities.Profile.Conditions;
|
||||
|
||||
@@ -15,6 +14,8 @@ namespace Artemis.Core
|
||||
{
|
||||
Parent = parent;
|
||||
Entity = new DisplayConditionListEntity();
|
||||
|
||||
Initialize();
|
||||
}
|
||||
|
||||
public DisplayConditionList(DisplayConditionPart parent, DisplayConditionListEntity entity)
|
||||
@@ -22,6 +23,8 @@ namespace Artemis.Core
|
||||
Parent = parent;
|
||||
Entity = entity;
|
||||
ListOperator = (ListOperator) entity.ListOperator;
|
||||
|
||||
Initialize();
|
||||
}
|
||||
|
||||
public DisplayConditionListEntity Entity { get; set; }
|
||||
@@ -120,13 +123,13 @@ namespace Artemis.Core
|
||||
return Entity;
|
||||
}
|
||||
|
||||
internal override void Initialize(IDataModelService dataModelService)
|
||||
internal void Initialize()
|
||||
{
|
||||
if (Entity.ListDataModelGuid == null)
|
||||
return;
|
||||
|
||||
// Get the data model and ensure the path is valid
|
||||
var dataModel = dataModelService.GetPluginDataModelByGuid(Entity.ListDataModelGuid.Value);
|
||||
var dataModel = DataModelStore.Get(Entity.ListDataModelGuid.Value)?.DataModel;
|
||||
if (dataModel == null || !dataModel.ContainsPath(Entity.ListPropertyPath))
|
||||
return;
|
||||
|
||||
@@ -143,8 +146,6 @@ namespace Artemis.Core
|
||||
Entity.Children.Clear();
|
||||
AddChild(new DisplayConditionGroup(this));
|
||||
}
|
||||
|
||||
Children[0].Initialize(dataModelService);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -2,7 +2,6 @@
|
||||
using System.Linq;
|
||||
using System.Linq.Expressions;
|
||||
using Artemis.Core.DataModelExpansions;
|
||||
using Artemis.Core.Services;
|
||||
using Artemis.Storage.Entities.Profile.Abstract;
|
||||
using Artemis.Storage.Entities.Profile.Conditions;
|
||||
using Newtonsoft.Json;
|
||||
@@ -18,6 +17,7 @@ namespace Artemis.Core
|
||||
Entity = new DisplayConditionListPredicateEntity();
|
||||
|
||||
ApplyParentList();
|
||||
Initialize();
|
||||
}
|
||||
|
||||
public DisplayConditionListPredicate(DisplayConditionPart parent, DisplayConditionListPredicateEntity entity)
|
||||
@@ -27,12 +27,13 @@ namespace Artemis.Core
|
||||
PredicateType = (ProfileRightSideType) entity.PredicateType;
|
||||
|
||||
ApplyParentList();
|
||||
Initialize();
|
||||
}
|
||||
|
||||
public DisplayConditionListPredicateEntity Entity { get; set; }
|
||||
|
||||
public ProfileRightSideType PredicateType { get; set; }
|
||||
public DisplayConditionOperator Operator { get; private set; }
|
||||
public ConditionOperator Operator { get; private set; }
|
||||
|
||||
public Type ListType { get; private set; }
|
||||
public DataModel ListDataModel { get; private set; }
|
||||
@@ -120,9 +121,9 @@ namespace Artemis.Core
|
||||
CreateExpression();
|
||||
}
|
||||
|
||||
public void UpdateOperator(DisplayConditionOperator displayConditionOperator)
|
||||
public void UpdateOperator(ConditionOperator conditionOperator)
|
||||
{
|
||||
if (displayConditionOperator == null)
|
||||
if (conditionOperator == null)
|
||||
{
|
||||
Operator = null;
|
||||
return;
|
||||
@@ -130,13 +131,13 @@ namespace Artemis.Core
|
||||
|
||||
if (LeftPropertyPath == null)
|
||||
{
|
||||
Operator = displayConditionOperator;
|
||||
Operator = conditionOperator;
|
||||
return;
|
||||
}
|
||||
|
||||
var leftType = GetTypeAtInnerPath(LeftPropertyPath);
|
||||
if (displayConditionOperator.SupportsType(leftType))
|
||||
Operator = displayConditionOperator;
|
||||
if (conditionOperator.SupportsType(leftType))
|
||||
Operator = conditionOperator;
|
||||
|
||||
CreateExpression();
|
||||
}
|
||||
@@ -203,7 +204,7 @@ namespace Artemis.Core
|
||||
Entity.OperatorType = Operator?.GetType().Name;
|
||||
}
|
||||
|
||||
internal override void Initialize(IDataModelService dataModelService)
|
||||
internal void Initialize()
|
||||
{
|
||||
// Left side
|
||||
if (Entity.LeftPropertyPath != null && ListContainsInnerPath(Entity.LeftPropertyPath))
|
||||
@@ -212,7 +213,7 @@ namespace Artemis.Core
|
||||
// Operator
|
||||
if (Entity.OperatorPluginGuid != null)
|
||||
{
|
||||
var conditionOperator = dataModelService.GetConditionOperator(Entity.OperatorPluginGuid.Value, Entity.OperatorType);
|
||||
var conditionOperator = ConditionOperatorStore.Get(Entity.OperatorPluginGuid.Value, Entity.OperatorType)?.ConditionOperator;
|
||||
if (conditionOperator != null)
|
||||
UpdateOperator(conditionOperator);
|
||||
}
|
||||
@@ -241,7 +242,7 @@ namespace Artemis.Core
|
||||
// If deserialization fails, use the type's default
|
||||
catch (JsonSerializationException e)
|
||||
{
|
||||
dataModelService.LogListPredicateDeserializationFailure(this, e);
|
||||
DeserializationLogger.LogListPredicateDeserializationFailure(this, e);
|
||||
rightSideValue = Activator.CreateInstance(leftSideType);
|
||||
}
|
||||
|
||||
@@ -255,7 +256,7 @@ namespace Artemis.Core
|
||||
}
|
||||
catch (JsonException e)
|
||||
{
|
||||
dataModelService.LogListPredicateDeserializationFailure(this, e);
|
||||
DeserializationLogger.LogListPredicateDeserializationFailure(this, e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,7 +2,6 @@
|
||||
using System.Linq;
|
||||
using System.Linq.Expressions;
|
||||
using Artemis.Core.DataModelExpansions;
|
||||
using Artemis.Core.Services;
|
||||
using Artemis.Storage.Entities.Profile.Abstract;
|
||||
using Artemis.Storage.Entities.Profile.Conditions;
|
||||
using Newtonsoft.Json;
|
||||
@@ -25,6 +24,8 @@ namespace Artemis.Core
|
||||
Parent = parent;
|
||||
PredicateType = predicateType;
|
||||
Entity = new DisplayConditionPredicateEntity();
|
||||
|
||||
Initialize();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -37,6 +38,8 @@ namespace Artemis.Core
|
||||
Parent = parent;
|
||||
Entity = entity;
|
||||
PredicateType = (ProfileRightSideType) entity.PredicateType;
|
||||
|
||||
Initialize();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -47,7 +50,7 @@ namespace Artemis.Core
|
||||
/// <summary>
|
||||
/// Gets the operator
|
||||
/// </summary>
|
||||
public DisplayConditionOperator Operator { get; private set; }
|
||||
public ConditionOperator Operator { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the currently used instance of the left data model
|
||||
@@ -175,11 +178,11 @@ namespace Artemis.Core
|
||||
/// <summary>
|
||||
/// Updates the operator of the predicate and re-compiles the expression
|
||||
/// </summary>
|
||||
/// <param name="displayConditionOperator"></param>
|
||||
public void UpdateOperator(DisplayConditionOperator displayConditionOperator)
|
||||
/// <param name="conditionOperator"></param>
|
||||
public void UpdateOperator(ConditionOperator conditionOperator)
|
||||
{
|
||||
// Calling CreateExpression will clear compiled expressions
|
||||
if (displayConditionOperator == null)
|
||||
if (conditionOperator == null)
|
||||
{
|
||||
Operator = null;
|
||||
CreateExpression();
|
||||
@@ -189,18 +192,18 @@ namespace Artemis.Core
|
||||
// No need to clear compiled expressions, without a left data model they are already null
|
||||
if (LeftDataModel == null)
|
||||
{
|
||||
Operator = displayConditionOperator;
|
||||
Operator = conditionOperator;
|
||||
return;
|
||||
}
|
||||
|
||||
var leftType = LeftDataModel.GetTypeAtPath(LeftPropertyPath);
|
||||
if (!displayConditionOperator.SupportsType(leftType))
|
||||
if (!conditionOperator.SupportsType(leftType))
|
||||
{
|
||||
throw new ArtemisCoreException($"Cannot apply operator {displayConditionOperator.GetType().Name} to this predicate because " +
|
||||
throw new ArtemisCoreException($"Cannot apply operator {conditionOperator.GetType().Name} to this predicate because " +
|
||||
$"it does not support left side type {leftType.Name}");
|
||||
}
|
||||
|
||||
Operator = displayConditionOperator;
|
||||
Operator = conditionOperator;
|
||||
CreateExpression();
|
||||
}
|
||||
|
||||
@@ -243,12 +246,12 @@ namespace Artemis.Core
|
||||
Entity.OperatorType = Operator?.GetType().Name;
|
||||
}
|
||||
|
||||
internal override void Initialize(IDataModelService dataModelService)
|
||||
internal void Initialize()
|
||||
{
|
||||
// Left side
|
||||
if (Entity.LeftDataModelGuid != null)
|
||||
{
|
||||
var dataModel = dataModelService.GetPluginDataModelByGuid(Entity.LeftDataModelGuid.Value);
|
||||
var dataModel = DataModelStore.Get(Entity.LeftDataModelGuid.Value)?.DataModel;
|
||||
if (dataModel != null && dataModel.ContainsPath(Entity.LeftPropertyPath))
|
||||
UpdateLeftSide(dataModel, Entity.LeftPropertyPath);
|
||||
}
|
||||
@@ -256,7 +259,7 @@ namespace Artemis.Core
|
||||
// Operator
|
||||
if (Entity.OperatorPluginGuid != null)
|
||||
{
|
||||
var conditionOperator = dataModelService.GetConditionOperator(Entity.OperatorPluginGuid.Value, Entity.OperatorType);
|
||||
var conditionOperator = ConditionOperatorStore.Get(Entity.OperatorPluginGuid.Value, Entity.OperatorType)?.ConditionOperator;
|
||||
if (conditionOperator != null)
|
||||
UpdateOperator(conditionOperator);
|
||||
}
|
||||
@@ -264,7 +267,7 @@ namespace Artemis.Core
|
||||
// Right side dynamic
|
||||
if (PredicateType == ProfileRightSideType.Dynamic && Entity.RightDataModelGuid != null)
|
||||
{
|
||||
var dataModel = dataModelService.GetPluginDataModelByGuid(Entity.RightDataModelGuid.Value);
|
||||
var dataModel = DataModelStore.Get(Entity.RightDataModelGuid.Value)?.DataModel;
|
||||
if (dataModel != null && dataModel.ContainsPath(Entity.RightPropertyPath))
|
||||
UpdateRightSide(dataModel, Entity.RightPropertyPath);
|
||||
}
|
||||
@@ -286,7 +289,7 @@ namespace Artemis.Core
|
||||
// If deserialization fails, use the type's default
|
||||
catch (JsonSerializationException e)
|
||||
{
|
||||
dataModelService.LogPredicateDeserializationFailure(this, e);
|
||||
DeserializationLogger.LogPredicateDeserializationFailure(this, e);
|
||||
rightSideValue = Activator.CreateInstance(leftSideType);
|
||||
}
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@ using System.Linq.Expressions;
|
||||
|
||||
namespace Artemis.Core
|
||||
{
|
||||
internal class EqualsConditionOperator : DisplayConditionOperator
|
||||
internal class EqualsConditionOperator : ConditionOperator
|
||||
{
|
||||
public override IReadOnlyCollection<Type> CompatibleTypes => new List<Type> {typeof(object)};
|
||||
|
||||
|
||||
+1
-1
@@ -4,7 +4,7 @@ using System.Linq.Expressions;
|
||||
|
||||
namespace Artemis.Core
|
||||
{
|
||||
internal class GreaterThanConditionOperator : DisplayConditionOperator
|
||||
internal class GreaterThanConditionOperator : ConditionOperator
|
||||
{
|
||||
public override IReadOnlyCollection<Type> CompatibleTypes => Constants.NumberTypes;
|
||||
|
||||
|
||||
+1
-1
@@ -4,7 +4,7 @@ using System.Linq.Expressions;
|
||||
|
||||
namespace Artemis.Core
|
||||
{
|
||||
internal class GreaterThanOrEqualConditionOperator : DisplayConditionOperator
|
||||
internal class GreaterThanOrEqualConditionOperator : ConditionOperator
|
||||
{
|
||||
public override IReadOnlyCollection<Type> CompatibleTypes => Constants.NumberTypes;
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@ using System.Linq.Expressions;
|
||||
|
||||
namespace Artemis.Core
|
||||
{
|
||||
internal class LessThanConditionOperator : DisplayConditionOperator
|
||||
internal class LessThanConditionOperator : ConditionOperator
|
||||
{
|
||||
public override IReadOnlyCollection<Type> CompatibleTypes => Constants.NumberTypes;
|
||||
|
||||
|
||||
+1
-1
@@ -4,7 +4,7 @@ using System.Linq.Expressions;
|
||||
|
||||
namespace Artemis.Core
|
||||
{
|
||||
internal class LessThanOrEqualConditionOperator : DisplayConditionOperator
|
||||
internal class LessThanOrEqualConditionOperator : ConditionOperator
|
||||
{
|
||||
public override IReadOnlyCollection<Type> CompatibleTypes => Constants.NumberTypes;
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@ using System.Linq.Expressions;
|
||||
|
||||
namespace Artemis.Core
|
||||
{
|
||||
internal class NotEqualConditionOperator : DisplayConditionOperator
|
||||
internal class NotEqualConditionOperator : ConditionOperator
|
||||
{
|
||||
public override IReadOnlyCollection<Type> CompatibleTypes => new List<Type> {typeof(object)};
|
||||
|
||||
|
||||
+1
-1
@@ -5,7 +5,7 @@ using System.Reflection;
|
||||
|
||||
namespace Artemis.Core
|
||||
{
|
||||
internal class StringContainsConditionOperator : DisplayConditionOperator
|
||||
internal class StringContainsConditionOperator : ConditionOperator
|
||||
{
|
||||
private readonly MethodInfo _contains;
|
||||
private readonly MethodInfo _toLower;
|
||||
|
||||
+1
-1
@@ -5,7 +5,7 @@ using System.Reflection;
|
||||
|
||||
namespace Artemis.Core
|
||||
{
|
||||
internal class StringEndsWithConditionOperator : DisplayConditionOperator
|
||||
internal class StringEndsWithConditionOperator : ConditionOperator
|
||||
{
|
||||
private readonly MethodInfo _endsWith;
|
||||
private readonly MethodInfo _toLower;
|
||||
|
||||
+1
-1
@@ -5,7 +5,7 @@ using System.Reflection;
|
||||
|
||||
namespace Artemis.Core
|
||||
{
|
||||
internal class StringEqualsConditionOperator : DisplayConditionOperator
|
||||
internal class StringEqualsConditionOperator : ConditionOperator
|
||||
{
|
||||
private readonly MethodInfo _toLower;
|
||||
|
||||
|
||||
+1
-1
@@ -5,7 +5,7 @@ using System.Reflection;
|
||||
|
||||
namespace Artemis.Core
|
||||
{
|
||||
internal class StringNotContainsConditionOperator : DisplayConditionOperator
|
||||
internal class StringNotContainsConditionOperator : ConditionOperator
|
||||
{
|
||||
private readonly MethodInfo _contains;
|
||||
private readonly MethodInfo _toLower;
|
||||
|
||||
+1
-1
@@ -5,7 +5,7 @@ using System.Reflection;
|
||||
|
||||
namespace Artemis.Core
|
||||
{
|
||||
internal class StringNotEqualConditionOperator : DisplayConditionOperator
|
||||
internal class StringNotEqualConditionOperator : ConditionOperator
|
||||
{
|
||||
private readonly MethodInfo _toLower;
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@ using System.Linq.Expressions;
|
||||
|
||||
namespace Artemis.Core
|
||||
{
|
||||
internal class StringNullConditionOperator : DisplayConditionOperator
|
||||
internal class StringNullConditionOperator : ConditionOperator
|
||||
{
|
||||
public StringNullConditionOperator()
|
||||
{
|
||||
|
||||
+1
-1
@@ -5,7 +5,7 @@ using System.Reflection;
|
||||
|
||||
namespace Artemis.Core
|
||||
{
|
||||
internal class StringStartsWithConditionOperator : DisplayConditionOperator
|
||||
internal class StringStartsWithConditionOperator : ConditionOperator
|
||||
{
|
||||
private readonly MethodInfo _startsWith;
|
||||
private readonly MethodInfo _toLower;
|
||||
|
||||
Reference in new issue
Block a user