StartPage.xaml.cs 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Threading.Tasks;
  5. using System.Windows;
  6. using System.Windows.Controls;
  7. using AIPlatform.Protocol.Entities;
  8. using AIPlatform.Protocol.Utilities;
  9. using LiveCharts;
  10. namespace aipdev
  11. {
  12. public class UnFinishedTask
  13. {
  14. /// <summary>
  15. /// Gets the index of the task.
  16. /// </summary>
  17. public int Index { get; }
  18. /// <summary>
  19. /// Gets the name of the task.
  20. /// </summary>
  21. public string TaskName { get; }
  22. /// <summary>
  23. /// Gets the start name of the task.
  24. /// </summary>
  25. public DateTime StartTime { get; }
  26. /// <summary>
  27. /// Gets the developer name of the task.
  28. /// </summary>
  29. public string DeveloperName { get; }
  30. /// <summary>
  31. /// Gets if the task has been assigned.
  32. /// </summary>
  33. public bool Assigned { get; }
  34. public UnFinishedTask(int index, string taskName, DateTime startTime, string developerName, bool assigned)
  35. {
  36. Index = index;
  37. TaskName = taskName;
  38. StartTime = startTime;
  39. DeveloperName = developerName;
  40. Assigned = assigned;
  41. }
  42. public override string ToString()
  43. {
  44. var state = Assigned ? "进行中" : "未分配";
  45. return $"{Index}. {TaskName}({DeveloperName}) 开始时间: {StartTime}, 状态: {state}";
  46. }
  47. }
  48. public class TaskInfo
  49. {
  50. /// <summary>
  51. /// Gets the name of the task.
  52. /// </summary>
  53. public string Name { get; set; }
  54. /// <summary>
  55. /// Gets the status of the task.
  56. /// </summary>
  57. public string Status { get; set; }
  58. /// <summary>
  59. /// Gets the startTime of the task.
  60. /// </summary>
  61. public string StartTime { get; set; }
  62. }
  63. public class DeveloperClientInfo
  64. {
  65. /// <summary>
  66. /// Gets or sets the version of the client.
  67. /// </summary>
  68. public string Version { get; set; }
  69. /// <summary>
  70. /// Gets or sets the description of the client.
  71. /// </summary>
  72. public string Description { get; set; }
  73. /// <summary>
  74. /// Gets the createTime of the client.
  75. /// </summary>
  76. public string CreateTime { get; set; }
  77. }
  78. /// <summary>
  79. /// Interaction logic for StartPage.xaml
  80. /// </summary>
  81. public partial class StartPage : UserControl, IContentPage
  82. {
  83. //private string _serverUrl = "http://192.168.1.109";
  84. public string PageName { get; set; }
  85. public bool IsHomePage { get; set; }
  86. public bool IsModalPage { get; set; }
  87. public StartPage()
  88. {
  89. InitializeComponent();
  90. PageName = "StartPage";
  91. IsHomePage = true;
  92. IsModalPage = false;
  93. }
  94. public void Close()
  95. {
  96. //DoNothing
  97. }
  98. public async void OnShow(object arg)
  99. {
  100. //SystemInformation.Source = new Uri($"{_serverUrl}:10101");
  101. ContentManager.ShowLoading();
  102. try
  103. {
  104. var systemAgentCount = await DeveloperManager.Shared.GetSystemAgentCountAsync();
  105. var workingAgentCount = await DeveloperManager.Shared.GetWorkingAgentCountAsync();
  106. var freeAgentCount = systemAgentCount - workingAgentCount;
  107. FreeAgentCount.Values = new ChartValues<int>() { freeAgentCount };
  108. WorkingAgentCount.Values = new ChartValues<int>() { workingAgentCount };
  109. var serverFolderCount = await DeveloperManager.Shared.GetImageCategoryCountAsync();
  110. SystemFolderCount.Values = new ChartValues<int>() { serverFolderCount };
  111. var developerFolderCount = await DeveloperManager.Shared.GetDeveloperFolderCountAsync();
  112. DeveloperFolderCount.Values = new ChartValues<int>() { developerFolderCount };
  113. var taskCount = await DeveloperManager.Shared.GetDeveloperTaskCountAsync();
  114. var executedTaskCount = await DeveloperManager.Shared.GetDeveloperExecutedTaskCountAsync();
  115. WaitingTaskCount.Values = new ChartValues<int>() { taskCount - executedTaskCount };
  116. ExecutedTaskCount.Values = new ChartValues<int>() { executedTaskCount };
  117. #region dataGridTaskList
  118. var top10Tasks = await DeveloperManager.Shared.GetTop10TasksAsync();
  119. var taskList = new List<TaskInfo>();
  120. foreach (var task in top10Tasks)
  121. {
  122. var taskStatus = await DeveloperManager.Shared.GetTrainTaskStatusResultAsync(task.Id);
  123. if (taskStatus == null)
  124. {
  125. continue;
  126. }
  127. var status = string.Empty;
  128. switch (taskStatus.Result)
  129. {
  130. case TaskResult.Processing:
  131. status = "正在处理";
  132. break;
  133. case TaskResult.Done:
  134. status = "已完成";
  135. break;
  136. case TaskResult.Failed:
  137. status = "执行失败";
  138. break;
  139. case TaskResult.Canceled:
  140. status = "已取消";
  141. break;
  142. case TaskResult.Waiting:
  143. status = "等待处理";
  144. break;
  145. default:
  146. status = "未执行";
  147. break;
  148. }
  149. var taskInfo = new TaskInfo
  150. {
  151. Name = task.Name,
  152. Status = status,
  153. StartTime = taskStatus.StartTime > new DateTime(1, 1, 1) ? taskStatus.StartTime.ToLocalTime().ToString() : string.Empty,
  154. };
  155. taskList.Add(taskInfo);
  156. }
  157. dataGridTaskList.ItemsSource = taskList;
  158. #endregion
  159. #region dataGridClientList
  160. var developerClientInfos = new List<DeveloperClientInfo>();
  161. var top10ClientInfos = await DeveloperManager.Shared.GetTop10ClientInfosAsync();
  162. foreach (var item in top10ClientInfos)
  163. {
  164. developerClientInfos.Add(new DeveloperClientInfo
  165. {
  166. Version = item.Version,
  167. CreateTime = item.CreateTime > new DateTime(1, 1, 1) ? item.CreateTime.ToShortDateString().ToString() : string.Empty,
  168. Description = item.Description,
  169. });
  170. }
  171. dataGridClientList.ItemsSource = developerClientInfos;
  172. #endregion
  173. }
  174. catch (Exception ex)
  175. {
  176. MessageBox.Show(Application.Current.MainWindow, $"加载服务器信息失败:{ex.Translate()}", "错误", MessageBoxButton.OK, MessageBoxImage.Error);
  177. }
  178. finally
  179. {
  180. ContentManager.HideLoading();
  181. }
  182. }
  183. public void OnHide()
  184. {
  185. //DoNoting
  186. }
  187. }
  188. }