Beispiel #1
0
        public async Task SetDataRequestDataAsync(DataRequest request)
        {
            var requestData = request.Data;

            requestData.SetWebLink(new Uri(Image.Urls.Full));
            requestData.Properties.Title = ResourcesHelper.GetResString("ShareTitle");
            requestData.Properties.ContentSourceWebLink         = new Uri(Image.Urls.Full);
            requestData.Properties.ContentSourceApplicationLink = new Uri(Image.Urls.Full);

            requestData.SetText(ShareText);

            var cachekey = _cacheKeyFactory.ProvideKey(LoadingUrl);
            var file     = await _cacheSupplier.TryGetCacheAsync(cachekey);

            if (file != null)
            {
                List <IStorageItem> imageItems = new List <IStorageItem>
                {
                    file
                };
                requestData.SetStorageItems(imageItems);

                var imageStreamRef = RandomAccessStreamReference.CreateFromFile(file);
                requestData.SetBitmap(imageStreamRef);
                requestData.Properties.Thumbnail = imageStreamRef;
            }
        }
Beispiel #2
0
        public async Task LoadBitmapAsync(bool setBitmap = true)
        {
            if (string.IsNullOrEmpty(RemoteUrl))
            {
                return;
            }

            var cacheKey = _cacheKeyFactory.ProvideKey(RemoteUrl);
            var file     = await _cacheSupplier.TryGetCacheAsync(cacheKey);

            if (file != null)
            {
                Debug.WriteLine($"====Find cache file: {cacheKey}");
                await SetImageSourceAsync(file);

                return;
            }

            Debug.WriteLine($"====Download file for: {cacheKey}");

            var token = CancellationTokenSourceFactory.CreateDefault(ImageDownloader.TIMEOUT_MILLIS).Create().Token;

            using (var stream = await ImageDownloader.GetEncodedImageFromUrlAsync(RemoteUrl, token))
            {
                var savedFile = await SaveEncodedImageToFileAsync(stream.AsStreamForRead());

                if (stream != null && setBitmap)
                {
                    stream.Seek(0);
                    await SetImageSourceAsync(stream);
                }
            }
        }
Beispiel #3
0
 private async Task <bool> CheckListImageDownloadedAsync(ImageItem image)
 {
     return(await _cacheSupplier.CheckCacheExistAsync(_cacheKeyFactory.ProvideKey(image.LoadingUrl)));
 }