mirror of
https://github.com/Artemis-RGB/Artemis
synced 2026-11-11 19:36:28 +00:00
Migrations - Added migration to segments
Layout - Fixed rotation not always applying (workaround) Conditions - Added string operators
This commit is contained in:
1 parent
dab11cb3e7
commit
385a30bec7
17 files changed
+317
-22
No files matched your search
@@ -34,6 +34,36 @@ namespace Artemis.Core.Models.Profile.Conditions
|
||||
/// </summary>
|
||||
public abstract string Icon { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets whether this condition operator supports a right side, defaults to true
|
||||
/// </summary>
|
||||
public bool SupportsRightSide { get; protected set; } = true;
|
||||
|
||||
public bool SupportsType(Type type)
|
||||
{
|
||||
if (type == null)
|
||||
return true;
|
||||
return CompatibleTypes.Any(t => t.IsCastableFrom(type));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a binary expression comparing two types
|
||||
/// </summary>
|
||||
/// <param name="leftSide">The parameter on the left side of the expression</param>
|
||||
/// <param name="rightSide">The parameter on the right side of the expression</param>
|
||||
/// <returns></returns>
|
||||
public abstract BinaryExpression CreateExpression(Expression leftSide, Expression rightSide);
|
||||
|
||||
/// <summary>
|
||||
/// Returns an expression that checks the given expression for null
|
||||
/// </summary>
|
||||
/// <param name="expression"></param>
|
||||
/// <returns></returns>
|
||||
protected Expression CreateNullCheckExpression(Expression expression)
|
||||
{
|
||||
return Expression.NotEqual(expression, Expression.Constant(null));
|
||||
}
|
||||
|
||||
internal void Register(PluginInfo pluginInfo, IDataModelService dataModelService)
|
||||
{
|
||||
if (_registered)
|
||||
@@ -63,20 +93,5 @@ namespace Artemis.Core.Models.Profile.Conditions
|
||||
// Profile editor service will call Unsubscribe
|
||||
_dataModelService.RemoveConditionOperator(this);
|
||||
}
|
||||
|
||||
public bool SupportsType(Type type)
|
||||
{
|
||||
if (type == null)
|
||||
return true;
|
||||
return CompatibleTypes.Any(t => t.IsCastableFrom(type));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a binary expression comparing two types
|
||||
/// </summary>
|
||||
/// <param name="leftSide">The parameter on the left side of the expression</param>
|
||||
/// <param name="rightSide">The parameter on the right side of the expression</param>
|
||||
/// <returns></returns>
|
||||
public abstract BinaryExpression CreateExpression(Expression leftSide, Expression rightSide);
|
||||
}
|
||||
}
|
||||
@@ -304,7 +304,11 @@ namespace Artemis.Core.Models.Profile.Conditions
|
||||
if (leftSideAccessor.Type.IsValueType && RightStaticValue == null)
|
||||
return;
|
||||
|
||||
var rightSideConstant = Expression.Constant(RightStaticValue);
|
||||
// If the right side value is null, the constant type cannot be inferred and must be provided manually
|
||||
var rightSideConstant = RightStaticValue != null
|
||||
? Expression.Constant(RightStaticValue)
|
||||
: Expression.Constant(null, leftSideAccessor.Type);
|
||||
|
||||
var conditionExpression = Operator.CreateExpression(leftSideAccessor, rightSideConstant);
|
||||
|
||||
StaticConditionLambda = Expression.Lambda<Func<DataModel, bool>>(conditionExpression, leftSideParameter);
|
||||
|
||||
+29
@@ -0,0 +1,29 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq.Expressions;
|
||||
using System.Reflection;
|
||||
|
||||
namespace Artemis.Core.Models.Profile.Conditions.Operators
|
||||
{
|
||||
public class StringContainsConditionOperator : DisplayConditionOperator
|
||||
{
|
||||
private readonly MethodInfo _toLower;
|
||||
private readonly MethodInfo _contains;
|
||||
|
||||
public StringContainsConditionOperator()
|
||||
{
|
||||
_toLower = typeof(string).GetMethod("ToLower", new Type[] { });
|
||||
_contains = typeof(string).GetMethod("Contains", new[] {typeof(string) });
|
||||
}
|
||||
|
||||
public override IReadOnlyCollection<Type> CompatibleTypes => new List<Type> {typeof(string)};
|
||||
|
||||
public override string Description => "Contains";
|
||||
public override string Icon => "Contain";
|
||||
|
||||
public override BinaryExpression CreateExpression(Expression leftSide, Expression rightSide)
|
||||
{
|
||||
return Expression.Equal(Expression.Call(Expression.Call(leftSide, _toLower), _contains, Expression.Call(rightSide, _toLower)), Expression.Constant(true));
|
||||
}
|
||||
}
|
||||
}
|
||||
+29
@@ -0,0 +1,29 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq.Expressions;
|
||||
using System.Reflection;
|
||||
|
||||
namespace Artemis.Core.Models.Profile.Conditions.Operators
|
||||
{
|
||||
public class StringEndsWithConditionOperator : DisplayConditionOperator
|
||||
{
|
||||
private readonly MethodInfo _toLower;
|
||||
private readonly MethodInfo _endsWith;
|
||||
|
||||
public StringEndsWithConditionOperator()
|
||||
{
|
||||
_toLower = typeof(string).GetMethod("ToLower", new Type[] { });
|
||||
_endsWith = typeof(string).GetMethod("EndsWith", new[] { typeof(string) });
|
||||
}
|
||||
|
||||
public override IReadOnlyCollection<Type> CompatibleTypes => new List<Type> { typeof(string) };
|
||||
|
||||
public override string Description => "Ends with";
|
||||
public override string Icon => "ContainEnd";
|
||||
|
||||
public override BinaryExpression CreateExpression(Expression leftSide, Expression rightSide)
|
||||
{
|
||||
return Expression.Equal(Expression.Call(Expression.Call(leftSide, _toLower), _endsWith, Expression.Call(rightSide, _toLower)), Expression.Constant(true));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq.Expressions;
|
||||
using System.Reflection;
|
||||
|
||||
namespace Artemis.Core.Models.Profile.Conditions.Operators
|
||||
{
|
||||
public class StringEqualsConditionOperator : DisplayConditionOperator
|
||||
{
|
||||
private readonly MethodInfo _toLower;
|
||||
|
||||
public StringEqualsConditionOperator()
|
||||
{
|
||||
_toLower = typeof(string).GetMethod("ToLower", new Type[] { });
|
||||
}
|
||||
|
||||
public override IReadOnlyCollection<Type> CompatibleTypes => new List<Type> {typeof(string)};
|
||||
|
||||
public override string Description => "Equals";
|
||||
public override string Icon => "Equal";
|
||||
|
||||
public override BinaryExpression CreateExpression(Expression leftSide, Expression rightSide)
|
||||
{
|
||||
return Expression.Equal(Expression.Call(leftSide, _toLower), Expression.Call(rightSide, _toLower));
|
||||
}
|
||||
}
|
||||
}
|
||||
+29
@@ -0,0 +1,29 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq.Expressions;
|
||||
using System.Reflection;
|
||||
|
||||
namespace Artemis.Core.Models.Profile.Conditions.Operators
|
||||
{
|
||||
public class StringNotContainsConditionOperator : DisplayConditionOperator
|
||||
{
|
||||
private readonly MethodInfo _toLower;
|
||||
private readonly MethodInfo _contains;
|
||||
|
||||
public StringNotContainsConditionOperator()
|
||||
{
|
||||
_toLower = typeof(string).GetMethod("ToLower", new Type[] { });
|
||||
_contains = typeof(string).GetMethod("Contains", new[] { typeof(string) });
|
||||
}
|
||||
|
||||
public override IReadOnlyCollection<Type> CompatibleTypes => new List<Type> { typeof(string) };
|
||||
|
||||
public override string Description => "Does not contain";
|
||||
public override string Icon => "FormatStrikethrough";
|
||||
|
||||
public override BinaryExpression CreateExpression(Expression leftSide, Expression rightSide)
|
||||
{
|
||||
return Expression.Equal(Expression.Call(Expression.Call(leftSide, _toLower), _contains, Expression.Call(rightSide, _toLower)), Expression.Constant(false));
|
||||
}
|
||||
}
|
||||
}
|
||||
+27
@@ -0,0 +1,27 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq.Expressions;
|
||||
using System.Reflection;
|
||||
|
||||
namespace Artemis.Core.Models.Profile.Conditions.Operators
|
||||
{
|
||||
public class StringNotEqualConditionOperator : DisplayConditionOperator
|
||||
{
|
||||
private readonly MethodInfo _toLower;
|
||||
|
||||
public StringNotEqualConditionOperator()
|
||||
{
|
||||
_toLower = typeof(string).GetMethod("ToLower", new Type[] { });
|
||||
}
|
||||
|
||||
public override IReadOnlyCollection<Type> CompatibleTypes => new List<Type> {typeof(string)};
|
||||
|
||||
public override string Description => "Does not equal";
|
||||
public override string Icon => "NotEqualVariant";
|
||||
|
||||
public override BinaryExpression CreateExpression(Expression leftSide, Expression rightSide)
|
||||
{
|
||||
return Expression.NotEqual(Expression.Call(leftSide, _toLower), Expression.Call(rightSide, _toLower));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq.Expressions;
|
||||
|
||||
namespace Artemis.Core.Models.Profile.Conditions.Operators
|
||||
{
|
||||
public class StringNullConditionOperator : DisplayConditionOperator
|
||||
{
|
||||
public StringNullConditionOperator()
|
||||
{
|
||||
SupportsRightSide = false;
|
||||
}
|
||||
|
||||
public override IReadOnlyCollection<Type> CompatibleTypes => new List<Type> {typeof(string)};
|
||||
|
||||
public override string Description => "Is null";
|
||||
public override string Icon => "Null";
|
||||
|
||||
public override BinaryExpression CreateExpression(Expression leftSide, Expression rightSide)
|
||||
{
|
||||
return Expression.Equal(leftSide, Expression.Constant(null, leftSide.Type));
|
||||
}
|
||||
}
|
||||
}
|
||||
+29
@@ -0,0 +1,29 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq.Expressions;
|
||||
using System.Reflection;
|
||||
|
||||
namespace Artemis.Core.Models.Profile.Conditions.Operators
|
||||
{
|
||||
public class StringStartsWithConditionOperator : DisplayConditionOperator
|
||||
{
|
||||
private readonly MethodInfo _toLower;
|
||||
private readonly MethodInfo _startsWith;
|
||||
|
||||
public StringStartsWithConditionOperator()
|
||||
{
|
||||
_toLower = typeof(string).GetMethod("ToLower", new Type[] { });
|
||||
_startsWith = typeof(string).GetMethod("StartsWith", new[] { typeof(string) });
|
||||
}
|
||||
|
||||
public override IReadOnlyCollection<Type> CompatibleTypes => new List<Type> { typeof(string) };
|
||||
|
||||
public override string Description => "Starts with";
|
||||
public override string Icon => "ContainStart";
|
||||
|
||||
public override BinaryExpression CreateExpression(Expression leftSide, Expression rightSide)
|
||||
{
|
||||
return Expression.Equal(Expression.Call(Expression.Call(leftSide, _toLower), _startsWith, Expression.Call(rightSide, _toLower)), Expression.Constant(true));
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user