private Bitmap DownloadImage(string imageUrl, string basePath) { // non-url base path means embedded resource if (!UrlHelper.IsUrl(basePath)) { string imagePath = String.Format(CultureInfo.InvariantCulture, "{0}.{1}", basePath, imageUrl); Bitmap image = ResourceHelper.LoadAssemblyResourceBitmap(imagePath); if (image != null) { return(image); } else { throw new ArgumentException("Invalid Image Resource Path: " + imageUrl); } } else { // calculate the image url imageUrl = UrlHelper.UrlCombineIfRelative(basePath, imageUrl); // try to get the credentials context WinInetCredentialsContext credentialsContext = null; try { credentialsContext = BlogClientHelper.GetCredentialsContext(_blogClient, _credentials, imageUrl); } catch (BlogClientOperationCancelledException) { } // download the image return(ImageHelper.DownloadBitmap(imageUrl, credentialsContext)); } }
private void ApplyCredentials(PageDownloadContext downloadContext, string url) { WinInetCredentialsContext credentialsContext = CreateCredentialsContext(url); if (credentialsContext != null && credentialsContext.CookieString != null) { downloadContext.CookieString = credentialsContext.CookieString.Cookies; } }
private void ApplyCredentials(PageAndReferenceDownloader downloader, string url) { WinInetCredentialsContext credentialsContext = CreateCredentialsContext(url); if (credentialsContext != null) { downloader.CredentialsContext = credentialsContext; } }
public BrowserMiniForm(string url, int downloadOptions, WinInetCredentialsContext credentialsContext) { // record url to navigate to _url = url; // standard "flyout" form behavior DismissOnDeactivate = true; // dock inset for drawing of border DockPadding.All = 1; // background color is white to minimize flashing problem when dismissing BackColor = Color.White; // initialize browser control _explorerBrowserControl = new ExplorerBrowserControl(); _explorerBrowserControl.Dock = DockStyle.Fill; Controls.Add(_explorerBrowserControl); // install download options if requested if (downloadOptions > 0) { _explorerBrowserControl.DownloadOptions = downloadOptions; } // install network credential if requested if (credentialsContext != null) { if (credentialsContext.NetworkCredential != null) { _explorerBrowserControl.NetworkCredential = credentialsContext.NetworkCredential; } if (credentialsContext.CookieString != null) { _explorerBrowserControl.SetCookies(credentialsContext.CookieString.Url, credentialsContext.CookieString.Cookies); } } // other options _explorerBrowserControl.Silent = true; // Navigate to about:blank for installation of ui customizations. Note that this step is CRITICAL // to ensuring that not only our custom ui hooks get installed but also to ensure that our DLCTL // options (which control security) are registered prior to the fectching of the content. _explorerBrowserControl.DocumentComplete += new BrowserDocumentEventHandler(_explorerBrowserControl_AboutBlankDocumentComplete); _explorerBrowserControl.Navigate("about:blank"); }
private IBlogProviderButtonNotification GetButtonNotification() { string notificationUrl = String.Format( CultureInfo.InvariantCulture, "{0}?blog_id={1}&button_id={2}&image_url={3}", NotificationUrl, HttpUtility.UrlEncode(_hostBlogId), HttpUtility.UrlEncode(_buttonId), HttpUtility.UrlEncode(ImageUrl)); // get the content HttpWebResponse response = null; XmlDocument xmlDocument = new XmlDocument(); try { using (Blog blog = new Blog(_blogId)) response = blog.SendAuthenticatedHttpRequest(notificationUrl, 10000); // parse the results xmlDocument.Load(response.GetResponseStream()); } catch (Exception) { throw; } finally { if (response != null) { response.Close(); } } // create namespace manager XmlNamespaceManager nsmgr = new XmlNamespaceManager(xmlDocument.NameTable); nsmgr.AddNamespace("n", "http://schemas.microsoft.com/wlw/buttons/notification"); // throw if the root element is not manifest if (xmlDocument.DocumentElement.LocalName.ToLower(CultureInfo.InvariantCulture) != "notification") { throw new ArgumentException("Not a valid writer button notification"); } // polling interval int checkAgainMinutes = XmlHelper.NodeInt(xmlDocument.SelectSingleNode("//n:checkAgainMinutes", nsmgr), 0); if (checkAgainMinutes == 0) { throw new ArgumentException("You must specify a value for checkAgainMinutes"); } TimeSpan pollingInterval = TimeSpan.FromMinutes(checkAgainMinutes); // notification text string notificationText = XmlHelper.NodeText(xmlDocument.SelectSingleNode("//n:text", nsmgr)); // notification image Bitmap notificationImage = null; string notificationImageUrl = XmlHelper.NodeText(xmlDocument.SelectSingleNode("//n:imageUrl", nsmgr)); if (notificationImageUrl != String.Empty) { // compute the absolute url then allow parameter substitution notificationImageUrl = BlogClientHelper.GetAbsoluteUrl(notificationImageUrl, NotificationUrl); notificationImageUrl = BlogClientHelper.FormatUrl(notificationImageUrl, _homepageUrl, _postApiUrl, _hostBlogId); // try to download it (will use the cache if available) // note that failing to download it is a recoverable error, we simply won't show a notification image try { // try to get a credentials context for the download WinInetCredentialsContext credentialsContext = null; try { credentialsContext = BlogClientHelper.GetCredentialsContext(_blogId, notificationImageUrl); } catch (BlogClientOperationCancelledException) { } // execute the download notificationImage = ImageHelper.DownloadBitmap(notificationImageUrl, credentialsContext); } catch (Exception ex) { Trace.WriteLine("Error downloading notification image: " + ex.ToString()); } } // clear notification on click bool clearNotificationOnClick = XmlHelper.NodeBool(xmlDocument.SelectSingleNode("//n:resetOnClick", nsmgr), true); // return the notification return(new BlogProviderButtonNotification(pollingInterval, notificationText, notificationImage, clearNotificationOnClick)); }
public void ViewContent(Control parent, Point menuLocation, int alternativeLocation, IDisposable disposeWhenDone) { try { if (!WinInet.InternetConnectionAvailable) { disposeWhenDone.Dispose(); DisplayMessage.Show(MessageId.InternetConnectionWarning); return; } // track resource that need to be disposed _disposeWhenDone = disposeWhenDone; using (new WaitCursor()) { // if the user is holding the CTRL button down then invalidate the cache bool forceResynchronize = (KeyboardHelper.GetModifierKeys() == Keys.Control); // setup download options int downloadOptions = DLCTL.DLIMAGES | DLCTL.NO_CLIENTPULL | DLCTL.NO_BEHAVIORS | DLCTL.NO_DLACTIVEXCTLS | DLCTL.SILENT; if (forceResynchronize) { downloadOptions |= DLCTL.RESYNCHRONIZE; } // determine cookies and/or network credentials WinInetCredentialsContext credentialsContext = null; try { credentialsContext = BlogClientHelper.GetCredentialsContext(_button.BlogId, _button.ContentUrl); } catch (BlogClientOperationCancelledException) { _disposeWhenDone.Dispose(); return; } // note that we have viewed the content _button.RecordButtonClicked(); // create the form and position it BrowserMiniForm form = new BrowserMiniForm(_button.ContentQueryUrl, downloadOptions, credentialsContext); form.StartPosition = FormStartPosition.Manual; form.Size = _button.ContentDisplaySize; if (!Screen.FromPoint(menuLocation).Bounds.Contains(menuLocation.X + form.Width, menuLocation.Y)) { menuLocation.X = alternativeLocation - form.Width; } form.Location = new Point(menuLocation.X + 1, menuLocation.Y); // subscribe to close event for disposal form.Closed += new EventHandler(form_Closed); // float above parent if we have one IMiniFormOwner miniFormOwner = parent.FindForm() as IMiniFormOwner; if (miniFormOwner != null) { form.FloatAboveOwner(miniFormOwner); } // show the form form.Show(); } } catch { disposeWhenDone.Dispose(); throw; } }