Пример #1
0
        public bool OpenScreen(String screenName
                               , string controllerName, Dictionary <String
                                                                    , object> parameters = null
                               , bool isBackCommand = false
                               , bool isRefresh     = false)
        {
            IDisposable rootControl = null;

            try
            {
                Busy = true;

                LogManager.Logger.ScreenOpening(screenName, controllerName, parameters);

                _back    = null;
                _forward = null;

                ValueStack = ValueStackContext.Current.CreateValueStack(_exceptionHandler);
                ValueStack.Push("common", CommonData);
                ValueStack.Push("context", this);
                ValueStack.Push("dao", Dal.Dao);
                ValueStack.Push("isTablet", UIDevice.CurrentDevice.Model.Contains("iPad"));

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

                if (parameters != null)
                {
                    foreach (var item in parameters)
                    {
                        ValueStack.Push(item.Key, item.Value);
                    }
                }

                IScreenController newController = BusinessProcessContext.Current.CreateScreenController(controllerName);
                ValueStack.SetCurrentController(newController);
                ValueStack.Push("controller", newController);
                screenName = newController.GetView(screenName);

                TabOrderManager.Create(this);

                var scr =
                    (Screen)
                    BusinessProcessContext.Current.CreateScreenFactory()
                    .CreateScreen(screenName, ValueStack, newController, null);

                rootControl   = RootControl;
                CurrentScreen = ControlsContext.Current.CreateScreenData(screenName, controllerName, scr);

                var viewController = new ScreenController(scr.View);

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

                    if (!isBackCommand)
                    {
                        _controller.PushViewController(viewController, true);
                    }
                    else
                    {
                        _controller.SetViewControllers(new[]
                        {
                            viewController,
                            _controller.TopViewController
                        }, false);
                        _controller.PopViewControllerAnimated(true);
                    }
                }
                else
                {
                    _controller.PopViewControllerAnimated(false);
                    _controller.PushViewController(viewController, false);
                }
            }
            catch (Exception ex)
            {
                HandleException(ex);
            }
            finally
            {
                LogManager.Logger.ScreenOpened();

                if (rootControl != null)
                {
                    rootControl.Dispose();
                }

                GC.Collect();

                ControlsContext.Current.ActionHandlerLocker.Release();
                Busy = false;
            }
            return(true);
        }