Esempio n. 1
0
        async private Task GetImageNow2(ImageRequest request)
        {
            if (string.IsNullOrWhiteSpace(request.ImgUri))
            {
                return;
            }
            var         tmpDir   = ApplicationData.Current.TemporaryFolder;
            StorageFile file     = null;
            var         fileName = Uri.EscapeDataString(request.ImgUri.TrimEnd('/'));

            if (fileName.Length > 30)
            {
                fileName = fileName.Substring(fileName.Length - 30, 30);
            }


            if (_files == null)
            {
                _files = (await tmpDir.GetFilesAsync()).Select(f => f.Name).ToList();
            }
            var exists = _files.Contains(fileName);

            if (exists)
            {
                try
                {
                    file = await tmpDir.GetFileAsync(fileName);
                }
                catch (Exception)
                {
                }
            }

            if (file == null)
            {
                var stream = await _xbmc.GetImageStream(request.ImgUri);

                file = await tmpDir.CreateFileAsync(fileName);

                var fileStream = await file.OpenStreamForWriteAsync();

                await stream.CopyToAsync(fileStream);

                fileStream.Dispose();
                _files.Add(fileName);
            }
            if (file != null)
            {
                request.InvokeCallback(new Uri(file.Path));
            }
        }
        private async Task GetImageNow2(ImageRequest request)
        {
            var stream = await _xbmc.GetImageStream(request.ImgUri);

            var file = await _tmpDir.CreateFileAsync(request.FileName);

            var fileStream = await file.OpenStreamForWriteAsync();

            await stream.CopyToAsync(fileStream);

            fileStream.Dispose();
            _files.Add(request.FileName);
            var filePath = Path.Combine(_tmpDir.Path, request.FileName);

            request.InvokeCallback(filePath);
        }