コード例 #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");
        }
コード例 #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");
        }
コード例 #3
0
                /// <summary>
                /// Called when deactivating.
                /// </summary>
                /// <param name="close">Indicates whether this instance will be closed.</param>
                /// <param name="cancellationToken">The cancellation token to cancel operation.</param>
                /// <returns>A task that represents the asynchronous operation.</returns>
                protected override async Task OnDeactivateAsync(bool close, CancellationToken cancellationToken)
                {
                    if (close)
                    {
                        foreach (var deactivate in this._items.OfType <IDeactivate>())
                        {
                            await deactivate.DeactivateAsync(true, cancellationToken);
                        }

                        this._items.Clear();
                    }
                    else
                    {
                        await ScreenExtensions.TryDeactivateAsync(this.ActiveItem, false, cancellationToken);
                    }
                }
コード例 #4
0
                private async Task CloseItemCoreAsync(T item, CancellationToken cancellationToken = default)
                {
                    if (item.Equals(this.ActiveItem))
                    {
                        var index = this._items.IndexOf(item);
                        var next  = this.DetermineNextItemToActivate(this._items, index);

                        await this.ChangeActiveItemAsync(next, true);
                    }
                    else
                    {
                        await ScreenExtensions.TryDeactivateAsync(item, true, cancellationToken);
                    }

                    this._items.Remove(item);
                }
コード例 #5
0
                private async Task CloseItemCoreAsync(T item, CancellationToken cancellationToken)
                {
                    if (item.Equals(ActiveItem))
                    {
                        int index = _items.IndexOf(item);
                        T   next  = DetermineNextItemToActivate(_items, index);

                        await ChangeActiveItemAsync(next, true, cancellationToken);
                    }
                    else
                    {
                        await ScreenExtensions.TryDeactivateAsync(item, true, cancellationToken);
                    }

                    _items.Remove(item);
                }
コード例 #6
0
                /// <summary>
                /// Deactivates the specified item.
                /// </summary>
                /// <param name="item">The item to close.</param>
                /// <param name="close">Indicates whether or not to close the item after deactivating it.</param>
                /// <param name="cancellationToken">The cancellation token to cancel operation.</param>
                /// <returns>A task that represents the asynchronous operation.</returns>
                public override async Task DeactivateItemAsync(T item, bool close, CancellationToken cancellationToken = default)
                {
                    if (item == null)
                    {
                        return;
                    }

                    if (close)
                    {
                        var closeResult = await this.CloseStrategy.ExecuteAsync(new[] { item }, CancellationToken.None);

                        if (closeResult.CloseCanOccur)
                        {
                            await this.CloseItemCoreAsync(item, cancellationToken);
                        }
                    }
                    else
                    {
                        await ScreenExtensions.TryDeactivateAsync(item, false, cancellationToken);
                    }
                }
コード例 #7
0
        private async Task RemoveDialogAsync(IDialog dialog, CancellationToken cancellationToken)
        {
            await semaphore.WaitAsync();

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

                if (instanceCounter.ContainsKey(dialog))
                {
                    var remaining = instanceCounter[dialog]--;
                    if (remaining > 0)
                    {
                        return;
                    }

                    instanceCounter.Remove(dialog);
                }

                Items.Remove(dialog);

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

                DialogClosed?.Invoke(this, dialog);
            }
            finally
            {
                semaphore.Release();
            }
        }
コード例 #8
0
                private async Task CloseItemCoreAsync(T item, CancellationToken cancellationToken = default)
                {
                    await ScreenExtensions.TryDeactivateAsync(item, true, cancellationToken);

                    this._items.Remove(item);
                }
コード例 #9
0
        public override async void ViewWillDisappear(bool animated)
        {
            base.ViewWillDisappear(animated);

            await ScreenExtensions.TryDeactivateAsync(viewModel, false);
        }
コード例 #10
0
ファイル: HomeActivity.cs プロジェクト: vb2ae/Caliburn.Micro
        protected override async void OnPause()
        {
            base.OnPause();

            await ScreenExtensions.TryDeactivateAsync(viewModel, false);
        }