WebBrowserForm.cs 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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.GoogleDrive
  7. {
  8. /// <summary>
  9. /// Represents form of the web browser.
  10. /// </summary>
  11. public partial class WebBrowserForm : BaseDialogForm
  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 Constructors
  27. /// <inheritdoc/>
  28. public WebBrowserForm(string url)
  29. {
  30. InitializeComponent();
  31. this.url = url;
  32. authCode = "";
  33. wbBrowser.Navigated += new WebBrowserNavigatedEventHandler(wbBrowser_Navigated);
  34. UIUtils.CheckRTL(this);
  35. }
  36. #endregion // Constructors
  37. #region Events Handlers
  38. private void WebBrowserForm_Shown(object sender, EventArgs e)
  39. {
  40. wbBrowser.Navigate(url);
  41. }
  42. private void btnOk_Click(object sender, EventArgs e)
  43. {
  44. authCode = Regex.Split(Regex.Split(wbBrowser.DocumentText, "code=")[1], "<")[0];
  45. }
  46. private void wbBrowser_Navigated(object sender, WebBrowserNavigatedEventArgs e)
  47. {
  48. if (wbBrowser.DocumentText.Contains("code="))
  49. {
  50. authCode = Regex.Split(Regex.Split(wbBrowser.DocumentText, "code=")[1], "<")[0];
  51. this.Close();
  52. }
  53. }
  54. #endregion // Events Handlers
  55. }
  56. }