Condition VMs - Simplification WIPpepepepe

This commit is contained in:
SpoinkyNL committed 2020-10-08 22:21:17 +02:00
1 parent 805cdc6782
commit 94bde1fe38
11 files changed
+73 -103

No files matched your search

@@ -2,7 +2,6 @@
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using Artemis.Core.DataModelExpansions;
using Artemis.Storage.Entities.Profile.Abstract;
using Artemis.Storage.Entities.Profile.Conditions;
@@ -73,47 +72,36 @@ namespace Artemis.Core
/// <summary>
/// Updates the list the predicate is evaluated on
/// </summary>
/// <param name="dataModel">The data model of the list</param>
/// <param name="path">The path pointing to the list inside the list</param>
public void UpdateList(DataModel? dataModel, string? path)
public void UpdateList(DataModelPath? path)
{
if (_disposed)
throw new ObjectDisposedException("DataModelConditionList");
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 list to an invalid path");
ListPath?.Dispose();
if (dataModel != null && path != null)
{
DataModelPath newPath = new DataModelPath(dataModel, path);
if (!newPath.IsValid)
throw new ArtemisCoreException($"New left path '{newPath}' is invalid");
Type listType = newPath.GetPropertyType()!;
if (!typeof(IList).IsAssignableFrom(listType))
throw new ArtemisCoreException($"Data model of type {dataModel.GetType().Name} does not contain a list at path '{newPath}'");
ListPath = path;
ListPath = newPath;
// Remove the old root group that was tied to the old data model
while (Children.Any())
RemoveChild(Children[0]);
if (path != null)
{
Type listType = path.GetPropertyType()!;
ListType = listType.GetGenericArguments()[0];
IsPrimitiveList = ListType.IsPrimitive || ListType.IsEnum || ListType == typeof(string);
// Create a new root group
AddChild(new DataModelConditionGroup(this));
}
else
{
ListPath = null;
ListType = null;
}
// Remove the old root group that was tied to the old data model
while (Children.Any())
RemoveChild(Children[0]);
if (dataModel == null)
return;
// Create a new root group
AddChild(new DataModelConditionGroup(this));
}
#region IDisposable
@@ -90,13 +90,10 @@ namespace Artemis.Core
/// 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)
public void UpdateRightSideDynamicList(DataModelPath? path)
{
RightPath?.Dispose();
if (path != null && DataModelConditionList.ListType != null)
RightPath = new DataModelPath(ListPredicateWrapperDataModel.Create(DataModelConditionList.ListType), path);
else
RightPath = null;
RightPath = path;
PredicateType = ListRightSideType.DynamicList;
}
@@ -105,27 +102,11 @@ namespace Artemis.Core
/// Updates the right side of the predicate using path to a value in a data model, makes the predicate dynamic and
/// re-compiles the expression
/// </summary>
/// <param name="dataModel"></param>
/// <param name="path">The path pointing to the right side value inside the list</param>
public void UpdateRightSideDynamic(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");
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;
PredicateType = ListRightSideType.Dynamic;
}
@@ -391,7 +372,7 @@ namespace Artemis.Core
Type rightSideType = RightPath.GetPropertyType()!;
if (leftType != null && !leftType.IsCastableFrom(rightSideType))
UpdateRightSideDynamic(null, null);
UpdateRightSideDynamic(null);
}
else if (PredicateType == ListRightSideType.DynamicList)
{
@@ -400,7 +381,7 @@ namespace Artemis.Core
Type rightSideType = RightPath.GetPropertyType()!;
if (leftType != null && !leftType.IsCastableFrom(rightSideType))
UpdateRightSideDynamic(null);
UpdateRightSideDynamicList(null);
}
else
{
@@ -190,7 +190,7 @@ namespace Artemis.Core
/// </summary>
/// <param name="dataModel">The data model of the parameter</param>
/// <param name="path">The path pointing to the parameter inside the data model</param>
public void UpdateParameter(DataModel dataModel, string path)
public void UpdateParameter(DataModel? dataModel, string? path)
{
if (_disposed)
throw new ObjectDisposedException("DataBindingModifier");
@@ -65,6 +65,19 @@ namespace Artemis.Core
SubscribeToDataModelStore();
}
internal DataModelPath(DataModelPath dataModelPath)
{
Target = dataModelPath.Target;
Path = dataModelPath.Path;
Entity = new DataModelPathEntity();
_segments = new LinkedList<DataModelPathSegment>();
Save();
Initialize();
SubscribeToDataModelStore();
}
/// <summary>
/// Gets the data model at which this path starts
/// </summary>