/// <summary> /// Create image handler for downloading video image if found and release the WebClient instance used for API call. /// </summary> private void HandlePostApiCall(object sender) { try { if (_videoImageUrl != null) { _imageLoadHandler = new ImageLoadHandler(HtmlContainer, OnLoadImageComplete); _imageLoadHandler.LoadImage(_videoImageUrl, HtmlTag != null ? HtmlTag.Attributes : null); } else { _imageLoadingComplete = true; SetErrorBorder(); } var webClient = (WebClient)sender; webClient.DownloadStringCompleted -= OnDownloadYoutubeApiCompleted; webClient.DownloadStringCompleted -= OnDownloadVimeoApiCompleted; webClient.Dispose(); HtmlContainer.RequestRefresh(IsLayoutRequired()); } catch { } }
/// <summary> /// Load Vimeo video data (title, image, link) by calling Vimeo API. /// </summary> private void LoadVimeoDataAsync(Uri uri) { ThreadPool.QueueUserWorkItem(state => { try { var apiUri = new Uri(string.Format( "http://vimeo.com/api/v2/video/{0}.json", uri.Segments[2])); var client = new WebClient(); client.Encoding = Encoding.UTF8; client.DownloadStringCompleted += OnDownloadVimeoApiCompleted; client.DownloadStringAsync(apiUri); } catch (Exception ex) { _imageLoadingComplete = true; SetErrorBorder(); HtmlContainer.ReportError(HtmlRenderErrorType.Iframe, "Failed to get vimeo video data: " + uri, ex); HtmlContainer.RequestRefresh(false); } }); }
/// <summary> /// Load YouTube video data (title, image, link) by calling YouTube API. /// </summary> private void LoadYoutubeDataAsync(Uri uri) { ThreadPool.QueueUserWorkItem(state => { try { var apiUri = new Uri( string.Format( "http://gdata.youtube.com/feeds/api/videos/{0}?v=2&alt=json", uri.Segments[2])); var client = new WebClient(); client.Encoding = Encoding.UTF8; client.DownloadStringCompleted += OnDownloadYoutubeApiCompleted; client.DownloadStringAsync(apiUri); } catch (Exception ex) { HtmlContainer.ReportError(HtmlRenderErrorType.Iframe, "Failed to get youtube video data: " + uri, ex); HtmlContainer.RequestRefresh(false); } }); }
void LoadImageAsync() { RImage image; if (this.Content != null && this.Content != CssConstants.Normal) { image = HtmlContainer.ResourceServer.GetImage( this.Content, HtmlTag != null ? HtmlTag.Attributes : null); } else { image = HtmlContainer.ResourceServer.GetImage( GetAttribute("src"), HtmlTag != null ? HtmlTag.Attributes : null); } _imageWord.Image = image; _imageWord.ImageRectangle = RRect.Empty; // rectangle; _imageLoadingComplete = true; _wordsSizeMeasured = false; if (_imageLoadingComplete && image == null) { SetErrorBorder(); } { var width = new CssLength(Width); var height = new CssLength(Height); var layout = (width.Number <= 0 || width.Unit != CssUnit.Pixels) || (height.Number <= 0 || height.Unit != CssUnit.Pixels); HtmlContainer.RequestRefresh(layout); } }
/// <summary> /// On image load process is complete with image or without update the image box. /// </summary> /// <param name="image">the image loaded or null if failed</param> /// <param name="rectangle">the source rectangle to draw in the image (empty - draw everything)</param> /// <param name="async">is the callback was called async to load image call</param> private void OnLoadImageComplete(RImage image, RRect rectangle, bool async) { _imageWord.Image = image; _imageWord.ImageRectangle = rectangle; _imageLoadingComplete = true; _wordsSizeMeasured = false; if (_imageLoadingComplete && image == null) { SetErrorBorder(); } if (async) { HtmlContainer.RequestRefresh(IsLayoutRequired()); } }
/// <summary> /// On image load process is complete with image or without update the image box. /// </summary> /// <param name="image">the image loaded or null if failed</param> /// <param name="rectangle">the source rectangle to draw in the image (empty - draw everything)</param> /// <param name="async">is the callback was called async to load image call</param> private void OnLoadImageComplete(RImage image, RRect rectangle, bool async) { _imageWord.Image = image; _imageWord.ImageRectangle = rectangle; _imageLoadingComplete = true; _wordsSizeMeasured = false; if (_imageLoadingComplete && image == null) { SetErrorBorder(); } if (!HtmlContainer.AvoidImagesLateLoading || async) { var width = new CssLength(Width); var height = new CssLength(Height); var layout = (width.Number <= 0 || width.Unit != CssUnit.Pixels) || (height.Number <= 0 || height.Unit != CssUnit.Pixels); HtmlContainer.RequestRefresh(layout); } }
/// <summary> /// Create image handler for downloading video image if found and release the WebClient instance used for API call. /// </summary> private void HandlePostApiCall(object sender) { try { if (_videoImageUrl == null) { _imageLoadingComplete = true; SetErrorBorder(); } var webClient = (WebClient)sender; webClient.DownloadStringCompleted -= OnDownloadYoutubeApiCompleted; webClient.DownloadStringCompleted -= OnDownloadVimeoApiCompleted; webClient.Dispose(); HtmlContainer.RequestRefresh(IsLayoutRequired()); } catch { } }