public void TestMultipleArgumentBooleanExpressions() { // expression tests // - empty multi-AND = true { IExpression[] args = new IExpression[] { }; Assert.IsTrue(Expr.CastTo <bool>(Expr.BoolAND(args).Evaluate(null), false)); } // - multi-AND true { IExpression[] args = new IExpression[] { Expr.Const(true), null, null, Expr.Const(true) }; Assert.IsTrue(Expr.CastTo <bool>(Expr.BoolAND(args).Evaluate(null), false)); } // multi-AND false { IExpression[] args = new IExpression[] { Expr.Const(true), null, null, Expr.Const(false) }; Assert.IsFalse(Expr.CastTo <bool>(Expr.BoolAND(args).Evaluate(null), false)); } // - empty multi-OR = false { IExpression[] args = new IExpression[] { }; Assert.IsFalse(Expr.CastTo <bool>(Expr.BoolOR(args).Evaluate(null), false)); } // - multi-OR false { IExpression[] args = new IExpression[] { Expr.Const(false), null, null, Expr.Const(false) }; Assert.IsFalse(Expr.CastTo <bool>(Expr.BoolOR(args).Evaluate(null), false)); } // multi-OR true { IExpression[] args = new IExpression[] { Expr.Const(false), null, null, Expr.Const(true) }; Assert.IsTrue(Expr.CastTo <bool>(Expr.BoolOR(args).Evaluate(null), false)); } }
/// <summary> /// Makes a rule filter. /// </summary> /// <param name="envAbbr">The (optional) name of the application processing the rules.</param> /// <param name="hostName">The (optional) name of the computer running the rules processor.</param> /// <param name="userName">The (optional) name of the user account hosting the rules processor.</param> /// <param name="instance">The (optional) instance name for the rule processor.</param> /// <param name="nameSpace">The (optional) instance namespace for the rule processor.</param> /// <returns></returns> public static IExpression MakeRuleFilter( string envAbbr, // optional environment short name string hostName, // optional name of computer string instance, // optional instance name string userName, string nameSpace) // optional name of the user { var clauses = new List <IExpression>(); if (envAbbr != null) { clauses.Add(Expr.BoolOR(Expr.IsNull(HostEnvName), Expr.IsEQU(HostEnvName, envAbbr))); } if (hostName != null) { clauses.Add(Expr.BoolOR(Expr.IsNull(HostComputer), Expr.IsEQU(HostComputer, hostName))); } clauses.Add(instance != null ? Expr.IsEQU(HostInstance, instance) : Expr.IsNull(HostInstance)); if (userName != null) { clauses.Add(Expr.BoolOR(Expr.IsNull(HostUserName), Expr.IsEQU(HostUserName, userName))); } if (nameSpace != null) { clauses.Add(Expr.BoolOR(Expr.IsNull(HostNameSpace), Expr.IsEQU(HostNameSpace, nameSpace))); } return(Expr.BoolAND(clauses.ToArray())); }
private static ScenarioRule MakeIrCurveScenarioRule(string scenarioId, int priority, string currency, string indexName, string indexTenor, string stressId, string description) { return(new ScenarioRule { ScenarioId = scenarioId, Category = ScenarioConst.IrPrefix, RuleId = "1", Disabled = false, Priority = priority, // base curve filter FilterExpr = Expr.BoolAND( Expr.BoolOR( Expr.IsEQU(CurveProp.PricingStructureType, "RateCurve"), Expr.IsEQU(CurveProp.PricingStructureType, "RateBasisCurve"), Expr.IsEQU(CurveProp.PricingStructureType, "RateSpreadCurve"), Expr.IsEQU(CurveProp.PricingStructureType, "DiscountCurve")), ((indexName != null) ? Expr.Contains(CurveProp.IndexName, indexName) : null), ((indexTenor != null) ? Expr.IsEQU(CurveProp.IndexTenor, indexTenor) : null), ((currency != null) ? Expr.IsEQU(CurveProp.Currency1, currency) : null)).Serialise(), // output RuleDesc = description, StressId = stressId }); }
private void BtnAutoCurveBuilderClick(object sender, EventArgs e) { var ccy = listBoxCurrencies.SelectedItems; IExpression query1 = ccy.Cast <object>().Aggregate <object, IExpression>(null, (current, cc) => Expr.BoolOR(current, Expr.IsEQU(CurveProp.Currency1, cc))); var pst = listBoxCurves.SelectedItems; var query2 = pst.Cast <object>().Aggregate <object, IExpression>(null, (current, ps) => Expr.BoolOR(current, Expr.IsEQU(CurveProp.PricingStructureType, ps))); var marketName = txtBoxMarket.Text; var query3 = Expr.IsEQU(CurveProp.Market, marketName); query2 = Expr.BoolAND(query1, query2, query3, Expr.IsEQU(EnvironmentProp.NameSpace, NameSpace), Expr.IsEQU(EnvironmentProp.Function, FunctionProp.QuotedAssetSet)); ISubscription newSubscription = _clientRef.Target.CreateSubscription <QuotedAssetSet>(query2); newSubscription.UserCallback = delegate(ISubscription subscription, ICoreItem item) { // note: this is running on a thread pool thread // add the item to the queue and post a callback _queuedItems.Locked(queue => queue.Enqueue(item)); _loggerRef.Target.LogDebug("Queued Item {0} created at {1}", item.Name, item.Created.ToString()); int count = Interlocked.Increment(ref _queuedCalls); //if (count % 10000 == 0) _loggerRef.Target.LogDebug("SubscribeCallback: Queued calls posted: {0}", count); _syncContext.Post(ReceiveNewItem, item); //chnanged from null }; newSubscription.Start(); _loggerRef.Target.LogDebug("Subscription started."); }
public void TestFailingExpressions() { // tests expressions that fail to evaluate on the server using (Reference <ILogger> loggerRef = Reference <ILogger> .Create(new TraceLogger(true))) { NamedValueSet serverSettings = new NamedValueSet(); serverSettings.Set(CfgPropName.NodeType, (int)NodeType.Router); serverSettings.Set(CfgPropName.EnvName, "UTT"); using (CoreServer server = new CoreServer(loggerRef, serverSettings)) { server.Start(); // save using (ICoreClient client1 = new CoreClientFactory(loggerRef).SetEnv("UTT").Create()) { client1.SaveObject(new TestData(), "AllValuesNotNull", new NamedValueSet("StrValue/String=A|NumValue/Int32=0"), TimeSpan.MaxValue); client1.SaveObject(new TestData(), "NumValueIsNull", new NamedValueSet("StrValue/String=A"), TimeSpan.MaxValue); client1.SaveObject(new TestData(), "StrValueIsNull", new NamedValueSet("NumValue/Int32=0"), TimeSpan.MaxValue); client1.SaveObject(new TestData(), "AllValuesAreNull", null, TimeSpan.MaxValue); } // load using expression using (ICoreClient client2 = new CoreClientFactory(loggerRef).SetEnv("UTT").Create()) { client2.DebugRequests = true; { var items = client2.LoadObjects <TestData>(Expr.BoolAND(Expr.IsEQU("StrValue", "A"), Expr.IsEQU("NumValue", 0))); Assert.AreEqual(1, items.Count); } { var items = client2.LoadObjects <TestData>(Expr.BoolOR(Expr.IsEQU("StrValue", "A"), Expr.IsEQU("NumValue", 0))); Assert.AreEqual(3, items.Count); } { // unknown/missing string property var items = client2.LoadObjects <TestData>(Expr.BoolOR(Expr.IsEQU("StrValue", "A"), Expr.IsEQU("XValue", "X"))); Assert.AreEqual(2, items.Count); } { // unknown/missing non-string property var items = client2.LoadObjects <TestData>(Expr.BoolOR(Expr.IsEQU("StrValue", "A"), Expr.IsEQU("YValue", 1))); Assert.AreEqual(2, items.Count); } { // property missing var items = client2.LoadObjects <TestData>(Expr.IsNull("StrValue")); Assert.AreEqual(2, items.Count); } { // property has value var items = client2.LoadObjects <TestData>(Expr.IsNotNull("StrValue")); Assert.AreEqual(2, items.Count); } { var items = client2.LoadObjects <TestData>(Expr.StartsWith("StrValue", "A")); Assert.AreEqual(2, items.Count); } { var items = client2.LoadObjects <TestData>(Expr.BoolOR(Expr.StartsWith("StrValue", "A"), Expr.IsEQU("NumValue", 0))); Assert.AreEqual(3, items.Count); } } } } }
public void TestExpressionEquality() { // expression equality tests // constant expressions { IExpression expr1 = Expr.Const(false); IExpression expr2 = Expr.Const(false); Assert.IsTrue(expr1.Equals(expr2)); } { IExpression expr1 = Expr.Const(false); IExpression expr2 = Expr.Const(true); Assert.IsFalse(expr1.Equals(expr2)); } { IExpression expr1 = Expr.Const("Value1"); IExpression expr2 = Expr.Const("Value1"); Assert.IsTrue(expr1.Equals(expr2)); } { IExpression expr1 = Expr.Const("Value1"); IExpression expr2 = Expr.Const("value1"); Assert.IsFalse(expr1.Equals(expr2)); } { IExpression expr1 = Expr.Const("Value1"); IExpression expr2 = Expr.Const("Value2"); Assert.IsFalse(expr1.Equals(expr2)); } // incompatibale types { IExpression expr1 = Expr.Const("Value1"); IExpression expr2 = Expr.Const(true); Assert.IsFalse(expr1.Equals(expr2)); } // property names are case insensitive { IExpression expr1 = Expr.IsEQU("Name", "Value"); IExpression expr2 = Expr.IsEQU("Name", "Value"); Assert.IsTrue(expr1.Equals(expr2)); } { IExpression expr1 = Expr.IsEQU("Name", "Value"); IExpression expr2 = Expr.IsEQU("name", "Value"); Assert.IsTrue(expr1.Equals(expr2)); } // order of evaluation is irrelevant { IExpression expr1 = Expr.BoolAND(Expr.IsEQU("Name1", "Value1"), Expr.IsEQU("Name2", "Value2")); IExpression expr2 = Expr.BoolAND(Expr.IsEQU("Name2", "Value2"), Expr.IsEQU("Name1", "Value1")); Assert.IsTrue(expr1.Equals(expr2)); } { IExpression expr1 = Expr.BoolOR(Expr.IsEQU("Name1", "Value1"), Expr.IsEQU("Name2", "Value2")); IExpression expr2 = Expr.BoolOR(Expr.IsEQU("Name2", "Value2"), Expr.IsEQU("Name1", "Value1")); Assert.IsTrue(expr1.Equals(expr2)); } // operator is important { IExpression expr1 = Expr.BoolOR(Expr.IsEQU("Name1", "Value1"), Expr.IsEQU("Name2", "Value2")); IExpression expr2 = Expr.BoolAND(Expr.IsEQU("Name1", "Value1"), Expr.IsEQU("Name2", "Value2")); Assert.IsFalse(expr1.Equals(expr2)); } // non-deterministic expressions are never equal { IExpression expr1 = Expr.FuncNow(); IExpression expr2 = Expr.FuncNow(); int hash1a = expr1.GetHashCode(); int hash2a = expr2.GetHashCode(); // these are usually equal but not always //Assert.AreEqual<int>(hash1a, hash2a); Thread.Sleep(30); // sleep at least 2 Windows time quanta (not ticks) int hash1b = expr1.GetHashCode(); int hash2b = expr2.GetHashCode(); Assert.AreNotEqual <int>(hash1a, hash1b); Assert.AreNotEqual <int>(hash1a, hash2b); } }