예제 #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 });
                }
            }
        }
예제 #2
0
파일: TokenString.cs 프로젝트: bcr/sdf
        public void TestStateAccess()
        {
            registry.AddType(typeof(stringfromstate));

            this.state += "stringydingy";

            Assert.AreEqual("stringydingy", TokenString.Eval(registry, state, "$[stringfromstate]"));
        }
예제 #3
0
파일: TokenString.cs 프로젝트: bcr/sdf
 public void SetUp()
 {
     this.registry = new TokenStringRegistry();
     this.state = new SDFState();
 }
예제 #4
0
 public void Evaluate(SDFState state, string name, Hashtable arguments)
 {
     ((TokenResult) state[typeof(TokenResult)]).Result = arguments["result"].ToString();
 }
예제 #5
0
 private void EvaluateChildExpressions(SDFState state)
 {
     this.rootExpressionChildren.Evaluate(state);
 }
예제 #6
0
 public void Evaluate(SDFState state, string name, Hashtable arguments)
 {
 }
예제 #7
0
 public void PostCreateExpression(SDFState state, string name, Hashtable arguments, ParsedExpressionList children)
 {
     ((ExpressionRegistry) state[typeof(ExpressionRegistry)]).AddAssembly(arguments["filename"].ToString());
 }
예제 #8
0
파일: SDF.cs 프로젝트: bcr/sdf
 public object Evaluate(SDFState state, string name, Hashtable arguments)
 {
     return arguments["string"].ToString();
 }
예제 #9
0
파일: SDF.cs 프로젝트: 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;
            }
        }
예제 #10
0
파일: SDF.cs 프로젝트: bcr/sdf
 public void SetUp()
 {
     this.output = new StandardOutputRedirector();
     this.state = new SDFState();
     SDF.Eval(this.state, "LoadExpressions filename='SDF.Print.dll'");
 }
예제 #11
0
파일: SDF.cs 프로젝트: bcr/sdf
 public static void Eval(SDFState state, string eval)
 {
     ParsedExpressionList expressionList = ExpressionParser.Parse(eval);
     Load(expressionList, state, new ProvidedStatePile());
     expressionList.Evaluate(state);
 }
예제 #12
0
파일: SDF.cs 프로젝트: 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 });
     }
 }
예제 #13
0
파일: TokenString.cs 프로젝트: bcr/sdf
 public string Evaluate(SDFState state, ArrayList arguments)
 {
     return (string) state[typeof(string)];
 }
예제 #14
0
파일: TokenString.cs 프로젝트: bcr/sdf
 public string Evaluate(SDFState state, ArrayList arguments)
 {
     return "dogdude";
 }
예제 #15
0
파일: SDF.cs 프로젝트: bcr/sdf
 public object CreateExpression(SDFState state, string name, Hashtable arguments)
 {
     return new ObjectBasedFactoryInstance();
 }
예제 #16
0
파일: SDF.cs 프로젝트: 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());
        }
예제 #17
0
파일: SDF.cs 프로젝트: bcr/sdf
 public void Evaluate(SDFState state, string name, Hashtable arguments)
 {
     Console.WriteLine("Dude this is {0}", arguments["message"]);
 }
예제 #18
0
파일: SDF.cs 프로젝트: bcr/sdf
 public static object CreateExpression(SDFState state, string name, Hashtable arguments)
 {
     return new FooAsFactory(name);
 }
예제 #19
0
 public void Evaluate(SDFState state, string name, Hashtable arguments)
 {
     if (name != GetType().Name)
     {
         this.rootExpressionChildren.Evaluate(state);
     }
 }
예제 #20
0
파일: SDF.cs 프로젝트: bcr/sdf
 public void Evaluate(SDFState state, string name, Hashtable arguments)
 {
     System.Console.WriteLine("I am {0}", this.name);
 }
예제 #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;
 }
예제 #22
0
파일: SDF.cs 프로젝트: bcr/sdf
 public void Evaluate(SDFState state, string name, Hashtable arguments)
 {
     System.Console.WriteLine("I am FooWithRequiredParamClassLevel {0}", arguments["argument"]);
 }
예제 #23
0
 public void PostCreateExpression(SDFState state, string name, Hashtable arguments, ParsedExpressionList children)
 {
     this.rootExpressionChildren = children;
 }
예제 #24
0
파일: SDF.cs 프로젝트: bcr/sdf
 public void Evaluate(SDFState state, string name, Hashtable arguments)
 {
     System.Console.WriteLine("I am FooWithRequiredState {0}", state[typeof(string)]);
 }
예제 #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;
                }
예제 #26
0
파일: SDF.cs 프로젝트: bcr/sdf
 public string Evaluate(SDFState state, ArrayList arguments)
 {
     return arguments[1].ToString().ToUpper();
 }
예제 #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;
     }
 }
예제 #28
0
파일: SDF.cs 프로젝트: bcr/sdf
 public object Evaluate(SDFState state, string name, Hashtable arguments)
 {
     return isTrue;
 }
예제 #29
0
 public void Evaluate(SDFState state)
 {
     Evaluate(this, state);
 }
예제 #30
0
파일: TokenString.cs 프로젝트: bcr/sdf
        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();
        }