Esempio n. 1
0
 public ScorableWhoami(IDialogStack stack)
 {
     SetField.NotNull(out this.stack, nameof(stack), stack);
 }
Esempio n. 2
0
 public ScorableSupport(IDialogStack stack)
 {
     SetField.NotNull(out DialogStackObject, nameof(stack), stack);
 }
Esempio n. 3
0
 /// <summary>
 /// Call this dialog by interrupting the stack.
 /// </summary>
 /// <remarks>
 /// This method helps us avoid a closure with environment capture in <see cref="WithConfirmOnResume"/>.
 /// </remarks>
 public async Task Action(ResumeDialogEvent @event, IDialogStack stack, CancellationToken token)
 {
     stack.Call(this.Void(stack), null);
 }
 /// <summary>
 /// Call a child dialog, add it to the top of the stack and post the message to the child dialog.
 /// </summary>
 /// <typeparam name="R">The type of result expected from the child dialog.</typeparam>
 /// <param name="stack">The dialog stack.</param>
 /// <param name="child">The child dialog.</param>
 /// <param name="resume">The method to resume when the child dialog has completed.</param>
 /// <param name="message">The message that will be posted to child dialog.</param>
 /// <param name="token">A cancellation token.</param>
 /// <returns>A task representing the Forward operation.</returns>
 public static async Task Forward <R>(this IDialogStack stack, IDialog <R> child, ResumeAfter <R> resume, IMessageActivity message, CancellationToken token)
 {
     await stack.Forward <R, IMessageActivity>(child, resume, message, token);
 }
Esempio n. 5
0
 public DialogContext(IBotToUser botToUser, IBotData botData, IDialogStack stack)
 {
     SetField.NotNull(out this.botToUser, nameof(botToUser), botToUser);
     SetField.NotNull(out this.botData, nameof(botData), botData);
     SetField.NotNull(out this.stack, nameof(stack), stack);
 }
 public CancelScorable(IDialogStack stack, Regex regex)
 {
     SetField.NotNull(out this.stack, nameof(stack), stack);
     SetField.NotNull(out this.regex, nameof(regex), regex);
 }
 /// <summary>
 /// Suspend the current dialog until the user has sent a message to the bot.
 /// </summary>
 /// <param name="stack">The dialog stack.</param>
 /// <param name="resume">The method to resume when the message has been received.</param>
 public static void Wait(this IDialogStack stack, ResumeAfter <IMessageActivity> resume)
 {
     stack.Wait <IMessageActivity>(resume);
 }
Esempio n. 8
0
        protected override void Load(ContainerBuilder builder)
        {
            base.Load(builder);

            builder.RegisterModule(new FiberModule <DialogTask>());

            // singleton components

            builder
            .Register(c => new ResourceManager("Microsoft.Bot.Builder.Resource.Resources", typeof(Resource.Resources).Assembly))
            .As <ResourceManager>()
            .SingleInstance();

            // every lifetime scope is driven by a message

            builder
            .Register((c, p) => p.TypedAs <IMessageActivity>())
            .AsSelf()
            .AsImplementedInterfaces()
            .InstancePerMatchingLifetimeScope(LifetimeScopeTag);

            // make the address and cookie available for the lifetime scope

            builder
            .RegisterType <Address>()
            .AsSelf()
            .InstancePerMatchingLifetimeScope(LifetimeScopeTag);

            builder
            .RegisterType <ResumptionCookie>()
            .AsSelf()
            .InstancePerMatchingLifetimeScope(LifetimeScopeTag);

            // components not marked as [Serializable]
            builder
            .RegisterType <MicrosoftAppCredentials>()
            .AsSelf()
            .SingleInstance();

            builder
            .RegisterType <BotIdResolver>()
            .As <IBotIdResolver>()
            .SingleInstance();

            builder
            // not resolving IEqualityComparer<Address> from container because it's a very local policy
            // and yet too broad of an interface.  could explore using tags for registration overrides.
            .Register(c => new LocalMutualExclusion <Address>(new ConversationAddressComparer()))
            .As <IScope <Address> >()
            .SingleInstance();

            builder
            .Register(c => new ConnectorClientFactory(c.Resolve <IMessageActivity>(), c.Resolve <MicrosoftAppCredentials>()))
            .As <IConnectorClientFactory>()
            .InstancePerLifetimeScope();

            builder
            .Register(c => c.Resolve <IConnectorClientFactory>().MakeConnectorClient())
            .As <IConnectorClient>()
            .InstancePerLifetimeScope();

            builder
            .Register(c => c.Resolve <IConnectorClientFactory>().MakeStateClient())
            .As <IStateClient>()
            .InstancePerLifetimeScope();

            builder
            .Register(c => new DetectChannelCapability(c.Resolve <IMessageActivity>()))
            .As <IDetectChannelCapability>()
            .InstancePerLifetimeScope();

            builder
            .Register(c => c.Resolve <IDetectChannelCapability>().Detect())
            .As <IChannelCapability>()
            .InstancePerLifetimeScope();

            builder.RegisterType <ConnectorStore>()
            .AsSelf()
            .InstancePerLifetimeScope();

            // If bot wants to use InMemoryDataStore instead of
            // ConnectorStore, the below registration should be used
            // as the inner IBotDataStore for CachingBotDataStore

            /*builder.RegisterType<InMemoryDataStore>()
             *  .AsSelf()
             *  .SingleInstance(); */

            builder.Register(c => new CachingBotDataStore(c.Resolve <ConnectorStore>(),
                                                          CachingBotDataStoreConsistencyPolicy.ETagBasedConsistency))
            .As <IBotDataStore <BotData> >()
            .AsSelf()
            .InstancePerLifetimeScope();

            builder
            .RegisterType <JObjectBotData>()
            .As <IBotData>()
            .InstancePerLifetimeScope();

            builder
            .Register(c => new BotDataBagStream(c.Resolve <IBotData>().PrivateConversationData, BlobKey))
            .As <Stream>()
            .InstancePerLifetimeScope();

            builder
            .RegisterType <DialogTask>()
            .AsSelf()
            .As <IDialogStack>()
            .InstancePerLifetimeScope();

            // Scorable implementing "/deleteprofile"
            builder
            .RegisterType <DeleteProfileScorable>()
            .As <IScorable <double> >()
            .InstancePerLifetimeScope();

            builder
            .Register(c =>
            {
                var stack      = c.Resolve <IDialogStack>();
                var fromStack  = stack.Frames.Select(f => f.Target).OfType <IScorable <double> >();
                var fromGlobal = c.Resolve <IScorable <double>[]>();
                // since the stack of scorables changes over time, this should be lazy
                var lazyScorables = fromStack.Concat(fromGlobal);
                var scorable      = new CompositeScorable <double>(c.Resolve <IComparer <double> >(), c.Resolve <ITraits <double> >(), lazyScorables);
                return(scorable);
            })
            .InstancePerLifetimeScope()
            .AsSelf();

            builder
            .Register(c =>
            {
                var cc = c.Resolve <IComponentContext>();

                Func <IPostToBot> makeInner = () =>
                {
                    var task           = cc.Resolve <DialogTask>();
                    IDialogStack stack = task;
                    IPostToBot post    = task;
                    post = new ReactiveDialogTask(post, stack, cc.Resolve <IStore <IFiberLoop <DialogTask> > >(), cc.Resolve <Func <IDialog <object> > >());
                    post = new ExceptionTranslationDialogTask(post);
                    post = new LocalizedDialogTask(post);
                    post = new ScoringDialogTask <double>(post, stack, cc.Resolve <CompositeScorable <double> >());
                    return(post);
                };

                IPostToBot outer = new PersistentDialogTask(makeInner, cc.Resolve <IMessageActivity>(), cc.Resolve <IConnectorClient>(), cc.Resolve <IBotToUser>(), cc.Resolve <IBotData>());
                outer            = new SerializingDialogTask(outer, cc.Resolve <Address>(), c.Resolve <IScope <Address> >());
                outer            = new PostUnhandledExceptionToUserTask(outer, cc.Resolve <IBotToUser>(), cc.Resolve <ResourceManager>(), cc.Resolve <TraceListener>());
                return(outer);
            })
            .As <IPostToBot>()
            .InstancePerLifetimeScope();

            builder
            .RegisterType <AlwaysSendDirect_BotToUser>()
            .AsSelf()
            .As <IBotToUser>()
            .InstancePerLifetimeScope();

            builder
            .RegisterType <DialogContext>()
            .As <IDialogContext>()
            .InstancePerLifetimeScope();
        }
 public HelpScorable(IDialogStack stack)
 {
     SetField.NotNull(out _stack, nameof(stack), stack);
 }
Esempio n. 10
0
 async Task IPostToBot.PostAsync <T>(T item, CancellationToken token)
 {
     this.fiber.Post(item);
     IDialogStack stack = this;
     await stack.PollAsync(token);
 }
Esempio n. 11
0
 public ViewServiceRepository(IDialogStack dialogStack)
 {
     DialogStack = dialogStack;
 }
Esempio n. 12
0
 public ScorableMakePayment(IDialogStack stack)
 {
     SetField.NotNull(out _stack, nameof(stack), stack);
 }
Esempio n. 13
0
 public WikiScorable(QnAMakerScorable inner, IDialogStack stack, IBotData botData)
 {
     SetField.NotNull(out this.inner, nameof(inner), inner);
     SetField.NotNull(out this.stack, nameof(stack), stack);
     SetField.NotNull(out this.botData, nameof(botData), botData);
 }
Esempio n. 14
0
 public SettingsScorable(IDialogStack stack, IContosoFlowersDialogFactory dialogFactory)
 {
     SetField.NotNull(out this.stack, nameof(stack), stack);
     SetField.NotNull(out this.dialogFactory, nameof(dialogFactory), dialogFactory);
 }