本文整理汇总了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());
}
示例2: HandledInteractionsShouldNotCauseException
public void HandledInteractionsShouldNotCauseException()
{
var interaction = new Interaction<Unit, bool>();
interaction.RegisterHandler(c => c.SetOutput(true));
interaction.Handle(Unit.Default).FirstAsync().Wait();
}
示例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));
}
示例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());
}
}
示例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());
}
}
示例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);
}