暫無描述
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

CredentialsUIImpl.cs 3.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. using System;
  2. using UnityEditor;
  3. using Codice.CM.Common;
  4. using System.Threading.Tasks;
  5. using Codice.Client.Common;
  6. using Codice.Client.Common.Connection;
  7. using PlasticGui;
  8. using Unity.PlasticSCM.Editor.UI;
  9. using Codice.Client.Common.Threading;
  10. using Unity.PlasticSCM.Editor.WebApi;
  11. namespace Unity.PlasticSCM.Editor.Configuration
  12. {
  13. internal class CredentialsUiImpl : AskCredentialsToUser.IGui
  14. {
  15. AskCredentialsToUser.DialogData AskCredentialsToUser.IGui.AskUserForCredentials(string servername, SEIDWorkingMode seidWorkingMode)
  16. {
  17. AskCredentialsToUser.DialogData result = null;
  18. GUIActionRunner.RunGUIAction(delegate
  19. {
  20. result = CredentialsDialog.RequestCredentials(
  21. servername, seidWorkingMode, ParentWindow.Get());
  22. });
  23. return result;
  24. }
  25. void AskCredentialsToUser.IGui.ShowSaveProfileErrorMessage(string message)
  26. {
  27. GUIActionRunner.RunGUIAction(delegate
  28. {
  29. GuiMessage.ShowError(string.Format(
  30. PlasticLocalization.GetString(
  31. PlasticLocalization.Name.CredentialsErrorSavingProfile),
  32. message));
  33. });
  34. }
  35. AskCredentialsToUser.DialogData AskCredentialsToUser.IGui.AskUserForSSOCredentials(
  36. string cloudServer)
  37. {
  38. AskCredentialsToUser.DialogData result = null;
  39. GUIActionRunner.RunGUIAction(delegate
  40. {
  41. result = RunSSOCredentialsRequest(
  42. cloudServer, CloudProjectSettings.accessToken);
  43. });
  44. return result;
  45. }
  46. AskCredentialsToUser.DialogData RunSSOCredentialsRequest(
  47. string cloudServer,
  48. string unityAccessToken)
  49. {
  50. if (string.IsNullOrEmpty(unityAccessToken))
  51. {
  52. return SSOCredentialsDialog.RequestCredentials(
  53. cloudServer, ParentWindow.Get());
  54. }
  55. TokenExchangeResponse tokenExchangeResponse =
  56. WaitUntilTokenExchange(unityAccessToken);
  57. // There is no internet connection, so no way to get credentials
  58. if (tokenExchangeResponse == null)
  59. {
  60. return new AskCredentialsToUser.DialogData(
  61. false, null, null, false,
  62. SEIDWorkingMode.SSOWorkingMode);
  63. }
  64. if (tokenExchangeResponse.Error == null)
  65. {
  66. return new AskCredentialsToUser.DialogData(
  67. true,
  68. tokenExchangeResponse.User,
  69. tokenExchangeResponse.AccessToken,
  70. false,
  71. SEIDWorkingMode.SSOWorkingMode);
  72. }
  73. return SSOCredentialsDialog.RequestCredentials(
  74. cloudServer, ParentWindow.Get());
  75. }
  76. static TokenExchangeResponse WaitUntilTokenExchange(
  77. string unityAccessToken)
  78. {
  79. TokenExchangeResponse result = null;
  80. Task.Run(() =>
  81. {
  82. try
  83. {
  84. result = WebRestApiClient.PlasticScm.
  85. TokenExchange(unityAccessToken);
  86. }
  87. catch (Exception ex)
  88. {
  89. ExceptionsHandler.LogException(
  90. "CredentialsUiImpl", ex);
  91. }
  92. }).Wait();
  93. return result;
  94. }
  95. }
  96. }