public void GetImageAsync(FacebookImageDimensions requestedSize, GetImageSourceAsyncCallback callback) { Verify.IsNotNull(callback, "callback"); Assert.IsNotNull(SourceService); Assert.IsNotNull(SourceService.WebGetter); SmallUri ss = _GetSmallUriFromRequestedSize(requestedSize); if (ss == default(SmallUri)) { callback(this, new GetImageSourceCompletedEventArgs(new InvalidOperationException("The requested image doesn't exist"), false, this)); } BitmapSource img; if (_TryGetFromWeakCache(requestedSize, out img)) { callback(this, new GetImageSourceCompletedEventArgs(img, this)); } var userState = new _ImageCallbackState { Callback = callback, RequestedSize = requestedSize }; SourceService.WebGetter.GetImageSourceAsync(this, userState, ss, _AddWeakCacheCallback); }
/// <summary> /// Starts download of requested image /// </summary> /// <param name="requestedSize">Size of the image</param> /// <param name="callback">Callback that will be called when download completes</param> public void GetImageAsync(FacebookImageDimensions requestedSize, GetImageSourceAsyncCallback callback) { #if !SILVERLIGHT dispatcher = Dispatcher.CurrentDispatcher; #else dispatcher = System.Windows.Deployment.Current.Dispatcher; #endif Uri = _normal; switch (requestedSize) { case FacebookImageDimensions.Big: Uri = _big; break; case FacebookImageDimensions.Small: Uri = _small; break; case FacebookImageDimensions.Square: Uri = _square; break; } if (Uri == null) { callback(this, new GetImageSourceCompletedEventArgs(new InvalidOperationException(), false, this)); return; } WebClientHelper wc = new WebClientHelper(callback); wc.RequestCompleted += new EventHandler <RequestCompletedEventArgs>(wc_RequestCompleted); wc.SendRequest(Uri, null, null); }
public bool IsCached(FacebookImageDimensions requestedSize) { SmallUri sizedString = _GetSmallUriFromRequestedSize(requestedSize); //Assert.IsNotDefault(sizedString); string path; return(SourceService.WebGetter.TryGetImageFile(sizedString, out path)); }
public static Size GetDimensionSize(FacebookImageDimensions dimensions) { Size size; if (_DimensionLookup.TryGetValue(dimensions, out size)) { return(size); } throw new ArgumentException("Invalid enum value", "dimensions"); }
internal void SaveToFile(FacebookImageDimensions requestedSize, string path, bool addExtension, FacebookImageSaveOptions options, SaveImageAsyncCallback callback, object userState, int?index, int?total) { Verify.IsNeitherNullNorEmpty(path, "path"); Verify.IsNotNull(callback, "callback"); Assert.Implies(total != null, index != null); Assert.Implies(total == null, index == null); SafeCopyFileOptions scfo = (options == FacebookImageSaveOptions.FindBetterName) ? SafeCopyFileOptions.FindBetterName : (options == FacebookImageSaveOptions.Overwrite) ? SafeCopyFileOptions.Overwrite : SafeCopyFileOptions.PreserveOriginal; SourceService.WebGetter.GetLocalImagePathAsync(this, null, _GetSmallUriFromRequestedSize(requestedSize), (sender, e) => { string cachePath = e.ImagePath; if (addExtension) { string ext = Path.GetExtension(cachePath); path = Path.ChangeExtension(path, ext); } try { string actualPath = Utility.SafeCopyFile(cachePath, path, scfo); if (actualPath == null) { throw new IOException("Unable to save the image to the requested location."); } SaveImageCompletedEventArgs sicea = null; if (total == null) { sicea = new SaveImageCompletedEventArgs(actualPath, userState); } else { sicea = new SaveImageCompletedEventArgs(actualPath, index.Value, total.Value, userState); } callback(this, sicea); return; } catch (Exception ex) { callback(this, new SaveImageCompletedEventArgs(ex, false, userState)); return; } }); }
private SmallUri _GetSmallUriFromRequestedSize(FacebookImageDimensions requestedSize) { // If one url type isn't available, try to fallback on other provided values. SmallUri?str = null; switch (requestedSize) { case FacebookImageDimensions.Big: str = _big ?? _normal ?? _small ?? _square; break; case FacebookImageDimensions.Small: str = _small ?? _normal ?? _big ?? _square; break; case FacebookImageDimensions.Square: str = _square ?? _small ?? _normal ?? _big; break; case FacebookImageDimensions.Normal: str = _normal ?? _big ?? _small ?? _square; break; } return(str ?? default(SmallUri)); }
private bool _TryGetFromWeakCache(FacebookImageDimensions requestedSize, out BitmapSource img) { img = null; switch (requestedSize) { case FacebookImageDimensions.Big: if (_bigWR != null) { img = _bigWR.Target as BitmapSource; } break; case FacebookImageDimensions.Normal: if (_normalWR != null) { img = _normalWR.Target as BitmapSource; } break; case FacebookImageDimensions.Small: if (_smallWR != null) { img = _smallWR.Target as BitmapSource; } break; case FacebookImageDimensions.Square: if (_squareWR != null) { img = _squareWR.Target as BitmapSource; } break; } return(img != null); }
public void SaveToFile(FacebookImageDimensions requestedSize, string path, bool addExtension, FacebookImageSaveOptions options, SaveImageAsyncCallback callback, object userState) { SaveToFile(requestedSize, path, addExtension, options, callback, userState, null, null); }
/// <summary> /// Starts download of requested image /// </summary> /// <param name="requestedSize">Size of the image</param> /// <param name="callback">Callback that will be called when download completes</param> public void GetImageAsync(FacebookImageDimensions requestedSize, GetImageSourceAsyncCallback callback) { #if !SILVERLIGHT dispatcher = Dispatcher.CurrentDispatcher; #else dispatcher = System.Windows.Deployment.Current.Dispatcher; #endif Uri = _normal; switch (requestedSize) { case FacebookImageDimensions.Big: Uri = _big; break; case FacebookImageDimensions.Small: Uri = _small; break; case FacebookImageDimensions.Square: Uri = _square; break; } if (Uri == null) { callback(this, new GetImageSourceCompletedEventArgs(new InvalidOperationException(), false, this)); return; } WebClientHelper wc = new WebClientHelper(callback); wc.RequestCompleted += new EventHandler<RequestCompletedEventArgs>(wc_RequestCompleted); wc.SendRequest(Uri, null, null); }