Exemple #1
0
        /// <summary>
        /// Initialize from a source, every item is added by calling InsertOrUpdate
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="writer"></param>
        /// <param name="copyFrom"></param>
        /// <returns></returns>
        public static async Task Initialize <T>(this ITableWriter <T> writer, ITableReader <T> copyFrom)
        {
            var list = await copyFrom.GetAll();

            foreach (var item in list)
            {
                var item1 = item;
                await writer.InsertOrUpdate(item, obj => item1);
            }
        }
Exemple #2
0
        /// <summary>
        /// This will ignore the exisiting TEntity and replace it.
        /// </summary>
        /// <typeparam name="TEntity"></typeparam>
        /// <param name="writer"></param>
        /// <param name="match"></param>
        /// <param name="replace"></param>
        public static Task Replace <TEntity>(this ITableWriter <TEntity> writer, TEntity match, Action <TEntity> replace)
        {
            if (writer == null)
            {
                throw new ArgumentNullException("writer");
            }

            var add = new Func <TEntity>(
                () =>
            {
                var e = match;
                replace(e);
                return(e);
            });

            Func <TEntity, TEntity> updatefun = entity =>
            {
                var item = match;
                replace(item);
                return(item);
            };

            return(writer.InsertOrUpdate(add(), updatefun));
        }