示例#1
0
        public Task <WithLoadingResult <Stream> > GetStream(string identifier, CancellationToken token)
        {
            try
            {
                var imageInformation = new ImageInformation();
                imageInformation.SetPath(identifier);
                imageInformation.SetFilePath(null);

                var result = WithLoadingResult.Encapsulate(Context.Assets.Open(identifier, Access.Streaming),
                                                           LoadingResult.ApplicationBundle, imageInformation);
                return(Task.FromResult(result));
            }
            catch (Java.IO.FileNotFoundException)
            {
                return(Task.FromResult(WithLoadingResult.Encapsulate((Stream)null, LoadingResult.NotFound)));
            }
            catch (Java.IO.IOException)
            {
                return(Task.FromResult(WithLoadingResult.Encapsulate((Stream)null, LoadingResult.NotFound)));
            }
            catch (FileNotFoundException)
            {
                return(Task.FromResult(WithLoadingResult.Encapsulate((Stream)null, LoadingResult.NotFound)));
            }
            catch (IOException)
            {
                return(Task.FromResult(WithLoadingResult.Encapsulate((Stream)null, LoadingResult.NotFound)));
            }
        }
示例#2
0
        public async Task <WithLoadingResult <Stream> > GetStream(string identifier, CancellationToken token)
        {
            var cachedStream = await DownloadCache.GetStreamAsync(identifier, token, Parameters.CacheDuration).ConfigureAwait(false);

            return(WithLoadingResult.Encapsulate(cachedStream.ImageStream,
                                                 cachedStream.RetrievedFromDiskCache ? LoadingResult.DiskCache : LoadingResult.Disk));
        }
示例#3
0
        public Task <WithLoadingResult <Stream> > GetStream(string identifier, CancellationToken token)
        {
            // Resource name is always without extension
            string resourceName = Path.GetFileNameWithoutExtension(identifier);

            int resourceId = 0;

            if (!_resourceIdentifiersCache.TryGetValue(resourceName, out resourceId))
            {
                resourceId = Context.Resources.GetIdentifier(resourceName.ToLower(), "drawable", Context.PackageName);
                _resourceIdentifiersCache.TryAdd(resourceName.ToLower(), resourceId);
            }

            Stream stream = null;

            if (resourceId != 0)
            {
                stream = Context.Resources.OpenRawResource(resourceId);
            }
            else
            {
                return(Task.FromResult(WithLoadingResult.Encapsulate((Stream)null, LoadingResult.NotFound)));
            }

            var imageInformation = new ImageInformation();

            imageInformation.SetPath(identifier);
            imageInformation.SetFilePath(null);

            var result = WithLoadingResult.Encapsulate(stream, LoadingResult.CompiledResource, imageInformation);

            return(Task.FromResult(result));
        }
        public async Task <WithLoadingResult <Stream> > GetStream(string identifier, CancellationToken token)
        {
            StorageFile file = null;

            try
            {
                var filePath = Path.GetDirectoryName(identifier);

                if (!string.IsNullOrWhiteSpace(filePath))
                {
                    file = await StorageFile.GetFileFromPathAsync(identifier);
                }
            }
            catch (Exception)
            {
            }

            if (file != null)
            {
                var imageInformation = new ImageInformation();
                imageInformation.SetPath(identifier);
                imageInformation.SetFilePath(identifier);

                return(WithLoadingResult.Encapsulate(await file.OpenStreamForReadAsync(), LoadingResult.Disk, imageInformation));
            }

            return(WithLoadingResult.Encapsulate <Stream>(null, LoadingResult.Disk));
        }
        public Task <WithLoadingResult <Stream> > GetStream(string identifier, CancellationToken token)
        {
            if (!FileStore.Exists(identifier))
            {
                return(Task.FromResult(WithLoadingResult.Encapsulate((Stream)null, LoadingResult.NotFound)));
            }

            var result = WithLoadingResult.Encapsulate(FileStore.GetInputStream(identifier), LoadingResult.Disk);

            return(Task.FromResult(result));
        }
示例#6
0
        public async Task <WithLoadingResult <Stream> > GetStream(string identifier, CancellationToken token)
        {
            var cachedStream = await DownloadCache.GetStreamAsync(identifier, token, Parameters.CacheDuration, Parameters.CustomCacheKey).ConfigureAwait(false);

            var imageInformation = new ImageInformation();

            imageInformation.SetPath(identifier);
            imageInformation.SetFilePath(await DownloadCache.GetDiskCacheFilePathAsync(identifier, Parameters.CustomCacheKey));

            return(WithLoadingResult.Encapsulate(cachedStream.ImageStream,
                                                 cachedStream.RetrievedFromDiskCache ? LoadingResult.DiskCache : LoadingResult.Internet, imageInformation));
        }
示例#7
0
        public Task <WithLoadingResult <Stream> > GetStream(string identifier, CancellationToken token)
        {
            if (!FileStore.Exists(identifier))
            {
                return(Task.FromResult(WithLoadingResult.Encapsulate((Stream)null, LoadingResult.NotFound)));
            }

            var imageInformation = new ImageInformation();

            imageInformation.SetPath(identifier);
            imageInformation.SetFilePath(identifier);

            var result = WithLoadingResult.Encapsulate(FileStore.GetInputStream(identifier), LoadingResult.Disk, imageInformation);

            return(Task.FromResult(result));
        }
        public async Task <WithLoadingResult <Stream> > GetStream(string identifier, CancellationToken token)
        {
            StorageFile file = null;

            try
            {
                string resPath = identifier.TrimStart('\\', '/');

                if (!resPath.StartsWith(@"Assets\") && !resPath.StartsWith("Assets/"))
                {
                    resPath = @"Assets\" + resPath;
                }

                var imgUri = new Uri("ms-appx:///" + resPath);
                file = await StorageFile.GetFileFromApplicationUriAsync(imgUri);
            }
            catch (Exception)
            {
                try
                {
                    var imgUri = new Uri("ms-appx:///" + identifier);
                    file = await StorageFile.GetFileFromApplicationUriAsync(imgUri);
                }
                catch (Exception)
                {
                }
            }


            if (file != null)
            {
                var imageInformation = new ImageInformation();
                imageInformation.SetPath(identifier);
                imageInformation.SetFilePath(file.Path);

                return(WithLoadingResult.Encapsulate(await file.OpenStreamForReadAsync(), LoadingResult.CompiledResource, imageInformation));
            }

            return(WithLoadingResult.Encapsulate <Stream>(null, LoadingResult.CompiledResource));
        }