Esempio n. 1
0
        public async Task Conductor_ConductWithTests()
        {
            var root = new Conductor <StateScreen> .Collection.AllActive();

            var child1 = new StateScreen
            {
                DisplayName = "screen1"
            };
            var child2 = new StateScreen(TimeSpan.FromSeconds(3))
            {
                DisplayName = "screen2"
            };

            var child3 = new StateScreen()
            {
                DisplayName = "screen3"
            };

            root.Items.Add(child1);
            root.Items.Add(child2);
            root.Items.Add(child3);

            await ScreenExtensions.TryActivateAsync(root).ConfigureAwait(false);

            await ScreenExtensions.TryDeactivateAsync(root, true).ConfigureAwait(false);

            Assert.True(child1.IsClosed, "child 1 should be closed");
            Assert.True(child2.IsClosed, "child 2 should be closed");
            Assert.True(child3.IsClosed, "child 3 should be closed");
        }
Esempio n. 2
0
        public async Task Screen_ConductWithTests()
        {
            var root = new Screen();

            var child1 = new StateScreen
            {
                DisplayName = "screen1"
            };
            // simulate a long deactivation process
            var child2 = new StateScreen(TimeSpan.FromSeconds(3))
            {
                DisplayName = "screen2"
            };

            var child3 = new StateScreen()
            {
                DisplayName = "screen3"
            };

            child1.ConductWith(root);
            child2.ConductWith(root);
            child3.ConductWith(root);

            await ScreenExtensions.TryActivateAsync(root).ConfigureAwait(false);

            await ScreenExtensions.TryDeactivateAsync(root, true).ConfigureAwait(false);

            Assert.True(child1.IsClosed, "child 1 should be closed");
            Assert.True(child2.IsClosed, "child 2 should be closed");
            Assert.True(child3.IsClosed, "child 3 should be closed");
        }
Esempio n. 3
0
                /// <summary>
                /// Activates the specified item.
                /// </summary>
                /// <param name="item">The item to activate.</param>
                /// <param name="cancellationToken">The cancellation token to cancel operation.</param>
                /// <returns>A task that represents the asynchronous operation.</returns>
                public override async Task ActivateItemAsync(T item, CancellationToken cancellationToken = default)
                {
                    if (item == null)
                    {
                        return;
                    }

                    item = this.EnsureItem(item);

                    if (this.IsActive)
                    {
                        await ScreenExtensions.TryActivateAsync(item, cancellationToken);
                    }

                    this.OnActivationProcessed(item, true);
                }
Esempio n. 4
0
                /// <summary>
                /// Activates the specified item.
                /// </summary>
                /// <param name="item">The item to activate.</param>
                /// <param name="cancellationToken">A cancellation token that can be used by other objects or threads to receive notice of cancellation.</param>
                /// <returns>A task that represents the asynchronous operation.</returns>
                public override async Task ActivateItemAsync(T item, CancellationToken cancellationToken = default)
                {
                    if (item != null && item.Equals(this.ActiveItem))
                    {
                        if (this.IsActive)
                        {
                            await ScreenExtensions.TryActivateAsync(item, cancellationToken);

                            this.OnActivationProcessed(item, true);
                        }

                        return;
                    }

                    await this.ChangeActiveItemAsync(item, false, cancellationToken);
                }
        private async Task AddDialogAsync(IDialog dialog, CancellationToken cancellationToken)
        {
            await semaphore.WaitAsync();

            try
            {
                if (dialog is IActivate activatable && !activatable.IsActive)
                {
                    await ScreenExtensions.TryActivateAsync(dialog, cancellationToken);
                }

                if (Items.Contains(dialog))
                {
                    if (!instanceCounter.ContainsKey(dialog))
                    {
                        instanceCounter.Add(dialog, 0);
                    }

                    instanceCounter[dialog]++;
                    return;
                }

                var topMostDialog = OpenDialogs.LastOrDefault();
                if (topMostDialog != null)
                {
                    topMostDialog.IsDialogEnabled = false;
                }

                dialog.IsDialogEnabled = true;
                Items.Add(dialog);

                DialogOpened?.Invoke(this, dialog);
            }
            finally
            {
                semaphore.Release();
            }
        }
Esempio n. 6
0
        /// <inheritdoc />
        public override async Task ActivateItemAsync(T item, CancellationToken cancellationToken = default)
        {
            if (item != null && item.Equals(this.ActiveItem))
            {
                if (this.IsActive)
                {
                    await ScreenExtensions.TryActivateAsync(item, cancellationToken);

                    this.OnActivationProcessed(item, true);
                }
                return;
            }

            var closeResult = await this.CloseStrategy.ExecuteAsync(new[] { this.ActiveItem }, cancellationToken);

            if (closeResult.CloseCanOccur)
            {
                await this.ChangeActiveItemAsync(item, true, cancellationToken);
            }
            else
            {
                this.OnActivationProcessed(item, false);
            }
        }
Esempio n. 7
0
        /// <inheritdoc />
        public override async Task ActivateItemAsync(T item, CancellationToken cancellationToken)
        {
            if (item != null && item.Equals(ActiveItem))
            {
                if (IsActive)
                {
                    await ScreenExtensions.TryActivateAsync(item, cancellationToken);

                    OnActivationProcessed(item, true);
                }
                return;
            }

            ICloseResult <T> closeResult = await CloseStrategy.ExecuteAsync(new[] { ActiveItem }, cancellationToken);

            if (closeResult.CloseCanOccur)
            {
                await ChangeActiveItemAsync(item, true, cancellationToken);
            }
            else
            {
                OnActivationProcessed(item, false);
            }
        }
        public override async void ViewDidLoad()
        {
            base.ViewDidLoad();

            await ScreenExtensions.TryActivateAsync(viewModel);
        }
Esempio n. 9
0
        public async Task ActivateAsync(object activationArgs)
        {
            if (IsInteractive(activationArgs))
            {
                // Initialize services that you need before app activation
                // take into account that the splash screen is shown while this code runs.
                await InitializeAsync();

                // Do not repeat app initialization when the Window already has content,
                // just ensure that the window is active
                if (Window.Current.Content == null)
                {
                    // Create a Shell or Frame to act as the navigation context
                    if (_shell?.Value == null)
                    {
                        var frame = new Frame();
                        NavigationService      = _container.RegisterNavigationService(frame);
                        Window.Current.Content = frame;
                    }
                    else
                    {
                        var viewModel = ViewModelLocator.LocateForView(_shell.Value);

                        ViewModelBinder.Bind(viewModel, _shell.Value, null);

                        await ScreenExtensions.TryActivateAsync(viewModel);

                        NavigationService      = _container.GetInstance <INavigationService>();
                        Window.Current.Content = _shell?.Value;
                    }
                }
            }

            var activationHandler = GetActivationHandlers()
                                    .FirstOrDefault(h => h.CanHandle(activationArgs));

            if (activationHandler != null)
            {
                await activationHandler.HandleAsync(activationArgs);
            }

            if (IsInteractive(activationArgs))
            {
                var activation = activationArgs as IActivatedEventArgs;
                if (activation.PreviousExecutionState == ApplicationExecutionState.Terminated)
                {
                    await Singleton <SuspendAndResumeService> .Instance.RestoreSuspendAndResumeData();
                }

                var defaultHandler = new DefaultActivationHandler(_defaultNavItem, NavigationService);
                if (defaultHandler.CanHandle(activationArgs))
                {
                    await defaultHandler.HandleAsync(activationArgs);
                }

                // Ensure the current window is active
                Window.Current.Activate();

                // Tasks after activation
                await StartupAsync();
            }
        }
Esempio n. 10
0
 /// <summary>
 /// Called when activating.
 /// </summary>
 /// <param name="cancellationToken">The cancellation token to cancel operation.</param>
 /// <returns>A task that represents the asynchronous operation.</returns>
 protected override Task OnActivateAsync(CancellationToken cancellationToken)
 {
     return(ScreenExtensions.TryActivateAsync(this.ActiveItem, cancellationToken));
 }
Esempio n. 11
0
        protected override async void OnResume()
        {
            base.OnResume();

            await ScreenExtensions.TryActivateAsync(viewModel);
        }