コード例 #1
0
        public static async Task CopyAsync(this IDataStore store, DocumentAddress sourceAddress, DocumentAddress targetAddress)
        {
            var source = store.ToChannel(sourceAddress);
            var target = store.ToChannel(targetAddress);

            if (target.Exists())
            {
                target.Delete();
            }

            await source
            .GetReadStream()
            .CopyToAsync(target.GetWriteStream())
            .ConfigureAwait(false);
        }
コード例 #2
0
        /// <summary>
        /// If the document with the specified <paramref name="address"/> does not exist,
        /// adds it using the specified <paramref name="addData"/> delegate.
        /// Else, returns it.
        /// </summary>
        public static Task <IResult <TData> > GetOrAddAsync <TData>(
            this IDocumentStore source, DocumentAddress address,
            Func <TData> addData) where TData : class
        {
            if (source is null)
            {
                throw new ArgumentNullException(nameof(source));
            }
            if (addData is null)
            {
                throw new ArgumentNullException(nameof(addData));
            }

            return(source.GetOrAddAsync(
                       address: address,
                       addDataAsync: _ => Task.FromResult(addData())
                       ));
        }
コード例 #3
0
        /// <summary>
        /// If the document with the specified <paramref name="address"/> does not exist,
        /// adds it using the specified <paramref name="addData"/> delegate.
        /// Else, Updates it using the specified <paramref name="updateData"/> delegate.
        /// </summary>
        public static Task <IResult <TData> > AddOrUpdateAsync <TData>(
            this IDocumentStore source, DocumentAddress address,
            Func <TData> addData, Func <TData, TData> updateData) where TData : class
        {
            if (source is null)
            {
                throw new ArgumentNullException(nameof(source));
            }
            if (addData is null)
            {
                throw new ArgumentNullException(nameof(addData));
            }
            if (updateData is null)
            {
                throw new ArgumentNullException(nameof(updateData));
            }

            return(source.AddOrUpdateAsync(
                       address: address,
                       addDataAsync: _ => Task.FromResult(addData()),
                       updateDataAsync: (_, data) => Task.FromResult(updateData(data))
                       ));
        }
コード例 #4
0
 public static IDataChannel ToChannel(this IDataStore store, DocumentAddress address) =>
 new DataChannel(store, address);
コード例 #5
0
        public static async Task MoveAsync(this IDataStore store, DocumentAddress sourceAddress, DocumentAddress targetAddress)
        {
            await store.CopyAsync(sourceAddress, targetAddress).ConfigureAwait(false);

            store.Delete(sourceAddress);
        }