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));
        }
Example #2
0
        public static bool TryDeserialize <ResultT>(this IDeserializer <ResultT> deserializer, Stream stream, out ResultT value, IProgress prog)
        {
            if (stream is null)
            {
                throw new ArgumentNullException(nameof(stream));
            }

            using var progStream = new ProgressStream(stream, stream.Length, prog, false);
            return(deserializer.TryDeserialize(progStream, out value));
        }
Example #3
0
        public static ResultT Deserialize <ResultT>(this IDeserializer <ResultT> deserializer, Stream stream, long length, IProgress prog)
        {
            if (deserializer is null)
            {
                throw new ArgumentNullException(nameof(deserializer));
            }

            if (stream is null)
            {
                throw new ArgumentNullException(nameof(stream));
            }

            using var progStream = new ProgressStream(stream, length, prog, false);
            return(deserializer.Deserialize(progStream));
        }
Example #4
0
        public static ResultT Deserialize <ResultT, M>(this IDeserializer <ResultT, M> deserializer, Stream stream, IProgress prog)
            where M : MediaType
        {
            if (deserializer is null)
            {
                throw new ArgumentNullException(nameof(deserializer));
            }

            if (stream is null)
            {
                throw new ArgumentNullException(nameof(stream));
            }

            using var progStream = new ProgressStream(stream, stream.Length, prog, false);
            return(deserializer.Deserialize(progStream));
        }
Example #5
0
        public Task <Stream> GetStreamAsync(ContentReference fileRef, IProgress prog)
        {
            if (fileRef is null)
            {
                throw new ArgumentNullException(nameof(fileRef));
            }

            if (!IsCached(fileRef))
            {
                throw new FileNotFoundException("File not found in disk cache!", fileRef.ToString());
            }

            var file       = Resolve(fileRef);
            var stream     = file.OpenRead();
            var progStream = new ProgressStream(stream, file.Length, prog, true);

            return(Task.FromResult((Stream)progStream));
        }
Example #6
0
        public Task <Stream> GetStreamAsync(ContentReference fileRef, IProgress prog)
        {
            if (fileRef is null)
            {
                throw new System.ArgumentNullException(nameof(fileRef));
            }

            if (!IsCached(fileRef))
            {
                throw new FileNotFoundException("File not found in memory cache!", fileRef.ToString());
            }

            var data       = store[fileRef.ContentType][fileRef.CacheID].ToArray();
            var stream     = new MemoryStream(data);
            var progStream = new ProgressStream(stream, data.Length, prog, true);

            return(Task.FromResult((Stream)progStream));
        }
Example #7
0
 public static bool TryDeserialize <ResultT>(this IDeserializer <ResultT> deserializer, Stream stream, out ResultT value, long length, IProgress prog)
 {
     using var progStream = new ProgressStream(stream, length, prog, false);
     return(deserializer.TryDeserialize(progStream, out value));
 }