예제 #1
0
        /// <summary>
        /// Downloads the specified url if there is not already a entry in the cache.
        /// </summary>
        /// <param name="blobCache">The blob cache to insert the item into.</param>
        /// <param name="url">The URL to download if not already in the cache.</param>
        /// <param name="expiration">A timespan that will be added to the current DateTime.</param>
        /// <param name="headers">The headers to specify when getting the entry.</param>
        /// <param name="fetchAlways">If we should fetch always and not return the cache entry if available.</param>
        /// <returns>A observable which will signal when the data is available.</returns>
        public static IObservable <byte[]> DownloadUrl(this IBlobCache blobCache, Uri url, TimeSpan expiration, Dictionary <string, string>?headers = null, bool fetchAlways = false)
        {
            if (blobCache is null)
            {
                throw new ArgumentNullException(nameof(blobCache));
            }

            return(blobCache.DownloadUrl(url, headers, fetchAlways, blobCache.Scheduler.Now + expiration));
        }
예제 #2
0
        /// <summary>
        /// Download data from an HTTP URL and insert the result into the
        /// cache. If the data is already in the cache, this returns
        /// a cached value. The URL itself is used as the key.
        /// </summary>
        /// <param name="blobCache">The blob cache associated with the action.</param>
        /// <param name="url">The URL to download.</param>
        /// <param name="headers">An optional Dictionary containing the HTTP
        /// request headers.</param>
        /// <param name="fetchAlways">Force a web request to always be issued, skipping the cache.</param>
        /// <param name="absoluteExpiration">An optional expiration date.</param>
        /// <returns>The data downloaded from the URL.</returns>
        public IObservable <byte[]> DownloadUrl(IBlobCache blobCache, string url, IDictionary <string, string> headers = null, bool fetchAlways = false, DateTimeOffset?absoluteExpiration = null)
        {
            if (blobCache is null)
            {
                throw new ArgumentNullException(nameof(blobCache));
            }

            return(blobCache.DownloadUrl(url, url, headers, fetchAlways, absoluteExpiration));
        }
예제 #3
0
        /// <summary>
        /// A combination of DownloadUrl and LoadImage, this method fetches an
        /// image from a remote URL (using the cached value if possible) and
        /// returns the image.
        /// </summary>
        /// <param name="blobCache">The blob cache to load the image from if available.</param>
        /// <param name="url">The URL to download.</param>
        /// <param name="fetchAlways">If we should always fetch the image from the URL even if we have one in the blob.</param>
        /// <param name="desiredWidth">Optional desired width, if not specified will be the default size.</param>
        /// <param name="desiredHeight">Optional desired height, if not specified will be the default size.</param>
        /// <param name="absoluteExpiration">An optional expiration date.</param>
        /// <returns>A Future result representing the bitmap image. blobCache
        /// Observable is guaranteed to be returned on the UI thread.</returns>
        public static IObservable <IBitmap> LoadImageFromUrl(this IBlobCache blobCache, Uri url, bool fetchAlways = false, float?desiredWidth = null, float?desiredHeight = null, DateTimeOffset?absoluteExpiration = null)
        {
            if (blobCache is null)
            {
                throw new ArgumentNullException(nameof(blobCache));
            }

            return(blobCache.DownloadUrl(url, null, fetchAlways, absoluteExpiration)
                   .SelectMany(ThrowOnBadImageBuffer)
                   .SelectMany(x => BytesToImage(x, desiredWidth, desiredHeight)));
        }
예제 #4
0
        public async Task <RestResponse> SendAsync(string method, string endpoint, CancellationToken cancelToken, bool headerOnly)
        {
            if (method != "GET")
            {
                throw new InvalidOperationException("This RestClient only supports GET requests.");
            }

            string uri   = Path.Combine(_baseUrl, endpoint);
            var    bytes = await _blobCache.DownloadUrl(uri, _headers);

            return(new RestResponse(HttpStatusCode.OK, _headers, new MemoryStream(bytes)));
        }
예제 #5
0
 public static IObservable <byte[]> DownloadUrl(this IBlobCache This, string url, TimeSpan expiration, Dictionary <string, string> headers = null, bool fetchAlways = false)
 {
     return(This.DownloadUrl(url, headers, fetchAlways, This.Scheduler.Now + expiration));
 }
예제 #6
0
 /// <summary>
 /// Download data from an HTTP URL and insert the result into the
 /// cache. If the data is already in the cache, this returns
 /// a cached value. The URL itself is used as the key.
 /// </summary>
 /// <param name="url">The URL to download.</param>
 /// <param name="headers">An optional Dictionary containing the HTTP
 /// request headers.</param>
 /// <param name="fetchAlways">Force a web request to always be issued, skipping the cache.</param>
 /// <param name="absoluteExpiration">An optional expiration date.</param>
 /// <returns>The data downloaded from the URL.</returns>
 public IObservable <byte[]> DownloadUrl(IBlobCache This, string url, IDictionary <string, string> headers = null, bool fetchAlways = false, DateTimeOffset?absoluteExpiration = null)
 {
     return(This.DownloadUrl(url, url, headers, fetchAlways, absoluteExpiration));
 }
예제 #7
0
 /// <summary>
 /// A combination of DownloadUrl and LoadImage, this method fetches an
 /// image from a remote URL (using the cached value if possible) and
 /// returns the image.
 /// </summary>
 /// <param name="key">The key to store with.</param>
 /// <param name="url">The URL to download.</param>
 /// <returns>A Future result representing the bitmap image. This
 /// Observable is guaranteed to be returned on the UI thread.</returns>
 public static IObservable <IBitmap> LoadImageFromUrl(this IBlobCache This, string key, string url, bool fetchAlways = false, float?desiredWidth = null, float?desiredHeight = null, DateTimeOffset?absoluteExpiration = null)
 {
     return(This.DownloadUrl(key, url, null, fetchAlways, absoluteExpiration)
            .SelectMany(ThrowOnBadImageBuffer)
            .SelectMany(x => bytesToImage(x, desiredWidth, desiredHeight)));
 }
예제 #8
0
 /// <summary>
 /// A combination of DownloadUrl and LoadImage, this method fetches an
 /// image from a remote URL (using the cached value if possible) and
 /// returns the image.
 /// </summary>
 /// <param name="url">The URL to download.</param>
 /// <returns>A Future result representing the bitmap image. This
 /// Observable is guaranteed to be returned on the UI thread.</returns>
 public static IObservable <IBitmap> LoadImageFromVpdb(this IBlobCache This, string url, bool fetchAlways = false, float?desiredWidth = null, float?desiredHeight = null, DateTimeOffset?absoluteExpiration = null)
 {
     return(This.DownloadUrl(new Uri(url).AbsoluteUri, VpdbClient.GetAuthHeaders(), fetchAlways, absoluteExpiration)
            .SelectMany(ThrowOnBadImageBuffer)
            .SelectMany(x => BytesToImage(x, desiredWidth, desiredHeight)));
 }
예제 #9
0
 /// <summary>
 /// A combination of DownloadUrl and LoadImage, this method fetches an
 /// image from a remote URL (using the cached value if possible) and
 /// returns the XAML image.
 /// </summary>
 /// <param name="url">The URL to download.</param>
 /// <returns>A Future result representing the bitmap image. This
 /// Observable is guaranteed to be returned on the UI thread.</returns>
 public static IObservable <BitmapImage> LoadImageFromUrl(this IBlobCache This, string url, bool fetchAlways = false, DateTimeOffset?absoluteExpiration = null)
 {
     return(This.DownloadUrl(url, null, fetchAlways, absoluteExpiration)
            .SelectMany(ThrowOnBadImageBuffer)
            .SelectMany(BytesToImage));
 }
예제 #10
0
 /// <summary>
 /// Download data from an HTTP URL and insert the result into the
 /// cache. If the data is already in the cache, this returns
 /// a cached value. The URL itself is used as the key.
 /// </summary>
 /// <param name="url">The URL to download.</param>
 /// <param name="headers">An optional Dictionary containing the HTTP
 /// request headers.</param>
 /// <param name="fetchAlways">Force a web request to always be issued, skipping the cache.</param>
 /// <param name="absoluteExpiration">An optional expiration date.</param>
 /// <returns>The data downloaded from the URL.</returns>
 public IObservable<byte[]> DownloadUrl(IBlobCache This, string url, IDictionary<string, string> headers = null, bool fetchAlways = false, DateTimeOffset? absoluteExpiration = null)
 {
     return This.DownloadUrl(url, url, headers, fetchAlways, absoluteExpiration);
 }