Ejemplo n.º 1
0
        void PrepareScriptCall(String expression)
        {
            int pos1 = expression.IndexOf("(");
            int pos2 = expression.IndexOf(")");

            _module = "";
            _func   = expression.Substring(1, pos1 - 1);
            String[] arr = _func.Split('.');
            if (arr.Length > 2)
            {
                throw new Exception(String.Format("Invalid expression '{0}'", expression));
            }
            if (arr.Length == 2)
            {
                _module = arr[0];
                _func   = arr[1];
            }

            String[] args = expression.Substring(pos1 + 1, pos2 - pos1 - 1).Split(',');
            _parameters = new object[args.Length];
            int i = 0;

            foreach (String arg in args)
            {
                if (IsLazy(arg))
                {
                    _parameters[i] = new Func <object>(() => _valueStack.Evaluate(arg));
                }
                else
                {
                    _parameters[i] = _valueStack.Evaluate(arg);
                }
                i++;
            }
        }
Ejemplo n.º 2
0
        private static void SetProperties(XmlNode node, ValueStack.ValueStack stack, object obj)
        {
            foreach (XmlAttribute a in node.Attributes)
            {
                if (String.IsNullOrEmpty(a.Prefix))
                {
                    PropertyInfo prop = obj.GetType()
                                        .GetProperty(a.Name, BindingFlags.IgnoreCase | BindingFlags.Public | BindingFlags.Instance);
                    if (prop == null)
                    {
                        throw new Exception(String.Format("Property '{0}' is not found in type '{1}'", a.Name,
                                                          obj.GetType().Name));
                    }

                    String aValue = ApplicationContext.Context.DAL.TranslateString(a.Value.Trim());

                    if (prop.PropertyType == typeof(DataBinder))
                    {
                        object bindedObject;
                        String propertyName;
                        stack.Evaluate(aValue, out bindedObject, out propertyName);

                        var binder = new DataBinder(obj, a.Name, bindedObject, propertyName);
                        prop.SetValue(obj, binder, null);
                    }
                    else if (prop.PropertyType == typeof(ActionHandler))
                    {
                        var handler = new ActionHandler(aValue, stack);
                        prop.SetValue(obj, handler, null);
                    }
                    else if (prop.PropertyType == typeof(ActionHandlerEx))
                    {
                        var handler = new ActionHandlerEx(aValue, stack, obj);
                        prop.SetValue(obj, handler, null);
                    }
                    else
                    {
                        object mexpr = stack.Evaluate(aValue, prop.PropertyType);
                        prop.SetValue(obj, mexpr, null);
                    }
                }
            }
        }
Ejemplo n.º 3
0
 private static string InitObjectId(XmlNode node, ValueStack.ValueStack stack, object obj)
 {
     foreach (XmlAttribute a in node.Attributes)
     {
         if (string.IsNullOrEmpty(a.Prefix) && a.Name.ToLower().Equals("id"))
         {
             string aValue = ApplicationContext.Context.DAL.TranslateString(a.Value);
             string id     = stack.Evaluate(aValue).ToString();
             stack.Push(id, obj);
             return(id);
         }
     }
     return(null);
 }
Ejemplo n.º 4
0
        private IContainer DoIterator(Iterator tag, IContainer parent, XmlNode node, ValueStack.ValueStack stack)
        {
            var collection = (IEnumerable)stack.Evaluate(tag.Value, null, false);

            var status = new IteratorStatus();

            if (!String.IsNullOrEmpty(tag.Status))
            {
                stack.Push(tag.Status, status); //push status variable
            }
            var list   = new ArrayList();
            var reader = collection as IDataReader;

            if (reader != null)
            {
                while (reader.Read())
                {
                    stack.Push(tag.Id, reader);
                    ProcessChildren(parent, node, stack);
                    status.Inc();
                }
            }
            else
            {
                foreach (var item in collection)
                {
                    list.Add(item);
                }

                foreach (var item in list)
                {
                    stack.Push(tag.Id, item);
                    ProcessChildren(parent, node, stack);
                    status.Inc();
                }
            }

            if (!String.IsNullOrEmpty(tag.Status))
            {
                stack.Values.Remove(tag.Status); //remove status variable
            }
            return(parent);
        }
Ejemplo n.º 5
0
        private IContainer DoPush(Push tag, IContainer parent, ValueStack.ValueStack stack, object newObject = null)
        {
            object expr = newObject;

            if (expr == null)
            {
                Type type = null;
                if (!String.IsNullOrEmpty(tag.Type))
                {
                    type = GetType().Assembly.GetType(tag.Type, false, true);
                }

                /*
                 * if (!String.IsNullOrEmpty(tag.Value))
                 *  if (!tag.Value.StartsWith("$")) //TODO
                 *      throw new ArgumentException(String.Format("Invalid Push expression '{0}'. Should start with '$'", tag.Value));
                 */
                expr = stack.Evaluate(tag.Value, type);
            }

            stack.Push(tag.Id, expr);
            return(parent);
        }