public UserControl Build(HermesViewModel parent, BooleanFunction model) { if (model == null) { return(null); } if (model is ComparisonOperator) { ComparisonOperatorViewModel viewModel = new ComparisonOperatorViewModel(parent, (ComparisonOperator)model); _View = new ComparisonOperatorView(viewModel); } else if (model is BooleanOperator) { BooleanOperator bo = (BooleanOperator)model; BooleanOperatorViewModel viewModel = new BooleanOperatorViewModel(parent, bo); List <BooleanFunctionViewModel> ovms = new List <BooleanFunctionViewModel>(); foreach (BooleanFunction f in bo.Operands) { ComparisonOperatorViewModel covm = new ComparisonOperatorViewModel(viewModel, (ComparisonOperator)f); ovms.Add(covm); } viewModel.Operands = new ObservableCollection <BooleanFunctionViewModel>(ovms); _View = new BooleanOperatorView(viewModel); } return(_View); }
/// <summary> /// Initializes a new instance of the <see cref="ConditionPair" /> class. /// </summary> /// <param name="type">The operator used to combine this collection with previous conditions.</param> /// <param name="left">The left condition.</param> /// <param name="right">The right condition.</param> /// <param name="nested">True if this collection is nested (wrapped in parentheses.</param> public ConditionPair(BooleanOperator type, ConditionBase left, ConditionBase right, bool nested) { Left = left; Right = right; IsNested = nested; BooleanOperator = type; }
public void Equals_GivenConditionValues_ShouldReturnTrue(string leftConditionTableName, string leftConditionColumnName, EqualityOperators leftConditionOperator, object leftConditionValue, BooleanOperator booleanOperator, string rightConditionTableName, string rightConditionColumnName, EqualityOperators rightConditionOperator, object rightConditionValue) { //---------------Set up test pack------------------- var leftCondition = new ConditionModel(leftConditionTableName, leftConditionColumnName, leftConditionOperator, leftConditionValue) { DatabaseProvider = new SqlServerDatabaseProvider() }; var rightCondition = new ConditionModel(rightConditionTableName, rightConditionColumnName, rightConditionOperator, rightConditionValue) { DatabaseProvider = new SqlServerDatabaseProvider() }; var conditionModel = new CompoundConditionModel(leftCondition, booleanOperator, rightCondition) { DatabaseProvider = new SqlServerDatabaseProvider() }; var compareCondition = new CompoundConditionModel(leftCondition, booleanOperator, rightCondition) { DatabaseProvider = new SqlServerDatabaseProvider() }; //---------------Assert Precondition---------------- //---------------Execute Test ---------------------- var equalResult = conditionModel.Equals(compareCondition); //---------------Test Result ----------------------- Assert.IsTrue(equalResult); }
public RangeOperation(BooleanOperator booleanOperator, string field, object from, object to) { Field = field; From = from; To = to; Operator = booleanOperator; }
public override BooleanFunction ReadJson(JsonReader reader, Type objectType, BooleanFunction existingValue, bool hasExistingValue, JsonSerializer serializer) { if (reader.TokenType == JsonToken.Null) { return(null); } JObject json = JObject.Load(reader); BooleanFunction target; JProperty operandsProperty = json.Properties().Where(p => p.Name == "Operands").FirstOrDefault(); if (operandsProperty == null) { target = new ComparisonOperator(null); DeserializeComparisonOperator(serializer, json, (ComparisonOperator)target); } else { target = new BooleanOperator(null); DeserializeBooleanOperator(serializer, json, (BooleanOperator)target); } return(target); }
public void ToString_GivenConditionValues_ShouldReturnExpectedStatement(string leftConditionTableName, string leftConditionColumnName, EqualityOperators leftConditionOperator, object leftConditionValue, BooleanOperator booleanOperator, string rightConditionTableName, string rightConditionColumnName, EqualityOperators rightConditionOperator, object rightConditionValue, string expectedStatement) { //---------------Set up test pack------------------- var leftCondition = new ConditionModel(leftConditionTableName, leftConditionColumnName, leftConditionOperator, leftConditionValue) { DatabaseProvider = new SqlServerDatabaseProvider() }; var rightCondition = new ConditionModel(rightConditionTableName, rightConditionColumnName, rightConditionOperator, rightConditionValue) { DatabaseProvider = new SqlServerDatabaseProvider() }; var compoundCondition = new CompoundConditionModel(leftCondition, booleanOperator, rightCondition) { DatabaseProvider = new SqlServerDatabaseProvider() }; //---------------Assert Precondition---------------- //---------------Execute Test ---------------------- var selectStatement = compoundCondition.ToString(); //---------------Test Result ----------------------- Assert.AreEqual(expectedStatement, selectStatement); }
public BooleanCombinationFilter(BooleanOperator op, IEnumerable<IFilter> operands) { _operator = op; _operands = new List<IFilter>(operands); if (_operands.Count == 0) throw new ArgumentException("The filter operands enumeration must not be empty"); }
public Face2D Build(CameraScene cameraScene, CirclePrimitive player, CirclePrimitive target) { // 3 steps: // 1. Make face from room bounds // 2. For each primitive make the occlusion field and cut it from the face // 3. Cut middle zone from the face, in this zone both the player and the target are visible, // but there aren't any camera angle to see them both Face2D res = MakeStartField(cameraScene.RoomBound); BooleanOperator bop = new BooleanOperator(); foreach (var circle_obstacle in cameraScene.Circles) { res = bop.Intersect(res, MakeOcclusionLoop(player, circle_obstacle, -0.1f)); } res = bop.Intersect(res, MakeOcclusionLoop(player, target, 0.0f)); foreach (var circle_obstacle in cameraScene.Circles) { res = bop.Intersect(res, MakeOcclusionLoop(target, circle_obstacle, 0.1f)); } res = bop.Intersect(res, MakeMiddleZone(player, target)); return(res); }
public GroupExpression( IReadOnlyCollection <IBooleanExpression> booleanExpressions, BooleanOperator booleanOperator) { BooleanExpressions = booleanExpressions; BooleanOperator = booleanOperator; }
public BooleanQueryClause(BooleanOperator @operator, QueryElement item1, QueryElement item2) { Type = QueryElementType.BooleanQueryClause; Operator = @operator; Item1 = item1; Item2 = item2; }
protected virtual string GetOperatorSql(BooleanOperator op) { bool not = ((op & BooleanOperator.Not) == BooleanOperator.Not); bool and = ((op & BooleanOperator.And) == BooleanOperator.And); bool or = ((op & BooleanOperator.Or) == BooleanOperator.Or); if (and) { if (not) { return("AND NOT"); } else { return("AND"); } } else if (or) { if (not) { return("OR NOT"); } else { return("OR"); } } else { return("NOT"); } }
public static IFilter CombineFilters(BooleanOperator op, IEnumerable<IFilter> filters) { if (filters == null) return null; IFilter[] filtersArray = filters.Where(fi => fi != null).ToArray(); return filtersArray.Length == 0 ? null : (filtersArray.Length == 1 ? filtersArray[0] : new BooleanCombinationFilter(op, filters.ToArray())); }
private void ConstructQuery(BaseNode node, int x, ref int y) { const int Horz = 100; const int Vert = 25; int index = 0; var label = new Label() { Text = node.Property?.Name, Left = x * Horz, Top = y * Vert, Width = 100, Height = 25 }; var button = new Button() { Text = mSigns[index], Left = x * Horz + label.Width, Top = y * Vert, Width = 35, Height = 25 }; var text = new TextBox() { Left = x * Horz + label.Width + button.Width, Top = y * Vert, Width = 100, Height = 25 }; button.Click += (object sender, EventArgs e) => { var self = sender as Button; index = (++index) % mSigns.Length; self.Text = mSigns[index]; node.ComparisonOperator = BooleanOperator.FromString( self.Text ); }; text.TextChanged += (object sender, EventArgs e) => { var self = sender as TextBox; node.Criterium = self.Text; }; QueryFlowLayout.Controls.Add(label); QueryFlowLayout.Controls.Add(button); QueryFlowLayout.Controls.Add(text); foreach (var kv in node.Nodes) { ++y; ConstructQuery(kv.Value, x + 1, ref y); } }
public BooleanOperatorViewModel(HermesViewModel parent, BooleanOperator model) : base(parent, model) { this.IntitializeViewModel(model); this.AddComparisonOperatorCommand = new DelegateCommand(this.AddComparisonOperator); this.AddInnerBooleanOperatorCommand = new DelegateCommand(this.AddInnerBooleanOperator); this.AddOuterBooleanOperatorCommand = new DelegateCommand(this.AddOuterBooleanOperator); this.RemoveBooleanOperatorCommand = new DelegateCommand(this.RemoveBooleanOperator); }
private void SetFirstFilterOperator(List <FilterOperationArgument> filters, BooleanOperator booleanOperator) { FilterOperationArgument argument = (filters != null) ? filters.FirstOrDefault <FilterOperationArgument>() : null; if (argument != null) { argument.BooleanOperator = booleanOperator; } }
public BooleanCombinationFilter(BooleanOperator op, IEnumerable <IFilter> operands) { _operator = op; _operands = new List <IFilter>(operands); if (_operands.Count == 0) { throw new ArgumentException("The filter operands enumeration must not be empty"); } }
public void Branch(BooleanOperator op, Register r1, Register r2, Label label) { AddLine(new Line(new BranchInstruction { Operator = op, One = r1, Another = r2, Target = new LabelTarget(label) })); }
public void AggregatedQueryTest() { var query = BooleanOperator.And(new [] { Query.Property("name").IsEqualTo("nikhil"), Query.Property("age").IsGreaterThanEqualTo(10), }); Console.WriteLine(query.ToString()); }
public static IFilter CombineFilters(BooleanOperator op, IEnumerable <IFilter> filters) { if (filters == null) { return(null); } IFilter[] filtersArray = filters.Where(fi => fi != null).ToArray(); return(filtersArray.Length == 0 ? null : (filtersArray.Length == 1 ? filtersArray[0] : new BooleanCombinationFilter(op, filters.ToArray()))); }
public ComparisonExpression( ValueExpression left, ValueExpression right, ComparisonOperator comparisonOperator, BooleanOperator booleanOperator) { Left = left ?? throw new ArgumentNullException(nameof(left)); Right = right ?? throw new ArgumentNullException(nameof(right)); ComparisonOperator = comparisonOperator; BooleanOperator = booleanOperator; }
private static IBooleanExpression ParseExpression(ExpressionReader reader, BooleanOperator booleanOperator) { var expressions = ParseBooleanExpressions(reader, booleanOperator).ToArray(); if (reader.Peek() != -1) { throw reader.UnexpectedCharacterException(); } return(expressions.Length == 1 ? expressions.Single() : new GroupExpression(expressions, booleanOperator)); }
public void BooleanCondition_ReturnFalse(BooleanOperator booleanOperator, params bool[] conditionResults) { //Arrange var contex = Mock.Of <IExecutionContext>(); var conditions = MockHelper.MakeMoqConditions(contex, conditionResults); //Action var booleanCondition = new BooleanCondition(booleanOperator, conditions); var result = booleanCondition.Evaluate(contex); //Assert Assert.False(result, $"should true"); }
private Either <RuntimeErrors, bool> Compare(object a, object b, BooleanOperator op) { if (a is string strA && b is string strB) { if (op.Op == "==") { return(Either.Success <RuntimeErrors, bool>(strB.Equals(strA))); } if (op.Op == "!=") { return(Either.Success <RuntimeErrors, bool>(!strB.Equals(strA))); } } if (a is int x && b is int y) { if (op.Op == ">") { return(Either.Success <RuntimeErrors, bool>(x > y)); } if (op.Op == "<") { return(Either.Success <RuntimeErrors, bool>(x < y)); } if (op.Op == "==") { return(Either.Success <RuntimeErrors, bool>(x == y)); } if (op.Op == "!=") { return(Either.Success <RuntimeErrors, bool>(x != y)); } if (op.Op == ">=") { return(Either.Success <RuntimeErrors, bool>(x >= y)); } if (op.Op == "<=") { return(Either.Success <RuntimeErrors, bool>(x <= y)); } } return(Either.Error <RuntimeErrors, bool>(new RuntimeErrors(new TypeMismatch()))); }
private static ComparisonExpression ParseComparison(ExpressionReader reader, BooleanOperator booleanOperator) { var left = ParseValue(reader); reader.SkipWhitespace(); var comparisonOperator = ParseOperator(reader); reader.SkipWhitespace(); var right = ParseValue(reader); return(new ComparisonExpression(left, right, comparisonOperator, booleanOperator)); }
public static string ToQueryForm(this BooleanOperator op) { switch (op) { case BooleanOperator.And: return("AND"); case BooleanOperator.Or: return("OR"); default: throw new NotImplementedException(op.ToString()); } }
public Argument Evaluate() { // If the argument doesn't have a value, false is assumed object l = Arguments[0].Evaluateble?.Evaluate().Value ?? false; object r = Arguments[2].Evaluateble?.Evaluate().Value ?? true; // Use the left argument to see which type the comparison should take ILogicalTypeOperator logicalOperator = new BooleanOperator(); LogicalOperator operation = (LogicalOperator)Arguments[1].Evaluateble.Evaluate().Value; object result = EvaluateOperation(l, r, logicalOperator, operation); return(new Argument(result, ResultingType)); }
async Task <WorkItem> IMasterWorkItemDb.GetNextItemAsync(string supplierFamily, long lastProcessedRevision) { // Get next work item with the given supplier name and with revision > the last processed revision var query = BooleanOperator.And(new[] { Query.Property("supplier_family").IsEqualTo(supplierFamily), Query.Property("version").IsGreaterThan(lastProcessedRevision) }); var changeLog = (await Articles.FindAllAsync("master_change_log", query.ToString(), pageSize: 1, orderBy: "version", sortOrder: SortOrder.Ascending)).SingleOrDefault(); if (changeLog == null) { return(null); } return(changeLog.ToMasterWorkItem()); }
private string TranslateOperator(BooleanOperator op) { switch (op) { case BooleanOperator.And: return("&"); case BooleanOperator.Or: return("|"); case BooleanOperator.Implication: return("->"); case BooleanOperator.Equivalence: return("<->"); default: return(string.Empty); } }
private void AddInnerBooleanOperator() { BooleanOperator model = this.Model as BooleanOperator; if (model == null) { return; } if (model.IsLeaf) { AddOuterBooleanOperator(); } else { BooleanOperator operand = new BooleanOperator(model) { Name = BooleanFunction.OR }; model.AddChild(operand); ComparisonOperator child = new ComparisonOperator(operand); operand.AddChild(child); BooleanOperatorViewModel viewModel = new BooleanOperatorViewModel(this, operand); ComparisonOperatorViewModel childVM = new ComparisonOperatorViewModel(viewModel, child); if (viewModel.Operands == null) { viewModel.Operands = new ObservableCollection <BooleanFunctionViewModel>() { childVM }; } else { viewModel.Operands.Add(childVM); } if (this.Operands == null) { this.Operands = new ObservableCollection <BooleanFunctionViewModel>() { viewModel }; } else { this.Operands.Add(viewModel); } } }
internal QueryFrame(string key, string value, string op) { if (string.IsNullOrWhiteSpace(key) || string.IsNullOrWhiteSpace(value) || string.IsNullOrWhiteSpace(op)) { throw new ArgumentNullException(); } BooleanOperator parseVal; if (!Enum.TryParse(CultureInfo.CurrentCulture.TextInfo.ToTitleCase(op), out parseVal)) { parseVal = BooleanOperator.Nil; } Key = key; Value = value; Operator = parseVal; }
private void AddNewCondition() { if (this.Parent is SelectStatementViewModel) { if (((SelectStatementViewModel)this.Parent).Tables.Count == 0) { Z.Notify(new Notification { Title = "Hermes", Content = "Предложение FROM не содержит ни одной таблицы!" }); return; } } if (_Model == null) { _Model = new ComparisonOperator(this.Parent.Model); SetModelToParent(); ComparisonOperatorViewModel viewModel = new ComparisonOperatorViewModel(this, (ComparisonOperator)_Model); this.View = new ComparisonOperatorView(viewModel); } else if (_Model is ComparisonOperator) { ComparisonOperatorViewModel currentVM = this.View.DataContext as ComparisonOperatorViewModel; BooleanOperator substitute = new BooleanOperator(this.Parent.Model); substitute.AddChild(_Model); BooleanOperatorViewModel substituteVM = new BooleanOperatorViewModel(this, substitute); ComparisonOperator child = new ComparisonOperator(substitute); substitute.AddChild(child); ComparisonOperatorViewModel childVM = new ComparisonOperatorViewModel(substituteVM, child); currentVM.Parent = substituteVM; substituteVM.Operands = new ObservableCollection <BooleanFunctionViewModel>() { currentVM, childVM }; BooleanOperatorView substituteView = new BooleanOperatorView(substituteVM); _Model = substitute; SetModelToParent(); this.IsCommandPanelVisible = false; this.View = substituteView; } }
private void VisitBooleanOperator(BooleanOperator expression) { int counter = 0; sql.Append("\n\t("); foreach (BooleanFunction function in expression.Operands) { sql.Append("\n\t"); if (counter > 0) { sql.Append($"{expression.Name} "); } VisitBooleanFunction(function); counter++; } sql.Append("\n\t)"); }
public static string ToStatementString(this BooleanOperator Operator) { switch (Operator) { case BooleanOperator.And: return("&&"); case BooleanOperator.Or: return("||"); case BooleanOperator.none: return(""); default: throw new ApplicationException("unsupported enum " + Operator.ToString()); } }
/// <summary> /// Constructs a blank inner join criteria, which will return all records unless you customize it. /// </summary> /// <param name="howToAddExpressions">How expressions will be added together. Determines /// if we do exp1 AND exp2 AND exp3, or if we do /// exp1 OR exp2 OR exp3.</param> public DaoJoinCriteria(BooleanOperator howToAddExpressions) : this(JoinType.Inner, null, howToAddExpressions) { }
/// <summary> /// Constructs an inner join criteria with one expression. /// </summary> /// <param name="firstExpr">The first expression to add.</param> /// <param name="howToAddExpressions">How expressions will be added together. Determines /// if we do exp1 AND exp2 AND exp3, or if we do /// exp1 OR exp2 OR exp3.</param> public DaoJoinCriteria(IJoinExpression firstExpr, BooleanOperator howToAddExpressions) : this(JoinType.Inner, firstExpr, howToAddExpressions) { }
/// <summary> /// Constructs a blank criteria, which will return all records unless you customize it. /// </summary> /// <param name="howToAddExpressions">How expressions will be added together. Determines /// if we do exp1 AND exp2 AND exp3, or if we do /// exp1 OR exp2 OR exp3.</param> /// <param name="typeOfJoin">Is this an inner join, left join, etc.</param> public DaoJoinCriteria(JoinType typeOfJoin, BooleanOperator howToAddExpressions) : this(typeOfJoin, null, howToAddExpressions) { }
/// <summary> /// Completely clears the object so that it may be used over again. /// </summary> public void Clear() { BoolType = BooleanOperator.And; Expressions.Clear(); Orders.Clear(); Start = -1; Limit = -1; }
/// <summary> /// Constructs a criteria with one expression. /// </summary> /// <param name="firstExpr">The first expression to add.</param> /// <param name="howToAddExpressions">How expressions will be added together. Determines /// if we do exp1 AND exp2 AND exp3, or if we do /// exp1 OR exp2 OR exp3.</param> /// <param name="typeOfJoin">Is this an inner join, left join, etc.</param> public DaoJoinCriteria(JoinType typeOfJoin, IJoinExpression firstExpr, BooleanOperator howToAddExpressions) { TypeOfJoin = typeOfJoin; BoolType = howToAddExpressions; if (firstExpr != null) { Expressions.Add(firstExpr); } }
/// <summary> /// Returns a nicely spaced AND or OR depending on the boolean type. /// </summary> /// <param name="boolType"></param> /// <returns></returns> protected static string BoolTypeToString(BooleanOperator boolType) { switch (boolType) { case BooleanOperator.And: return " AND "; case BooleanOperator.Or: return " OR "; default: throw new NotSupportedException("Type of expression condition '" + boolType + " not supported."); } }
public BooleanExpression(IExpression left, IExpression right, BooleanOperator operation) : base(left, right) { this.operation = operation; }
public ComplexCondition(String operand1, String operand2, BooleanOperator op) { this.operand1 = new Condition(operand1); this.operand2 = new Condition(operand2); }
/// <summary> /// Converts the list of expressions from this criteria into SQL, and appends to the /// given string builder. /// </summary> /// <param name="queryToAddTo">Query we're adding the expression to.</param> /// <param name="boolType">Whether to AND or OR the expressions together.</param> /// <param name="expressions">The expressions to add to the query.</param> /// <param name="mapping">Class mapping for the class we're dealing with.</param> /// <param name="colPrefix">What to prefix column names with, I.E. "Table." for "Table.Column". /// May be null if no prefix is desired. May be something other than /// the table name if the tables are being aliased.</param> protected void ExpressionListToQuery(SqlDaQuery queryToAddTo, BooleanOperator boolType, IEnumerable<IExpression> expressions, ClassMapping mapping, string colPrefix) { // starts out false for the first one. bool needsBooleanOperator = false; string boolText = BoolTypeToString(boolType); foreach (IExpression expr in expressions) { try { if (expr == null) { throw new NullReferenceException("Can't convert a null expression to SQL."); } // After the first guy writes something, we need an operator. if (ExpressionToQuery(queryToAddTo, expr, mapping, colPrefix, needsBooleanOperator ? boolText : "")) { needsBooleanOperator = true; } } catch (Exception e) { throw new UnableToConstructSqlException("Unable to add expression to query: " + expr, _connDesc, e); } } }
public ComplexCondition(Condition operand1, Condition operand2, BooleanOperator op) { this.operand1 = operand1; this.operand2 = operand2; this.op = op; }
/// <summary> /// Constructs a blank criteria, which will return all records unless you customize it. /// </summary> /// <param name="howToAddExpressions">How expressions will be added together. Determines /// if we do exp1 AND exp2 AND exp3, or if we do /// exp1 OR exp2 OR exp3.</param> public DaoCriteria(BooleanOperator howToAddExpressions) : this(null, howToAddExpressions) { }
/// <summary> /// Constructs a criteria with one expression. /// </summary> /// <param name="firstExpr">The first expression to add.</param> /// <param name="howToAddExpressions">How expressions will be added together. Determines /// if we do exp1 AND exp2 AND exp3, or if we do /// exp1 OR exp2 OR exp3.</param> public DaoCriteria(IExpression firstExpr, BooleanOperator howToAddExpressions) { BoolType = howToAddExpressions; if (firstExpr != null) { Expressions.Add(firstExpr); } }
protected virtual string GetOperatorSql (BooleanOperator op) { bool not = ((op & BooleanOperator.Not) == BooleanOperator.Not); bool and = ((op & BooleanOperator.And) == BooleanOperator.And); bool or = ((op & BooleanOperator.Or) == BooleanOperator.Or); if (and) if (not) return "AND NOT"; else return "AND"; else if (or) if (not) return "OR NOT"; else return "OR"; else return "NOT"; }
public BooleanExpression (IExpression left, BooleanOperator op, IExpression right) { Left = left; Operator = op; Right = right; }
public IJobSearch WhereKeywordsBooleanOperator(BooleanOperator useValue) { _BooleanOperator = useValue; return this; }
/// <summary> /// Completely clears the object so that it may be used over again. /// </summary> public void Clear() { TypeOfJoin = JoinType.Inner; BoolType = BooleanOperator.And; Expressions.Clear(); Orders.Clear(); Start = -1; Limit = -1; }
public static IFilter CombineFilters(BooleanOperator op, params IFilter[] filters) { return CombineFilters(op, (IEnumerable<IFilter>) filters); }
/// <summary> /// Makes this DaoCriteria into a copy of the other one. Any existing /// orders, expressions, etc. on this one are lost. /// </summary> /// <param name="other">Criteria to copy everything from.</param> public void CopyFrom(DaoCriteria other) { if (other == null) { Clear(); } else { BoolType = other.BoolType; Expressions.Clear(); Expressions.AddRange(other.Expressions); Orders.Clear(); Orders.AddRange(other.Orders); Start = other.Start; Limit = other.Limit; } }