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); }
/// <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()) )); }
/// <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)) )); }
public static IDataChannel ToChannel(this IDataStore store, DocumentAddress address) => new DataChannel(store, address);
public static async Task MoveAsync(this IDataStore store, DocumentAddress sourceAddress, DocumentAddress targetAddress) { await store.CopyAsync(sourceAddress, targetAddress).ConfigureAwait(false); store.Delete(sourceAddress); }