ClientInfoForm.cs 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. using System;
  2. using System.Windows.Forms;
  3. using FastReport.Forms;
  4. using FastReport.Utils;
  5. namespace FastReport.Cloud.StorageClient.GoogleDrive
  6. {
  7. /// <summary>
  8. /// Represents the Client Info diabolg form.
  9. /// </summary>
  10. public partial class ClientInfoForm : BaseDialogForm
  11. {
  12. #region Fields
  13. #pragma warning disable FR0001 // Field names must be longer than 2 characters.
  14. private string id;
  15. #pragma warning restore FR0001 // Field names must be longer than 2 characters.
  16. private string secret;
  17. private string auth;
  18. private bool isBtnOkClicked = false;
  19. GoogleDriveStorageClient client;
  20. #endregion // Fields
  21. #region Properties
  22. /// <summary>
  23. /// Gets the client ID.
  24. /// </summary>
  25. public string Id
  26. {
  27. get { return id; }
  28. }
  29. /// <summary>
  30. /// Gets the client secret.
  31. /// </summary>
  32. public string Secret
  33. {
  34. get { return secret; }
  35. }
  36. /// <summary>
  37. /// Gets the client Auth key.
  38. /// </summary>
  39. public string AuthKey
  40. {
  41. get { return auth; }
  42. }
  43. #endregion // Properties
  44. #region Constructors
  45. /// <summary>
  46. /// Initializes a new instance of the <see cref="ClientInfoForm"/> class.
  47. /// </summary>
  48. public ClientInfoForm()
  49. {
  50. this.id = "";
  51. this.secret = "";
  52. client = new GoogleDriveStorageClient();
  53. InitializeComponent();
  54. Localize();
  55. UIUtils.CheckRTL(this);
  56. UpdateDpiDependencies();
  57. }
  58. #endregion // Constructors
  59. #region Public Methods
  60. /// <inheritdoc/>
  61. public override void Localize()
  62. {
  63. base.Localize();
  64. MyRes res = new MyRes("Cloud,SkyDrive");
  65. this.Text = res.Get("ClientInfoDialog");
  66. labelClientId.Text = res.Get("ClientId");
  67. labelClientSecret.Text = res.Get("ClientSecret");
  68. }
  69. #endregion // Public Methods
  70. #region Events Handlers
  71. private void btnOk_Click(object sender, EventArgs e)
  72. {
  73. if (String.IsNullOrEmpty(tbClientKey.Text))
  74. {
  75. id = tbClientId.Text;
  76. secret = tbClientSecret.Text;
  77. client.ClientInfo = new SkyDrive.ClientInfo("", Id, Secret);
  78. ProcessHelper.StartProcess(client.GetAuthorizationUrl());
  79. if (!isBtnOkClicked)
  80. Height += this.LogicalToDevice(30);
  81. tbClientId.Enabled = false;
  82. tbClientSecret.Enabled = false;
  83. tbClientKey.Visible = true;
  84. labelKey.Visible = true;
  85. isBtnOkClicked = true;
  86. }
  87. else
  88. {
  89. client.AuthCode = tbClientKey.Text;
  90. string token = client.GetAccessToken();
  91. client.IsUserAuthorized = true;
  92. XmlItem xi = Config.Root.FindItem("GoogleDriveCloud").FindItem("StorageSettings");
  93. xi.SetProp("ClientId", client.ClientInfo.Id);
  94. xi.SetProp("ClientSecret", client.ClientInfo.Secret);
  95. xi.SetProp("AuthCode", client.AuthCode);
  96. xi.SetProp("IsUserAuthorized", client.IsUserAuthorized.ToString());
  97. xi.SetProp("AccessToken", client.AccessToken);
  98. DialogResult = DialogResult.OK;
  99. this.Close();
  100. }
  101. }
  102. #endregion // Events Handlers
  103. }
  104. }