DeveloperCenter.xaml.cs 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. using System;
  2. using System.IO;
  3. using System.Windows;
  4. using System.Windows.Controls;
  5. using Microsoft.Win32;
  6. using AIPlatform.Protocol.Utilities;
  7. namespace aipdev
  8. {
  9. /// <summary>
  10. /// Interaction logic for DeveloperCenter.xaml
  11. /// </summary>
  12. public partial class DeveloperCenter : UserControl, IContentPage
  13. {
  14. public string PageName { get; set; }
  15. public bool IsHomePage { get; set; }
  16. public bool IsModalPage { get; set; }
  17. public DeveloperCenter()
  18. {
  19. InitializeComponent();
  20. PageName = "DeveloperCenter";
  21. IsHomePage = false;
  22. IsModalPage = false;
  23. }
  24. public void Close()
  25. {
  26. //throw new NotImplementedException();
  27. }
  28. public async void OnShow(object arg)
  29. {
  30. ContentManager.ShowLoading();
  31. try
  32. {
  33. var developer = await DeveloperManager.Shared.GetAccountAsync();
  34. DevName.Text = developer.Name;
  35. DevFullName.Text = developer.FullName;
  36. if (developer.DeveloperAuthorityInfo != null && !string.IsNullOrEmpty(developer.DeveloperAuthorityInfo.WorkTokenId))
  37. {
  38. WorkToken.Visibility = Visibility.Visible;
  39. WorkToken.Text = developer.DeveloperAuthorityInfo.WorkTokenId;
  40. WorkTokenExpireTime.Text = developer.DeveloperAuthorityInfo.WorkTokenExpireTime.ToString();
  41. }
  42. else
  43. {
  44. WorkToken.Visibility = Visibility.Hidden;
  45. WorkTokenExpireTime.Text = string.Empty;
  46. }
  47. }
  48. catch (Exception ex)
  49. {
  50. MessageBox.Show(Application.Current.MainWindow, $"加载开发者信息失败:{ex.Translate()}", "错误", MessageBoxButton.OK, MessageBoxImage.Error);
  51. }
  52. finally
  53. {
  54. ContentManager.HideLoading();
  55. }
  56. }
  57. public void OnHide()
  58. {
  59. //DoNothing
  60. }
  61. private void OnChangePasswordClick(object sender, RoutedEventArgs e)
  62. {
  63. var changePasswordWindow = new ChangePasswordWindow() { Owner = Application.Current.MainWindow };
  64. changePasswordWindow.ShowDialog();
  65. }
  66. private async void OnDownloadSdkClick(object sender, RoutedEventArgs e)
  67. {
  68. ContentManager.ShowLoading();
  69. try
  70. {
  71. var sdkData = await DeveloperManager.Shared.DownloadSdkAsync();
  72. if (sdkData != null)
  73. {
  74. var saveFileDialog = new SaveFileDialog
  75. {
  76. //FileName = "sdk",
  77. Filter = "*.zip|*.zip"
  78. };
  79. if (saveFileDialog.ShowDialog() == true)
  80. {
  81. await File.WriteAllBytesAsync(saveFileDialog.FileName, sdkData);
  82. }
  83. }
  84. else
  85. {
  86. throw new InvalidOperationException("服务器未返回SDK数据");
  87. }
  88. }
  89. catch (Exception ex)
  90. {
  91. MessageBox.Show(Application.Current.MainWindow, $"下载SDK失败:{ex.Translate()}", "错误", MessageBoxButton.OK, MessageBoxImage.Error);
  92. }
  93. finally
  94. {
  95. ContentManager.HideLoading();
  96. }
  97. }
  98. private async void OnDownloadSimulatorClick(object sender, RoutedEventArgs e)
  99. {
  100. ContentManager.ShowLoading();
  101. try
  102. {
  103. var simulatorData = await DeveloperManager.Shared.DownloadSdkSimulatorAsync();
  104. if (simulatorData != null)
  105. {
  106. var saveFileDialog = new SaveFileDialog
  107. {
  108. //FileName = "Simulator",
  109. Filter = "*.zip|*.zip"
  110. };
  111. if (saveFileDialog.ShowDialog() == true)
  112. {
  113. await File.WriteAllBytesAsync(saveFileDialog.FileName, simulatorData);
  114. }
  115. }
  116. else
  117. {
  118. throw new InvalidOperationException("服务器未返回SDK模拟器数据");
  119. }
  120. }
  121. catch (Exception ex)
  122. {
  123. MessageBox.Show(Application.Current.MainWindow, $"下载SDK模拟器失败:{ex.Translate()}", "错误", MessageBoxButton.OK, MessageBoxImage.Error);
  124. }
  125. finally
  126. {
  127. ContentManager.HideLoading();
  128. }
  129. }
  130. }
  131. }