public virtual IReturnVector executeFunction(Rete engine, IParameter[] params_Renamed) { Decimal bdval = new Decimal(0); if (params_Renamed.Length == 1) { if (params_Renamed[0] is ValueParam) { ValueParam n = (ValueParam)params_Renamed[0]; bdval = n.BigDecimalValue; } else if (params_Renamed[0] is BoundParam) { BoundParam bp = (BoundParam)params_Renamed[0]; bdval = (Decimal)engine.getBinding(bp.VariableName); } else if (params_Renamed[0] is FunctionParam2) { FunctionParam2 n = (FunctionParam2)params_Renamed[0]; n.Engine = engine; n.lookUpFunction(); IReturnVector rval = (IReturnVector)n.Value; bdval = rval.firstReturnValue().BigDecimalValue; } double bdh = System.Math.Log(Decimal.ToDouble(bdval)); //.pow(Math.E, bdval.doubleValue()); bdval = new Decimal(bdh); } DefaultReturnVector ret = new DefaultReturnVector(); DefaultReturnValue rv = new DefaultReturnValue(Constants.BIG_DECIMAL, bdval); ret.addReturnValue(rv); return(ret); }
public virtual IReturnVector executeFunction(Rete engine, IParameter[] params_Renamed) { bool bound = false; if (params_Renamed.Length == 2) { String name = params_Renamed[0].StringValue; Object val = null; if (params_Renamed[1] is ValueParam) { val = params_Renamed[1].Value; } else if (params_Renamed[1] is FunctionParam2) { FunctionParam2 fp2 = (FunctionParam2)params_Renamed[1]; fp2.Engine = engine; fp2.lookUpFunction(); DefaultReturnVector drv = (DefaultReturnVector)fp2.Value; val = drv.firstReturnValue().Value; } engine.setBindingValue(name, val); bound = true; } DefaultReturnVector ret = new DefaultReturnVector(); DefaultReturnValue rv = new DefaultReturnValue(Constants.BOOLEAN_OBJECT, bound); ret.addReturnValue(rv); return(ret); }
public virtual IReturnVector executeFunction(Rete engine, IParameter[] params_Renamed) { bool boolVal = true; if (params_Renamed != null) { if (params_Renamed.Length == 1) { if (params_Renamed[0] is ValueParam) { ValueParam n = (ValueParam)params_Renamed[0]; boolVal = n.BooleanValue; } else if (params_Renamed[0] is BoundParam) { BoundParam bp = (BoundParam)params_Renamed[0]; boolVal = ((Boolean)engine.getBinding(bp.VariableName)); } else if (params_Renamed[0] is FunctionParam2) { FunctionParam2 n = (FunctionParam2)params_Renamed[0]; n.Engine = engine; n.lookUpFunction(); IReturnVector rval = (IReturnVector)n.Value; boolVal = rval.firstReturnValue().BooleanValue; } boolVal = (boolVal == false); } } DefaultReturnVector ret = new DefaultReturnVector(); DefaultReturnValue rv = new DefaultReturnValue(Constants.BOOLEAN_OBJECT, boolVal); ret.addReturnValue(rv); return(ret); }
public virtual IReturnVector executeFunction(Rete engine, IParameter[] params_Renamed) { Decimal bdval = new Decimal(0); if (params_Renamed != null) { if (params_Renamed[0] is ValueParam) { bdval = params_Renamed[0].BigDecimalValue; } else if (params_Renamed[0] is BoundParam) { BoundParam bp = (BoundParam)params_Renamed[0]; bdval = (Decimal)engine.getBinding(bp.VariableName); } else if (params_Renamed[0] is FunctionParam2) { FunctionParam2 n = (FunctionParam2)params_Renamed[0]; n.Engine = engine; n.lookUpFunction(); IReturnVector rval = (IReturnVector)n.Value; bdval = rval.firstReturnValue().BigDecimalValue; } for (int idx = 1; idx < params_Renamed.Length; idx++) { if (params_Renamed[idx] is ValueParam) { ValueParam n = (ValueParam)params_Renamed[idx]; Decimal bd = n.BigDecimalValue; bdval = Decimal.Multiply(bdval, bd); } else if (params_Renamed[idx] is FunctionParam2) { FunctionParam2 n = (FunctionParam2)params_Renamed[idx]; n.Engine = engine; n.lookUpFunction(); IReturnVector rval = (IReturnVector)n.Value; Decimal bd = rval.firstReturnValue().BigDecimalValue; if (idx == 0) { bdval = bd; } else { bdval = Decimal.Multiply(bdval, bd); } } } } DefaultReturnVector ret = new DefaultReturnVector(); DefaultReturnValue rv = new DefaultReturnValue(Constants.BIG_DECIMAL, bdval); ret.addReturnValue(rv); return(ret); }
public virtual IReturnVector executeFunction(Rete engine, IParameter[] params_Renamed) { double dval = 0; if (params_Renamed != null) { if (params_Renamed.Length == 1) { if (params_Renamed[0] is ValueParam) { ValueParam n = (ValueParam)params_Renamed[0]; dval = n.DoubleValue; dval = System.Math.Cos(dval); } else if (params_Renamed[0] is BoundParam) { BoundParam bp = (BoundParam)params_Renamed[0]; dval = bp.DoubleValue; dval = System.Math.Cos(dval); } else if (params_Renamed[0] is FunctionParam2) { FunctionParam2 n = (FunctionParam2)params_Renamed[0]; n.Engine = engine; n.lookUpFunction(); IReturnVector rval = (IReturnVector)n.Value; dval = rval.firstReturnValue().DoubleValue; dval = System.Math.Cos(dval); } } } DefaultReturnVector ret = new DefaultReturnVector(); DefaultReturnValue rv = new DefaultReturnValue(Constants.DOUBLE_PRIM_TYPE, dval); ret.addReturnValue(rv); return(ret); }
public virtual IReturnVector executeFunction(Rete engine, IParameter[] params_Renamed) { Object result = null; if (params_Renamed != null) { if (params_Renamed.Length >= 3) { bool conditionValue = false; if (params_Renamed[0] is ValueParam) { ValueParam n = (ValueParam)params_Renamed[0]; conditionValue = n.BooleanValue; } else if (params_Renamed[0] is BoundParam) { BoundParam bp = (BoundParam)params_Renamed[0]; conditionValue = ((Boolean)engine.getBinding(bp.VariableName)); } else if (params_Renamed[0] is FunctionParam2) { FunctionParam2 n = (FunctionParam2)params_Renamed[0]; n.Engine = engine; n.lookUpFunction(); IReturnVector rval = (IReturnVector)n.Value; conditionValue = rval.firstReturnValue().BooleanValue; } if (params_Renamed[1] is ValueParam && "then".Equals(params_Renamed[1].StringValue)) { bool elseExpressions = false; for (int i = 2; i < params_Renamed.Length; ++i) { if (params_Renamed[i] is ValueParam && "else".Equals(params_Renamed[i].StringValue)) { elseExpressions = true; } else { if ((conditionValue && !elseExpressions) || (!conditionValue && elseExpressions)) { if (params_Renamed[i] is ValueParam) { ValueParam n = (ValueParam)params_Renamed[i]; result = n.Value; } else if (params_Renamed[i] is BoundParam) { BoundParam bp = (BoundParam)params_Renamed[i]; result = engine.getBinding(bp.VariableName); } else if (params_Renamed[i] is FunctionParam2) { FunctionParam2 n = (FunctionParam2)params_Renamed[i]; n.Engine = engine; n.lookUpFunction(); IReturnVector rval = (IReturnVector)n.Value; if (rval.size() > 0) { result = rval.firstReturnValue().Value; } } } } } } } } DefaultReturnVector ret = new DefaultReturnVector(); DefaultReturnValue rv = new DefaultReturnValue(Constants.OBJECT_TYPE, result); ret.addReturnValue(rv); return(ret); }
public virtual IReturnVector executeFunction(Rete engine, IParameter[] params_Renamed) { Object o = null; String classname = null; if (params_Renamed != null && params_Renamed.Length == 1) { if (params_Renamed[0] is ValueParam) { ValueParam n = (ValueParam)params_Renamed[0]; classname = n.StringValue; } else if (params_Renamed[0] is BoundParam) { BoundParam bp = (BoundParam)params_Renamed[0]; classname = (String)engine.getBinding(bp.VariableName); } else if (params_Renamed[0] is FunctionParam2) { FunctionParam2 n = (FunctionParam2)params_Renamed[0]; n.Engine = engine; n.lookUpFunction(); IReturnVector rval = (IReturnVector)n.Value; classname = rval.firstReturnValue().StringValue; } try { Type classDefinition = classnameResolver.resolveClass(classname); o = CreateNewInstance(classDefinition); if (o is IFunctionGroup) { engine.declareFunctionGroup((IFunctionGroup)o); } } catch (UnauthorizedAccessException e) { // TODO Auto-generated catch block System.Diagnostics.Trace.WriteLine(e.Message); } catch (SecurityException e) { // TODO Auto-generated catch block System.Diagnostics.Trace.WriteLine(e.Message); } catch (ArgumentException e) { // TODO Auto-generated catch block System.Diagnostics.Trace.WriteLine(e.Message); } catch (Exception e) { // TODO Auto-generated catch block Trace.WriteLine(e.Message); } } DefaultReturnVector ret = new DefaultReturnVector(); DefaultReturnValue rv = new DefaultReturnValue(Constants.OBJECT_TYPE, o); ret.addReturnValue(rv); return(ret); }
public virtual IReturnVector executeFunction(Rete engine, IParameter[] params_Renamed) { String sval = new String("".ToCharArray()); if (params_Renamed != null) { if (params_Renamed.Length == 1) { if (params_Renamed[0] is ValueParam) { ValueParam n = (ValueParam)params_Renamed[0]; sval = n.StringValue; IFunction aFunction = engine.findFunction(sval); if (aFunction != null) { sval = aFunction.toPPString(null, 0); } else { sval = toPPString(null, 0); } } else if (params_Renamed[0] is BoundParam) { BoundParam bp = (BoundParam)params_Renamed[0]; sval = bp.StringValue; IFunction aFunction = engine.findFunction(sval); if (aFunction != null) { sval = aFunction.toPPString(null, 0); } else { sval = toPPString(null, 0); } } else if (params_Renamed[0] is FunctionParam2) { FunctionParam2 n = (FunctionParam2)params_Renamed[0]; n.Engine = engine; n.lookUpFunction(); IReturnVector rval = (IReturnVector)n.Value; sval = rval.firstReturnValue().StringValue; IFunction aFunction = engine.findFunction(sval); if (aFunction != null) { sval = aFunction.toPPString(null, 0); } else { sval = toPPString(null, 0); } } } else { sval = toPPString(null, 0); } } DefaultReturnVector ret = new DefaultReturnVector(); DefaultReturnValue rv = new DefaultReturnValue(Constants.STRING_TYPE, sval); ret.addReturnValue(rv); return(ret); }
public virtual IReturnVector executeFunction(Rete engine, IParameter[] params_Renamed) { Object o = null; Object ro = null; String methodname = null; Type[] argsclass = null; Object[] args = null; if (params_Renamed != null) { if (params_Renamed[0] is ValueParam) { ValueParam n = (ValueParam)params_Renamed[0]; o = n.Value; } else if (params_Renamed[0] is BoundParam) { BoundParam bp = (BoundParam)params_Renamed[0]; o = engine.getBinding(bp.VariableName); } else if (params_Renamed[0] is FunctionParam2) { FunctionParam2 n = (FunctionParam2)params_Renamed[0]; n.Engine = engine; n.lookUpFunction(); IReturnVector rval = (IReturnVector)n.Value; o = rval.firstReturnValue().Value; } if (params_Renamed[1] is ValueParam) { ValueParam n = (ValueParam)params_Renamed[1]; methodname = n.StringValue; } else if (params_Renamed[1] is BoundParam) { BoundParam bp = (BoundParam)params_Renamed[1]; methodname = (String)engine.getBinding(bp.VariableName); } else if (params_Renamed[1] is FunctionParam2) { FunctionParam2 n = (FunctionParam2)params_Renamed[1]; n.Engine = engine; n.lookUpFunction(); IReturnVector rval = (IReturnVector)n.Value; methodname = rval.firstReturnValue().StringValue; } if (params_Renamed.Length > 2) { argsclass = new Type[params_Renamed.Length - 1]; args = new Object[params_Renamed.Length - 1]; } for (int idx = 2; idx < params_Renamed.Length; idx++) { if (params_Renamed[idx] is ValueParam) { ValueParam n = (ValueParam)params_Renamed[idx]; argsclass[idx - 1] = n.Value.GetType(); args[idx - 1] = n.Value; } else if (params_Renamed[idx] is BoundParam) { BoundParam bp = (BoundParam)params_Renamed[idx]; argsclass[idx - 1] = engine.getBinding(bp.VariableName).GetType(); args[idx - 1] = engine.getBinding(bp.VariableName); } else if (params_Renamed[idx] is FunctionParam2) { FunctionParam2 n = (FunctionParam2)params_Renamed[idx]; n.Engine = engine; n.lookUpFunction(); IReturnVector rval = (IReturnVector)n.Value; argsclass[idx - 1] = rval.firstReturnValue().Value.GetType(); args[idx - 1] = rval.firstReturnValue().Value; } } try { Type classDefinition = o.GetType(); MethodInfo method = classDefinition.GetMethod(methodname, (Type[])argsclass); ro = method.Invoke(o, (Object[])args); } catch (UnauthorizedAccessException e) { // TODO Auto-generated catch block System.Diagnostics.Trace.WriteLine(e.Message); } catch (SecurityException e) { // TODO Auto-generated catch block System.Diagnostics.Trace.WriteLine(e.Message); } catch (MethodAccessException e) { // TODO Auto-generated catch block System.Diagnostics.Trace.WriteLine(e.Message); } catch (ArgumentException e) { // TODO Auto-generated catch block System.Diagnostics.Trace.WriteLine(e.Message); } catch (TargetInvocationException e) { // TODO Auto-generated catch block System.Diagnostics.Trace.WriteLine(e.Message); } } DefaultReturnVector ret = new DefaultReturnVector(); DefaultReturnValue rv = new DefaultReturnValue(Constants.OBJECT_TYPE, ro); ret.addReturnValue(rv); return(ret); }
public virtual IReturnVector executeFunction(Rete engine, IParameter[] params_Renamed) { Object o = null; String classname = null; Type[] argsclass = null; Object[] args = null; if (params_Renamed != null) { if (params_Renamed[0] is ValueParam) { ValueParam n = (ValueParam)params_Renamed[0]; classname = n.StringValue; } else if (params_Renamed[0] is BoundParam) { BoundParam bp = (BoundParam)params_Renamed[0]; classname = (String)engine.getBinding(bp.VariableName); } else if (params_Renamed[0] is FunctionParam2) { FunctionParam2 n = (FunctionParam2)params_Renamed[0]; n.Engine = engine; n.lookUpFunction(); IReturnVector rval = (IReturnVector)n.Value; classname = rval.firstReturnValue().StringValue; } args = new Object[params_Renamed.Length - 1]; for (int idx = 1; idx < params_Renamed.Length; idx++) { if (params_Renamed[idx] is ValueParam) { ValueParam n = (ValueParam)params_Renamed[idx]; args[idx - 1] = n.Value; } else if (params_Renamed[idx] is BoundParam) { BoundParam bp = (BoundParam)params_Renamed[idx]; args[idx - 1] = engine.getBinding(bp.VariableName); } else if (params_Renamed[idx] is FunctionParam2) { FunctionParam2 n = (FunctionParam2)params_Renamed[idx]; n.Engine = engine; n.lookUpFunction(); IReturnVector rval = (IReturnVector)n.Value; args[idx - 1] = rval.firstReturnValue().Value; } } try { Type classDefinition = classnameResolver.resolveClass(classname); ConstructorInfo foundConstructor = null; for (int idx = 0; idx < classDefinition.GetConstructors().Length; idx++) { ConstructorInfo constructor = classDefinition.GetConstructors()[idx]; ParameterInfo[] parameterClasses = constructor.GetParameters(); if (parameterClasses.Length == args.Length) { bool match = true; for (int i = 0; i < parameterClasses.Length; ++i) { match &= (parameterClasses[i].GetType().IsInstanceOfType(args[i]) || args[i] == null); } if (match) { foundConstructor = constructor; break; } } } if (foundConstructor != null) { o = foundConstructor.Invoke(args); } } catch (UnauthorizedAccessException e) { // TODO Auto-generated catch block System.Diagnostics.Trace.WriteLine(e.Message); } catch (SecurityException e) { // TODO Auto-generated catch block System.Diagnostics.Trace.WriteLine(e.Message); } catch (ArgumentException e) { // TODO Auto-generated catch block System.Diagnostics.Trace.WriteLine(e.Message); } catch (TargetInvocationException e) { // TODO Auto-generated catch block System.Diagnostics.Trace.WriteLine(e.Message); } catch (Exception e) { // TODO Auto-generated catch block System.Diagnostics.Trace.WriteLine(e.Message); } } DefaultReturnVector ret = new DefaultReturnVector(); DefaultReturnValue rv = new DefaultReturnValue(Constants.OBJECT_TYPE, o); ret.addReturnValue(rv); return(ret); }
public virtual IReturnVector executeFunction(Rete engine, IParameter[] params_Renamed) { DefaultReturnVector ret = new DefaultReturnVector(); bool eq = false; if (params_Renamed != null && params_Renamed.Length > 1) { Object first = null; if (params_Renamed[0] is ValueParam) { ValueParam n = (ValueParam)params_Renamed[0]; first = n.Value; } else if (params_Renamed[0] is BoundParam) { BoundParam bp = (BoundParam)params_Renamed[0]; first = (Decimal)engine.getBinding(bp.VariableName); } else if (params_Renamed[0] is FunctionParam2) { FunctionParam2 n = (FunctionParam2)params_Renamed[0]; n.Engine = engine; n.lookUpFunction(); IReturnVector rval = (IReturnVector)n.Value; first = rval.firstReturnValue().Value; } bool eval = true; for (int idx = 1; idx < params_Renamed.Length; idx++) { Object right = null; if (params_Renamed[idx] is ValueParam) { ValueParam n = (ValueParam)params_Renamed[idx]; right = n.Value; } else if (params_Renamed[idx] is BoundParam) { BoundParam bp = (BoundParam)params_Renamed[idx]; right = engine.getBinding(bp.VariableName); } else if (params_Renamed[idx] is FunctionParam2) { FunctionParam2 n = (FunctionParam2)params_Renamed[idx]; n.Engine = engine; n.lookUpFunction(); IReturnVector rval = (IReturnVector)n.Value; right = rval.firstReturnValue().Value; } if (first == null && right != null) { eval = false; break; } else if (first != null && !first.Equals(right)) { eval = false; break; } } eq = eval; } DefaultReturnValue rv = new DefaultReturnValue(Constants.BOOLEAN_OBJECT, eq); ret.addReturnValue(rv); return(ret); }