Ejemplo n.º 1
0
        protected virtual async Task Write(IBotContext context, StoreItems changes = null)
        {
            if (changes == null)
            {
                changes = new StoreItems();
            }

            if (this._settings.PersistUserState)
            {
                changes[UserKey(context)] = context.State.User ?? new UserState();
            }

            if (this._settings.PersistConversationState)
            {
                changes[ConversationKey(context)] = context.State.Conversation ?? new ConversationState();
            }

            if (this._settings.LastWriterWins)
            {
                foreach (var item in changes)
                {
                    ((StoreItem)changes[item.Key]).eTag = "*";
                }
            }

            await _storage.Write(changes).ConfigureAwait(false);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Storage extension to Read as strong typed StoreItem objects
        /// </summary>
        /// <typeparam name="StoreItemT"></typeparam>
        /// <param name="storage"></param>
        /// <param name="keys"></param>
        /// <returns></returns>
        public static async Task <StoreItems <StoreItemT> > Read <StoreItemT>(this IStorage storage, params string[] keys) where StoreItemT : class
        {
            var storeItems = await storage.Read(keys).ConfigureAwait(false);

            var newResults = new StoreItems <StoreItemT>();

            foreach (var kv in storeItems)
            {
                newResults[kv.Key] = kv.Value as StoreItemT;
            }
            return(newResults);
        }