Ejemplo n.º 1
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)
        {
            // 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 virtual Task <Tuple <Stream, LoadingResult, ImageInformation> > Resolve(string identifier, TaskParameter parameters, CancellationToken token)
        {
            // Resource name is always without extension
            string resourceName = Path.GetFileNameWithoutExtension(identifier);

            int resourceId = 0;

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

            if (resourceId == 0)
            {
                throw new FileNotFoundException(identifier);
            }

            token.ThrowIfCancellationRequested();
            Stream stream = Context.Resources.OpenRawResource(resourceId);

            if (stream == null)
            {
                throw new FileNotFoundException(identifier);
            }

            var imageInformation = new ImageInformation();

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

            return(Task.FromResult(new Tuple <Stream, LoadingResult, ImageInformation>(
                                       stream, LoadingResult.CompiledResource, imageInformation)));
        }
Ejemplo n.º 5
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)));
            }
        }
        public virtual Task<Tuple<Stream, LoadingResult, ImageInformation>> Resolve(string identifier, TaskParameter parameters, CancellationToken token)
        {
            // Resource name is always without extension
            string resourceName = Path.GetFileNameWithoutExtension(identifier);

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

            if (resourceId == 0)
                throw new FileNotFoundException(identifier);

            token.ThrowIfCancellationRequested();
            Stream stream  = Context.Resources.OpenRawResource(resourceId);

            if (stream == null)
                throw new FileNotFoundException(identifier);

            var imageInformation = new ImageInformation();
            imageInformation.SetPath(identifier);
            imageInformation.SetFilePath(identifier);

            return Task.FromResult(new Tuple<Stream, LoadingResult, ImageInformation>(
                stream, LoadingResult.CompiledResource, imageInformation));
        }
        public async virtual Task<Tuple<Stream, LoadingResult, ImageInformation>> Resolve(string identifier, TaskParameter parameters, 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);

                token.ThrowIfCancellationRequested();
                var stream = await file.OpenStreamForReadAsync();

                return new Tuple<Stream, LoadingResult, ImageInformation>(stream, LoadingResult.Disk, imageInformation);
            }

            throw new FileNotFoundException(identifier);
        }
Ejemplo n.º 8
0
        public async virtual Task <DataResolverResult> Resolve(string identifier, TaskParameter parameters, CancellationToken token)
        {
            StorageFile file = null;

            try
            {
                var filePath = Path.GetDirectoryName(identifier);
                if (!string.IsNullOrWhiteSpace(filePath))
                {
                    file = await Cache.FFSourceBindingCache.GetFileAsync(identifier);
                }
            }
            catch (Exception)
            {
            }

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

                token.ThrowIfCancellationRequested();
                var stream = await file.OpenStreamForReadAsync();

                return(new DataResolverResult(stream, LoadingResult.Disk, imageInformation));
            }

            throw new FileNotFoundException(identifier);
        }
		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));
			}
		}
Ejemplo n.º 10
0
        public async virtual Task <Tuple <Stream, LoadingResult, ImageInformation> > Resolve(string identifier, TaskParameter parameters, 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);

                var stream = await file.OpenStreamForReadAsync();

                return(new Tuple <Stream, LoadingResult, ImageInformation>(stream, LoadingResult.Disk, imageInformation));
            }

            throw new FileNotFoundException(identifier);
        }
Ejemplo n.º 11
0
        public async Task <UIImageData> GetData(string identifier, CancellationToken token)
        {
            var downloadedData = await DownloadCache.GetAsync(identifier, token, Parameters.CacheDuration, Parameters.CustomCacheKey, Parameters.CacheType).ConfigureAwait(false);

            var bytes  = downloadedData.Bytes;
            var path   = downloadedData.CachedPath;
            var result = downloadedData.RetrievedFromDiskCache ? LoadingResult.DiskCache : LoadingResult.Internet;

            var imageInformation = new ImageInformation();

            imageInformation.SetPath(identifier);
            var allowDiskCaching = Parameters.CacheType.HasValue == false || Parameters.CacheType == CacheType.All || Parameters.CacheType == CacheType.Disk;

            if (allowDiskCaching)
            {
                imageInformation.SetFilePath(await DownloadCache.GetDiskCacheFilePathAsync(identifier, Parameters.CustomCacheKey));
            }

            return(new UIImageData()
            {
                Data = bytes,
                Result = result,
                ResultIdentifier = path,
                ImageInformation = imageInformation
            });
        }
        public virtual Task <Tuple <Stream, LoadingResult, ImageInformation> > Resolve(string identifier, TaskParameter parameters, CancellationToken token)
        {
            string file = null;

            int scale = (int)ScaleHelper.Scale;

            if (scale > 1)
            {
                var          filename  = Path.GetFileNameWithoutExtension(identifier);
                var          extension = Path.GetExtension(identifier);
                const string pattern   = "{0}@{1}x{2}";

                while (scale > 1)
                {
                    token.ThrowIfCancellationRequested();

                    var tmpFile = string.Format(pattern, filename, scale, extension);
                    if (FileStore.Exists(tmpFile))
                    {
                        file = tmpFile;
                        break;
                    }
                    scale--;
                }
            }

            if (string.IsNullOrEmpty(file) && FileStore.Exists(identifier))
            {
                file = identifier;
            }

            token.ThrowIfCancellationRequested();

            if (!string.IsNullOrEmpty(file))
            {
                var stream           = FileStore.GetInputStream(file, true);
                var imageInformation = new ImageInformation();
                imageInformation.SetPath(identifier);
                imageInformation.SetFilePath(file);

                var result = (LoadingResult)(int)parameters.Source;

                if (parameters.LoadingPlaceholderPath == identifier)
                {
                    result = (LoadingResult)(int)parameters.LoadingPlaceholderSource;
                }
                else if (parameters.ErrorPlaceholderPath == identifier)
                {
                    result = (LoadingResult)(int)parameters.ErrorPlaceholderSource;
                }

                return(Task.FromResult(new Tuple <Stream, LoadingResult, ImageInformation>(
                                           stream, result, imageInformation)));
            }

            throw new FileNotFoundException(identifier);
        }
Ejemplo n.º 13
0
        public async Task <WithLoadingResult <Stream> > GetStream(string identifier, CancellationToken token)
        {
            var cachedStream = await DownloadCache.GetStreamAsync(identifier, token, Parameters.CacheDuration, Parameters.CustomCacheKey, Parameters.CacheType).ConfigureAwait(false);

            var imageInformation = new ImageInformation();

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

            var allowDiskCaching = Parameters.CacheType.HasValue == false || Parameters.CacheType == CacheType.All || Parameters.CacheType == CacheType.Disk;

            if (allowDiskCaching)
            {
                imageInformation.SetFilePath(await DownloadCache.GetDiskCacheFilePathAsync(identifier, Parameters.CustomCacheKey));
            }

            return(WithLoadingResult.Encapsulate(cachedStream.ImageStream,
                                                 cachedStream.RetrievedFromDiskCache ? LoadingResult.DiskCache : LoadingResult.Internet, imageInformation));
        }
Ejemplo n.º 14
0
 public virtual async Task <DataResolverResult> Resolve(string identifier, TaskParameter parameters, CancellationToken token)
 {
     if (File.Exists(identifier))
     {
         ImageInformation imageInformation = new ImageInformation();
         imageInformation.SetPath(identifier);
         imageInformation.SetFilePath(identifier);
         token.ThrowIfCancellationRequested();
         return(new DataResolverResult(await Task.Run(() => File.OpenRead(identifier)), LoadingResult.Disk, imageInformation));
     }
     throw new FileNotFoundException(identifier);
 }
        public virtual Task<Tuple<Stream, LoadingResult, ImageInformation>> Resolve(string identifier, TaskParameter parameters, CancellationToken token)
        {
            string file = null;

            int scale = (int)ScaleHelper.Scale;
            if (scale > 1)
            {
                var filename = Path.GetFileNameWithoutExtension(identifier);
                var extension = Path.GetExtension(identifier);
                const string pattern = "{0}@{1}x{2}";

                while (scale > 1)
                {
                    token.ThrowIfCancellationRequested();

                    var tmpFile = string.Format(pattern, filename, scale, extension);
                    if (FileStore.Exists(tmpFile))
                    {
                        file = tmpFile;
                        break;
                    }
                    scale--;
                }
            }

            if (string.IsNullOrEmpty(file) && FileStore.Exists(identifier))
            {
                file = identifier;
            }

            token.ThrowIfCancellationRequested();

            if (!string.IsNullOrEmpty(file))
            {
                var stream = FileStore.GetInputStream(file, true);
                var imageInformation = new ImageInformation();
                imageInformation.SetPath(identifier);
                imageInformation.SetFilePath(file);

                var result = (LoadingResult)(int)parameters.Source;

                if (parameters.LoadingPlaceholderPath == identifier)
                    result = (LoadingResult)(int)parameters.LoadingPlaceholderSource;
                else if (parameters.ErrorPlaceholderPath == identifier)
                    result = (LoadingResult)(int)parameters.ErrorPlaceholderSource;

                return Task.FromResult(new Tuple<Stream, LoadingResult, ImageInformation>(
                    stream, result, imageInformation));
            }

            throw new FileNotFoundException(identifier);
        }
        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, false), LoadingResult.Disk, imageInformation);
            return Task.FromResult(result);
        }
Ejemplo n.º 17
0
		public async Task<WithLoadingResult<Stream>> GetStream(string identifier, CancellationToken token)
		{
			var cachedStream = await DownloadCache.GetStreamAsync(identifier, token, Parameters.CacheDuration, Parameters.CustomCacheKey, Parameters.CacheType).ConfigureAwait(false);

			var imageInformation = new ImageInformation();
			imageInformation.SetPath(identifier);
            var allowDiskCaching = Parameters.CacheType.HasValue == false || Parameters.CacheType == CacheType.All || Parameters.CacheType == CacheType.Disk;
            if (allowDiskCaching)
		    {
                imageInformation.SetFilePath(await DownloadCache.GetDiskCacheFilePathAsync(identifier, Parameters.CustomCacheKey));
            }

			return WithLoadingResult.Encapsulate(cachedStream.ImageStream,
				cachedStream.RetrievedFromDiskCache ? LoadingResult.DiskCache : LoadingResult.Internet, imageInformation);
		}
        public virtual Task<Tuple<Stream, LoadingResult, ImageInformation>> Resolve(string identifier, TaskParameter parameters, CancellationToken token)
        {
            token.ThrowIfCancellationRequested();
            var stream = Context.Assets.Open(identifier, Access.Streaming);

            if (stream == null)
                throw new FileNotFoundException(identifier);

            var imageInformation = new ImageInformation();
            imageInformation.SetPath(identifier);
            imageInformation.SetFilePath(null);

            return Task.FromResult(new Tuple<Stream, LoadingResult, ImageInformation>(
                stream, LoadingResult.ApplicationBundle, imageInformation));
        }
Ejemplo n.º 19
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));
        }
Ejemplo n.º 20
0
        private async Task <DataResolverResult> ResolveFromNamedResourceAsync(string fileName, string identifier, TaskParameter parameters, CancellationToken token)
        {
            PImage image = null;

            try
            {
#if __IOS__ || __TVOS__
                await ImageService.Instance.Config.MainThreadDispatcher.PostAsync(() => image = PImage.FromBundle(identifier)).ConfigureAwait(false);
#elif __MACOS__
                await ImageService.Instance.Config.MainThreadDispatcher.PostAsync(() => image = PImage.ImageNamed(identifier)).ConfigureAwait(false);
#endif
            }
            catch { }

            if (image == null && fileName != identifier)
            {
                try
                {
#if __IOS__ || __TVOS__
                    await ImageService.Instance.Config.MainThreadDispatcher.PostAsync(() => image = PImage.FromBundle(fileName)).ConfigureAwait(false);
#elif __MACOS__
                    await ImageService.Instance.Config.MainThreadDispatcher.PostAsync(() => image = PImage.ImageNamed(fileName)).ConfigureAwait(false);
#endif
                }
                catch { }
            }

            if (image != null)
            {
                token.ThrowIfCancellationRequested();

                var imageInformation = new ImageInformation();
                imageInformation.SetPath(identifier);
                imageInformation.SetFilePath(null);

                var container = new DecodedImage <object>()
                {
                    Image = image
                };

                var result = new DataResolverResult(container, LoadingResult.CompiledResource, imageInformation);

                return(result);
            }

            return(null);
        }
Ejemplo n.º 21
0
        public async virtual Task <DataResolverResult> Resolve(string identifier, TaskParameter parameters, CancellationToken token)
        {
            if (!File.Exists(identifier))
            {
                return(await resource.Resolve(identifier, parameters, token));
            }

            var imageInformation = new ImageInformation();

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

            token.ThrowIfCancellationRequested();
            var stream = File.Open(identifier, FileMode.Open);

            return(new DataResolverResult(stream, LoadingResult.Disk, imageInformation));
        }
        public async virtual Task<Tuple<Stream, LoadingResult, ImageInformation>> Resolve(string identifier, TaskParameter parameters, CancellationToken token)
        {
            var downloadedData = await DownloadCache.DownloadAndCacheIfNeededAsync(identifier, parameters, Configuration, token).ConfigureAwait(false);

            if (token.IsCancellationRequested)
            {
                downloadedData?.ImageStream?.Dispose();
                token.ThrowIfCancellationRequested();
            }

            var imageInformation = new ImageInformation();
            imageInformation.SetPath(identifier);
            imageInformation.SetFilePath(downloadedData?.FilePath);

            return new Tuple<Stream, LoadingResult, ImageInformation>(
                downloadedData?.ImageStream, downloadedData.RetrievedFromDiskCache ? LoadingResult.DiskCache : LoadingResult.Internet, imageInformation);
        }
Ejemplo n.º 23
0
        public virtual Task <DataResolverResult> Resolve(string identifier, TaskParameter parameters, CancellationToken token)
        {
            token.ThrowIfCancellationRequested();
            var stream = Context.Assets.Open(identifier, Access.Streaming);

            if (stream == null)
            {
                throw new FileNotFoundException(identifier);
            }

            var imageInformation = new ImageInformation();

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

            return(Task.FromResult(new DataResolverResult(stream, LoadingResult.ApplicationBundle, imageInformation)));
        }
Ejemplo n.º 24
0
        public Task <Tuple <Stream, LoadingResult, ImageInformation> > Resolve(string identifier, TaskParameter parameters, CancellationToken token)
        {
            if (!FileStore.Exists(identifier))
            {
                throw new FileNotFoundException(identifier);
            }

            var stream = FileStore.GetInputStream(identifier, true);

            var imageInformation = new ImageInformation();

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

            return(Task.FromResult(new Tuple <Stream, LoadingResult, ImageInformation>(
                                       stream, LoadingResult.Disk, imageInformation)));
        }
Ejemplo n.º 25
0
        public Task <Tuple <Stream, LoadingResult, ImageInformation> > Resolve(string identifier, TaskParameter parameters, CancellationToken token)
        {
            var stream = Context.Assets.Open(identifier, Access.Streaming);

            if (stream == null)
            {
                throw new FileNotFoundException(identifier);
            }

            var imageInformation = new ImageInformation();

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

            return(Task.FromResult(new Tuple <Stream, LoadingResult, ImageInformation>(
                                       stream, LoadingResult.ApplicationBundle, imageInformation)));
        }
        public async Task <UIImageData> GetData(string identifier, CancellationToken token)
        {
            UIImage image = null;
            await _mainThreadDispatcher.PostAsync(() => image = UIImage.FromBundle(identifier)).ConfigureAwait(false);

            var imageInformation = new ImageInformation();

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

            return(new UIImageData()
            {
                Image = image,
                Result = LoadingResult.CompiledResource,
                ResultIdentifier = identifier,
                ImageInformation = imageInformation
            });
        }
        public virtual Task<Tuple<Stream, LoadingResult, ImageInformation>> Resolve(string identifier, TaskParameter parameters, CancellationToken token)
        {
            if (!FileStore.Exists(identifier))
            {
                throw new FileNotFoundException(identifier);
            }

            token.ThrowIfCancellationRequested();

            var stream = FileStore.GetInputStream(identifier, true);

            var imageInformation = new ImageInformation();
            imageInformation.SetPath(identifier);
            imageInformation.SetFilePath(identifier);

            return Task.FromResult(new Tuple<Stream, LoadingResult, ImageInformation>(
                stream, LoadingResult.Disk, imageInformation));          
        }
Ejemplo n.º 28
0
		public async Task<UIImageData> GetData(string identifier, CancellationToken token)
		{
			var downloadedData = await DownloadCache.GetAsync(identifier, token, Parameters.CacheDuration, Parameters.CustomCacheKey, Parameters.CacheType).ConfigureAwait(false);
			var bytes = downloadedData.Bytes;
			var path = downloadedData.CachedPath;
			var result = downloadedData.RetrievedFromDiskCache ? LoadingResult.DiskCache : LoadingResult.Internet;

			var imageInformation = new ImageInformation();
			imageInformation.SetPath(identifier);
			imageInformation.SetFilePath(await DownloadCache.GetDiskCacheFilePathAsync(identifier, Parameters.CustomCacheKey));

			return new UIImageData() { 
				Data = bytes, 
				Result = result, 
				ResultIdentifier = path,
				ImageInformation = imageInformation
			};
		}
Ejemplo n.º 29
0
        public async virtual Task <DataResolverResult> Resolve(string identifier, TaskParameter parameters, CancellationToken token)
        {
            var downloadedData = await DownloadCache.DownloadAndCacheIfNeededAsync(identifier, parameters, Configuration, token).ConfigureAwait(false);

            if (token.IsCancellationRequested)
            {
                downloadedData?.ImageStream.TryDispose();
                token.ThrowIfCancellationRequested();
            }

            var imageInformation = new ImageInformation();

            imageInformation.SetPath(identifier);
            imageInformation.SetFilePath(downloadedData?.FilePath);

            return(new DataResolverResult(
                       downloadedData?.ImageStream, downloadedData.RetrievedFromDiskCache ? LoadingResult.DiskCache : LoadingResult.Internet, imageInformation));
        }
Ejemplo n.º 30
0
        public virtual Task <DataResolverResult> Resolve(string identifier, TaskParameter parameters, CancellationToken token)
        {
            if (!FileStore.Exists(identifier))
            {
                throw new FileNotFoundException(identifier);
            }

            token.ThrowIfCancellationRequested();

            var stream = FileStore.GetInputStream(identifier, true);

            var imageInformation = new ImageInformation();

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

            return(Task.FromResult(new DataResolverResult(
                                       stream, LoadingResult.Disk, imageInformation)));
        }
        public async virtual Task<Tuple<Stream, LoadingResult, ImageInformation>> Resolve(string identifier, TaskParameter parameters, 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);

                token.ThrowIfCancellationRequested();
                var stream = await file.OpenStreamForReadAsync();

                return new Tuple<Stream, LoadingResult, ImageInformation>(stream, LoadingResult.CompiledResource, imageInformation);
            }

            throw new FileNotFoundException(identifier);
        }
        public async virtual Task <Tuple <Stream, LoadingResult, ImageInformation> > Resolve(string identifier, TaskParameter parameters, 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);

                token.ThrowIfCancellationRequested();
                var stream = await file.OpenStreamForReadAsync();

                return(new Tuple <Stream, LoadingResult, ImageInformation>(stream, LoadingResult.CompiledResource, imageInformation));
            }

            throw new FileNotFoundException(identifier);
        }
        private async Task <UIImageData> GetDataInternal(string identifier, CancellationToken token)
        {
            var bytes = await FileStore.ReadBytesAsync(identifier, token).ConfigureAwait(false);

            var result = (LoadingResult)(int)_source;             // Some values of ImageSource and LoadingResult are shared

            var imageInformation = new ImageInformation();

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

            return(new UIImageData()
            {
                Data = bytes,
                Result = result,
                ResultIdentifier = identifier,
                ImageInformation = imageInformation
            });
        }
        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));
        }
Ejemplo n.º 35
0
        public Task <Tuple <Stream, LoadingResult, ImageInformation> > Resolve(string identifier, TaskParameter parameters, CancellationToken token)
        {
            var fileName  = Path.GetFileNameWithoutExtension(identifier);
            var extension = Path.GetExtension(identifier).TrimStart('.');

            var bundle = NSBundle._AllBundles.FirstOrDefault(bu => !string.IsNullOrEmpty(bu.PathForResource(fileName, extension)));

            if (bundle != null)
            {
                var url    = bundle.GetUrlForResource(fileName, extension);
                var stream = FileStore.GetInputStream(url.Path, true);

                var imageInformation = new ImageInformation();
                imageInformation.SetPath(identifier);
                imageInformation.SetFilePath(url.Path);

                return(Task.FromResult(new Tuple <Stream, LoadingResult, ImageInformation>(
                                           stream, LoadingResult.CompiledResource, imageInformation)));
            }

            throw new FileNotFoundException(identifier);
        }
Ejemplo n.º 36
0
        private async Task <DataResolverResult> ResolveFromAssetCatalogAsync(string fileName, string identifier, TaskParameter parameters, CancellationToken token)
        {
#if __IOS__ || __TVOS__
            if (!UIDevice.CurrentDevice.CheckSystemVersion(9, 0))
            {
                return(null);
            }
#endif

            NSDataAsset asset = null;

            try
            {
                await ImageService.Instance.Config.MainThreadDispatcher.PostAsync(() => asset = new NSDataAsset(identifier, NSBundle.MainBundle)).ConfigureAwait(false);
            }
            catch { }

            if (asset == null && fileName != identifier)
            {
                try
                {
                    await ImageService.Instance.Config.MainThreadDispatcher.PostAsync(() => asset = new NSDataAsset(fileName, NSBundle.MainBundle)).ConfigureAwait(false);
                }
                catch { }
            }

            if (asset != null)
            {
                token.ThrowIfCancellationRequested();
                var stream           = asset.Data?.AsStream();
                var imageInformation = new ImageInformation();
                imageInformation.SetPath(identifier);
                imageInformation.SetFilePath(null);

                return(new DataResolverResult(stream, LoadingResult.CompiledResource, imageInformation));
            }

            return(null);
        }
Ejemplo n.º 37
0
        public Task <Tuple <Stream, LoadingResult, ImageInformation> > Resolve(string identifier, TaskParameter parameters, CancellationToken token)
        {
            if (!identifier.StartsWith("resource://", StringComparison.OrdinalIgnoreCase))
            {
                throw new Exception("Only resource:// scheme is supported");
            }


            Uri      uri      = new Uri(identifier);
            Assembly assembly = null;

            var    parts        = uri.OriginalString.Substring(11).Split('?');
            string resourceName = parts.First();

            if (parts.Count() > 1)
            {
                var name         = Uri.UnescapeDataString(uri.Query.Substring(10));
                var assemblyName = new AssemblyName(name);
                assembly = Assembly.Load(assemblyName);
            }

            if (assembly == null)
            {
                MethodInfo callingAssemblyMethod = typeof(Assembly).GetTypeInfo().GetDeclaredMethod("GetCallingAssembly");
                assembly = (Assembly)callingAssemblyMethod.Invoke(null, new object[0]);
            }

            var imageInformation = new ImageInformation();

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

            var stream = assembly.GetManifestResourceStream(resourceName);

            return(Task.FromResult(new Tuple <Stream, LoadingResult, ImageInformation>(
                                       stream, LoadingResult.EmbeddedResource, imageInformation)));
        }
Ejemplo n.º 38
0
#pragma warning disable CS1998 // 이 비동기 메서드에는 'await' 연산자가 없으며 메서드가 동시에 실행됩니다.
        public virtual async Task <DataResolverResult> Resolve(string identifier, TaskParameter parameters, CancellationToken token)
#pragma warning restore CS1998 // 이 비동기 메서드에는 'await' 연산자가 없으며 메서드가 동시에 실행됩니다.
        {
            try
            {
                if (TrimmedResource.ContainsKey(identifier))
                {
                    identifier = TrimmedResource[identifier];
                }

                var data  = Application.GetResourceStream(new Uri(identifier, UriKind.Relative));
                var image = new ImageInformation();
                image.SetPath(identifier);
                image.SetFilePath(identifier);

                token.ThrowIfCancellationRequested();

                return(new DataResolverResult(data.Stream, LoadingResult.CompiledResource, image));
            }
            catch (IOException io)
            {
                throw new FileNotFoundException(identifier, io);
            }
        }
        public virtual async Task <Tuple <Stream, LoadingResult, ImageInformation> > Resolve(string identifier, TaskParameter parameters, CancellationToken token)
        {
            NSBundle bundle       = null;
            var      filename     = Path.GetFileNameWithoutExtension(identifier);
            var      tmpPath      = Path.GetDirectoryName(identifier).Trim('/');
            var      filenamePath = string.IsNullOrWhiteSpace(tmpPath) ? null : tmpPath + "/";

            foreach (var fileType in fileTypes)
            {
                string file      = null;
                var    extension = Path.HasExtension(identifier) ? Path.GetExtension(identifier) : string.IsNullOrWhiteSpace(fileType) ? string.Empty : "." + fileType;

                token.ThrowIfCancellationRequested();

                int scale = (int)ScaleHelper.Scale;
                if (scale > 1)
                {
                    while (scale > 1)
                    {
                        token.ThrowIfCancellationRequested();

                        var tmpFile = string.Format("{0}@{1}x{2}", filename, scale, extension);
                        bundle = NSBundle._AllBundles.FirstOrDefault(bu =>
                        {
                            var path = string.IsNullOrWhiteSpace(filenamePath) ?
                                       bu.PathForResource(tmpFile, null) :
                                       bu.PathForResource(tmpFile, null, filenamePath);
                            return(!string.IsNullOrWhiteSpace(path));
                        });

                        if (bundle != null)
                        {
                            file = tmpFile;
                            break;
                        }
                        scale--;
                    }
                }

                token.ThrowIfCancellationRequested();

                if (file == null)
                {
                    var tmpFile = string.Format(filename + extension);
                    file   = tmpFile;
                    bundle = NSBundle._AllBundles.FirstOrDefault(bu =>
                    {
                        var path = string.IsNullOrWhiteSpace(filenamePath) ?
                                   bu.PathForResource(tmpFile, null) :
                                   bu.PathForResource(tmpFile, null, filenamePath);

                        return(!string.IsNullOrWhiteSpace(path));
                    });
                }

                token.ThrowIfCancellationRequested();

                if (bundle != null)
                {
                    string path = !string.IsNullOrEmpty(filenamePath) ? bundle.PathForResource(file, null, filenamePath) : bundle.PathForResource(file, null);

                    var stream           = FileStore.GetInputStream(path, true);
                    var imageInformation = new ImageInformation();
                    imageInformation.SetPath(identifier);
                    imageInformation.SetFilePath(path);

                    return(new Tuple <Stream, LoadingResult, ImageInformation>(
                               stream, LoadingResult.CompiledResource, imageInformation));
                }

                token.ThrowIfCancellationRequested();

                if (string.IsNullOrEmpty(fileType))
                {
                    //Asset catalog
                    NSDataAsset asset = null;

                    try
                    {
                        await MainThreadDispatcher.Instance.PostAsync(() => asset = new NSDataAsset(filename)).ConfigureAwait(false);
                    }
                    catch (Exception) { }

                    if (asset != null)
                    {
                        token.ThrowIfCancellationRequested();
                        var stream           = asset.Data?.AsStream();
                        var imageInformation = new ImageInformation();
                        imageInformation.SetPath(identifier);
                        imageInformation.SetFilePath(null);

                        return(new Tuple <Stream, LoadingResult, ImageInformation>(
                                   stream, LoadingResult.CompiledResource, imageInformation));
                    }


                    NSImage image = null;

                    try
                    {
                        await MainThreadDispatcher.Instance.PostAsync(() => image = NSImage.ImageNamed(filename)).ConfigureAwait(false);
                    }
                    catch (Exception) { }

                    if (image != null)
                    {
                        token.ThrowIfCancellationRequested();
                        var imageRep = new NSBitmapImageRep(image.AsTiff());
                        var stream   = imageRep.RepresentationUsingTypeProperties(NSBitmapImageFileType.Png)
                                       .AsStream();
                        //var stream = image.AsPNG()?.AsStream();
                        var imageInformation = new ImageInformation();
                        imageInformation.SetPath(identifier);
                        imageInformation.SetFilePath(null);

                        return(new Tuple <Stream, LoadingResult, ImageInformation>(
                                   stream, LoadingResult.CompiledResource, imageInformation));
                    }
                }
            }

            throw new FileNotFoundException(identifier);
        }
Ejemplo n.º 40
0
        private Task <DataResolverResult> ResolveFromBundlesAsync(string fileName, string identifier, TaskParameter parameters, CancellationToken token)
        {
            NSBundle bundle       = null;
            var      ext          = Path.GetExtension(identifier)?.TrimStart(new char[] { '.' });
            var      tmpPath      = Path.GetDirectoryName(identifier)?.Trim('/');
            var      filenamePath = string.IsNullOrWhiteSpace(tmpPath) ? null : tmpPath + "/";
            var      hasExtension = !string.IsNullOrWhiteSpace(ext);

            var fileTypes = hasExtension ? new[] { ext } : _fileTypes;

            foreach (var fileType in fileTypes)
            {
                string file     = null;
                string lastPath = null;

                token.ThrowIfCancellationRequested();

                var scale = (int)ScaleHelper.Scale;
                if (scale > 1)
                {
                    while (scale > 1)
                    {
                        token.ThrowIfCancellationRequested();

                        var tmpFile = string.Format("{0}@{1}x", fileName, scale);
                        bundle = NSBundle._AllBundles.FirstOrDefault(bu =>
                        {
                            lastPath = string.IsNullOrWhiteSpace(filenamePath) ?
                                       bu.PathForResource(tmpFile, fileType) :
                                       bu.PathForResource(tmpFile, fileType, filenamePath);

                            return(!string.IsNullOrWhiteSpace(lastPath));
                        });

                        if (bundle != null)
                        {
                            file = tmpFile;
                            break;
                        }

                        scale--;
                    }
                }

                token.ThrowIfCancellationRequested();

                if (file == null)
                {
                    bundle = NSBundle._AllBundles.FirstOrDefault(bu =>
                    {
                        lastPath = string.IsNullOrWhiteSpace(filenamePath) ?
                                   bu.PathForResource(fileName, fileType) :
                                   bu.PathForResource(fileName, fileType, filenamePath);

                        return(!string.IsNullOrWhiteSpace(lastPath));
                    });
                }

                token.ThrowIfCancellationRequested();

                if (bundle != null)
                {
                    var stream           = FileStore.GetInputStream(lastPath, true);
                    var imageInformation = new ImageInformation();
                    imageInformation.SetPath(identifier);
                    imageInformation.SetFilePath(lastPath);
                    var result = new DataResolverResult(stream, LoadingResult.CompiledResource, imageInformation);

                    return(Task.FromResult(result));
                }
            }

            return(Task.FromResult <DataResolverResult>(null));
        }
        public virtual async Task<Tuple<Stream, LoadingResult, ImageInformation>> Resolve(string identifier, TaskParameter parameters, CancellationToken token)
        {
            NSBundle bundle = null;
            string file = null;
            var filename = Path.GetFileNameWithoutExtension(identifier);
            var extension = Path.GetExtension(identifier);
            const string pattern = "{0}@{1}x{2}";

            foreach (var fileType in fileTypes)
            {
                token.ThrowIfCancellationRequested();

                int scale = (int)ScaleHelper.Scale;
                if (scale > 1)
                {
                    while (scale > 1)
                    {
                        token.ThrowIfCancellationRequested();

                        var tmpFile = string.Format(pattern, filename, scale, extension);
                        bundle = NSBundle._AllBundles.FirstOrDefault(bu =>
                        {
                            var path = bu.PathForResource(tmpFile, fileType);
                            return !string.IsNullOrWhiteSpace(path);
                        });

                        if (bundle != null)
                        {
                            file = tmpFile;
                            break;
                        }
                        scale--;
                    }
                }

                token.ThrowIfCancellationRequested();

                if (file == null)
                {
                    file = identifier;
                    bundle = NSBundle._AllBundles.FirstOrDefault(bu =>
                    {
                        var path = bu.PathForResource(file, fileType);
                        return !string.IsNullOrWhiteSpace(path);
                    });
                }

                token.ThrowIfCancellationRequested();

                if (bundle != null)
                {
                    var path = bundle.PathForResource(file, fileType);

                    var stream = FileStore.GetInputStream(path, true);
                    var imageInformation = new ImageInformation();
                    imageInformation.SetPath(identifier);
                    imageInformation.SetFilePath(path);

                    return new Tuple<Stream, LoadingResult, ImageInformation>(
                        stream, LoadingResult.CompiledResource, imageInformation);
                }
            }

            //Asset catalog
            token.ThrowIfCancellationRequested();

            if (UIDevice.CurrentDevice.CheckSystemVersion(9, 0))
            {
                NSDataAsset asset = null;

                try
                {
                    await MainThreadDispatcher.Instance.PostAsync(() => asset = new NSDataAsset(filename)).ConfigureAwait(false);
                }
                catch (Exception) { }

                if (asset != null)
                {
                    token.ThrowIfCancellationRequested();
                    var stream = asset.Data?.AsStream();
                    var imageInformation = new ImageInformation();
                    imageInformation.SetPath(identifier);
                    imageInformation.SetFilePath(null);

                    return new Tuple<Stream, LoadingResult, ImageInformation>(
                        stream, LoadingResult.CompiledResource, imageInformation);
                }
            }
            else if (UIDevice.CurrentDevice.CheckSystemVersion(7, 0))
            {
                UIImage image = null;

                try
                {
                    await MainThreadDispatcher.Instance.PostAsync(() => image = UIImage.FromBundle(filename)).ConfigureAwait(false);
                }
                catch (Exception) { }

                if (image != null)
                {
                    token.ThrowIfCancellationRequested();
                    var stream = image.AsPNG()?.AsStream();
                    var imageInformation = new ImageInformation();
                    imageInformation.SetPath(identifier);
                    imageInformation.SetFilePath(null);

                    return new Tuple<Stream, LoadingResult, ImageInformation>(
                        stream, LoadingResult.CompiledResource, imageInformation);
                }
            }

            throw new FileNotFoundException(identifier);
        }
        public async virtual Task <DataResolverResult> Resolve(string identifier, TaskParameter parameters, CancellationToken token)
        {
            StorageFile file = null;
            await _cacheLock.WaitAsync(token).ConfigureAwait(false);

            token.ThrowIfCancellationRequested();

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

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

                var imgUri = new Uri("ms-appx:///" + resPath);
                var key    = imgUri.ToString();
                if (!_cache.TryGetValue(key, out file))
                {
                    file = await StorageFile.GetFileFromApplicationUriAsync(imgUri);

                    if (_cache.Count >= 128)
                    {
                        _cache.Clear();
                    }

                    _cache[key] = file;
                }
            }
            catch (Exception)
            {
                try
                {
                    var imgUri = new Uri("ms-appx:///" + identifier);
                    var key    = imgUri.ToString();
                    if (!_cache.TryGetValue(key, out file))
                    {
                        file = await StorageFile.GetFileFromApplicationUriAsync(imgUri);

                        if (_cache.Count >= 128)
                        {
                            _cache.Clear();
                        }

                        _cache[key] = file;
                    }
                }
                catch (Exception)
                {
                }
            }
            finally
            {
                _cacheLock.Release();
            }

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

                token.ThrowIfCancellationRequested();
                var stream = await file.OpenStreamForReadAsync().ConfigureAwait(false);

                return(new DataResolverResult(stream, LoadingResult.CompiledResource, imageInformation));
            }

            throw new FileNotFoundException(identifier);
        }
        public virtual async Task <Tuple <Stream, LoadingResult, ImageInformation> > Resolve(string identifier, TaskParameter parameters, CancellationToken token)
        {
            NSBundle bundle       = null;
            var      filename     = Path.GetFileNameWithoutExtension(identifier);
            var      tmpPath      = Path.GetDirectoryName(identifier).Trim('/');
            var      filenamePath = string.IsNullOrWhiteSpace(tmpPath) ? null : tmpPath + "/";

            foreach (var fileType in fileTypes)
            {
                string file      = null;
                var    extension = Path.HasExtension(identifier) ? Path.GetExtension(identifier) : string.IsNullOrWhiteSpace(fileType) ? string.Empty : "." + fileType;

                token.ThrowIfCancellationRequested();

                int scale = (int)ScaleHelper.Scale;
                if (scale > 1)
                {
                    while (scale > 1)
                    {
                        token.ThrowIfCancellationRequested();

                        var tmpFile = string.Format("{0}@{1}x{2}", filename, scale, extension);
                        bundle = NSBundle._AllBundles.FirstOrDefault(bu =>
                        {
                            var path = string.IsNullOrWhiteSpace(filenamePath) ?
                                       bu.PathForResource(tmpFile, null) :
                                       bu.PathForResource(tmpFile, null, filenamePath);
                            return(!string.IsNullOrWhiteSpace(path));
                        });

                        if (bundle != null)
                        {
                            file = tmpFile;
                            break;
                        }
                        scale--;
                    }
                }

                token.ThrowIfCancellationRequested();

                if (file == null)
                {
                    var tmpFile = string.Format(filename + extension);
                    file   = tmpFile;
                    bundle = NSBundle._AllBundles.FirstOrDefault(bu =>
                    {
                        var path = string.IsNullOrWhiteSpace(filenamePath) ?
                                   bu.PathForResource(tmpFile, null) :
                                   bu.PathForResource(tmpFile, null, filenamePath);

                        return(!string.IsNullOrWhiteSpace(path));
                    });
                }

                token.ThrowIfCancellationRequested();

                if (bundle != null)
                {
                    string path = !string.IsNullOrEmpty(filenamePath) ? bundle.PathForResource(file, null, filenamePath) : bundle.PathForResource(file, null);

                    var stream           = FileStore.GetInputStream(path, true);
                    var imageInformation = new ImageInformation();
                    imageInformation.SetPath(identifier);
                    imageInformation.SetFilePath(path);

                    return(new Tuple <Stream, LoadingResult, ImageInformation>(
                               stream, LoadingResult.CompiledResource, imageInformation));
                }

                token.ThrowIfCancellationRequested();

                if (string.IsNullOrEmpty(fileType))
                {
                    //Asset catalog
                    bool tryAssetsCatalog = true;
#if __IOS__
                    if (!UIDevice.CurrentDevice.CheckSystemVersion(9, 0))
                    {
                        tryAssetsCatalog = false;
                    }
#endif
                    if (tryAssetsCatalog)
                    {
                        NSDataAsset asset = null;

                        try
                        {
                            await ImageService.Instance.Config.MainThreadDispatcher.PostAsync(() => asset = new NSDataAsset(filename)).ConfigureAwait(false);
                        }
                        catch (Exception) { }

                        if (asset != null)
                        {
                            token.ThrowIfCancellationRequested();
                            var stream           = asset.Data?.AsStream();
                            var imageInformation = new ImageInformation();
                            imageInformation.SetPath(identifier);
                            imageInformation.SetFilePath(null);

                            return(new Tuple <Stream, LoadingResult, ImageInformation>(
                                       stream, LoadingResult.CompiledResource, imageInformation));
                        }
                    }

                    PImage image = null;

                    try
                    {
#if __IOS__
                        await ImageService.Instance.Config.MainThreadDispatcher.PostAsync(() => image = PImage.FromBundle(filename)).ConfigureAwait(false);
#elif __MACOS__
                        await ImageService.Instance.Config.MainThreadDispatcher.PostAsync(() => image = NSImage.ImageNamed(filename)).ConfigureAwait(false);
#endif
                    }
                    catch (Exception) { }

                    if (image != null)
                    {
                        token.ThrowIfCancellationRequested();

                        var stream = image.AsPngStream();

                        var imageInformation = new ImageInformation();
                        imageInformation.SetPath(identifier);
                        imageInformation.SetFilePath(null);

                        return(new Tuple <Stream, LoadingResult, ImageInformation>(
                                   stream, LoadingResult.CompiledResource, imageInformation));
                    }
                }
            }

            throw new FileNotFoundException(identifier);
        }