当前位置: 首页>>代码示例>>C#>>正文


C# Interaction.Handle方法代码示例

本文整理汇总了C#中Interaction.Handle方法的典型用法代码示例。如果您正苦于以下问题:C# Interaction.Handle方法的具体用法?C# Interaction.Handle怎么用?C# Interaction.Handle使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Interaction的用法示例。


在下文中一共展示了Interaction.Handle方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: UnhandledInteractionsShouldCauseException

        public void UnhandledInteractionsShouldCauseException()
        {
            var interaction = new Interaction<string, Unit>();
            Assert.Throws<UnhandledInteractionException<string, Unit>>(() => interaction.Handle("foo").FirstAsync().Wait());

            interaction.RegisterHandler(_ => { });
            interaction.RegisterHandler(_ => { });
            Assert.Throws<UnhandledInteractionException<string, Unit>>(() => interaction.Handle("foo").FirstAsync().Wait());
        }
开发者ID:reactiveui,项目名称:ReactiveUI,代码行数:9,代码来源:InteractionsTest.cs

示例2: HandledInteractionsShouldNotCauseException

        public void HandledInteractionsShouldNotCauseException()
        {
            var interaction = new Interaction<Unit, bool>();
            interaction.RegisterHandler(c => c.SetOutput(true));

            interaction.Handle(Unit.Default).FirstAsync().Wait();
        }
开发者ID:reactiveui,项目名称:ReactiveUI,代码行数:7,代码来源:InteractionsTest.cs

示例3: FileListViewModel

        public FileListViewModel(IScreen host)
        {
            HostScreen = host;

            Files = new ReactiveList<string>(new []
            {
                "c:/temp/foo.txt",
                "c:/temp/bar.txt",
                "c:/temp/baseball.dat",
                "c:/temp/basketball.dat",
                "c:/temp/handegg.dat"
            });

            var confirmDelete = new Interaction<Unit, string>();

            DeleteFile = ReactiveCommand.CreateFromTask(
                async () =>
                {
                    var fileToDelete = SelectedFile;
                    var baseMessage = $"Do you really want to delete {fileToDelete}?";
                    var help = "\nConfirm by entering the full file name below.";
                    var message = baseMessage + help;
                    var abort = this
                        .WhenAnyValue(x => x.SelectedFile)
                        .Skip(1)
                        .Select(_ => Unit.Default);

                    ConfirmDeleteViewModel = new ConfirmEventViewModel(abort, confirmDelete)
                    {
                        Message = message
                    };

                    while (true)
                    {
                        var confirmation = await confirmDelete.Handle(Unit.Default);

                        if (confirmation == fileToDelete)
                        {
                            SelectedFile = null;
                            Files.Remove(fileToDelete);
                            ConfirmDeleteViewModel = null;
                            break;
                        }

                        if (confirmation == null)
                        {
                            ConfirmDeleteViewModel = null;
                            break;
                        }

                        ConfirmDeleteViewModel.Message = baseMessage + "\nYou didn't type the right thing." + help;
                    }
                },
                this.WhenAnyValue(vm => vm.SelectedFile).Select(s => s != null));
        }
开发者ID:moswald,项目名称:RxUI-ConfirmationExample,代码行数:55,代码来源:FileListViewModel.cs

示例4: NestedHandlersAreExecutedInReverseOrderOfSubscription

        public void NestedHandlersAreExecutedInReverseOrderOfSubscription()
        {
            var interaction = new Interaction<Unit, string>();

            using (interaction.RegisterHandler(x => x.SetOutput("A"))) {
                Assert.Equal("A", interaction.Handle(Unit.Default).FirstAsync().Wait());

                using (interaction.RegisterHandler(x => x.SetOutput("B"))) {
                    Assert.Equal("B", interaction.Handle(Unit.Default).FirstAsync().Wait());

                    using (interaction.RegisterHandler(x => x.SetOutput("C"))) {
                        Assert.Equal("C", interaction.Handle(Unit.Default).FirstAsync().Wait());
                    }

                    Assert.Equal("B", interaction.Handle(Unit.Default).FirstAsync().Wait());
                }

                Assert.Equal("A", interaction.Handle(Unit.Default).FirstAsync().Wait());
            }
        }
开发者ID:reactiveui,项目名称:ReactiveUI,代码行数:20,代码来源:InteractionsTest.cs

示例5: HandlersCanOptNotToHandleTheInteraction

        public void HandlersCanOptNotToHandleTheInteraction()
        {
            var interaction = new Interaction<bool, string>();

            var handler1A = interaction.RegisterHandler(x => x.SetOutput("A"));
            var handler1B = interaction.RegisterHandler(
                x => {
                    // only handle if the input is true
                    if (x.Input) {
                        x.SetOutput("B");
                    }
                });
            var handler1C = interaction.RegisterHandler(x => x.SetOutput("C"));

            using (handler1A) {
                using (handler1B) {
                    using (handler1C) {
                        Assert.Equal("C", interaction.Handle(false).FirstAsync().Wait());
                        Assert.Equal("C", interaction.Handle(true).FirstAsync().Wait());
                    }

                    Assert.Equal("A", interaction.Handle(false).FirstAsync().Wait());
                    Assert.Equal("B", interaction.Handle(true).FirstAsync().Wait());
                }

                Assert.Equal("A", interaction.Handle(false).FirstAsync().Wait());
                Assert.Equal("A", interaction.Handle(true).FirstAsync().Wait());
            }
        }
开发者ID:reactiveui,项目名称:ReactiveUI,代码行数:29,代码来源:InteractionsTest.cs

示例6: HandlersCanContainAsynchronousCode

        public void HandlersCanContainAsynchronousCode()
        {
            var scheduler = new TestScheduler();
            var interaction = new Interaction<Unit, string>();

            // even though handler B is "slow" (i.e. mimicks waiting for the user), it takes precedence over A, so we expect A to never even be called
            var handler1AWasCalled = false;
            var handler1A = interaction.RegisterHandler(
                x => {
                    x.SetOutput("A");
                    handler1AWasCalled = true;
                });
            var handler1B = interaction.RegisterHandler(
                x =>
                    Observable
                        .Return(Unit.Default)
                        .Delay(TimeSpan.FromSeconds(1), scheduler)
                        .Do(_ => x.SetOutput("B")));

            using (handler1A)
            using (handler1B) {
                var result = interaction
                    .Handle(Unit.Default)
                    .CreateCollection(ImmediateScheduler.Instance);

                Assert.Equal(0, result.Count);
                scheduler.AdvanceBy(TimeSpan.FromSeconds(0.5).Ticks);
                Assert.Equal(0, result.Count);
                scheduler.AdvanceBy(TimeSpan.FromSeconds(0.6).Ticks);
                Assert.Equal(1, result.Count);
                Assert.Equal("B", result[0]);
            }

            Assert.False(handler1AWasCalled);
        }
开发者ID:reactiveui,项目名称:ReactiveUI,代码行数:35,代码来源:InteractionsTest.cs


注:本文中的Interaction.Handle方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。