当前位置: 首页>>代码示例>>C#>>正文


C# IApiClient.GetImageStreamAsync方法代码示例

本文整理汇总了C#中IApiClient.GetImageStreamAsync方法的典型用法代码示例。如果您正苦于以下问题:C# IApiClient.GetImageStreamAsync方法的具体用法?C# IApiClient.GetImageStreamAsync怎么用?C# IApiClient.GetImageStreamAsync使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在IApiClient的用法示例。


在下文中一共展示了IApiClient.GetImageStreamAsync方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: GetRemoteBitmapAsyncInternal

        /// <summary>
        /// Gets the remote bitmap async.
        /// </summary>
        /// <param name="apiClient">The API client.</param>
        /// <param name="url">The URL.</param>
        /// <param name="cancellationToken">The cancellation token.</param>
        /// <returns>Task{BitmapImage}.</returns>
        /// <exception cref="ArgumentNullException">url</exception>
        private async Task<BitmapImage> GetRemoteBitmapAsyncInternal(IApiClient apiClient, string url, CancellationToken cancellationToken)
        {
            if (string.IsNullOrEmpty(url))
            {
                throw new ArgumentNullException("url");
            }

            var cachePath = _remoteImageCache.GetResourcePath(url.GetMD5().ToString());

            try
            {
                return GetCachedBitmapImage(cachePath);
            }
            catch (IOException)
            {
                // Cache file doesn't exist or is currently being written to.
            }

            cancellationToken.ThrowIfCancellationRequested();

            var semaphore = GetImageFileLock(cachePath);
            await semaphore.WaitAsync(cancellationToken).ConfigureAwait(false);

            // Look in the cache again
            try
            {
                var img = GetCachedBitmapImage(cachePath);
                semaphore.Release();
                return img;
            }
            catch (IOException)
            {
                // Cache file doesn't exist or is currently being written to.
            }

            try
            {
                using (var httpStream = await apiClient.GetImageStreamAsync(url, cancellationToken).ConfigureAwait(false))
                {
                    var parentPath = Path.GetDirectoryName(cachePath);

                    if (!Directory.Exists(parentPath))
                    {
                        Directory.CreateDirectory(parentPath);
                    }

                    using (var fileStream = new FileStream(cachePath, FileMode.Create, FileAccess.Write, FileShare.Read, StreamDefaults.DefaultFileStreamBufferSize, true))
                    {
                        await httpStream.CopyToAsync(fileStream).ConfigureAwait(false);
                    }

                    return GetCachedBitmapImage(cachePath);
                }
            }
            finally
            {
                semaphore.Release();
            }
        }
开发者ID:chandum2,项目名称:Emby.Theater,代码行数:67,代码来源:ImageManager.cs

示例2: UpdateUserImage

        private async Task UpdateUserImage(UserDto user, IApiClient apiClient, CancellationToken cancellationToken)
        {
            if (user.HasPrimaryImage)
            {
                var isImageCached = await _localAssetManager.HasImage(user).ConfigureAwait(false);

                if (!isImageCached)
                {
                    var imageUrl = apiClient.GetUserImageUrl(user, new ImageOptions
                    {
                        ImageType = ImageType.Primary
                    });

                    using (var stream = await apiClient.GetImageStreamAsync(imageUrl, cancellationToken).ConfigureAwait(false))
                    {
                        await _localAssetManager.SaveImage(user, stream).ConfigureAwait(false);
                    }
                }
            }
            else
            {
                await _localAssetManager.DeleteImage(user).ConfigureAwait(false);
            }
        }
开发者ID:daltekkie,项目名称:Emby.ApiClient,代码行数:24,代码来源:OfflineUserSync.cs


注:本文中的IApiClient.GetImageStreamAsync方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。