Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
msft-shahins committed May 11, 2016
2 parents d1e5fec + 16ca102 commit fe946cc
Showing 180 changed files with 21,065 additions and 3,633 deletions.
10 changes: 8 additions & 2 deletions CSharp/Documentation/Dialogs.cs
Original file line number Diff line number Diff line change
@@ -4,6 +4,7 @@
/// \tableofcontents
/// [LUIS]: http://luis.ai
/// [How to Setup LUIS]: http://aka.ms/bf-node-nl
/// [Buttons]: http://docs.botframework.com/connector/message-actions/#actions-on-attachments
///
/// \section Overview
/// %Dialogs model a conversational process, where the exchange of messages between bot and user
@@ -145,11 +146,16 @@
///
/// The Chain methods provide a fluent interface to dialogs that is usable in linq query syntax. The compiled form of linq query syntax often leverages anonymous methods.
/// If these anonymous methods do not reference the environment of local variables, then these anonymous methods have no state and are trivially serializable. However, if
/// the anonymous method captures any local variable in the environment, the resulting closure object (generated by the compiler) is not marked as serializable. The %Bot Builder
/// the anonymous method captures any local variable in the environment, the resulting closure object (generated by the compiler) is not marked as serializable. The %Bot %Builder
/// will detect this situation and throw a ClosureCaptureException to help diagnose the issue.
///
/// If you wish to try to leverage reflection to serialize classes that are not marked as serializable, the library has a reflection-based serialization surrogate that
/// can be registered with Autofac as follows:
/// ~~~
/// var builder = new ContainerBuilder();
/// builder.RegisterModule(new DialogModule());
/// builder.RegisterModule(new ReflectionSurrogateModule());
/// ~~~
///
/// \dontinclude Microsoft.Bot.Builder.Tests\ChainTests.cs
/// \skip includeReflection
@@ -217,5 +223,5 @@
/// \section Conclusion
/// Through this description we have seen how you can easily create stateless bots that can reuse dialog building blocks
/// ranging from simple prompts to advanced natural language. As a next step, you should explore \ref forms which
/// describes how the %Bot Builder framework can automatically build dialogs from a C# class you want the user to fill in.
/// describes how the %Bot %Builder framework can automatically build dialogs from a C# class you want the user to fill in.
}
2 changes: 1 addition & 1 deletion CSharp/Documentation/Documentation.csproj
Original file line number Diff line number Diff line change
@@ -11,7 +11,7 @@
<SccAuxPath>SAK</SccAuxPath>
<SccProvider>SAK</SccProvider>
<ProjectGuid>{72C60ACB-4804-4584-AD49-00289A89F227}</ProjectGuid>
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
<TargetFrameworkVersion>v4.6</TargetFrameworkVersion>
<TargetFrameworkProfile />
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)' == 'Documentation'">
175 changes: 164 additions & 11 deletions CSharp/Documentation/Forms.cs

Large diffs are not rendered by default.

5 changes: 5 additions & 0 deletions CSharp/Documentation/Overview.cs
Original file line number Diff line number Diff line change
@@ -89,3 +89,8 @@ namespace Microsoft.Bot.Builder.Internals.Fibers { }
/// <summary>Namespace for the machinery needed to talk to http://luis.ai.</summary>
/// <remarks>This namespace is not useful for most developers.</remarks>
namespace Microsoft.Bot.Builder.Luis { }

/// <summary>
/// Namespace for resources.
/// </summary>
namespace Microsoft.Bot.Builder.Resource { }
2 changes: 1 addition & 1 deletion CSharp/Documentation/app.config
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<startup><supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" /></startup>
<startup><supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6" /></startup>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
49 changes: 41 additions & 8 deletions CSharp/Library/Dialogs/BotData.cs
Original file line number Diff line number Diff line change
@@ -37,16 +37,17 @@

using Microsoft.Bot.Builder.Internals.Fibers;
using Microsoft.Bot.Connector;
using System.IO;

namespace Microsoft.Bot.Builder.Dialogs.Internals
{
public abstract class BotDataBase<T> : IBotData
{
protected readonly Message mesage;
protected readonly Message message;

public BotDataBase(Message message)
{
SetField.NotNull(out this.mesage, nameof(mesage), message);
SetField.NotNull(out this.message, nameof(BotDataBase<T>.message), message);
}

protected abstract T MakeData();
@@ -56,11 +57,11 @@ IBotDataBag IBotData.ConversationData
{
get
{
var data = (T)this.mesage.BotConversationData;
var data = (T)this.message.BotConversationData;
if (data == null)
{
data = this.MakeData();
this.mesage.BotConversationData = data;
this.message.BotConversationData = data;
}

return this.WrapData(data);
@@ -71,11 +72,11 @@ IBotDataBag IBotData.PerUserInConversationData
{
get
{
var data = (T)this.mesage.BotPerUserInConversationData;
var data = (T)this.message.BotPerUserInConversationData;
if (data == null)
{
data = this.MakeData();
this.mesage.BotPerUserInConversationData = data;
this.message.BotPerUserInConversationData = data;
}

return this.WrapData(data);
@@ -86,11 +87,11 @@ IBotDataBag IBotData.UserData
{
get
{
var data = (T)this.mesage.BotUserData;
var data = (T)this.message.BotUserData;
if (data == null)
{
data = this.MakeData();
this.mesage.BotUserData = data;
this.message.BotUserData = data;
}

return this.WrapData(data);
@@ -209,4 +210,36 @@ protected override IBotDataBag WrapData(JObject data)
return new Bag(data);
}
}

public sealed class BotDataBagStream : MemoryStream
{
private readonly IBotDataBag bag;
private readonly string key;
public BotDataBagStream(IBotDataBag bag, string key)
{
SetField.NotNull(out this.bag, nameof(bag), bag);
SetField.NotNull(out this.key, nameof(key), key);

byte[] blob;
if (this.bag.TryGetValue(key, out blob))
{
this.Write(blob, 0, blob.Length);
this.Position = 0;
}
}

public override void Flush()
{
base.Flush();

var blob = this.ToArray();
this.bag.SetValue(this.key, blob);
}

public override void Close()
{
this.Flush();
base.Close();
}
}
}
70 changes: 55 additions & 15 deletions CSharp/Library/Dialogs/BotToUser.cs
Original file line number Diff line number Diff line change
@@ -31,14 +31,14 @@
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//

using Microsoft.Bot.Builder.Internals.Fibers;
using Microsoft.Bot.Connector;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;

using Microsoft.Bot.Builder.Internals.Fibers;
using Microsoft.Bot.Connector;

namespace Microsoft.Bot.Builder.Dialogs.Internals
{
public sealed class SendLastInline_BotToUser : IBotToUser
@@ -90,26 +90,39 @@ async Task IBotToUser.PostAsync(Message message, CancellationToken cancellationT
}
}

public sealed class BotToUserQueue : IBotToUser
public sealed class AlwaysSendDirect_BotToUser : IBotToUser
{
private readonly Message toBot;
private readonly Queue<Message> queue = new Queue<Message>();
public BotToUserQueue(Message toBot)
private readonly IConnectorClient client;
public AlwaysSendDirect_BotToUser(Message toBot, IConnectorClient client)
{
SetField.NotNull(out this.toBot, nameof(toBot), toBot);
SetField.NotNull(out this.client, nameof(client), client);
}
public void Clear()

Message IBotToUser.MakeMessage()
{
this.queue.Clear();
var toUser = this.toBot.CreateReplyMessage();
toUser.BotUserData = this.toBot.BotUserData;
toUser.BotConversationData = this.toBot.BotConversationData;
toUser.BotPerUserInConversationData = this.toBot.BotPerUserInConversationData;
return toUser;
}

public IEnumerable<Message> Messages
async Task IBotToUser.PostAsync(Message message, CancellationToken cancellationToken)
{
get
{
return this.queue;
}
await this.client.Messages.SendMessageAsync(message, cancellationToken);
}
}

public sealed class BotToUserQueue : IBotToUser
{
private readonly Message toBot;
private readonly Queue<Message> queue;
public BotToUserQueue(Message toBot, Queue<Message> queue)
{
SetField.NotNull(out this.toBot, nameof(toBot), toBot);
SetField.NotNull(out this.queue, nameof(queue), queue);
}

Message IBotToUser.MakeMessage()
@@ -145,7 +158,34 @@ Message IBotToUser.MakeMessage()
async Task IBotToUser.PostAsync(Message message, CancellationToken cancellationToken)
{
await this.inner.PostAsync(message, cancellationToken);
await this.writer.WriteLineAsync(message.Text);
await this.writer.WriteLineAsync($"{message.Text}{ActionsToText(message.Attachments)}");
}

private static string ActionsToText(IList<Attachment> attachments)
{
var buttonAttachments = attachments?.Where(attachment => attachment.Actions?.Count > 0);
string text = string.Empty;
if (buttonAttachments != null)
{
foreach (var attachment in buttonAttachments)
{
if (attachment != null && attachment.Actions != null && attachment.Actions.Count() > 0)
{
foreach (var action in attachment.Actions)
{
if (!string.IsNullOrEmpty(action.Message))
{
text += $"\n{action.Message}. {action.Title}";
}
else
{
text += $"\n* {action.Title}";
}
}
}
}
}
return text;
}
}
}
Loading

0 comments on commit fe946cc

Please sign in to comment.