Esempio n. 1
0
        public void ShowScreen_ActiveItemSetToScreen()
        {
            var fakeScreen = new FakeViewModel();
            var screenHost = new ScreenHost();

            screenHost.ShowScreen(fakeScreen);

            Assert.Equal(fakeScreen, screenHost.ActiveItem);
        }
Esempio n. 2
0
 private void OnHostClosed(ScreenHost host)
 {
     host.Closed -= OnHostClosed;
     _screens.Remove(host.Key);
     if (!host.Persist(_persistenceService, out var e))
     {
         OnException($"Unable to restore screen: {host.Key}", e);
     }
     host.Dispose();
 }
Esempio n. 3
0
        public void IUserInputBeforeClosedRequestScreenOpen_InteractivelyCloseAllScreens_ActiveItemStillIUserInputBeforeClosedRequestScreen()
        {
            var currentlyOpenFakeScreen = new FakeViewModel();
            var screenHost = new ScreenHost();

            screenHost.ShowScreen(currentlyOpenFakeScreen);

            screenHost.InteractivelyCloseAllScreens(() => { });

            Assert.Equal(currentlyOpenFakeScreen, screenHost.ActiveItem);
        }
Esempio n. 4
0
        private void OnHostClosed(ScreenHost host)
        {
            host.Closed -= OnHostClosed;
            _screens.Remove(host.Key);
            Exception e;

            if (!host.Persist(_persistenceService, out e))
            {
                OnException(string.Format("Unable to restore screen: {0}", host.Key), e);
            }
            host.Dispose();
        }
Esempio n. 5
0
        public void IUserInputBeforeClosedRequestScreenOpen_ShowScreen_ActiveItemStillIUserInputBeforeClosedRequestScreen()
        {
            var currentlyOpenFakeScreen = new FakeViewModel();
            var fakeScreenToOpen        = new FakeViewModel();
            var screenHost = new ScreenHost();

            screenHost.ShowScreen(currentlyOpenFakeScreen);

            screenHost.ShowScreen(fakeScreenToOpen);

            Assert.Equal(currentlyOpenFakeScreen, screenHost.ActiveItem);
        }
Esempio n. 6
0
        public void IUserInputBeforeClosedRequestScreenOpen_InteractivelyCloseAllScreens_ContinuationSetsActiveItemToNull()
        {
            var    currentlyOpenFakeScreen = new FakeViewModel();
            var    screenHost   = new ScreenHost();
            Action continuation = () => { };

            currentlyOpenFakeScreen.ContinueIfCanCloseAction += c => continuation = c;
            screenHost.ShowScreen(currentlyOpenFakeScreen);

            screenHost.InteractivelyCloseAllScreens(() => { });
            continuation();

            Assert.Null(screenHost.ActiveItem);
        }
Esempio n. 7
0
        public void IUserInputBeforeClosedRequestScreenOpen_InteractivelyCloseAllScreens_ContinuationCallsContination()
        {
            var    currentlyOpenFakeScreen = new FakeViewModel();
            var    screenHost     = new ScreenHost();
            var    continationRun = false;
            Action continuation   = () => { };

            currentlyOpenFakeScreen.ContinueIfCanCloseAction += c => continuation = c;
            screenHost.ShowScreen(currentlyOpenFakeScreen);

            screenHost.InteractivelyCloseAllScreens(() => continationRun = true);
            continuation();

            Assert.True(continationRun);
        }
Esempio n. 8
0
        public void IUserInputBeforeClosedRequestScreenOpen_ShowScreenAndRunContinuation_ActiveItemSetToScreen()
        {
            var    currentlyOpenFakeScreen = new FakeViewModel();
            var    fakeScreenToOpen        = new FakeViewModel();
            Action continuation            = () => { };

            currentlyOpenFakeScreen.ContinueIfCanCloseAction += c => continuation = c;
            var screenHost = new ScreenHost();

            screenHost.ShowScreen(currentlyOpenFakeScreen);

            screenHost.ShowScreen(fakeScreenToOpen);
            continuation();

            Assert.Equal(fakeScreenToOpen, screenHost.ActiveItem);
        }
Esempio n. 9
0
        private void Show(Type idType, string instanceId, object parameter, bool isPopup)
        {
            var        key = new NamedType(idType, instanceId);
            ScreenHost host;

            if (_screens.TryGetValue(key, out host))
            {
                host.BringToFront(isPopup);
                return;
            }

            ScreenFactory factory;

            if (!_factories.TryGetValue(key.Type, out factory))
            {
                return;
            }

            IScreen   logic;
            TBaseView view;
            Exception e;

            if (!factory.TryCreate(instanceId, parameter, out logic, out view, out e))
            {
                OnException(string.Format("Unable to create screen: {0}", key), e);
                return;
            }

            host = new ScreenHost(key, view, logic, CreateScreen, CreatePopup, factory.PopupAttribute);
            _screens.Add(key, host);
            host.Closed += OnHostClosed;

            var setupable = logic as IInternalScreen;

            if (setupable != null)
            {
                setupable.Setup(host.Close);
            }

            if (!host.Restore(_persistenceService, out e))
            {
                OnException(string.Format("Unable to restore screen: {0}", key), e);
            }

            host.Show(isPopup);
        }
Esempio n. 10
0
        private ScreenHost CreateScreenHost(Type idType, string instanceId, Func <IInternalScreen, object> getParameter, bool isPopup, PopupAttribute popupAttribute = null)
        {
            var key = new NamedType(idType, instanceId);

            if (_screens.TryGetValue(key, out var host))
            {
                host.BringToFront(isPopup);
                return(null);
            }

            if (!_factories.TryGetValue(key.Type, out var factory))
            {
                return(null);
            }

            if (!factory.TryCreate(instanceId, getParameter, out var logic, out var view, out var e))
            {
                OnException($"Unable to create screen: {key}", e);
                return(null);
            }

            popupAttribute = popupAttribute ?? factory.PopupAttribute;
            host           = new ScreenHost(key, view, logic, CreateScreen, ShowScreen, CreatePopup, ShowPopup, popupAttribute);
            _screens.Add(key, host);
            host.Closed += OnHostClosed;

            if (logic is IInternalScreen internalScreen)
            {
                internalScreen.Setup(host.Close);
            }

            if (!host.Restore(_persistenceService, out e))
            {
                OnException($"Unable to restore screen: {key}", e);
            }

            return(host);
        }