CreateNewTaskWindow.xaml.cs 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. using System;
  2. using System.Windows;
  3. using AIPlatform.Protocol.Entities;
  4. using AIPlatform.Protocol.Utilities;
  5. namespace aipdev
  6. {
  7. /// <summary>
  8. /// Interaction logic for CreateNewTaskWindow.xaml
  9. /// </summary>
  10. public partial class CreateNewTaskWindow : Window
  11. {
  12. /// <summary>
  13. /// Get or set the task name.
  14. /// </summary>
  15. public string NewTaskName { get; private set; }
  16. /// <summary>
  17. /// Get or set the organization of the task.
  18. /// </summary>
  19. public EntityBase Organization { get; set; }
  20. /// <summary>
  21. /// Get or set the package.
  22. /// </summary>
  23. public EntityBase Package { get; private set; }
  24. /// <summary>
  25. /// Get or set the folder.
  26. /// </summary>
  27. public EntityBase Folder { get; private set; }
  28. /// <summary>
  29. /// Get or set the test folder.
  30. /// </summary>
  31. public EntityBase TestFolder { get; private set; }
  32. /// <summary>
  33. /// Get or set the start args.
  34. /// </summary>
  35. public string TaskStartArgs { get; private set; }
  36. /// <summary>
  37. /// Gets or the result Model name.
  38. /// </summary>
  39. public string ResultModelName { get; private set; }
  40. /// <summary>
  41. /// Get or set the script package framework.
  42. /// </summary>
  43. public TrainScriptPackageFramework TrainScriptPackageFramework { get; private set; }
  44. public CreateNewTaskWindow()
  45. {
  46. InitializeComponent();
  47. Loaded += OnLoaded;
  48. TaskName.Focus();
  49. }
  50. private async void OnLoaded(object sender, RoutedEventArgs e)
  51. {
  52. ContentManager.ShowLoading();
  53. try
  54. {
  55. var developerAccount = await DeveloperManager.Shared.GetAccountAsync();
  56. foreach (var item in developerAccount.Organizations)
  57. {
  58. OrganizationList.Items.Add(item);
  59. }
  60. if (OrganizationList.Items.Count > 0)
  61. {
  62. OrganizationList.SelectedIndex = 0;
  63. }
  64. var devFolders = await DeveloperManager.Shared.GetDeveloperFoldersAsync(0, 1000, true);
  65. foreach (var devFolder in devFolders)
  66. {
  67. FolderList.Items.Add(devFolder);
  68. TestFolderList.Items.Add(devFolder);
  69. }
  70. var scriptPackages = await DeveloperManager.Shared.GetTrainScriptPackagesAsync();
  71. foreach (var scriptPackage in scriptPackages)
  72. {
  73. ScriptPackageList.Items.Add(scriptPackage);
  74. }
  75. }
  76. catch (Exception ex)
  77. {
  78. MessageBox.Show(Application.Current.MainWindow, $"加载数据失败:{ex.Translate()}", "错误", MessageBoxButton.OK, MessageBoxImage.Error);
  79. }
  80. finally
  81. {
  82. ContentManager.HideLoading();
  83. }
  84. }
  85. private void OnOkClick(object sender, RoutedEventArgs e)
  86. {
  87. if (string.IsNullOrWhiteSpace(TaskName.Text) || string.IsNullOrEmpty(TaskName.Text))
  88. {
  89. MessageBox.Show(Application.Current.MainWindow, "请填写任务名", "错误", MessageBoxButton.OK, MessageBoxImage.Error);
  90. return;
  91. }
  92. if (OrganizationList.SelectedIndex == -1)
  93. {
  94. MessageBox.Show(Application.Current.MainWindow, "请选择组织", "错误", MessageBoxButton.OK, MessageBoxImage.Error);
  95. return;
  96. }
  97. if (FolderList.SelectedIndex == -1)
  98. {
  99. MessageBox.Show(Application.Current.MainWindow, "请选择数据文件夹", "错误", MessageBoxButton.OK, MessageBoxImage.Error);
  100. return;
  101. }
  102. if (ScriptPackageList.SelectedIndex == -1)
  103. {
  104. MessageBox.Show(Application.Current.MainWindow, "请选择脚本包", "错误", MessageBoxButton.OK, MessageBoxImage.Error);
  105. return;
  106. }
  107. //if(string.IsNullOrWhiteSpace(ModelName.Text) || string.IsNullOrEmpty(ModelName.Text))
  108. //{
  109. // MessageBox.Show(Application.Current.MainWindow, "请填写结果模型名", "错误", MessageBoxButton.OK, MessageBoxImage.Error);
  110. // return;
  111. //}
  112. NewTaskName = TaskName.Text.Trim();
  113. Organization = (EntityBase)OrganizationList.SelectedItem;
  114. var folder = (DeveloperFolder)FolderList.SelectedItem;
  115. Folder = new EntityBase { Id = folder.Id, Name = folder.Name };
  116. if (TestFolderList.SelectedItem != null)
  117. {
  118. var testFolder = (DeveloperFolder)TestFolderList.SelectedItem;
  119. TestFolder = new EntityBase { Id = testFolder.Id, Name = testFolder.Name };
  120. }
  121. else
  122. {
  123. TestFolder = new EntityBase();
  124. }
  125. var package = (TrainScriptPackage)ScriptPackageList.SelectedItem;
  126. Package = new EntityBase { Id = package.Id, Name = package.Name };
  127. TrainScriptPackageFramework = ((TrainScriptPackage)ScriptPackageList.SelectedItem).Framework;
  128. TaskStartArgs = StartArgs.Text.Trim();
  129. //ResultModelName = ModelName.Text.Trim();
  130. Close();
  131. }
  132. private void OnCloseClick(object sender, RoutedEventArgs e)
  133. {
  134. Close();
  135. }
  136. }
  137. }