public static async Task <ResultT> LoadAsync <ResultT>( this ICacheSourceLayer layer, IDeserializer <ResultT> deserializer, ContentReference fileRef, IProgress prog = null) { if (layer is null) { throw new ArgumentNullException(nameof(layer)); } if (deserializer is null) { throw new ArgumentNullException(nameof(deserializer)); } if (fileRef is null) { throw new ArgumentNullException(nameof(fileRef)); } var progs = prog.Split("Read", "Decode"); using var stream = await layer .GetStreamAsync(fileRef, progs[0]) .ConfigureAwait(false); using var progStream = new ProgressStream(stream, stream.Length, progs[1], false); return(deserializer.Deserialize(progStream)); }
public static async Task SendContentAsync( this HttpListenerResponse response, ICacheSourceLayer layer, ContentReference fileRef) { if (layer is null) { throw new ArgumentNullException(nameof(layer)); } if (fileRef is null) { throw new ArgumentNullException(nameof(fileRef)); } response.SetFileName(fileRef.ContentType, fileRef.FileName); using var stream = await layer .GetStreamAsync(fileRef, null) .ConfigureAwait(false); await response .SendStreamAsync(fileRef.ContentType, stream) .ConfigureAwait(false); }
public static bool TryLoadJson <ResultT>( this ICacheSourceLayer layer, string name, out ResultT value, IProgress prog = null) where ResultT : class { var deserializer = new JsonFactory <ResultT>(); var fileRef = name + MediaType.Application.Json; return(layer.TryLoad(deserializer, fileRef, out value, prog)); }
public static Task <Stream> OpenAsync( this ICacheSourceLayer layer, ContentReference fileRef) { if (layer is null) { throw new ArgumentNullException(nameof(layer)); } if (fileRef is null) { throw new ArgumentNullException(nameof(fileRef)); } return(layer.GetStreamAsync(fileRef, null)); }
public static bool TryLoad <ResultT>( this ICacheSourceLayer layer, IDeserializer <ResultT> deserializer, ContentReference fileRef, out ResultT value, IProgress prog = null) where ResultT : class { value = default; var task = layer.LoadAsync(deserializer, fileRef, prog); Task.WaitAny(task); if (task.IsSuccessful()) { value = task.Result; } return(value != default); }
public static async Task CopyToAsync( this ICacheSourceLayer fromLayer, ContentReference fromRef, ICacheDestinationLayer toLayer, ContentReference toRef, IProgress prog = null) { if (fromLayer is null) { throw new ArgumentNullException(nameof(fromLayer)); } if (fromRef is null) { throw new ArgumentNullException(nameof(fromRef)); } if (toLayer is null) { throw new ArgumentNullException(nameof(toLayer)); } if (toRef is null) { throw new ArgumentNullException(nameof(toRef)); } if (fromLayer.IsCached(fromRef)) { using var inStream = await fromLayer .GetStreamAsync(fromRef, prog) .ConfigureAwait(false); using var outStream = toLayer.Create(toRef); await inStream .CopyToAsync(outStream) .ConfigureAwait(false); } }
this ICacheSourceLayer source, IFactory <ResultT, MediaTypeT> deserializer)