Beispiel #1
0
        public static void Evaluate(ParsedExpressionList expressionList, SDFState state)
        {
            Object lastExpressionObject = null;

            foreach (Object o in expressionList)
            {
                if (o is ParsedExpressionList)
                {
                    if (lastExpressionObject != null)
                    {
                        state += lastExpressionObject;
                        try
                        {
                            Evaluate((ParsedExpressionList) o, state);
                        }
                        finally
                        {
                            state -= lastExpressionObject;
                        }
                        lastExpressionObject = null;
                    }
                }
                else
                {
                    ParsedExpression expression = (ParsedExpression) o;
                    MethodInfo method = expression.Expression.GetType().GetMethod("Evaluate");

                    lastExpressionObject = method.Invoke(expression.Expression, new Object[] { state, expression.ExpressionName, expression.Arguments });
                }
            }
        }
Beispiel #2
0
        public void TestStateAccess()
        {
            registry.AddType(typeof(stringfromstate));

            this.state += "stringydingy";

            Assert.AreEqual("stringydingy", TokenString.Eval(registry, state, "$[stringfromstate]"));
        }
Beispiel #3
0
 public void SetUp()
 {
     this.registry = new TokenStringRegistry();
     this.state = new SDFState();
 }
Beispiel #4
0
 public void Evaluate(SDFState state, string name, Hashtable arguments)
 {
     ((TokenResult) state[typeof(TokenResult)]).Result = arguments["result"].ToString();
 }
Beispiel #5
0
 private void EvaluateChildExpressions(SDFState state)
 {
     this.rootExpressionChildren.Evaluate(state);
 }
Beispiel #6
0
 public void Evaluate(SDFState state, string name, Hashtable arguments)
 {
 }
Beispiel #7
0
 public void PostCreateExpression(SDFState state, string name, Hashtable arguments, ParsedExpressionList children)
 {
     ((ExpressionRegistry) state[typeof(ExpressionRegistry)]).AddAssembly(arguments["filename"].ToString());
 }
Beispiel #8
0
Datei: SDF.cs Projekt: bcr/sdf
 public object Evaluate(SDFState state, string name, Hashtable arguments)
 {
     return arguments["string"].ToString();
 }
Beispiel #9
0
Datei: SDF.cs Projekt: bcr/sdf
        public static void Load(ParsedExpressionList expressionList, SDFState state, ProvidedStatePile parentExpressionStatePile)
        {
            ExpressionRegistry expressions = (ExpressionRegistry) state[typeof(ExpressionRegistry)];
            ParsedExpression expression = null;
            TokenStringRegistry tokenStringRegistry = (TokenStringRegistry) state[typeof(TokenStringRegistry)];

            foreach (Object o in expressionList)
            {
                if (o is ParsedExpressionList)
                {
                    MaybeCallPostCreateExpression(state, expression, (ParsedExpressionList) o);
                    parentExpressionStatePile.AddProvidedStateFromObject(expression.Expression);
                    expression = null;
                    Load((ParsedExpressionList) o, state, parentExpressionStatePile);
                    parentExpressionStatePile.RemoveLastProvidedState();
                }
                else
                {
                    if (expression != null)
                    {
                        MaybeCallPostCreateExpression(state, expression, null);
                    }

                    expression = (ParsedExpression) o;
                    BindArguments(expression.Arguments, tokenStringRegistry);

                    {
                        object newObject = null;

                        object foundObject = expressions[expression.ExpressionName];
                        Type type = foundObject as Type;

                        if ((foundObject != null) && (type == null))
                        {
                            type = foundObject.GetType();
                        }

                        if (type == null)
                        {
                            throw new SDFException(String.Format("Unknown expression '{0}'", expression.ExpressionName));
                        }

                        {
                            MethodInfo method = type.GetMethod("CreateExpression");

                            if (method != null)
                            {
                                newObject = method.Invoke(foundObject, new Object[] { state, expression.ExpressionName, expression.Arguments });
                                type = newObject.GetType();
                            }
                            else
                            {
                                newObject = type.GetConstructor(new Type[0]).Invoke(null);
                            }
                        }

                        {
                            // On the class, see if there are SDFArgument attributes

                            foreach (SDFArgumentAttribute argument in type.GetCustomAttributes(typeof(SDFArgumentAttribute), false))
                            {
                                // If the argument is required, then whine if it wasn't specified

                                if ((argument.Required) && (!expression.Arguments.Contains(argument.Name)))
                                {
                                    throw new SDFException(String.Format("Rquired argument '{0}' was not specified", argument.Name));
                                }
                            }
                        }

                        // Set arguments to properties if required

                        {
                            // For each property, check to see if it has an SDFArgument attribute

                            foreach (PropertyInfo property in type.GetProperties())
                            {
                                foreach (SDFArgumentAttribute argument in property.GetCustomAttributes(typeof(SDFArgumentAttribute), false))
                                {
                                    // If the argument is required, then whine if it wasn't specified

                                    if ((argument.Required) && (!expression.Arguments.Contains(property.Name)))
                                    {
                                        throw new SDFException(String.Format("Rquired argument '{0}' was not specified", property.Name));
                                    }

                                    // Set the property

                                    property.GetSetMethod().Invoke(newObject, new Object[] { expression.Arguments[property.Name] });
                                }
                            }
                        }

                        {
                            MethodInfo method = type.GetMethod("Evaluate");

                            // Now check to see if there's any required state

                            foreach (SDFStateRequiredAttribute stateRequired in method.GetCustomAttributes(typeof(SDFStateRequiredAttribute), false))
                            {
                                if ((state[stateRequired.RequiredType] == null) && (!parentExpressionStatePile.Contains(stateRequired.RequiredType)))
                                {
                                    throw new SDFException(String.Format("Required state '{0}' was not found", stateRequired.RequiredType.Name));
                                }
                            }
                        }

                        expression.Expression = newObject;
                    }
                }
            }

            if (expression != null)
            {
                MaybeCallPostCreateExpression(state, expression, null);
                expression = null;
            }
        }
Beispiel #10
0
Datei: SDF.cs Projekt: bcr/sdf
 public void SetUp()
 {
     this.output = new StandardOutputRedirector();
     this.state = new SDFState();
     SDF.Eval(this.state, "LoadExpressions filename='SDF.Print.dll'");
 }
Beispiel #11
0
Datei: SDF.cs Projekt: bcr/sdf
 public static void Eval(SDFState state, string eval)
 {
     ParsedExpressionList expressionList = ExpressionParser.Parse(eval);
     Load(expressionList, state, new ProvidedStatePile());
     expressionList.Evaluate(state);
 }
Beispiel #12
0
Datei: SDF.cs Projekt: bcr/sdf
 private static void MaybeCallPostCreateExpression(SDFState state, ParsedExpression expression, ParsedExpressionList children)
 {
     MethodInfo postCreateMethod = expression.Expression.GetType().GetMethod("PostCreateExpression");
     if (postCreateMethod != null)
     {
         postCreateMethod.Invoke(expression.Expression, new Object[] { state, expression.ExpressionName, expression.Arguments, children });
     }
 }
Beispiel #13
0
 public string Evaluate(SDFState state, ArrayList arguments)
 {
     return (string) state[typeof(string)];
 }
Beispiel #14
0
 public string Evaluate(SDFState state, ArrayList arguments)
 {
     return "dogdude";
 }
Beispiel #15
0
Datei: SDF.cs Projekt: bcr/sdf
 public object CreateExpression(SDFState state, string name, Hashtable arguments)
 {
     return new ObjectBasedFactoryInstance();
 }
Beispiel #16
0
Datei: SDF.cs Projekt: bcr/sdf
        public void TestExpressionRequiredStatePresent()
        {
            this.state += "hear me roar";

            ((ExpressionRegistry) this.state[typeof(ExpressionRegistry)]).AddType(typeof(FooWithRequiredState));

            SDF.Eval(this.state, "FooWithRequiredState");

            Assert.AreEqual("I am FooWithRequiredState hear me roar\n", this.output.ToString());
        }
Beispiel #17
0
Datei: SDF.cs Projekt: bcr/sdf
 public void Evaluate(SDFState state, string name, Hashtable arguments)
 {
     Console.WriteLine("Dude this is {0}", arguments["message"]);
 }
Beispiel #18
0
Datei: SDF.cs Projekt: bcr/sdf
 public static object CreateExpression(SDFState state, string name, Hashtable arguments)
 {
     return new FooAsFactory(name);
 }
Beispiel #19
0
 public void Evaluate(SDFState state, string name, Hashtable arguments)
 {
     if (name != GetType().Name)
     {
         this.rootExpressionChildren.Evaluate(state);
     }
 }
Beispiel #20
0
Datei: SDF.cs Projekt: bcr/sdf
 public void Evaluate(SDFState state, string name, Hashtable arguments)
 {
     System.Console.WriteLine("I am {0}", this.name);
 }
Beispiel #21
0
 public static object CreateExpression(SDFState state, string name, Hashtable arguments)
 {
     TokenExpression o = new TokenExpression();
     ((TokenStringRegistry) state[typeof(TokenStringRegistry)]).AddObject(arguments["name"].ToString(), o.Token);
     return o;
 }
Beispiel #22
0
Datei: SDF.cs Projekt: bcr/sdf
 public void Evaluate(SDFState state, string name, Hashtable arguments)
 {
     System.Console.WriteLine("I am FooWithRequiredParamClassLevel {0}", arguments["argument"]);
 }
Beispiel #23
0
 public void PostCreateExpression(SDFState state, string name, Hashtable arguments, ParsedExpressionList children)
 {
     this.rootExpressionChildren = children;
 }
Beispiel #24
0
Datei: SDF.cs Projekt: bcr/sdf
 public void Evaluate(SDFState state, string name, Hashtable arguments)
 {
     System.Console.WriteLine("I am FooWithRequiredState {0}", state[typeof(string)]);
 }
Beispiel #25
0
                public string Evaluate(SDFState state, ArrayList arguments)
                {
                    TokenResult result = new TokenResult();

                    state += result;
                    try
                    {
                        parent.EvaluateChildExpressions(state);
                    }
                    finally
                    {
                        state -= result;
                    }
                    return result.Result;
                }
Beispiel #26
0
Datei: SDF.cs Projekt: bcr/sdf
 public string Evaluate(SDFState state, ArrayList arguments)
 {
     return arguments[1].ToString().ToUpper();
 }
Beispiel #27
0
 public object CreateExpression(SDFState state, string name, Hashtable arguments)
 {
     if (name == GetType().Name)
     {
         object o = new Expression();
         ((ExpressionRegistry) state[typeof(ExpressionRegistry)]).AddObject(arguments["name"].ToString(), o);
         return o;
     }
     else
     {
         return this;
     }
 }
Beispiel #28
0
Datei: SDF.cs Projekt: bcr/sdf
 public object Evaluate(SDFState state, string name, Hashtable arguments)
 {
     return isTrue;
 }
Beispiel #29
0
 public void Evaluate(SDFState state)
 {
     Evaluate(this, state);
 }
Beispiel #30
0
        public string ToString(SDFState state)
        {
            StringBuilder returnString = new StringBuilder();

            if (this.arguments.Count > 0)
            {
                MethodInfo method = this.Token.GetType().GetMethod("Evaluate");

                // Call the token with the arguments

                returnString.Append(method.Invoke(this.Token, new Object[] { state, this.arguments }).ToString());
            }
            else
            {
                foreach (object o in this.elements)
                {
                    if (o is TokenString)
                    {
                        returnString.Append(((TokenString) o).ToString(state));
                    }
                    else
                    {
                        returnString.Append(o.ToString());
                    }
                }
            }

            return returnString.ToString();
        }