Core - Flattened namespaces

Shared UI - Flattened namespaces
Shared UI - General housekeeping
Project - Code cleanup
This commit is contained in:
SpoinkyNL committed 2020-09-01 00:14:08 +02:00
1 parent 029e39ec1d
commit 8718d01eae
454 files changed
+1678 -1938

No files matched your search

@@ -1,8 +1,8 @@
using System.Collections.Generic;
using Artemis.Core.Services.Interfaces;
using Artemis.Core.Services;
using Artemis.Storage.Entities.Profile.Abstract;
namespace Artemis.Core.Models.Profile.Conditions.Abstract
namespace Artemis.Core
{
/// <summary>
/// An abstract class for display condition parts
@@ -10,7 +10,7 @@ namespace Artemis.Core.Models.Profile.Conditions.Abstract
public abstract class DisplayConditionPart
{
private readonly List<DisplayConditionPart> _children = new List<DisplayConditionPart>();
/// <summary>
/// Gets the parent of this part
/// </summary>
@@ -1,12 +1,10 @@
using System;
using System.Linq;
using Artemis.Core.Models.Profile.Conditions.Abstract;
using Artemis.Core.Services.Interfaces;
using Artemis.Storage.Entities.Profile;
using Artemis.Core.Services;
using Artemis.Storage.Entities.Profile.Abstract;
using Artemis.Storage.Entities.Profile.Conditions;
namespace Artemis.Core.Models.Profile.Conditions
namespace Artemis.Core
{
/// <summary>
/// A group containing zero to many <see cref="DisplayConditionPart" />s which it evaluates using a boolean specific
@@ -2,15 +2,12 @@
using System.Collections;
using System.Linq;
using System.Linq.Expressions;
using Artemis.Core.Exceptions;
using Artemis.Core.Models.Profile.Conditions.Abstract;
using Artemis.Core.Plugins.DataModelExpansions;
using Artemis.Core.Services.Interfaces;
using Artemis.Storage.Entities.Profile;
using Artemis.Core.DataModelExpansions;
using Artemis.Core.Services;
using Artemis.Storage.Entities.Profile.Abstract;
using Artemis.Storage.Entities.Profile.Conditions;
namespace Artemis.Core.Models.Profile.Conditions
namespace Artemis.Core
{
public class DisplayConditionList : DisplayConditionPart
{
@@ -33,6 +30,8 @@ namespace Artemis.Core.Models.Profile.Conditions
public DataModel ListDataModel { get; private set; }
public string ListPropertyPath { get; private set; }
public Func<object, IList> CompiledListAccessor { get; set; }
public override bool Evaluate()
{
if (CompiledListAccessor == null)
@@ -59,6 +58,47 @@ namespace Artemis.Core.Models.Profile.Conditions
};
}
public void UpdateList(DataModel dataModel, string path)
{
if (dataModel != null && path == null)
throw new ArtemisCoreException("If a data model is provided, a path is also required");
if (dataModel == null && path != null)
throw new ArtemisCoreException("If path is provided, a data model is also required");
if (dataModel != null)
{
if (!dataModel.ContainsPath(path))
throw new ArtemisCoreException($"Data model of type {dataModel.GetType().Name} does not contain a property at path '{path}'");
if (dataModel.GetListTypeAtPath(path) == null)
throw new ArtemisCoreException($"The path '{path}' does not contain a list");
}
// Remove the old root group that was tied to the old data model
while (Children.Any())
RemoveChild(Children[0]);
ListDataModel = dataModel;
ListPropertyPath = path;
if (dataModel == null)
return;
// Create a new root group
AddChild(new DisplayConditionGroup(this));
CreateExpression();
}
public void CreateExpression()
{
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();
}
internal override void ApplyToEntity()
{
// Target list
@@ -103,51 +143,9 @@ namespace Artemis.Core.Models.Profile.Conditions
Entity.Children.Clear();
AddChild(new DisplayConditionGroup(this));
}
Children[0].Initialize(dataModelService);
}
public void UpdateList(DataModel dataModel, string path)
{
if (dataModel != null && path == null)
throw new ArtemisCoreException("If a data model is provided, a path is also required");
if (dataModel == null && path != null)
throw new ArtemisCoreException("If path is provided, a data model is also required");
if (dataModel != null)
{
if (!dataModel.ContainsPath(path))
throw new ArtemisCoreException($"Data model of type {dataModel.GetType().Name} does not contain a property at path '{path}'");
if (dataModel.GetListTypeAtPath(path) == null)
throw new ArtemisCoreException($"The path '{path}' does not contain a list");
}
// Remove the old root group that was tied to the old data model
while (Children.Any())
RemoveChild(Children[0]);
ListDataModel = dataModel;
ListPropertyPath = path;
if (dataModel == null)
return;
// Create a new root group
AddChild(new DisplayConditionGroup(this));
CreateExpression();
}
public void CreateExpression()
{
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();
}
public Func<object, IList> CompiledListAccessor { get; set; }
}
public enum ListOperator
@@ -1,16 +1,13 @@
using System;
using System.Linq;
using System.Linq.Expressions;
using Artemis.Core.Exceptions;
using Artemis.Core.Extensions;
using Artemis.Core.Models.Profile.Conditions.Abstract;
using Artemis.Core.Plugins.DataModelExpansions;
using Artemis.Core.Services.Interfaces;
using Artemis.Core.DataModelExpansions;
using Artemis.Core.Services;
using Artemis.Storage.Entities.Profile.Abstract;
using Artemis.Storage.Entities.Profile.Conditions;
using Newtonsoft.Json;
namespace Artemis.Core.Models.Profile.Conditions
namespace Artemis.Core
{
public class DisplayConditionListPredicate : DisplayConditionPart
{
@@ -2,11 +2,9 @@
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using Artemis.Core.Extensions;
using Artemis.Core.Plugins;
using Artemis.Core.Services.Interfaces;
using Artemis.Core.Services;
namespace Artemis.Core.Models.Profile.Conditions
namespace Artemis.Core
{
/// <summary>
/// A display condition operator is used by the conditions system to perform a specific boolean check
@@ -1,16 +1,13 @@
using System;
using System.Linq;
using System.Linq.Expressions;
using Artemis.Core.Exceptions;
using Artemis.Core.Extensions;
using Artemis.Core.Models.Profile.Conditions.Abstract;
using Artemis.Core.Plugins.DataModelExpansions;
using Artemis.Core.Services.Interfaces;
using Artemis.Core.DataModelExpansions;
using Artemis.Core.Services;
using Artemis.Storage.Entities.Profile.Abstract;
using Artemis.Storage.Entities.Profile.Conditions;
using Newtonsoft.Json;
namespace Artemis.Core.Models.Profile.Conditions
namespace Artemis.Core
{
/// <summary>
/// A predicate in a display condition using either two data model values or one data model value and a
@@ -198,8 +195,10 @@ namespace Artemis.Core.Models.Profile.Conditions
var leftType = LeftDataModel.GetTypeAtPath(LeftPropertyPath);
if (!displayConditionOperator.SupportsType(leftType))
{
throw new ArtemisCoreException($"Cannot apply operator {displayConditionOperator.GetType().Name} to this predicate because " +
$"it does not support left side type {leftType.Name}");
}
Operator = displayConditionOperator;
CreateExpression();
@@ -2,7 +2,7 @@
using System.Collections.Generic;
using System.Linq.Expressions;
namespace Artemis.Core.Models.Profile.Conditions.Operators
namespace Artemis.Core
{
internal class EqualsConditionOperator : DisplayConditionOperator
{
@@ -2,7 +2,7 @@
using System.Collections.Generic;
using System.Linq.Expressions;
namespace Artemis.Core.Models.Profile.Conditions.Operators
namespace Artemis.Core
{
internal class GreaterThanConditionOperator : DisplayConditionOperator
{
@@ -2,7 +2,7 @@
using System.Collections.Generic;
using System.Linq.Expressions;
namespace Artemis.Core.Models.Profile.Conditions.Operators
namespace Artemis.Core
{
internal class GreaterThanOrEqualConditionOperator : DisplayConditionOperator
{
@@ -2,7 +2,7 @@
using System.Collections.Generic;
using System.Linq.Expressions;
namespace Artemis.Core.Models.Profile.Conditions.Operators
namespace Artemis.Core
{
internal class LessThanConditionOperator : DisplayConditionOperator
{
@@ -2,7 +2,7 @@
using System.Collections.Generic;
using System.Linq.Expressions;
namespace Artemis.Core.Models.Profile.Conditions.Operators
namespace Artemis.Core
{
internal class LessThanOrEqualConditionOperator : DisplayConditionOperator
{
@@ -2,11 +2,11 @@
using System.Collections.Generic;
using System.Linq.Expressions;
namespace Artemis.Core.Models.Profile.Conditions.Operators
namespace Artemis.Core
{
internal class NotEqualConditionOperator : DisplayConditionOperator
{
public override IReadOnlyCollection<Type> CompatibleTypes => new List<Type> { typeof(object) };
public override IReadOnlyCollection<Type> CompatibleTypes => new List<Type> {typeof(object)};
public override string Description => "Does not equal";
public override string Icon => "NotEqualVariant";
@@ -3,17 +3,17 @@ using System.Collections.Generic;
using System.Linq.Expressions;
using System.Reflection;
namespace Artemis.Core.Models.Profile.Conditions.Operators
namespace Artemis.Core
{
internal class StringContainsConditionOperator : DisplayConditionOperator
{
private readonly MethodInfo _toLower;
private readonly MethodInfo _contains;
private readonly MethodInfo _toLower;
public StringContainsConditionOperator()
{
_toLower = typeof(string).GetMethod("ToLower", new Type[] { });
_contains = typeof(string).GetMethod("Contains", new[] {typeof(string) });
_contains = typeof(string).GetMethod("Contains", new[] {typeof(string)});
}
public override IReadOnlyCollection<Type> CompatibleTypes => new List<Type> {typeof(string)};
@@ -3,20 +3,20 @@ using System.Collections.Generic;
using System.Linq.Expressions;
using System.Reflection;
namespace Artemis.Core.Models.Profile.Conditions.Operators
namespace Artemis.Core
{
internal class StringEndsWithConditionOperator : DisplayConditionOperator
{
private readonly MethodInfo _toLower;
private readonly MethodInfo _endsWith;
private readonly MethodInfo _toLower;
public StringEndsWithConditionOperator()
{
_toLower = typeof(string).GetMethod("ToLower", new Type[] { });
_endsWith = typeof(string).GetMethod("EndsWith", new[] { typeof(string) });
_endsWith = typeof(string).GetMethod("EndsWith", new[] {typeof(string)});
}
public override IReadOnlyCollection<Type> CompatibleTypes => new List<Type> { typeof(string) };
public override IReadOnlyCollection<Type> CompatibleTypes => new List<Type> {typeof(string)};
public override string Description => "Ends with";
public override string Icon => "ContainEnd";
@@ -3,7 +3,7 @@ using System.Collections.Generic;
using System.Linq.Expressions;
using System.Reflection;
namespace Artemis.Core.Models.Profile.Conditions.Operators
namespace Artemis.Core
{
internal class StringEqualsConditionOperator : DisplayConditionOperator
{
@@ -3,20 +3,20 @@ using System.Collections.Generic;
using System.Linq.Expressions;
using System.Reflection;
namespace Artemis.Core.Models.Profile.Conditions.Operators
namespace Artemis.Core
{
internal class StringNotContainsConditionOperator : DisplayConditionOperator
{
private readonly MethodInfo _toLower;
private readonly MethodInfo _contains;
private readonly MethodInfo _toLower;
public StringNotContainsConditionOperator()
{
_toLower = typeof(string).GetMethod("ToLower", new Type[] { });
_contains = typeof(string).GetMethod("Contains", new[] { typeof(string) });
_contains = typeof(string).GetMethod("Contains", new[] {typeof(string)});
}
public override IReadOnlyCollection<Type> CompatibleTypes => new List<Type> { typeof(string) };
public override IReadOnlyCollection<Type> CompatibleTypes => new List<Type> {typeof(string)};
public override string Description => "Does not contain";
public override string Icon => "FormatStrikethrough";
@@ -3,7 +3,7 @@ using System.Collections.Generic;
using System.Linq.Expressions;
using System.Reflection;
namespace Artemis.Core.Models.Profile.Conditions.Operators
namespace Artemis.Core
{
internal class StringNotEqualConditionOperator : DisplayConditionOperator
{
@@ -2,7 +2,7 @@
using System.Collections.Generic;
using System.Linq.Expressions;
namespace Artemis.Core.Models.Profile.Conditions.Operators
namespace Artemis.Core
{
internal class StringNullConditionOperator : DisplayConditionOperator
{
@@ -3,20 +3,20 @@ using System.Collections.Generic;
using System.Linq.Expressions;
using System.Reflection;
namespace Artemis.Core.Models.Profile.Conditions.Operators
namespace Artemis.Core
{
internal class StringStartsWithConditionOperator : DisplayConditionOperator
{
private readonly MethodInfo _toLower;
private readonly MethodInfo _startsWith;
private readonly MethodInfo _toLower;
public StringStartsWithConditionOperator()
{
_toLower = typeof(string).GetMethod("ToLower", new Type[] { });
_startsWith = typeof(string).GetMethod("StartsWith", new[] { typeof(string) });
_startsWith = typeof(string).GetMethod("StartsWith", new[] {typeof(string)});
}
public override IReadOnlyCollection<Type> CompatibleTypes => new List<Type> { typeof(string) };
public override IReadOnlyCollection<Type> CompatibleTypes => new List<Type> {typeof(string)};
public override string Description => "Starts with";
public override string Icon => "ContainStart";