private static object CreateObject(Type t, IValueStack stack) { Tuple <ConstructorInfo, ParameterInfo[]> ctor = FindConstructor(t); ConstructorInfo ci = ctor.Item1; ParameterInfo[] parameters = ctor.Item2; var args = new object[parameters.Length]; for (int i = 0; i < parameters.Length; i++) { args[i] = stack.Values[parameters[i].Name]; } object obj = ci.Invoke(args); var aware = obj as IApplicationContextAware; if (aware != null) { var context = (IApplicationContext)stack.Values["context"]; aware.SetApplicationContext(context); } return(obj); }
private object DoInclude(IInclude tag, IContainer parent, IValueStack stack) { var dal = ApplicationContext.Current.Dal; object component = CreateObject(stack, dal.GetScreenByName(tag.File)); if (!(component is IComponent)) { throw new Exception("Only Component container is allowed to be included"); } object[] controls = ((IContainer)component).Controls; if (parent != null) { foreach (var control in controls) { parent.AddChild(control); } return(parent); } // uglu hack: так как метод Build возвращает object, а нам нужно вернуть несколько объектов // , мы можем вернуть тут массив, но должны помнить, // что это массив (см. Controls/LayoutableContainerBehaviour.cs метод Inject) return(controls); }
public object CreateObject(IValueStack stack, System.IO.Stream stream) { var doc = new XmlDocument(); doc.Load(stream); return(Build(null, doc.DocumentElement, stack)); }
public IConfiguration CreateConfiguration(IValueStack stack) { Stream bpData = ApplicationContext.Current.Dal.GetConfiguration(); var factory = new ObjectFactory(); return((IConfiguration)factory.CreateObject(stack, bpData)); }
public IBusinessProcess CreateBusinessProcess(String bpName, IValueStack stack) { Stream bpData = Application.ApplicationContext.Current.Dal.GetBusinessProcess(bpName); var factory = new ObjectFactory(); return((WorkingProcess.BusinessProcess)factory.CreateObject(stack, bpData)); }
private void ProcessChildren(IContainer parent, XmlNode node, IValueStack stack) { XmlNode child = node.FirstChild; while (child != null) { Build(parent, child, stack); child = child.NextSibling; } }
protected ActionHandlerAbstract(string expression, IValueStack valueStack, IList<object> parameters) { Expression = expression; _valueStack = valueStack; _parameters = parameters; if (expression.StartsWith("$") && expression.Contains("(")) PrepareScriptCall(expression); else throw new Exception("Incorrect action: " + expression); }
public object CreateScreen(string screenName, IValueStack stack, IScreenController controller, object styleCache) { controller.SetCurrentScreenController(); string tsName = "CreateScreen: " + screenName; TimeStamp.Start(tsName); var screenStream = ApplicationContext.Current.Dal.GetScreenByName(screenName); if (screenStream == null) { throw new Exception(String.Format("Can't load screen {0}", screenName)); } TimeStamp.Log(tsName, "Prepare"); TimeStamp.Start(tsName); controller.OnLoading(screenName); TimeStamp.Log(tsName, "OnLoading invoke"); TimeStamp.Start(tsName); var scr = (IControl <object>)ObjectFactory.CreateObject(stack, screenStream); TimeStamp.Log(tsName, "Parse screen"); TimeStamp.Start(tsName); // GC.Collect(); // TimeStamp.Log(tsName, "GC collect"); // TimeStamp.Start(tsName); scr.CreateView(); // TODO: Replace to platform controllers TimeStamp.Log(tsName, "Create views"); ApplyStyles(screenName, scr, styleCache); TimeStamp.Start(tsName); controller.OnLoad(screenName); TimeStamp.Log(tsName, "OnLoad invoke"); ApplicationContext.Current.Dal.ClearStringCache(); TimeStamp.WriteAll(); TimeCollector.WriteAll(); return(scr); }
private IContainer DoPush(IPush tag, IContainer parent, IValueStack stack) { Type type = null; if (!string.IsNullOrEmpty(tag.Type)) { type = GetType().Assembly.GetType(tag.Type, false, true); } object expr = stack.Evaluate(tag.Value, type); stack.Push(tag.Id, expr); return(parent); }
public object CreateScreen(string screenName, IValueStack stack, IScreenController controller, object styleCache) { controller.SetCurrentScreenController(); string tsName = "CreateScreen: " + screenName; TimeStamp.Start(tsName); var screenStream = ApplicationContext.Current.Dal.GetScreenByName(screenName); if (screenStream == null) throw new Exception(String.Format("Can't load screen {0}", screenName)); TimeStamp.Log(tsName, "Prepare"); TimeStamp.Start(tsName); controller.OnLoading(screenName); TimeStamp.Log(tsName, "OnLoading invoke"); TimeStamp.Start(tsName); var scr = (IControl<object>)ObjectFactory.CreateObject(stack, screenStream); TimeStamp.Log(tsName, "Parse screen"); TimeStamp.Start(tsName); // GC.Collect(); // TimeStamp.Log(tsName, "GC collect"); // TimeStamp.Start(tsName); scr.CreateView(); // TODO: Replace to platform controllers TimeStamp.Log(tsName, "Create views"); ApplyStyles(screenName, scr, styleCache); TimeStamp.Start(tsName); controller.OnLoad(screenName); TimeStamp.Log(tsName, "OnLoad invoke"); ApplicationContext.Current.Dal.ClearStringCache(); TimeStamp.WriteAll(); TimeCollector.WriteAll(); return scr; }
protected ActionHandlerAbstract(string expression, IValueStack valueStack, IList <object> parameters) { Expression = expression; _valueStack = valueStack; _parameters = parameters; if (expression.StartsWith("$") && expression.Contains("(")) { PrepareScriptCall(expression); } else { throw new Exception("Incorrect action: " + expression); } }
private static void LoadStepState(IValueStack stack, object obj, string id) { var persistable = obj as IPersistable; if (persistable != null) { stack.Persistables.Add(id, persistable); var context = (IApplicationContext)stack.Values["context"]; object state; if (context.Workflow.BusinessProcess.AllowStatePersist && context.Workflow.CurrentStep.State.TryGetValue(id, out state)) { persistable.SetState(state); } } }
public ScriptInterpreter( IFnRoutinesCaller fnRoutinesCaller, IVariableManager variableManager, IValueStack stack ) { if (fnRoutinesCaller == null) { throw new ArgumentNullException(); } _fnRoutinesCaller = fnRoutinesCaller; if (stack == null) { throw new ArgumentNullException(); } _stack = stack; if (variableManager == null) { throw new ArgumentNullException(); } _variableManager = variableManager; }
private IContainer DoIf(IIf tag, IContainer parent, XmlNode node, IValueStack stack) { bool value = stack.BooleanExpression(tag.Test); if (value) { ProcessChildren(parent, node, stack); } else { XmlNode ifNode = node.NextSibling; if (ifNode != null && !(ifNode is XmlComment)) { Type t = TypeFromNode(ifNode); if (t.GetInterfaces().Contains(typeof(IElse))) { ProcessChildren(parent, ifNode, stack); } } } return(parent); }
private static void SetProperties(XmlNode node, IValueStack stack, object obj) { foreach (XmlAttribute a in node.Attributes) { if (string.IsNullOrEmpty(a.Prefix)) { PropertyInfo prop = FindProperty(obj.GetType(), a.Name); String aValue = a.Value; if (prop.PropertyType == typeof(IDataBinder)) { object bindedObject; String propertyName; stack.Evaluate(aValue, out bindedObject, out propertyName); var binder = ControlsContext.Current.CreateDataBinder(obj, a.Name, bindedObject, propertyName); prop.SetValue(obj, binder, null); } else if (prop.PropertyType == typeof(IActionHandler)) { var handler = ControlsContext.Current.CreateActionHandler(aValue, stack); prop.SetValue(obj, handler, null); } else if (prop.PropertyType == typeof(IActionHandlerEx)) { var handler = ControlsContext.Current.CreateActionHandlerEx(aValue, stack, obj); prop.SetValue(obj, handler, null); } else { object mexpr = stack.Evaluate(aValue, prop.PropertyType); prop.SetValue(obj, mexpr, null); } } } }
public Evaluator(IValueStack valueStack, ITranslator translator) { _executor = new Executor(valueStack, translator); _parser = new ExpressionParser(_executor); }
public IEvaluator CreateEvaluator(IValueStack valueStack) { return new Evaluator(valueStack, _applicationContext.Dal); }
public IActionHandlerEx CreateActionHandlerEx(string expression, IValueStack valueStack, object sender) { return(new ActionHandlerEx(expression, valueStack, sender)); }
private static object CreateObject(Type t, IValueStack stack) { Tuple<ConstructorInfo, ParameterInfo[]> ctor = FindConstructor(t); ConstructorInfo ci = ctor.Item1; ParameterInfo[] parameters = ctor.Item2; var args = new object[parameters.Length]; for (int i = 0; i < parameters.Length; i++) args[i] = stack.Values[parameters[i].Name]; object obj = ci.Invoke(args); var aware = obj as IApplicationContextAware; if (aware != null) { var context = (IApplicationContext)stack.Values["context"]; aware.SetApplicationContext(context); } return obj; }
public Executor(IValueStack valueStack, ITranslator translator) { _valueStack = valueStack; _translator = translator; }
public object Build(IContainer parent, XmlNode node, IValueStack stack) { if (node is XmlComment) return null; Type t = TypeFromNode(node); if (node.NamespaceURI == MarkupElementAttribute.ValueStackNamespace) { //control flow tag var tag = (IValueStackTag)CreateObject(t, stack); foreach (XmlAttribute a in node.Attributes) { PropertyInfo pi = FindProperty(t, a.Name); //string value = ApplicationContext.Current.Dal.TranslateString(a.Value); pi.SetValue(tag, a.Value); } var push = tag as IPush; if (push != null) return DoPush(push, parent, stack); var iif = tag as IIf; if (iif != null) return DoIf(iif, parent, node, stack); if (tag is IElse) return parent; var iterator = tag as IIterator; if (iterator != null) return DoIterator(iterator, parent, node, stack); var include = tag as IInclude; if (include != null) return DoInclude(include, parent, stack); throw new Exception("Unknown tag"); } //ui control object obj = CreateObject(t, stack); SetProperties(node, stack, obj); string id = null; var layoutable = obj as ILayoutable; if (layoutable != null) id = layoutable.Id; if (parent != null) parent.AddChild(obj); if (obj is IDataBind) (obj as IDataBind).DataBind(); if (id != null) { stack.Push(id, obj); // add current object to value stack LoadStepState(stack, obj, id); } var container = obj as IContainer; if (container != null) ProcessChildren(container, node, stack); return obj; }
protected virtual void SetUp() { _stack = new ValueStack(); }
private IContainer DoIterator(IIterator tag, IContainer parent, XmlNode node, IValueStack stack) { var collection = (IEnumerable)stack.Evaluate(tag.Value, null, false); IIteratorStatus status = ValueStackContext.Current.CreateIteratorStatus(); 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); }
public IActionHandler CreateActionHandler(string expression, IValueStack valueStack) { return(new ActionHandler(expression, valueStack)); }
public ActionHandler(string expression, IValueStack valueStack) : base(expression, valueStack, new List <object>()) { }
private static void LoadStepState(IValueStack stack, object obj, string id) { var persistable = obj as IPersistable; if (persistable != null) { stack.Persistables.Add(id, persistable); var context = (IApplicationContext)stack.Values["context"]; object state; if (context.Workflow.BusinessProcess.AllowStatePersist && context.Workflow.CurrentStep.State.TryGetValue(id, out state)) persistable.SetState(state); } }
public ActionHandlerEx(string expression, IValueStack valueStack, object sender) : base(expression, valueStack, CreateParameters(sender)) { }
private object DoInclude(IInclude tag, IContainer parent, IValueStack stack) { var dal = ApplicationContext.Current.Dal; object component = CreateObject(stack, dal.GetScreenByName(tag.File)); if (!(component is IComponent)) throw new Exception("Only Component container is allowed to be included"); object[] controls = ((IContainer)component).Controls; if (parent != null) { foreach (var control in controls) parent.AddChild(control); return parent; } // uglu hack: так как метод Build возвращает object, а нам нужно вернуть несколько объектов // , мы можем вернуть тут массив, но должны помнить, // что это массив (см. Controls/LayoutableContainerBehaviour.cs метод Inject) return controls; }
private IContainer DoIf(IIf tag, IContainer parent, XmlNode node, IValueStack stack) { bool value = stack.BooleanExpression(tag.Test); if (value) ProcessChildren(parent, node, stack); else { XmlNode ifNode = node.NextSibling; if (ifNode != null && !(ifNode is XmlComment)) { Type t = TypeFromNode(ifNode); if (t.GetInterfaces().Contains(typeof(IElse))) ProcessChildren(parent, ifNode, stack); } } return parent; }
public object Build(IContainer parent, XmlNode node, IValueStack stack) { if (node is XmlComment) { return(null); } Type t = TypeFromNode(node); if (node.NamespaceURI == MarkupElementAttribute.ValueStackNamespace) { //control flow tag var tag = (IValueStackTag)CreateObject(t, stack); foreach (XmlAttribute a in node.Attributes) { PropertyInfo pi = FindProperty(t, a.Name); //string value = ApplicationContext.Current.Dal.TranslateString(a.Value); pi.SetValue(tag, a.Value); } var push = tag as IPush; if (push != null) { return(DoPush(push, parent, stack)); } var iif = tag as IIf; if (iif != null) { return(DoIf(iif, parent, node, stack)); } if (tag is IElse) { return(parent); } var iterator = tag as IIterator; if (iterator != null) { return(DoIterator(iterator, parent, node, stack)); } var include = tag as IInclude; if (include != null) { return(DoInclude(include, parent, stack)); } throw new Exception("Unknown tag"); } //ui control object obj = CreateObject(t, stack); SetProperties(node, stack, obj); string id = null; var layoutable = obj as ILayoutable; if (layoutable != null) { id = layoutable.Id; } if (parent != null) { parent.AddChild(obj); } if (obj is IDataBind) { (obj as IDataBind).DataBind(); } if (id != null) { stack.Push(id, obj); // add current object to value stack LoadStepState(stack, obj, id); } var container = obj as IContainer; if (container != null) { ProcessChildren(container, node, stack); } return(obj); }
public object CreateObject(IValueStack stack, System.IO.Stream stream) { var doc = new XmlDocument(); doc.Load(stream); return Build(null, doc.DocumentElement, stack); }
public IConfiguration CreateConfiguration(IValueStack stack) { Stream bpData = ApplicationContext.Current.Dal.GetConfiguration(); var factory = new ObjectFactory(); return (IConfiguration)factory.CreateObject(stack, bpData); }
private IContainer DoIterator(IIterator tag, IContainer parent, XmlNode node, IValueStack stack) { var collection = (IEnumerable)stack.Evaluate(tag.Value, null, false); IIteratorStatus status = ValueStackContext.Current.CreateIteratorStatus(); 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; }
public IEvaluator CreateEvaluator(IValueStack valueStack) { return(new Evaluator(valueStack, _applicationContext.Dal)); }
private IContainer DoPush(IPush tag, IContainer parent, IValueStack stack) { Type type = null; if (!string.IsNullOrEmpty(tag.Type)) type = GetType().Assembly.GetType(tag.Type, false, true); object expr = stack.Evaluate(tag.Value, type); stack.Push(tag.Id, expr); return parent; }
public ActionHandler(string expression, IValueStack valueStack) : base(expression, valueStack, new List<object>()) { }