Пример #1
0
 /// <summary>
 /// Attempts to get an image from the catalog for the specified url.
 /// </summary>
 /// <param name="imageUrl">The url for the image.</param>
 /// <param name="options">The image options.</param>
 /// <returns>The image if one is currently stored in the catalog or null if one does not exist.</returns>
 public byte[] TryGetImage(string imageUrl, ImageOptions options)
 {
     return(this.imageCache.TryGet(this.GetRequestKey(imageUrl, options)));
 }
Пример #2
0
        private RemoteImageRequest AttemptRetry(RemoteImageRequest failedRequest, string imageUrl, ImageOptions options)
        {
            if (!failedRequest.IsRequestCompleted)
            {
                throw new ArgumentException("The request has not completed.", nameof(failedRequest));
            }

            if (failedRequest.Task.Result.ResultCode == ServiceResultCode.Success)
            {
                throw new ArgumentException("The request was successful, no retry needed.", nameof(failedRequest));
            }

            if (failedRequest.Task.Result.ResultCode == ServiceResultCode.ResourceNotFound ||
                failedRequest.RetryCounter == this.maxRetryAttempts)
            {
                return(failedRequest);
            }

            int retryCounter = failedRequest.RetryCounter;

            if (failedRequest.Task.Result.ResultCode != ServiceResultCode.NetworkUnavailable)
            {
                // If the network is unavailable we will keep retrying until it becomes available.
                // It is assumed that the underlying remote client is optimized to handle network status
                // so that a call to make repeated remote request is cheap.

                retryCounter++;
            }

            string requestKey = this.GetRequestKey(imageUrl, options);

            this.TryRemoveRequest(requestKey);

            return(this.TryStartImageRequest(imageUrl, options, retryCounter));
        }
Пример #3
0
        /// <summary>
        /// Removes the specified image from the cache if it exists.
        /// </summary>
        /// <param name="imageUrl">The url for the image.</param>
        /// <param name="options">The image options for the image.</param>
        public void RemoveCachedImage(string imageUrl, ImageOptions options)
        {
            string key = this.GetRequestKey(imageUrl, options);

            this.imageCache.Remove(key);
        }
Пример #4
0
        /// <summary>
        /// Gets whether or not an image for the specified url is currently stored in cache.
        /// </summary>
        /// <param name="imageUrl">The url for the image.</param>
        /// <param name="options">The options for the image.</param>
        /// <returns>True if the image for the url is currently stored in cache, otherwise false.</returns>
        public bool IsInCache(string imageUrl, ImageOptions options)
        {
            string requestKey = this.GetRequestKey(imageUrl, options);

            return(this.imageCache.Exists(requestKey));
        }
Пример #5
0
        /// <summary>
        /// Adds the specified image into the cache if it does not exist or updates it if one already exists.
        /// </summary>
        /// <param name="imageUrl">The url for the image.</param>
        /// <param name="options">The image options for the image.</param>
        /// <param name="imageData">The image as bytes.</param>
        public void AddOrUpdateCachedImage(string imageUrl, ImageOptions options, byte[] imageData)
        {
            string key = this.GetRequestKey(imageUrl, options);

            this.imageCache.Put(key, imageData);
        }