simple multiple message sends (untested)

This commit is contained in:
Will Portnoy 2016-03-25 11:19:43 -07:00
Родитель 2d18fc7447
Коммит e10f53d09f
3 изменённых файлов: 19 добавлений и 5 удалений

Просмотреть файл

@ -66,9 +66,10 @@ namespace Microsoft.Bot.Builder
var waits = new WaitFactory();
var frames = new FrameFactory(waits);
IBotData toBotData = new Internals.JObjectBotData(toBot);
IConnectorClient client = new ConnectorClient();
var provider = new Serialization.SimpleServiceLocator()
{
waits, frames, toBotData
waits, frames, toBotData, client
};
var formatter = CompositionRoot.MakeBinaryFormatter(provider);
@ -87,7 +88,7 @@ namespace Microsoft.Bot.Builder
else
{
IFiberLoop fiber = new Fiber(frames);
context = new Internals.DialogContext(toBotData, fiber);
context = new Internals.DialogContext(client, toBotData, fiber);
var root = MakeRoot();
var loop = Methods.Void(Methods.Loop(context.ToRest<T>(root.StartAsync), int.MaxValue));
fiber.Call(loop, default(T));

Просмотреть файл

@ -46,23 +46,27 @@ namespace Microsoft.Bot.Builder.Internals
[Serializable]
public sealed class DialogContext : IDialogContext, IUserToBot, ISerializable
{
private readonly IConnectorClient client;
private readonly IBotData data;
private readonly IFiberLoop fiber;
public DialogContext(IBotData data, IFiberLoop fiber)
public DialogContext(IConnectorClient client, IBotData data, IFiberLoop fiber)
{
Field.SetNotNull(out this.client, nameof(client), client);
Field.SetNotNull(out this.data, nameof(data), data);
Field.SetNotNull(out this.fiber, nameof(fiber), fiber);
}
public DialogContext(SerializationInfo info, StreamingContext context)
{
Field.SetNotNullFrom(out this.client, nameof(client), info);
Field.SetNotNullFrom(out this.data, nameof(data), info);
Field.SetNotNullFrom(out this.fiber, nameof(fiber), info);
}
void ISerializable.GetObjectData(SerializationInfo info, StreamingContext context)
{
info.AddValue(nameof(this.client), this.client);
info.AddValue(nameof(this.data), this.data);
info.AddValue(nameof(this.fiber), this.fiber);
}
@ -139,6 +143,12 @@ namespace Microsoft.Bot.Builder.Internals
async Task IBotToUser.PostAsync(Message message, CancellationToken cancellationToken)
{
if (this.toUser != null)
{
await this.client.Messages.SendMessageAsync(this.toUser, cancellationToken);
this.toUser = null;
}
Field.SetNotNull(out this.toUser, nameof(message), message);
}
@ -149,6 +159,8 @@ namespace Microsoft.Bot.Builder.Internals
this.toBot = message;
this.fiber.Post(message);
await this.fiber.PollAsync();
var toUser = this.toUser;
this.toUser = null;
return toUser;
}

Просмотреть файл

@ -34,6 +34,7 @@
using System;
using System.Threading.Tasks;
using Microsoft.Bot.Connector;
using Microsoft.Bot.Builder.Fibers;
using Microsoft.VisualStudio.TestTools.UnitTesting;
@ -66,10 +67,10 @@ namespace Microsoft.Bot.Builder.Tests
public static async Task<Internals.DialogContext> MakeContextAsync(IDialog<object> root)
{
var client = new Mock<IConnectorClient>(MockBehavior.Strict);
var data = new Internals.JObjectBotData(new Connector.Message());
IFiberLoop fiber = new Fiber(new FrameFactory(new WaitFactory()));
var context = new Internals.DialogContext(data, fiber);
var context = new Internals.DialogContext(client.Object, data, fiber);
var loop = Methods.Void(Methods.Loop(context.ToRest<object>(root.StartAsync), int.MaxValue));
fiber.Call(loop, null);
await fiber.PollAsync();