Exemple #1
0
        public DialogStateManager(DialogContext dc, DialogStateManagerConfiguration configuration = null)
        {
            ComponentRegistration.Add(new DialogsComponentRegistration());

            dialogContext      = dc ?? throw new ArgumentNullException(nameof(dc));
            this.Configuration = configuration ?? dc.Context.TurnState.Get <DialogStateManagerConfiguration>();
            if (this.Configuration == null)
            {
                this.Configuration = new DialogStateManagerConfiguration();

                // get all of the component memory scopes
                foreach (var component in ComponentRegistration.Components.OfType <IComponentMemoryScopes>())
                {
                    foreach (var memoryScope in component.GetMemoryScopes())
                    {
                        this.Configuration.MemoryScopes.Add(memoryScope);
                    }
                }

                // get all of the component path resolvers
                foreach (var component in ComponentRegistration.Components.OfType <IComponentPathResolvers>())
                {
                    foreach (var pathResolver in component.GetPathResolvers())
                    {
                        this.Configuration.PathResolvers.Add(pathResolver);
                    }
                }
            }

            // cache for any other new dialogStatemanager instances in this turn.
            dc.Context.TurnState.Set <DialogStateManagerConfiguration>(this.Configuration);
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="DialogStateManager"/> class.
        /// </summary>
        /// <param name="dc">The dialog context for the current turn of the conversation.</param>
        /// <param name="configuration">Configuration for the dialog state manager. Default is <c>null</c>.</param>
        public DialogStateManager(DialogContext dc, DialogStateManagerConfiguration configuration = null)
        {
            ComponentRegistration.Add(new DialogsComponentRegistration());

            _dialogContext = dc ?? throw new ArgumentNullException(nameof(dc));
            Configuration  = configuration ?? dc.Context.TurnState.Get <DialogStateManagerConfiguration>();
            if (Configuration == null)
            {
                Configuration = new DialogStateManagerConfiguration();

                // Legacy memory scopes from static ComponentRegistration which is now obsolete.
                var memoryScopes = ComponentRegistration.Components
                                   .OfType <IComponentMemoryScopes>()
                                   .SelectMany(c => c.GetMemoryScopes())
                                   .ToList();

                // Merge new registrations from turn state
                memoryScopes.AddRange(dc.Context.TurnState.Get <IEnumerable <MemoryScope> >() ?? Enumerable.Empty <MemoryScope>());

                // Get all of the component memory scopes.
                foreach (var scope in memoryScopes)
                {
                    Configuration.MemoryScopes.Add(scope);
                }

                // Legacy memory scopes from static ComponentRegistration which is now obsolete.
                var pathResolvers = ComponentRegistration.Components
                                    .OfType <IComponentPathResolvers>()
                                    .SelectMany(c => c.GetPathResolvers())
                                    .ToList();

                // Merge new registrations from turn state
                pathResolvers.AddRange(dc.Context.TurnState.Get <IEnumerable <IPathResolver> >() ?? Enumerable.Empty <IPathResolver>());

                // Get all of the component path resolvers.
                foreach (var pathResolver in pathResolvers)
                {
                    Configuration.PathResolvers.Add(pathResolver);
                }
            }

            // cache for any other new dialogStatemanager instances in this turn.
            dc.Context.TurnState.Set(Configuration);
        }