Nenhuma descrição
Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

AutoConfig.cs 2.7KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. using System;
  2. using Codice.Client.Common;
  3. using Codice.CM.Common;
  4. using Codice.LogWrapper;
  5. using PlasticGui;
  6. using PlasticGui.WorkspaceWindow.Home;
  7. using Unity.PlasticSCM.Editor.Configuration.CloudEdition.Welcome;
  8. using Unity.PlasticSCM.Editor.WebApi;
  9. using UnityEngine;
  10. namespace Unity.PlasticSCM.Editor.Configuration
  11. {
  12. internal static class AutoConfig
  13. {
  14. internal static TokenExchangeResponse PlasticCredentials(
  15. string unityAccessToken,
  16. string serverName)
  17. {
  18. SetupUnityEditionToken.CreateCloudEditionTokenIfNeeded();
  19. var startTick = Environment.TickCount;
  20. var tokenExchangeResponse = WebRestApiClient.PlasticScm.TokenExchange(unityAccessToken);
  21. mLog.DebugFormat("TokenExchange time {0} ms", Environment.TickCount - startTick);
  22. if (tokenExchangeResponse == null)
  23. {
  24. var warning = PlasticLocalization.GetString(PlasticLocalization.Name.TokenExchangeResponseNull);
  25. mLog.Warn(warning);
  26. Debug.LogWarning(warning);
  27. return null;
  28. }
  29. if (tokenExchangeResponse.Error != null)
  30. {
  31. var warning = string.Format(
  32. PlasticLocalization.GetString(PlasticLocalization.Name.TokenExchangeResponseError),
  33. tokenExchangeResponse.Error.Message, tokenExchangeResponse.Error.ErrorCode);
  34. mLog.ErrorFormat(warning);
  35. Debug.LogWarning(warning);
  36. return tokenExchangeResponse;
  37. }
  38. if (string.IsNullOrEmpty(tokenExchangeResponse.AccessToken))
  39. {
  40. var warning = string.Format(
  41. PlasticLocalization.GetString(PlasticLocalization.Name.TokenExchangeAccessEmpty),
  42. tokenExchangeResponse.User);
  43. mLog.InfoFormat(warning);
  44. Debug.LogWarning(warning);
  45. return tokenExchangeResponse;
  46. }
  47. // This creates the client.conf if needed but doesn't overwrite it if it exists already,
  48. // and it also updates the profiles.conf and tokens.conf with the new AccessToken
  49. UserAccounts.SaveAccount(
  50. serverName,
  51. SEIDWorkingMode.SSOWorkingMode, // Hub sign-in working mode
  52. tokenExchangeResponse.User,
  53. tokenExchangeResponse.AccessToken,
  54. null,
  55. null,
  56. null);
  57. CloudEditionWelcomeWindow.SaveDefaultCloudServer(
  58. serverName,
  59. tokenExchangeResponse.User);
  60. return tokenExchangeResponse;
  61. }
  62. static readonly ILog mLog = PlasticApp.GetLogger("AutoConfig");
  63. }
  64. }