示例#1
0
        public object CreateObject(ValueStack.ValueStack stack, System.IO.Stream stream)
        {
            var doc = new XmlDocument();

            doc.Load(stream);
            return(Build(null, doc.DocumentElement, stack));
        }
        public BusinessProcess.BusinessProcess CreateBusinessProcess(String bpName, ValueStack.ValueStack stack)
        {
            System.IO.Stream bpData  = BitMobile.Application.ApplicationContext.Context.DAL.GetBusinessProcess(bpName);
            ObjectFactory    factory = new ObjectFactory();

            return((BusinessProcess.BusinessProcess)factory.CreateObject(stack, bpData));
        }
        public Configuration.Configuration CreateConfiguration(ValueStack.ValueStack stack)
        {
            System.IO.Stream bpData  = BitMobile.Application.ApplicationContext.Context.DAL.GetConfiguration();
            ObjectFactory    factory = new ObjectFactory();

            return((Configuration.Configuration)factory.CreateObject(stack, bpData));
        }
示例#4
0
        private void ProcessChildren(IContainer parent, XmlNode node, ValueStack.ValueStack stack)
        {
            XmlNode child = node.FirstChild;

            while (child != null)
            {
                Build(parent, child, stack);
                child = child.NextSibling;
            }
        }
示例#5
0
        BusinessProcess.BusinessProcess LoadBusinessProcess()
        {
            ValueStack = new ValueStack.ValueStack(_exceptionHandler);
            ValueStack.Push("context", this);
            ValueStack.Push("isTablet", UIDevice.CurrentDevice.Model.Contains("iPad"));

            _configuration = ConfigurationFactory.CreateInstance().CreateConfiguration(ValueStack);

            return(BusinessProcessFactory.CreateInstance().CreateBusinessProcess(_configuration.BusinessProcess.File, ValueStack));
        }
示例#6
0
        public ActionHandlerEx(string expression, ValueStack.ValueStack valueStack, object sender)
        {
            expression = expression.Trim();

            _valueStack = valueStack;

            if (expression.StartsWith("$") && expression.Contains("("))
                PrepareScriptCall(expression, sender);
            else
                throw new Exception("Incorrect action: " + expression);
        }
示例#7
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);
 }
示例#8
0
        public object CreateScreen <T>(String screenName, ValueStack.ValueStack stack, BitMobile.Controllers.ScreenController controller) where T : StyleSheet, new()
        {
            string TS_NAME = "CreateScreen: " + screenName;

            TimeStamp.Start("Total");
            TimeStamp.Start(TS_NAME);

            System.IO.Stream screenStream = ApplicationContext.Context.DAL.GetScreenByName(screenName);
            if (screenStream == null)
            {
                throw new Exception(String.Format("Can't load screen {0}", screenName));
            }

            TimeStamp.Log(TS_NAME, "Prepare");
            TimeStamp.Start(TS_NAME);

            controller.OnLoading();

            TimeStamp.Log(TS_NAME, "OnLoading invoke");
            TimeStamp.Start(TS_NAME);

            IControl <object> scr = (IControl <object>)objectFactory.CreateObject(stack, screenStream);

            TimeStamp.Log(TS_NAME, "CreateInstance objects");
            TimeStamp.Start(TS_NAME);

            scr.CreateView(); // TODO: Replace to platform controllers

            TimeStamp.Log(TS_NAME, "CreateInstance views");
            TimeStamp.Start(TS_NAME);

            ApplyStyles(screenName, scr as IStyledObject, new T());

            TimeStamp.Log(TS_NAME, "Apply styles");
            TimeStamp.Start(TS_NAME);

            controller.OnLoad();

            TimeStamp.Log(TS_NAME, "OnLoad invoke");

            TimeStamp.Log("Total");
            TimeStamp.WriteLog();
            TimeCollector.Write("CallFunction");
            TimeCollector.Stop("CallFunction");
            TimeCollector.Write("CallFunctionNoException");
            TimeCollector.Stop("CallFunctionNoException");

            return(scr);
        }
示例#9
0
        public ActionHandler(string expression, ValueStack.ValueStack valueStack)
        {
            expression = expression.Trim();

            _valueStack = valueStack;

            if (expression.StartsWith("$") && expression.Contains("("))
            {
                PrepareScriptCall(expression);
            }
            else
            {
                throw new Exception("Incorrect action: " + expression);
            }
        }
示例#10
0
        private static void LoadStepState(ValueStack.ValueStack 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.CurrentStep.State.TryGetValue(id, out state))
                {
                    persistable.SetState(state);
                }
            }
        }
示例#11
0
        private IContainer DoInclude(Include tag, IContainer parent, ValueStack.ValueStack stack)
        {
            var dal = ApplicationContext.Context.DAL;

            object component = CreateObject(stack, dal.GetScreenByName(tag.File));

            if (!(component is Component))
            {
                throw new Exception("Only Component container is allowed to be included");
            }

            object[] controls = ((IContainer)component).Controls;
            foreach (object child in controls)
            {
                parent.AddChild(child);
            }
            return(parent);
        }
示例#12
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);
                    }
                }
            }
        }
示例#13
0
        private static object CreateObject(Type t, ValueStack.ValueStack stack)
        {
            object     obj;
            MethodInfo mi = t.GetMethod("CreateInstance", BindingFlags.Static | BindingFlags.Public);

            if (mi != null)
            {
                ParameterInfo[] parameters = mi.GetParameters();
                var             args       = new object[parameters.Length];
                for (int i = 0; i < parameters.Length; i++)
                {
                    args[i] = stack.Values[parameters[i].Name];
                }
                obj = mi.Invoke(null, args);
            }
            else
            {
                ConstructorInfo[] constructors = t.GetConstructors();
                if (constructors.Length == 0)
                {
                    throw new Exception(String.Format("Unable to create instance of {0}", t.FullName));
                }
                ConstructorInfo ci         = constructors[constructors.Length - 1]; //last one..
                ParameterInfo[] parameters = ci.GetParameters();
                var             args       = new object[parameters.Length];
                for (int i = 0; i < parameters.Length; i++)
                {
                    args[i] = stack.Values[parameters[i].Name];
                }
                obj = ci.Invoke(args);
            }

            var context = (IApplicationContext)stack.Values["context"];

            var aware = obj as IApplicationContextAware;

            if (aware != null)
            {
                aware.SetApplicationContext(context);
            }

            return(obj);
        }
示例#14
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);
        }
示例#15
0
        private IContainer DoIf(If tag, IContainer parent, XmlNode node, ValueStack.ValueStack stack)
        {
            bool value = stack.BooleanExpression(tag.Test);

            if (value)
            {
                ProcessChildren(parent, node, stack);
            }
            else
            {
                XmlNode ifNode = node.NextSibling;
                if (ifNode != null)
                {
                    Type t = TypeFromNode(ifNode);
                    if (t == typeof(Else))
                    {
                        ProcessChildren(parent, ifNode, stack);
                    }
                }
            }

            return(parent);
        }
示例#16
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);
        }
示例#17
0
        void StartApplication()
        {
            _commonData.UserId = DAL.UserId;

            ValueStack = new ValueStack.ValueStack(BitBrowserApp.Current.ExceptionHandler);
            ValueStack.Push("context", this);
            ValueStack.Push("isTablet", IsTablet());

            try
            {
                _configuration = ConfigurationFactory.CreateInstance().CreateConfiguration(ValueStack);
            }
            catch (ResourceNotFoundException e)
            {
                ReturnToStartMenu(e.FriendlyMessage, e.Report);
                return;
            }

            try
            {
                _businessProcess = BusinessProcessFactory.CreateInstance().CreateBusinessProcess(_configuration.BusinessProcess.File, ValueStack);
            }
            catch (ResourceNotFoundException e)
            {
                ReturnToStartMenu(e.FriendlyMessage, e.Report);
                return;
            }

            LoadingProgress = null;

            _loadComplete();
            _loadComplete = null;

            _settings.SetClearCacheDisabled();

            _businessProcess.Start(this);
        }
示例#18
0
        public bool OpenScreen(string screenName, String controllerName
            , Dictionary<string, object> parameters = null
            , bool isBackCommand = false
            , bool isRefresh = false)
        {
            try
            {
                ActionHandler.Busy = true;
                ActionHandlerEx.Busy = true;

                _baseActivity.ClearNavigationEvents();

                DateTime startLoading = DateTime.Now;

                ValueStack = new ValueStack.ValueStack(BitBrowserApp.Current.ExceptionHandler);
                ValueStack.Push("common", _commonData);
                ValueStack.Push("context", this);
                ValueStack.Push("dao", DAL.DAO);
                ValueStack.Push("activity", _baseActivity);

                foreach (var variable in GlobalVariables)
                    ValueStack.Push(variable.Key, variable.Value);

                if (parameters != null)
                    foreach (KeyValuePair<String, object> item in parameters)
                        ValueStack.Push(item.Key, item.Value);

                var controller = ControllerFactory.CreateInstance().CreateController<Controllers.ScreenController>(controllerName);
                ValueStack.Push("controller", controller);
                screenName = controller.GetView(screenName);

                var scr = (Screen)ScreenFactory.CreateInstance().CreateScreen<AndroidStyleSheet>(screenName, ValueStack, controller);
                var currentScreen = new ScreenData(screenName, controllerName, scr);

                FlipScreen(scr.View, isBackCommand, isRefresh);

                if (Settings.DevelopModeEnabled)
                {
                    string message = string.Format("{0}\n{1}"
                        , screenName
                        , (DateTime.Now - startLoading).ToString("ss\\.ff"));
                    Toast.MakeText(_baseActivity, message, ToastLength.Short).Show();
                }

                ThreadPool.QueueUserWorkItem(Finish, CurrentScreen);

                CurrentScreen = currentScreen;

                return true;
            }
            catch (Exception e)
            {
                HandleException(e);

                return false;
            }
        }
示例#19
0
        public bool OpenScreen(string screenName, String controllerName
                               , Dictionary <string, object> parameters = null
                               , bool isBackCommand = false
                               , bool isRefresh     = false)
        {
            try
            {
                ActionHandler.Busy   = true;
                ActionHandlerEx.Busy = true;

                _baseActivity.ClearNavigationEvents();

                DateTime startLoading = DateTime.Now;

                ValueStack = new ValueStack.ValueStack(BitBrowserApp.Current.ExceptionHandler);
                ValueStack.Push("common", _commonData);
                ValueStack.Push("context", this);
                ValueStack.Push("dao", DAL.DAO);
                ValueStack.Push("activity", _baseActivity);

                foreach (var variable in GlobalVariables)
                {
                    ValueStack.Push(variable.Key, variable.Value);
                }

                if (parameters != null)
                {
                    foreach (KeyValuePair <String, object> item in parameters)
                    {
                        ValueStack.Push(item.Key, item.Value);
                    }
                }

                var controller = ControllerFactory.CreateInstance().CreateController <Controllers.ScreenController>(controllerName);
                ValueStack.Push("controller", controller);
                screenName = controller.GetView(screenName);

                var scr           = (Screen)ScreenFactory.CreateInstance().CreateScreen <AndroidStyleSheet>(screenName, ValueStack, controller);
                var currentScreen = new ScreenData(screenName, controllerName, scr);

                FlipScreen(scr.View, isBackCommand, isRefresh);

                if (Settings.DevelopModeEnabled)
                {
                    string message = string.Format("{0}\n{1}"
                                                   , screenName
                                                   , (DateTime.Now - startLoading).ToString("ss\\.ff"));
                    Toast.MakeText(_baseActivity, message, ToastLength.Short).Show();
                }

                ThreadPool.QueueUserWorkItem(Finish, CurrentScreen);

                CurrentScreen = currentScreen;

                return(true);
            }
            catch (Exception e)
            {
                HandleException(e);

                return(false);
            }
        }
示例#20
0
		BusinessProcess.BusinessProcess LoadBusinessProcess ()
		{
			ValueStack = new ValueStack.ValueStack (_exceptionHandler);
			ValueStack.Push ("context", this);
			ValueStack.Push ("isTablet", UIDevice.CurrentDevice.Model.Contains ("iPad"));

			_configuration = ConfigurationFactory.CreateInstance ().CreateConfiguration (ValueStack);

			return BusinessProcessFactory.CreateInstance ().CreateBusinessProcess (_configuration.BusinessProcess.File, ValueStack);
		}
示例#21
0
        public bool OpenScreen(String screenName
                               , string controllerName, Dictionary <String
                                                                    , object> parameters = null
                               , bool isBackCommand = false
                               , bool isRefresh     = false)
        {
            try {
                Busy = true;

                _back    = null;
                _forward = null;

                ValueStack = new ValueStack.ValueStack(_exceptionHandler);
                ValueStack.Push("common", _commonData);
                ValueStack.Push("context", this);
                ValueStack.Push("dao", DAL.DAO);

                foreach (var variable in GlobalVariables)
                {
                    ValueStack.Push(variable.Key, variable.Value);
                }

                if (parameters != null)
                {
                    foreach (KeyValuePair <String, object> item in parameters)
                    {
                        ValueStack.Push(item.Key, item.Value);
                    }
                }

                Controllers.ScreenController newController =
                    ControllerFactory.CreateInstance().CreateController <Controllers.ScreenController> (controllerName);
                ValueStack.Push("controller", newController);
                screenName = newController.GetView(screenName);

                TabOrderManager.Create(this);

                Screen scr = (Screen)Factory.ScreenFactory.CreateInstance().CreateScreen <IOSStyleSheet> (screenName, ValueStack, newController);

                if (CurrentScreen != null)
                {
                    ((IDisposable)CurrentScreen.Screen).Dispose();
                }
                CurrentScreen = new ScreenData(screenName, controllerName, scr);

                ScreenController viewController = new ScreenController(scr.View);

                if (!isRefresh)
                {
                    _controller.SetViewControllers(new UIViewController[] {
                        _controller.TopViewController
                    }, false);

                    if (!isBackCommand)
                    {
                        _controller.PushViewController(viewController, true);
                    }
                    else
                    {
                        _controller.SetViewControllers(new UIViewController[] {
                            viewController,
                            _controller.TopViewController
                        }, false);
                        _controller.PopViewControllerAnimated(true);
                    }
                }
                else
                {
                    _controller.PopViewControllerAnimated(false);
                    _controller.PushViewController(viewController, false);
                }
            } catch (Exception ex) {
                HandleException(ex);
            } finally {
                ActionHandler.Busy   = false;
                ActionHandlerEx.Busy = false;
                Busy = false;
            }
            return(true);
        }
示例#22
0
 public ViewFactory(String rootFolder, ValueStack.ValueStack stack)
 {
     this.rootFolder = rootFolder;
     this.stack = stack;
 }
示例#23
0
 public HtmlView(ValueStack.ValueStack stack, String html)
 {
     _stack = stack;
     _html = html;
 }
示例#24
0
        object Build(IContainer parent, XmlNode node, ValueStack.ValueStack stack)
        {
            if (node is XmlComment)
            {
                return(null);
            }

            Type t = TypeFromNode(node);

            if (t.IsSubclassOf(typeof(ValueStackTag)))
            {
                //control flow tag
                ConstructorInfo ci  = t.GetConstructor(new Type[] { });
                var             tag = (ValueStackTag)ci.Invoke(new object[] { });
                foreach (XmlAttribute a in node.Attributes)
                {
                    PropertyInfo pi    = t.GetProperty(a.Name, BindingFlags.IgnoreCase | BindingFlags.Public | BindingFlags.Instance);
                    string       value = ApplicationContext.Context.DAL.TranslateString(a.Value);
                    pi.SetValue(tag, Convert.ChangeType(value, pi.PropertyType), null);
                }

                if (tag is Include)
                {
                    return(DoInclude((Include)tag, parent, stack));
                }

                if (tag is If)
                {
                    return(DoIf((If)tag, parent, node, stack));
                }

                if (tag is Else)
                {
                    return(parent);
                }

                if (tag is Iterator)
                {
                    return(DoIterator((Iterator)tag, parent, node, stack));
                }

                if (tag is Push)
                {
                    object newObject = null;
                    if (node.ChildNodes.Count == 1)
                    {
                        newObject = Build(null, node.FirstChild, stack);
                    }
                    return(DoPush((Push)tag, parent, stack, newObject));
                }

                throw new Exception("Unknown tag");
            }
            else
            {
                //ui control

                object obj = CreateObject(t, stack);

                string id = InitObjectId(node, stack, obj);

                SetProperties(node, stack, obj);

                if (parent != null)
                {
                    parent.AddChild(obj);
                }

                if (obj is IDataBind)
                {
                    (obj as IDataBind).DataBind();
                }

                if (id != null)
                {
                    LoadStepState(stack, obj, id);
                }

                if (obj is IContainer)
                {
                    ProcessChildren((IContainer)obj, node, stack);
                }

                return(obj);
            }
        }
示例#25
0
        void StartApplication()
        {
            _commonData.UserId = DAL.UserId;

            ValueStack = new ValueStack.ValueStack(BitBrowserApp.Current.ExceptionHandler);
            ValueStack.Push("context", this);
            ValueStack.Push("isTablet", IsTablet());

            try
            {
                _configuration = ConfigurationFactory.CreateInstance().CreateConfiguration(ValueStack);
            }
            catch (ResourceNotFoundException e)
            {
                ReturnToStartMenu(e.FriendlyMessage, e.Report);
                return;
            }

            try
            {
                _businessProcess = BusinessProcessFactory.CreateInstance().CreateBusinessProcess(_configuration.BusinessProcess.File, ValueStack);
            }
            catch (ResourceNotFoundException e)
            {
                ReturnToStartMenu(e.FriendlyMessage, e.Report);
                return;
            }

            LoadingProgress = null;

            _loadComplete();
            _loadComplete = null;

            _settings.SetClearCacheDisabled();

            _businessProcess.Start(this);
        }
示例#26
0
		public bool OpenScreen (String screenName
			, string controllerName, Dictionary<String
			, object> parameters = null
			, bool isBackCommand = false
			, bool isRefresh = false)
		{
			try {

				Busy = true;

				_back = null;
				_forward = null;

				ValueStack = new ValueStack.ValueStack (_exceptionHandler);
				ValueStack.Push ("common", _commonData);
				ValueStack.Push ("context", this);
				ValueStack.Push ("dao", DAL.DAO);

				foreach (var variable in GlobalVariables)
					ValueStack.Push (variable.Key, variable.Value);

				if (parameters != null) {
					foreach (KeyValuePair<String, object> item in parameters) {
						ValueStack.Push (item.Key, item.Value);
					}
				}

				Controllers.ScreenController newController = 
					ControllerFactory.CreateInstance ().CreateController<Controllers.ScreenController> (controllerName);
				ValueStack.Push ("controller", newController);
				screenName = newController.GetView (screenName);

				TabOrderManager.Create (this);

				Screen scr = (Screen)Factory.ScreenFactory.CreateInstance ().CreateScreen<IOSStyleSheet> (screenName, ValueStack, newController);

				if (CurrentScreen != null)
					((IDisposable)CurrentScreen.Screen).Dispose ();
				CurrentScreen = new ScreenData (screenName, controllerName, scr);

				ScreenController viewController = new ScreenController (scr.View);

				if (!isRefresh) {
					_controller.SetViewControllers (new UIViewController[] {
						_controller.TopViewController
					}, false);

					if (!isBackCommand) {
						_controller.PushViewController (viewController, true);
					} else {
						_controller.SetViewControllers (new UIViewController[] {
							viewController,
							_controller.TopViewController
						}, false);
						_controller.PopViewControllerAnimated (true);
					}
				} else {
					_controller.PopViewControllerAnimated (false);
					_controller.PushViewController (viewController, false);
				}
			} catch (Exception ex) {
				HandleException (ex);
			} finally {
				ActionHandler.Busy = false;
				ActionHandlerEx.Busy = false;
				Busy = false;
			}
			return true;
		}
示例#27
0
 public HtmlView(ValueStack.ValueStack stack, String html)
 {
     _stack = stack;
     _html  = html;
 }
示例#28
0
 public ViewFactory(String rootFolder, ValueStack.ValueStack stack)
 {
     this.rootFolder = rootFolder;
     this.stack      = stack;
 }