123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209 |
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Threading.Tasks;
- using System.Windows;
- using System.Windows.Controls;
- using AIPlatform.Protocol.Entities;
- using AIPlatform.Protocol.Utilities;
- using LiveCharts;
- namespace aipdev
- {
- public class UnFinishedTask
- {
- /// <summary>
- /// Gets the index of the task.
- /// </summary>
- public int Index { get; }
- /// <summary>
- /// Gets the name of the task.
- /// </summary>
- public string TaskName { get; }
- /// <summary>
- /// Gets the start name of the task.
- /// </summary>
- public DateTime StartTime { get; }
- /// <summary>
- /// Gets the developer name of the task.
- /// </summary>
- public string DeveloperName { get; }
- /// <summary>
- /// Gets if the task has been assigned.
- /// </summary>
- public bool Assigned { get; }
- public UnFinishedTask(int index, string taskName, DateTime startTime, string developerName, bool assigned)
- {
- Index = index;
- TaskName = taskName;
- StartTime = startTime;
- DeveloperName = developerName;
- Assigned = assigned;
- }
- public override string ToString()
- {
- var state = Assigned ? "进行中" : "未分配";
- return $"{Index}. {TaskName}({DeveloperName}) 开始时间: {StartTime}, 状态: {state}";
- }
- }
- public class TaskInfo
- {
- /// <summary>
- /// Gets the name of the task.
- /// </summary>
- public string Name { get; set; }
- /// <summary>
- /// Gets the status of the task.
- /// </summary>
- public string Status { get; set; }
- /// <summary>
- /// Gets the startTime of the task.
- /// </summary>
- public string StartTime { get; set; }
- }
- public class DeveloperClientInfo
- {
- /// <summary>
- /// Gets or sets the version of the client.
- /// </summary>
- public string Version { get; set; }
- /// <summary>
- /// Gets or sets the description of the client.
- /// </summary>
- public string Description { get; set; }
- /// <summary>
- /// Gets the createTime of the client.
- /// </summary>
- public string CreateTime { get; set; }
- }
- /// <summary>
- /// Interaction logic for StartPage.xaml
- /// </summary>
- public partial class StartPage : UserControl, IContentPage
- {
- //private string _serverUrl = "http://192.168.1.109";
- public string PageName { get; set; }
- public bool IsHomePage { get; set; }
- public bool IsModalPage { get; set; }
- public StartPage()
- {
- InitializeComponent();
- PageName = "StartPage";
- IsHomePage = true;
- IsModalPage = false;
- }
- public void Close()
- {
- //DoNothing
- }
- public async void OnShow(object arg)
- {
- //SystemInformation.Source = new Uri($"{_serverUrl}:10101");
- ContentManager.ShowLoading();
- try
- {
- var systemAgentCount = await DeveloperManager.Shared.GetSystemAgentCountAsync();
- var workingAgentCount = await DeveloperManager.Shared.GetWorkingAgentCountAsync();
- var freeAgentCount = systemAgentCount - workingAgentCount;
- FreeAgentCount.Values = new ChartValues<int>() { freeAgentCount };
- WorkingAgentCount.Values = new ChartValues<int>() { workingAgentCount };
- var serverFolderCount = await DeveloperManager.Shared.GetImageCategoryCountAsync();
- SystemFolderCount.Values = new ChartValues<int>() { serverFolderCount };
- var developerFolderCount = await DeveloperManager.Shared.GetDeveloperFolderCountAsync();
- DeveloperFolderCount.Values = new ChartValues<int>() { developerFolderCount };
- var taskCount = await DeveloperManager.Shared.GetDeveloperTaskCountAsync();
- var executedTaskCount = await DeveloperManager.Shared.GetDeveloperExecutedTaskCountAsync();
- WaitingTaskCount.Values = new ChartValues<int>() { taskCount - executedTaskCount };
- ExecutedTaskCount.Values = new ChartValues<int>() { executedTaskCount };
- #region dataGridTaskList
- var top10Tasks = await DeveloperManager.Shared.GetTop10TasksAsync();
- var taskList = new List<TaskInfo>();
- foreach (var task in top10Tasks)
- {
- var taskStatus = await DeveloperManager.Shared.GetTrainTaskStatusResultAsync(task.Id);
- if (taskStatus == null)
- {
- continue;
- }
- var status = string.Empty;
- switch (taskStatus.Result)
- {
- case TaskResult.Processing:
- status = "正在处理";
- break;
- case TaskResult.Done:
- status = "已完成";
- break;
- case TaskResult.Failed:
- status = "执行失败";
- break;
- case TaskResult.Canceled:
- status = "已取消";
- break;
- case TaskResult.Waiting:
- status = "等待处理";
- break;
- default:
- status = "未执行";
- break;
- }
- var taskInfo = new TaskInfo
- {
- Name = task.Name,
- Status = status,
- StartTime = taskStatus.StartTime > new DateTime(1, 1, 1) ? taskStatus.StartTime.ToLocalTime().ToString() : string.Empty,
- };
- taskList.Add(taskInfo);
- }
- dataGridTaskList.ItemsSource = taskList;
- #endregion
- #region dataGridClientList
- var developerClientInfos = new List<DeveloperClientInfo>();
- var top10ClientInfos = await DeveloperManager.Shared.GetTop10ClientInfosAsync();
- foreach (var item in top10ClientInfos)
- {
- developerClientInfos.Add(new DeveloperClientInfo
- {
- Version = item.Version,
- CreateTime = item.CreateTime > new DateTime(1, 1, 1) ? item.CreateTime.ToShortDateString().ToString() : string.Empty,
- Description = item.Description,
- });
- }
- dataGridClientList.ItemsSource = developerClientInfos;
- #endregion
- }
- catch (Exception ex)
- {
- MessageBox.Show(Application.Current.MainWindow, $"加载服务器信息失败:{ex.Translate()}", "错误", MessageBoxButton.OK, MessageBoxImage.Error);
- }
- finally
- {
- ContentManager.HideLoading();
- }
- }
- public void OnHide()
- {
- //DoNoting
- }
- }
- }
|