Ejemplo n.º 1
0
        public override object Execute(IContext context, Stream writer)
        {
            if (_expression != null)
            {
                object data = _expression.Execute(context, writer);

                if (data != null)
                {
                    string val;

                    if (data is Array)
                    {
                        val = WriteArray((Array)data);
                    }
                    else
                    {
                        val = data.ToString();
                    }


                    byte[] bytes = WebAppConfig.TemplateFileEncoding.GetBytes(val);
                    writer.Write(bytes, 0, bytes.Length);
                }
            }

            return(null);
        }
Ejemplo n.º 2
0
        public override object Execute(IContext context, Stream writer)
        {
            if (_expression is IdentifierExpression)
            {
                IdentifierExpression ident = (IdentifierExpression)_expression;
                object value = ident.Execute(context, writer);

                if (Util.IsInteger(value))
                {
                    Int64 tmp = Convert.ToInt64(value) - 1;

                    if (tmp >= Int32.MinValue && tmp <= Int32.MaxValue)
                    {
                        value = (Int32)tmp;
                    }
                    else
                    {
                        value = tmp;
                    }
                }
                else
                {
                    value = Convert.ToDouble(value) - 1;
                }

                context[ident.Name] = value;
            }
            else
            {
                _expression.Execute(context, writer);
            }

            return(null);
        }
Ejemplo n.º 3
0
        public override object Execute(IContext context, Stream writer)
        {
            object lValue = _leftSide.Execute(context, writer);

            if (lValue is Function)
            {
                Function np = lValue as Function;

                object result;

                object[] args = GetArgs(context, writer);

                try
                {
                    result = np.Type.InvokeMember(np.MethodName, BindingFlags.InvokeMethod, null, np.DataObject, args);
                }
                catch (MissingMethodException ex)
                {
                    throw ex;
                }
                catch (TargetInvocationException ex)
                {
                    throw ex;
                }

                return(result);
            }
            else if (lValue is IList <MethodSchema> )
            {
                object result;

                object[] args = GetArgs(context, writer);

                IList <MethodSchema> methods = lValue as IList <MethodSchema>;

                try
                {
                    result = MethodInvoker.Invoke(context.Controller, methods, args);
                }
                catch (MissingMethodException ex)
                {
                    throw ex;
                }
                catch (TargetInvocationException ex)
                {
                    throw ex;
                }

                return(result);
            }

            return(null);
        }
Ejemplo n.º 4
0
        public override object Execute(IContext context, Stream writer)
        {
            if (_test != null && Util.ToBool(_test.Execute(context, writer)))
            {
                _statements.Execute(context, writer);
            }
            else if (_elseStatements != null)
            {
                _elseStatements.Execute(context, writer);
            }

            return(null);
        }
Ejemplo n.º 5
0
        public override object Execute(IContext context, Stream writer)
        {
            bool test = Util.ToBool(_test.Execute(context, writer));

            if (test)
            {
                return(_left.Execute(context, writer));
            }
            else
            {
                return(_right.Execute(context, writer));
            }
        }
Ejemplo n.º 6
0
        public override object Execute(IContext context, Stream writer)
        {
            if (_init != null)
            {
                EvalCollection(context, _init, writer);
            }

            while ((_test != null) && Util.ToBool(_test.Execute(context, writer)))
            {
                _blockStatement.Execute(context, writer);
                EvalCollection(context, _inc, writer);
            }

            return(null);
        }
Ejemplo n.º 7
0
        public override object Execute(IContext context, Stream writer)
        {
            object lValue = _left.Execute(context, writer);
            object result = null;
            IdentifierExpression ident = _right as IdentifierExpression;

            if (lValue == null)
            {
                throw new ParseException(string.Format("variable '{0}' not exists at line: {1} column:{2}", RelatedToken.Data, RelatedToken.StartLocation.LineIndex + 1, RelatedToken.StartLocation.CharacterIndex + 1));
            }
            else if (lValue is IDictionary)
            {
                IDictionary dic = lValue as IDictionary;
                result = dic[ident.Name];
            }
            else
            {
                Type type = lValue.GetType();

                if (_isMember)
                {
                    result = new Function(ident.Name, lValue, type);
                }
                else
                {
                    PropertyInfo pInfo = type.GetProperty(ident.Name, BindingFlags.Public | BindingFlags.Instance);

                    if (pInfo == null)
                    {
                        throw new ParseException(string.Format("variable '{0}' do not have property '{1}' at line: {2} column:{3}", RelatedToken.Data, ident.Name, RelatedToken.StartLocation.LineIndex + 1, RelatedToken.StartLocation.CharacterIndex + 1));
                    }
                    else
                    {
                        result = pInfo.GetValue(lValue, null);
                    }
                }
            }

            return(result);
        }
Ejemplo n.º 8
0
 public override object Execute(IContext context, Stream writer)
 {
     return(_expression.Execute(context, writer));
 }
Ejemplo n.º 9
0
        public override object Execute(IContext context, Stream writer)
        {
            object lValue = _leftSide.Execute(context, writer);
            object rValue = _expressions.Execute(context, writer);

            if (lValue is Array)
            {
                Array arrRight = (Array)rValue;

                if (arrRight.Length == 1)
                {
                    Array arrLeft = (Array)lValue;

                    return(arrLeft.GetValue(Convert.ToInt32(arrRight.GetValue(0))));
                }
                else if (arrRight.Length > 1)
                {
                    object o = lValue;
                    for (int i = 0; i < arrRight.Length; i++)
                    {
                        if (o is Array)
                        {
                            o = ((Array)o).GetValue(Convert.ToInt32(arrRight.GetValue(i)));
                        }
                        else
                        {
                            break;
                        }
                    }

                    return(o);
                }
                else
                {
                    throw new CException("Syntax error, value expected of array");
                }
            }
            else if (lValue is IDictionary)
            {
                IDictionary dic      = (IDictionary)lValue;
                Array       arrRight = (Array)rValue;

                if (arrRight.Length == 1)
                {
                    return(dic[arrRight.GetValue(0)]);
                }
            }
            else if (lValue is IList)
            {
                IList ls       = (IList)lValue;
                Array arrRight = (Array)rValue;

                if (arrRight.Length == 1)
                {
                    return(ls[Convert.ToInt32(arrRight.GetValue(0))]);
                }
            }
            else
            {
                Type         type     = lValue.GetType();
                PropertyInfo property = type.GetProperty("Item");

                if (property != null)
                {
                    object[] arrRight = (object[])rValue;

                    return(property.GetValue(lValue, arrRight));
                }
            }

            return(null);
        }
Ejemplo n.º 10
0
        public override object Execute(IContext context, Stream writer)
        {
            object obj = _collection.Execute(context, writer);

            object varData = null;

            if (context.ContainsKey(_varName))
            {
                varData = context[_varName];
            }

            if (obj is IEnumerable)
            {
                IEnumerable em        = (IEnumerable)obj;
                int         index     = 0;
                bool        isOdd     = true;
                string      indexName = _varName + "_index";
                string      oddName   = _varName + "_odd";
                object      indexData;
                object      oddData;

                context.TryGetValue(indexName, out indexData);
                context.TryGetValue(oddName, out oddData);

                foreach (object o in em)
                {
                    try
                    {
                        context[_varName]  = o;
                        context[indexName] = index++;
                        context[oddName]   = isOdd;

                        _blockStatement.Execute(context, writer);

                        isOdd = !isOdd;
                        context.Remove(_varName);
                        context.Remove(indexName);
                        context.Remove(oddName);
                    }
                    catch (BreakException)
                    {
                        break;
                    }
                    catch (ContinueException)
                    {
                        continue;
                    }
                }

                if (indexData != null)
                {
                    context[indexName] = indexData;
                }

                if (oddData != null)
                {
                    context[oddName] = oddData;
                }
            }
            else
            {
                if (obj != null)
                {
                    PropertyInfo[] properties = obj.GetType().GetProperties(BindingFlags.Public | BindingFlags.Instance);

                    foreach (PropertyInfo info in properties)
                    {
                        try
                        {
                            context[_varName] = info.GetValue(obj, null);
                            _blockStatement.Execute(context, writer);
                            context.Remove(_varName);
                        }
                        catch (BreakException)
                        {
                            break;
                        }
                        catch (ContinueException)
                        {
                            continue;
                        }
                    }
                }
            }

            if (varData != null)
            {
                context[_varName] = varData;
            }

            return(null);
        }