diff --git a/src/Artemis.Core/Models/Profile/Conditions/DataModelConditionList.cs b/src/Artemis.Core/Models/Profile/Conditions/DataModelConditionList.cs
index c09736df7..ef1261628 100644
--- a/src/Artemis.Core/Models/Profile/Conditions/DataModelConditionList.cs
+++ b/src/Artemis.Core/Models/Profile/Conditions/DataModelConditionList.cs
@@ -43,7 +43,7 @@ namespace Artemis.Core
///
/// Gets the path of the list property
///
- public DataModelPath? ListPath { get; set; }
+ public DataModelPath? ListPath { get; private set; }
///
/// Gets the type of the content of the list this predicate is evaluated on
@@ -82,15 +82,15 @@ namespace Artemis.Core
throw new ArtemisCoreException("Cannot update list to an invalid path");
ListPath?.Dispose();
- ListPath = path;
+ ListPath = path != null ? new DataModelPath(path) : null;
// Remove the old root group that was tied to the old data model
while (Children.Any())
RemoveChild(Children[0]);
- if (path != null)
+ if (ListPath != null)
{
- Type listType = path.GetPropertyType()!;
+ Type listType = ListPath.GetPropertyType()!;
ListType = listType.GetGenericArguments()[0];
IsPrimitiveList = ListType.IsPrimitive || ListType.IsEnum || ListType == typeof(string);
@@ -99,7 +99,6 @@ namespace Artemis.Core
}
else
{
- ListPath = null;
ListType = null;
}
}
@@ -171,12 +170,21 @@ namespace Artemis.Core
// Ensure the list path is valid and points to a list
DataModelPath listPath = new DataModelPath(null, Entity.ListPath);
Type listType = listPath.GetPropertyType()!;
- if (!listPath.IsValid || !typeof(IList).IsAssignableFrom(listType))
+ // Can't check this on an invalid list, if it becomes valid later lets hope for the best
+ if (listPath.IsValid && !typeof(IList).IsAssignableFrom(listType))
return;
ListPath = listPath;
- ListType = listType.GetGenericArguments()[0];
- IsPrimitiveList = ListType.IsPrimitive || ListType.IsEnum || ListType == typeof(string);
+ if (ListPath.IsValid)
+ {
+ ListType = listType.GetGenericArguments()[0];
+ IsPrimitiveList = ListType.IsPrimitive || ListType.IsEnum || ListType == typeof(string);
+ }
+ else
+ {
+ ListType = null;
+ IsPrimitiveList = false;
+ }
// There should only be one child and it should be a group
if (Entity.Children.SingleOrDefault() is DataModelConditionGroupEntity rootGroup)
diff --git a/src/Artemis.Core/Models/Profile/Conditions/DataModelConditionListPredicate.cs b/src/Artemis.Core/Models/Profile/Conditions/DataModelConditionListPredicate.cs
index e53b29698..baabcf6be 100644
--- a/src/Artemis.Core/Models/Profile/Conditions/DataModelConditionListPredicate.cs
+++ b/src/Artemis.Core/Models/Profile/Conditions/DataModelConditionListPredicate.cs
@@ -54,9 +54,15 @@ namespace Artemis.Core
///
public DataModelConditionList DataModelConditionList { get; private set; }
- public DataModelPath? LeftPath { get; set; }
+ ///
+ /// Gets the path of the left property
+ ///
+ public DataModelPath? LeftPath { get; private set; }
- public DataModelPath? RightPath { get; set; }
+ ///
+ /// Gets the path of the right property
+ ///
+ public DataModelPath? RightPath { get; private set; }
///
/// Gets the right static value, only used it is
@@ -70,17 +76,17 @@ namespace Artemis.Core
/// Updates the left side of the predicate
///
/// The path pointing to the left side value inside the list
- public void UpdateLeftSide(string? path)
+ public void UpdateLeftSide(DataModelPath? path)
{
if (DataModelConditionList.IsPrimitiveList)
throw new ArtemisCoreException("Cannot apply a left side to a predicate inside a primitive list");
+ if (path != null && !path.IsValid)
+ throw new ArtemisCoreException("Cannot update left side of predicate to an invalid path");
+
LeftPath?.Dispose();
- if (path != null && DataModelConditionList.ListType != null)
- LeftPath = new DataModelPath(ListPredicateWrapperDataModel.Create(DataModelConditionList.ListType), path);
- else
- LeftPath = null;
-
+ LeftPath = path != null ? new DataModelPath(path) : null;
+
ValidateOperator();
ValidateRightSide();
}
@@ -92,8 +98,11 @@ namespace Artemis.Core
/// The path pointing to the right side value inside the list
public void UpdateRightSideDynamicList(DataModelPath? path)
{
+ if (path != null && !path.IsValid)
+ throw new ArtemisCoreException("Cannot update right side of predicate to an invalid path");
+
RightPath?.Dispose();
- RightPath = path;
+ RightPath = path != null ? new DataModelPath(path) : null;
PredicateType = ListRightSideType.DynamicList;
}
diff --git a/src/Artemis.Core/Models/Profile/Conditions/DataModelConditionPredicate.cs b/src/Artemis.Core/Models/Profile/Conditions/DataModelConditionPredicate.cs
index 12e7a5b6f..c37ebf1c1 100644
--- a/src/Artemis.Core/Models/Profile/Conditions/DataModelConditionPredicate.cs
+++ b/src/Artemis.Core/Models/Profile/Conditions/DataModelConditionPredicate.cs
@@ -48,12 +48,12 @@ namespace Artemis.Core
///
/// Gets the path of the left property
///
- public DataModelPath? LeftPath { get; set; }
+ public DataModelPath? LeftPath { get; private set; }
///
/// Gets the path of the right property
///
- public DataModelPath? RightPath { get; set; }
+ public DataModelPath? RightPath { get; private set; }
///
/// Gets the right static value, only used it is
@@ -66,27 +66,14 @@ namespace Artemis.Core
///
/// Updates the left side of the predicate
///
- /// The data model of the left side value
/// The path pointing to the left side value inside the data model
- public void UpdateLeftSide(DataModel? dataModel, string? path)
+ public void UpdateLeftSide(DataModelPath? path)
{
- if (dataModel != null && path == null)
- throw new ArtemisCoreException("If a data model is provided, a path is also required");
- if (dataModel == null && path != null)
- throw new ArtemisCoreException("If path is provided, a data model is also required");
+ if (path != null && !path.IsValid)
+ throw new ArtemisCoreException("Cannot update left side of predicate to an invalid path");
LeftPath?.Dispose();
- if (dataModel != null)
- {
- DataModelPath newPath = new DataModelPath(dataModel, path);
- if (!newPath.IsValid)
- throw new ArtemisCoreException($"New left path '{newPath}' is invalid");
- LeftPath = newPath;
- }
- else
- {
- LeftPath = null;
- }
+ LeftPath = path != null ? new DataModelPath(path) : null;
ValidateOperator();
ValidateRightSide();
@@ -95,27 +82,14 @@ namespace Artemis.Core
///
/// Updates the right side of the predicate, makes the predicate dynamic and re-compiles the expression
///
- /// The data model of the right side value
/// The path pointing to the right side value inside the data model
- public void UpdateRightSide(DataModel? dataModel, string? path)
+ public void UpdateRightSideDynamic(DataModelPath? path)
{
- if (dataModel != null && path == null)
- throw new ArtemisCoreException("If a data model is provided, a path is also required");
- if (dataModel == null && path != null)
- throw new ArtemisCoreException("If path is provided, a data model is also required");
+ if (path != null && !path.IsValid)
+ throw new ArtemisCoreException("Cannot update right side of predicate to an invalid path");
RightPath?.Dispose();
- if (dataModel != null)
- {
- DataModelPath newPath = new DataModelPath(dataModel, path);
- if (!newPath.IsValid)
- throw new ArtemisCoreException($"New right path '{newPath}' is invalid");
- RightPath = newPath;
- }
- else
- {
- RightPath = null;
- }
+ RightPath = path != null ? new DataModelPath(path) : null;
PredicateType = ProfileRightSideType.Dynamic;
}
@@ -124,7 +98,7 @@ namespace Artemis.Core
/// Updates the right side of the predicate, makes the predicate static and re-compiles the expression
///
/// The right side value to use
- public void UpdateRightSide(object? staticValue)
+ public void UpdateRightSideStatic(object? staticValue)
{
PredicateType = ProfileRightSideType.Static;
RightPath?.Dispose();
@@ -253,7 +227,7 @@ namespace Artemis.Core
ConditionOperatorStore.ConditionOperatorRemoved += ConditionOperatorStoreOnConditionOperatorRemoved;
// Left side
- if (Entity.LeftPath != null)
+ if (Entity.LeftPath != null)
LeftPath = new DataModelPath(null, Entity.LeftPath);
// Operator
@@ -288,12 +262,12 @@ namespace Artemis.Core
rightSideValue = Activator.CreateInstance(leftSideType);
}
- UpdateRightSide(rightSideValue);
+ UpdateRightSideStatic(rightSideValue);
}
else
{
// Hope for the best...
- UpdateRightSide(JsonConvert.DeserializeObject(Entity.RightStaticValue));
+ UpdateRightSideStatic(JsonConvert.DeserializeObject(Entity.RightStaticValue));
}
}
catch (JsonReaderException)
@@ -328,14 +302,14 @@ namespace Artemis.Core
Type rightSideType = RightPath.GetPropertyType()!;
if (leftType != null && !leftType.IsCastableFrom(rightSideType))
- UpdateRightSide(null, null);
+ UpdateRightSideDynamic(null);
}
else
{
if (RightStaticValue != null && (leftType == null || leftType.IsCastableFrom(RightStaticValue.GetType())))
- UpdateRightSide(RightStaticValue);
+ UpdateRightSideStatic(RightStaticValue);
else
- UpdateRightSide(null);
+ UpdateRightSideStatic(null);
}
}
diff --git a/src/Artemis.Core/Models/Profile/DataModel/DataModelPath.cs b/src/Artemis.Core/Models/Profile/DataModel/DataModelPath.cs
index b98fcdcb4..78cc14677 100644
--- a/src/Artemis.Core/Models/Profile/DataModel/DataModelPath.cs
+++ b/src/Artemis.Core/Models/Profile/DataModel/DataModelPath.cs
@@ -14,6 +14,7 @@ namespace Artemis.Core
///
public class DataModelPath : IStorageModel, IDisposable
{
+ private bool _disposed;
private readonly LinkedList _segments;
private Expression>? _accessorLambda;
@@ -52,6 +53,26 @@ namespace Artemis.Core
SubscribeToDataModelStore();
}
+ ///
+ /// Creates a new instance of the class based on an existing path
+ ///
+ /// The path to base the new instance on
+ public DataModelPath(DataModelPath dataModelPath)
+ {
+ if (dataModelPath == null)
+ throw new ArgumentNullException(nameof(dataModelPath));
+
+ Target = dataModelPath.Target;
+ Path = dataModelPath.Path;
+ Entity = new DataModelPathEntity();
+
+ _segments = new LinkedList();
+
+ Save();
+ Initialize();
+ SubscribeToDataModelStore();
+ }
+
internal DataModelPath(DataModel? target, DataModelPathEntity entity)
{
Target = target;
@@ -65,26 +86,11 @@ namespace Artemis.Core
SubscribeToDataModelStore();
}
- internal DataModelPath(DataModelPath dataModelPath)
- {
- Target = dataModelPath.Target;
- Path = dataModelPath.Path;
- Entity = new DataModelPathEntity();
-
- _segments = new LinkedList();
-
- Save();
- Initialize();
- SubscribeToDataModelStore();
- }
-
///
/// Gets the data model at which this path starts
///
public DataModel? Target { get; private set; }
- internal DataModelPathEntity Entity { get; }
-
///
/// Gets the data model GUID of the if it is a
///
@@ -108,7 +114,10 @@ namespace Artemis.Core
///
/// Gets a boolean indicating whether this data model path points to a list
///
- public bool PointsToList => Segments.LastOrDefault()?.GetPropertyType() != null && typeof(IList).IsAssignableFrom(Segments.LastOrDefault()?.GetPropertyType());
+ public bool PointsToList => Segments.LastOrDefault()?.GetPropertyType() != null &&
+ typeof(IList).IsAssignableFrom(Segments.LastOrDefault()?.GetPropertyType());
+
+ internal DataModelPathEntity Entity { get; }
internal Func