private static void PopulateConditionResults(object obj, object value, ValueCondition valueCondition, ConditionResult result, bool status) { result.Condition = valueCondition; result.Pattern.Add(status); if (status) // if it's passed. { result.PassedObjects.Add(obj); return; } result.FailedObjects.Add(obj); string valueString = value == null ? "null" : value.ToString(); if (valueString.Contains("BH.oM") && !(valueCondition.ReferenceValue is Type)) { valueString = BH.Engine.Reflection.Query.PropertyValue(value, "Name") as string; } string conditionText = valueCondition.ToString(); conditionText = conditionText.Replace(valueCondition.PropertyName + " ", ""); result.FailInfo.Add($"{(string.IsNullOrWhiteSpace(valueCondition.Clause) ? "" : valueCondition.Clause + " failed: ")}" + $"{valueCondition.PropertyName} must be {conditionText}, but is {valueString ?? "empty"}."); }
public void ToString_GreaterThan() { var vc = new ValueCondition <int>((e) => 0, "foo"); var c = vc > 7; Assert.AreEqual("foo > 7", c.ToString()); }
public List <TblUsers> GetUsers() { string ptrn = SearchPattern.Value; if (ptrn.IsNull()) { return(ServerModel.DB.Query <TblUsers>(null)); } else { var vc = new ValueCondition <string>("%" + ptrn + "%"); return(ServerModel.DB.Query <TblUsers>(new OrCondtion( new CompareCondition <string>( DataObject.Schema.Login, vc, COMPARE_KIND.LIKE), new CompareCondition <string>( DataObject.Schema.FirstName, vc, COMPARE_KIND.LIKE), new CompareCondition <string>( DataObject.Schema.Email, vc, COMPARE_KIND.LIKE) ))); } }
private static ConditionResult ConvertToValueConditionAndVerify(List <object> objects, IValueCondition cond) { ConditionResult result = new ConditionResult() { Condition = cond }; var refValue = cond.ReferenceValue; if (refValue == null) { BH.Engine.Reflection.Compute.RecordNote($"A {cond.GetType().Name}'s {nameof(cond.ReferenceValue)} was null. Make sure this is intended.\nTo check for null/not null, consider using a {nameof(IsNull)} instead."); } ValueCondition valueCondition = cond.ToValueCondition(); ConditionResult valueCondRes = VerifyCondition(objects, valueCondition); result.FailedObjects = valueCondRes.FailedObjects; result.PassedObjects = valueCondRes.PassedObjects; result.Pattern = valueCondRes.Pattern; result.FailInfo = valueCondRes.FailInfo; return(result); }
public List<TblUsers> GetUsers() { string ptrn = SearchPattern.Value; if (ptrn.IsNull()) { return ServerModel.DB.Query<TblUsers>(null); } else { var vc = new ValueCondition<string>("%" + ptrn + "%"); return ServerModel.DB.Query<TblUsers>(new OrCondtion( new CompareCondition<string>( DataObject.Schema.Login, vc, COMPARE_KIND.LIKE), new CompareCondition<string>( DataObject.Schema.FirstName, vc, COMPARE_KIND.LIKE), new CompareCondition<string>( DataObject.Schema.Email, vc, COMPARE_KIND.LIKE) )); } }
public void Build_ExpresstionWithCustomMethod_Test() { var con = new ValueCondition("A", CompareOperation.Equals, "NewID()"); var express = new DataTableExpressionRender().BuildCondition(con); Assert.IsTrue(express.Contains("NewID()")); }
public void ToString_LessEquals() { var vc = new ValueCondition <int>((e) => 0, "foo"); var c = vc <= 7; Assert.AreEqual("foo <= 7", c.ToString()); }
protected virtual string BuildValueCondition(ValueCondition fieldCondition, IDictionary <string, object> outPutParameters = null) { var builder = new StringBuilder() .Append(Common.GetSqlName(fieldCondition.Field)) .Append(GetOperator(fieldCondition.Operation)); switch (fieldCondition.Operation) { case CompareOperation.Contains: case CompareOperation.NotContains: case CompareOperation.StartsWith: case CompareOperation.EndsWith: { var value = string.Format(GetFilterPattern(fieldCondition.Operation), fieldCondition.Value); AddToBuilder(builder, outPutParameters, fieldCondition.Field, value); } break; case CompareOperation.In: case CompareOperation.NotIn: { builder.Append("("); var values = fieldCondition.Value as object[] ?? new[] { fieldCondition.Value }; for (var i = 0; i < values.Length; i++) { if (i > 0) { builder.Append(","); } AddToBuilder(builder, outPutParameters, fieldCondition.Field, values[i]); } builder.Append(")"); } break; case CompareOperation.IsNull: case CompareOperation.NotNull: break; case CompareOperation.Equals: case CompareOperation.NotEquals: case CompareOperation.GreaterThan: case CompareOperation.LessThan: case CompareOperation.GreaterThanOrEquals: case CompareOperation.LessThanOrEquals: AddToBuilder(builder, outPutParameters, fieldCondition.Field, fieldCondition.Value); break; } return(builder.ToString()); }
private static ConditionResult VerifyCondition(List <object> objects, IConditionTolerance comparisonCondition) { ValueCondition vc = comparisonCondition as ValueCondition; if (vc != null) { return(VerifyCondition(objects, vc)); } BH.Engine.Reflection.Compute.RecordError($"Failed to verify Condition of type {comparisonCondition.GetType().Name}"); return(new ConditionResult()); }
public override void Init() { Debug.Log("S"); _rootNode = new BTPrioritySelector(null); ValueCondition vc = new ValueCondition(10, true); ValueCondition vd = new ValueCondition(10, false); DieCondition die = new DieCondition(); EnemyInSight sight = new EnemyInSight(); CheckSelfToTargetDistance CTD = new CheckSelfToTargetDistance(vo.AttackDistance, false); CheckSelfToTargetDistance CTD2 = new CheckSelfToTargetDistance(vo.AttackDistance, true); AiTestAction1 first = new AiTestAction1(vc); AiTestAction2 second = new AiTestAction2(vd); BTDieAction dieAction = new BTDieAction(3); BTPortalAction portalAction = new BTPortalAction(); BTAttackAction attackAction = new BTAttackAction(vo.AttackCD); BTChaseAction ChaseAction = new BTChaseAction(); BTParallel p = new BTParallel(die); _rootNode.AddChild(p); p.AddChild(dieAction); p.AddChild(new PlayAnimatorAction("Die")); BTPrioritySelector Select = new BTPrioritySelector(null); BTPrioritySelector Select2 = new BTPrioritySelector(null); BTParallel p2 = new BTParallel(ParallelFunction.And, sight); _rootNode.AddChild(Select); Select.AddChild(p2); p2.AddChild(portalAction); p2.AddChild(new PlayAnimatorAction("Run")); Select.AddChild(Select2); BTParallel p3 = new BTParallel(ParallelFunction.And, CTD); p3.AddChild(attackAction); p3.AddChild(new PlayAnimatorAction("attack1")); BTParallel p4 = new BTParallel(ParallelFunction.Or, null); p4.AddChild(ChaseAction); p4.AddChild(new PlayAnimatorAction("Run")); Select2.AddChild(p3); Select2.AddChild(p4); }
protected virtual DataRow[] FindRowsByPrimaryKeys(DataRow row, DataTable compareTable) { Guard.ArgumentIsNotNull(CompareKeys, nameof(CompareKeys)); ICondition filter = null; foreach (var col in CompareKeys) { var con = new ValueCondition(col.Column, CompareOperation.Equals, GetValue(col, row)); filter = filter == null ? con : filter.And(con); } return(compareTable.Select(DataTableExpressionRender.BuildCondition(filter))); }
static string GetSymbol(ValueCondition condition) { switch (condition) { case ValueCondition.IsNull: return("IS NULL"); case ValueCondition.NotNull: return("IS NOT NULL"); default: throw new ArgumentException("Unknown WHERE operator: " + condition); } }
public StringProperty(Func <IA11yElement, string> valueGetter) { GetStringPropertyValue = valueGetter; this.Null = CreateNullCondition(); this.NotNull = ~Null; this.Empty = CreateEmptyCondition(); this.NotEmpty = ~Empty; this.NullOrEmpty = Null | Empty; this.NotNullOrEmpty = NotNull & NotEmpty; this.WhiteSpace = CreateWhitespaceCondition(); this.NotWhiteSpace = ~WhiteSpace; this.IncludesSpecialCharacters = CreateIncludesSpecialCharactersCondition(); this.ExcludesSpecialCharacters = ~IncludesSpecialCharacters; this.Length = CreateLengthCondition(); }
public static ValueCondition ToValueCondition(this IValueCondition iValueCondition) { ValueCondition valueCond = iValueCondition as ValueCondition; if (valueCond != null) { return(valueCond); } ValueComparisons valueComparison = ValueComparisons.EqualTo; switch (iValueCondition.GetType().Name) { case (nameof(IsEqualTo)): valueComparison = ValueComparisons.EqualTo; break; case (nameof(IsLessThan)): valueComparison = ValueComparisons.LessThan; break; case (nameof(IsLessThanOrEqualTo)): valueComparison = ValueComparisons.LessThanOrEqualTo; break; case (nameof(IsGreaterThan)): valueComparison = ValueComparisons.GreaterThan; break; case (nameof(IsGreaterThanOrEqualTo)): valueComparison = ValueComparisons.GreaterThanOrEqualTo; break; } ValueCondition valueCondition = new ValueCondition() { Clause = iValueCondition.Clause, Comment = iValueCondition.Comment, Comparison = valueComparison, Name = iValueCondition.Name, Source = iValueCondition.Source, ReferenceValue = iValueCondition.ReferenceValue, Tolerance = iValueCondition.Tolerance, PropertyName = iValueCondition.PropertyName }; return(valueCondition); }
public void Delete <TDataObject>(IList <int> ids) where TDataObject : class, IIntKeyedDataObject, new() { if (ids.Count > 0) { using (var scope = DBScope("Removing multiple " + typeof(TDataObject).Name + ". Count = " + ids.Count)) { foreach (var i in ids) { Logger.WriteLine("ID = " + i); Cache.Remove(FormatCacheKey <TDataObject>(i)); } RunInTransaction(scope.Connection, (cn, transaction) => { using (var cmd = cn.CreateCommand()) { cmd.Transaction = transaction; var sc = new SqlSerializationContext((SqlCommand)cmd); DataObjectSqlSerializer <TDataObject> . AppendSoftDeleteSql(sc, ids); sc.Finish(); cmd.LexExecuteNonQuery(); } if (DataObjectInfo <TDataObject> .IsSecured) { var idCond = new ValueCondition <int>(0); var updOp = new UpdateOperation <TblPermissions>( new CompareCondition <int> ( new PropertyCondition <int>(ObjectTypeHelper.GetObjectType(typeof(TDataObject)).GetSecurityAtr().Name + "Ref"), idCond, COMPARE_KIND.EQUAL ), new PropertyAssignement <int>(DataObject.Schema.SysState, new ValueCondition <int>(1))); foreach (var id in ids) { idCond.Value = id; Update(updOp, cn, transaction); } } }); } } }
public void Triggers_ValueCondition_TriggerCount(MatchType matchType, int cmp, int count_until_exclusive, int expected_result) { ObservableValue <int> x = new ObservableValue <int>(-1); ICondition cond = new ValueCondition <int>(ref x, matchType, cmp); int triggercount = 0; Action action = () => { triggercount++; Console.Write(" " + x.Value); }; Trigger trigger = new Trigger(cond, action); Console.Write("Trigger at: "); for (int i = 0; i < count_until_exclusive; i++) { x.Value = i; } Assert.That(triggercount, Is.EqualTo(expected_result)); }
/// <summary> /// StringProperty constructor with property description /// </summary> /// <param name="valueGetter"></param> /// <param name="propertyDescription"> /// Represents a string property of an element such as "Name", "LocalizedControlType", etc. /// This may also apply to patterns, so please include the pattern name where applicable. /// This information may be visible to users. /// </param> public StringProperty(Func <IA11yElement, string> valueGetter, string propertyDescription) { GetStringPropertyValue = valueGetter; PropertyDescription = propertyDescription; this.Null = CreateNullCondition(); this.Empty = CreateEmptyCondition(); this.NotNull = ~Null; this.NotEmpty = ~Empty; this.NullOrEmpty = Null | Empty; this.NotNullOrEmpty = NotNull & NotEmpty; this.WhiteSpace = CreateWhitespaceCondition(); this.NotWhiteSpace = ~WhiteSpace; this.NullOrWhiteSpace = NullOrEmpty | WhiteSpace; this.NotNullOrWhiteSpace = ~NullOrWhiteSpace; this.IncludesPrivateUnicodeCharacters = CreateIncludesPrivateUnicodeCharactersCondition(); this.ExcludesPrivateUnicodeCharacters = ~IncludesPrivateUnicodeCharacters; this.Length = CreateLengthCondition(); }
public void Triggers_ValueCondition_TriggerCount_Or(MatchType matchType1, int cmp1, MatchType matchType2, int cmp2, int count_until_exclusive, int expected_result) { ObservableValue <int> x = new ObservableValue <int>(-1); ICondition cond1 = new ValueCondition <int>(ref x, matchType1, cmp1); ICondition cond2 = new ValueCondition <int>(ref x, matchType2, cmp2); int triggercount = 0; Action action = () => { triggercount++; Console.Write(" " + x.Value); }; Trigger trigger = new Trigger(cond1.Or(cond2), action); Console.Write("Trigger at: "); for (int i = 0; i < count_until_exclusive; i++) { x.Value = i; } Assert.That(triggercount, Is.EqualTo(expected_result * 2)); // because there are two observable links, 2 events is expected per change. }
public void PopulateSteps() { Step s = new Step(browser, dal, -1); ValueCondition vc = new ValueCondition("this is a text area", dal, browser); vc.ConditionElement = aux; TypeAction ta = new TypeAction("I found a little 'Chrome'", dal, browser, main); ClickAction ca = new ClickAction(dal, browser, button); s.Conditions.Add(vc); s.Actions.Add(ta); s.Actions.Add(ca); steps.Add(s); steps.Add(s); steps.Add(s); steps.Add(s); }
internal SchemaTypeSingleCondition(StringLiteral s) { RawCondition = s.Value; var cp = new ConditionParser("[" + RawCondition + "]"); var cnd = cp.Parse(); if (cnd.Count != 1) { throw new InvalidDataException("Invalid condition '" + RawCondition + "'."); } var c0 = cnd[0] as ValueCondition; if (c0 == null) { throw new InvalidDataException("Invalid condition '" + RawCondition + "'."); } Condition = c0; }
public override IDataBase GetDataBase() { if (!outSocket.IsConnected() || !inputSocket01.IsConnected()) { return(default(IDataBase)); } ValueCondition condition = new ValueCondition(); JsonValueCondition json = new JsonValueCondition(); json.typeID = Id; json.value1 = v1; json.value2 = v2; json.percentage = percentage; json.valueType = (int)valueType; json.valueConditionType = (int)valueConditionType; json.nextStateID = GetOutputAiId; json.currestStateID = GetInputAiId; json.createType = condition.GetType().FullName; return(json); }
public void GetHashCode_ThrowsNotSupportedException() { var p = new ValueCondition <string>((e) => "abc", "test"); p.GetHashCode(); }
public void Equals_OtherIsDifferentType_ThrowsNotSupportedException() { var p = new ValueCondition <string>((e) => "abc", "test"); p.Equals("abc"); }
public PPriceSensor(string instrument, ValueCondition greaterOrEqual, decimal price) { this.Instrument = instrument; this.ValueCondition = greaterOrEqual; this.Value = price; }
/// <summary> /// Represents a coditional clause the column is set to fit a specific condition. /// </summary> /// <param name="column"></param> /// <param name="condition"></param> public WhereClause(string column, ValueCondition condition) : this() { whereClauseString = string.Format("{0} {1}", column, GetSymbol(condition) ); }
/// <summary> /// Append a new conition with a logical AND and cast to another query type /// </summary> /// <typeparam name="Q"></typeparam> /// <param name="column"></param> /// <param name="condition"></param> /// <returns></returns> public Q Where <Q>(string column, ValueCondition condition) where Q : ConditionalQuery { return((Q)Where(new WhereClause(column, condition))); }
/// <summary> /// Append a new conition with a logical AND /// </summary> /// <param name="column"></param> /// <param name="condition"></param> /// <returns></returns> public ConditionalQuery Where(string column, ValueCondition condition) { return(Where(new WhereClause(column, condition))); }
private static ConditionResult VerifyCondition(List <object> objects, ValueCondition valueCondition) { ConditionResult conditionResult = new ConditionResult() { Condition = valueCondition }; var refValue = valueCondition.ReferenceValue; if (refValue == null) { BH.Engine.Reflection.Compute.RecordNote($"A {nameof(ValueCondition)}'s {nameof(valueCondition.ReferenceValue)} was null. Make sure this is intended.\nTo check for null/not null, consider using a {nameof(IsNull)} instead."); } foreach (var obj in objects) { bool passed = true; // Value to be compared to the referenceValue. object value = obj.ValueFromSource(valueCondition.PropertyName); // If no propertyName was assigned, assume we want to compare the entire object. if (string.IsNullOrWhiteSpace(valueCondition.PropertyName)) { value = obj; } // Basic cases (check for nullity) if (valueCondition.ReferenceValue == null && value == null) { passed = true; PopulateConditionResults(obj, value, valueCondition, conditionResult, passed); continue; } if (valueCondition.ReferenceValue == null && value != null) { passed = false; PopulateConditionResults(obj, value, valueCondition, conditionResult, passed); continue; } else if (valueCondition.ReferenceValue != null && value == null) { if (valueCondition.PropertyName == "Type" && valueCondition.ReferenceValue is Type) { passed = obj.GetType() == (Type)valueCondition.ReferenceValue; } else { passed = false; } PopulateConditionResults(obj, value, valueCondition, conditionResult, passed); continue; } // Try a numerical comparison. double numericalValue; if (double.TryParse(value?.ToString(), out numericalValue)) { double referenceNumValue; double.TryParse(valueCondition.ReferenceValue?.ToString(), out referenceNumValue); double numTolerance; if (!double.TryParse(valueCondition.Tolerance?.ToString(), out numTolerance)) { numTolerance = 1e-03; } passed = NumericalComparison(numericalValue, referenceNumValue, numTolerance, valueCondition.Comparison); PopulateConditionResults(obj, value, valueCondition, conditionResult, passed); continue; } // Consider some other way to compare objects. if (valueCondition.Comparison == ValueComparisons.EqualTo) { // If the referenceValue is a Type, convert this ValueCondition to a IsOfType condition. if (valueCondition.ReferenceValue is Type) { IsOfType typeCondition = new IsOfType() { Type = valueCondition.ReferenceValue as Type }; var TypeCondResult = VerifyCondition(new List <object>() { value }, typeCondition); conditionResult.PassedObjects.Add(TypeCondResult.PassedObjects); conditionResult.FailedObjects.Add(TypeCondResult.FailedObjects); conditionResult.FailInfo.Add(TypeCondResult.FailInfo.FirstOrDefault()); conditionResult.Pattern.Add(TypeCondResult.Pattern.FirstOrDefault()); conditionResult.Condition = valueCondition; continue; } passed = CompareEquality(value, valueCondition.ReferenceValue, valueCondition.Tolerance); PopulateConditionResults(obj, value, valueCondition, conditionResult, passed); } } return(conditionResult); }