//protected Type _type; //public CustomParameterBase(Type type) //{ // _type = type; //} public void Apply(IRuleElement element) { if (element is T t) { InnerApply(t); } }
public bool Process(IRuleElement variable, Operator @operator) { switch (@operator.Value) { case Operators.NotEqual: return(NotEqual(Value, variable.Value)); case Operators.Equal: return(Equal(Value, variable.Value)); case Operators.GreaterThan: return(GreaterThan(Value, variable.Value)); case Operators.GreaterThanOrEqual: return(GreaterThanOrEqual(Value, variable.Value)); case Operators.LessThan: return(LessThan(Value, variable.Value)); case Operators.LessThanOrEqual: return(LessThanOrEqual(Value, variable.Value)); case Operators.Contains: return(Contains(Value, variable.Value)); default: throw new ArgumentOutOfRangeException(nameof(@operator)); } }
public static IEnumerable <string> AllGraphicTags(this IRuleElement t) { var tags = new List <string>(); if (t.GraphicTag != null) { tags.Add(t.GraphicTag); } tags.AddRange(t.AlternativeGraphicTags); return(tags); }
/// <summary> /// Данный функционал вынесен отдельно для того, чтобы можно было повторно использовать в ModRuleEntity /// </summary> /// <typeparam name="T"></typeparam> /// <param name="rule"></param> /// <param name="serializerRoot"></param> /// <param name="definition"></param> /// <returns></returns> protected virtual T InnerGetRule <T>(ref IRuleElement rule, IRuleSerializerRoot serializerRoot, string definition) where T : IRuleElement { if (serializerRoot == null) { throw new ArgumentNullException(nameof(serializerRoot)); } if (rule == null) { rule = serializerRoot.Container <T>().Deserialize(definition); } return((T)rule); }
public static bool FindFirstTile <TRenderTile>(this ITileRegistry <TRenderTile> tileSet, IRuleElement t, out TRenderTile result) { foreach (var tg in t.AllGraphicTags()) { if (tileSet.TryFind(tg, out TRenderTile g)) { result = g; return(true); } } result = default(TRenderTile); return(false); }
private Proposition ProcessOperator(Guid contextId, Operator @operator) { IRuleElement rhs = _stack.Pop(); IRuleElement lhs = _stack.Pop(); string propName = string.Empty; if ((Operators)@operator.Value == Operators.Not) { propName = string.Join(" ", "(", @operator.Name, lhs.Name, ":", lhs.Value, ")"); } else { propName = string.Join(" ", "(", string.Join("", lhs.Name, ":", lhs.Value), @operator.Name, string.Join("", rhs.Name, ":", rhs.Value), ")"); } return(new Proposition(propName, lhs.Process(rhs, @operator))); }
public bool Process(IRuleElement inProposition, Operator @operator) { switch (@operator.Value) { case Operators.And: return(And((bool)Value, (bool)inProposition.Value)); case Operators.Not: return(Not((bool)Value)); case Operators.Or: return(Or((bool)Value, (bool)inProposition.Value)); case Operators.Xor: return(Xor((bool)Value, (bool)inProposition.Value)); default: throw new ArgumentOutOfRangeException(nameof(@operator)); } }
public override string Serialize(IRuleElement element) { throw new NotImplementedException(); }
public Proposition Evaluate(RuleContext context, Queue <IRuleElement> elements = default(Queue <IRuleElement>)) { if (elements == null) { elements = new Queue <IRuleElement>(Elements.ToArray()); } int count = elements.Count; int groupCount = 0; for (int i = 0; i < count; i++) { IRuleElement e = elements.Dequeue(); IRuleElement element = context.Find(e.Name); if (e.GetType() != typeof(Operator)) { _stack.Push(element ?? e); } else if ((Operators)e.Value == Operators.StartGrouping) { groupCount++; var rule = new Rule($"Group_{groupCount}"); var proposition = rule.Evaluate(context, elements); _stack.Push(proposition); count = elements.Count + 1; } else if ((Operators)e.Value == Operators.EndGrouping) { if (_stack.Count > 1) { throw new InvalidOperationException("Invalid group expression."); } return((Proposition)_stack.Pop()); } else { string cacheName = string.Join(" ", Name, context.Name); if (!cache.TryGetValue(cacheName, out Proposition proposition)) { proposition = ProcessOperator(context.Id, (Operator)e); if (i == (count - 1)) { cache.TryAdd(cacheName, proposition); return(proposition); } } if (i == (count - 1)) { return(proposition); } else { _stack.Push(proposition); } } } return((Proposition)_stack.Pop()); }
public bool Check(IRuleElement element) { return((element is T t) ? InnerCheck(t) : true); }
public bool CheckCustomParameters(IRuleElement element) { return(CheckParameters?.TrueForAll(c => c.Check(element)) ?? true); }
/// <summary> /// Применяет кастомные праметры к элементу, если таковые найдутся - соответствующие его типу /// </summary> public void ApplyCustomParameters(IRuleElement element) { ApplyParameters?.ForEach(c => c.Apply(element)); }
public bool Process(IRuleElement element, Operator @operator) { throw new InvalidOperationException("This operation is not available on this rule element."); }
public void AddElement(IRuleElement element) { _collection.Add(element); }