WebBrowserForm.cs 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. using System;
  2. using System.Text.RegularExpressions;
  3. using System.Windows.Forms;
  4. using FastReport.Forms;
  5. using FastReport.Utils;
  6. namespace FastReport.Cloud.StorageClient.Box
  7. {
  8. /// <summary>
  9. /// Represents form of the web browser.
  10. /// </summary>
  11. public partial class WebBrowserForm : BaseForm
  12. {
  13. #region Fields
  14. private string url;
  15. private string authCode;
  16. #endregion // Fields
  17. #region Properties
  18. /// <summary>
  19. /// Gets obtained authorization code.
  20. /// </summary>
  21. public string AuthCode
  22. {
  23. get { return authCode; }
  24. }
  25. #endregion // Properties
  26. #region Constructros
  27. /// <inheritdoc/>
  28. public WebBrowserForm(string url)
  29. {
  30. InitializeComponent();
  31. this.url = url;
  32. authCode = "";
  33. UIUtils.CheckRTL(this);
  34. }
  35. #endregion // Constructros
  36. #region Events Handlers
  37. private void WebBrowserForm_Shown(object sender, EventArgs e)
  38. {
  39. wbBrowser.Navigate(url);
  40. }
  41. private void wbBrowser_Navigated(object sender, WebBrowserNavigatedEventArgs e)
  42. {
  43. if (wbBrowser.Url.ToString().Contains("code="))
  44. {
  45. Console.WriteLine(wbBrowser.Url.ToString());
  46. authCode = Regex.Split(Regex.Split(wbBrowser.Url.ToString(), "code=")[1], "<")[0];
  47. Close();
  48. }
  49. }
  50. #endregion // Events Handlers
  51. }
  52. }