コード例 #1
0
        /// <summary>
        /// Gets the specified request.
        /// </summary>
        /// <param name="request">The request.</param>
        /// <returns>System.Object.</returns>
        public async Task <object> Get(GetRemoteImage request)
        {
            var urlHash          = request.ImageUrl.GetMD5();
            var pointerCachePath = GetFullCachePath(urlHash.ToString());

            string contentPath;

            try
            {
                contentPath = _fileSystem.ReadAllText(pointerCachePath);

                if (_fileSystem.FileExists(contentPath))
                {
                    return(await ResultFactory.GetStaticFileResult(Request, contentPath).ConfigureAwait(false));
                }
            }
            catch (FileNotFoundException)
            {
                // Means the file isn't cached yet
            }
            catch (IOException)
            {
                // Means the file isn't cached yet
            }

            await DownloadImage(request.ImageUrl, urlHash, pointerCachePath).ConfigureAwait(false);

            // Read the pointer file again
            contentPath = _fileSystem.ReadAllText(pointerCachePath);

            return(await ResultFactory.GetStaticFileResult(Request, contentPath).ConfigureAwait(false));
        }
コード例 #2
0
        /// <summary>
        /// Gets the remote image.
        /// </summary>
        /// <param name="request">The request.</param>
        /// <returns>Task{System.Object}.</returns>
        private async Task <object> GetRemoteImage(GetRemoteImage request)
        {
            var urlHash          = request.Url.GetMD5();
            var pointerCachePath = GetFullCachePath(urlHash.ToString());

            string contentPath;

            try
            {
                using (var reader = new StreamReader(pointerCachePath))
                {
                    contentPath = await reader.ReadToEndAsync().ConfigureAwait(false);
                }

                if (File.Exists(contentPath))
                {
                    return(ToStaticFileResult(contentPath));
                }
            }
            catch (FileNotFoundException)
            {
                // Means the file isn't cached yet
            }

            await DownloadImage(request.Url, urlHash, pointerCachePath).ConfigureAwait(false);

            // Read the pointer file again
            using (var reader = new StreamReader(pointerCachePath))
            {
                contentPath = await reader.ReadToEndAsync().ConfigureAwait(false);
            }

            return(ToStaticFileResult(contentPath));
        }
コード例 #3
0
 /// <summary>
 /// Gets the specified request.
 /// </summary>
 /// <param name="request">The request.</param>
 /// <returns>System.Object.</returns>
 public object Get(GetRemoteImage request)
 {
     return(GetAsync(request).Result);
 }
コード例 #4
0
        /// <summary>
        /// Gets the specified request.
        /// </summary>
        /// <param name="request">The request.</param>
        /// <returns>System.Object.</returns>
        public object Get(GetRemoteImage request)
        {
            var task = GetRemoteImage(request);

            return(task.Result);
        }