ChangeAgentWindow.xaml.cs 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. using System;
  2. using System.Linq;
  3. using System.Windows;
  4. using AIPlatform.Protocol.Entities;
  5. using AIPlatform.Protocol.Utilities;
  6. namespace aipdev
  7. {
  8. /// <summary>
  9. /// Interaction logic for ChangeAgentWindow.xaml
  10. /// </summary>
  11. public partial class ChangeAgentWindow : Window
  12. {
  13. public AgentInfoEx SelectedAgent { get; private set; }
  14. public long AgentId { get; private set; }
  15. /// <summary>
  16. /// Gets if dialog is filled and OK.
  17. /// </summary>
  18. public bool Ok { get; private set; }
  19. public ChangeAgentWindow(long agentId)
  20. {
  21. InitializeComponent();
  22. AgentId = agentId;
  23. Loaded += OnLoaded;
  24. }
  25. private async void OnLoaded(object sender, RoutedEventArgs e)
  26. {
  27. ContentManager.ShowLoading();
  28. try
  29. {
  30. AgentInfoEx findAgent = null;
  31. var agentInfos = await DeveloperManager.Shared.GetAgentsAsync();
  32. if (agentInfos != null)
  33. {
  34. findAgent = agentInfos.FirstOrDefault(x => x.Id == AgentId);
  35. }
  36. foreach (var item in agentInfos)
  37. {
  38. Agents.Items.Add(item);
  39. }
  40. if (Agents.Items.Count > 0 && findAgent != null)
  41. {
  42. Agents.SelectedIndex = Agents.Items.IndexOf(findAgent);
  43. }
  44. else if (Agents.Items.Count == 0)
  45. {
  46. MessageBox.Show(Application.Current.MainWindow, $"没有符合的工作站", "提示", MessageBoxButton.OK, MessageBoxImage.Warning);
  47. }
  48. }
  49. catch (Exception ex)
  50. {
  51. MessageBox.Show(Application.Current.MainWindow, $"加载工作站列表失败:{ex.Translate()}", "错误", MessageBoxButton.OK, MessageBoxImage.Error);
  52. }
  53. finally
  54. {
  55. ContentManager.HideLoading();
  56. }
  57. }
  58. private void OnCloseClick(object sender, RoutedEventArgs e)
  59. {
  60. Ok = false;
  61. Close();
  62. }
  63. private void OnOKClick(object sender, RoutedEventArgs e)
  64. {
  65. SelectedAgent = (AgentInfoEx)Agents.SelectedItem;
  66. if (SelectedAgent == null)
  67. {
  68. MessageBox.Show(this, "请选择目标工作站", "错误", MessageBoxButton.OK, MessageBoxImage.Error);
  69. }
  70. else
  71. {
  72. Ok = true;
  73. Close();
  74. }
  75. }
  76. }
  77. }