123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384 |
- using System;
- using System.Linq;
- using System.Windows;
- using AIPlatform.Protocol.Entities;
- using AIPlatform.Protocol.Utilities;
- namespace aipdev
- {
- /// <summary>
- /// Interaction logic for ChangeAgentWindow.xaml
- /// </summary>
- public partial class ChangeAgentWindow : Window
- {
- public AgentInfoEx SelectedAgent { get; private set; }
- public long AgentId { get; private set; }
- /// <summary>
- /// Gets if dialog is filled and OK.
- /// </summary>
- public bool Ok { get; private set; }
- public ChangeAgentWindow(long agentId)
- {
- InitializeComponent();
- AgentId = agentId;
- Loaded += OnLoaded;
- }
- private async void OnLoaded(object sender, RoutedEventArgs e)
- {
- ContentManager.ShowLoading();
- try
- {
- AgentInfoEx findAgent = null;
- var agentInfos = await DeveloperManager.Shared.GetAgentsAsync();
- if (agentInfos != null)
- {
- findAgent = agentInfos.FirstOrDefault(x => x.Id == AgentId);
- }
- foreach (var item in agentInfos)
- {
- Agents.Items.Add(item);
- }
- if (Agents.Items.Count > 0 && findAgent != null)
- {
- Agents.SelectedIndex = Agents.Items.IndexOf(findAgent);
- }
- else if (Agents.Items.Count == 0)
- {
- MessageBox.Show(Application.Current.MainWindow, $"没有符合的工作站", "提示", MessageBoxButton.OK, MessageBoxImage.Warning);
- }
- }
- catch (Exception ex)
- {
- MessageBox.Show(Application.Current.MainWindow, $"加载工作站列表失败:{ex.Translate()}", "错误", MessageBoxButton.OK, MessageBoxImage.Error);
- }
- finally
- {
- ContentManager.HideLoading();
- }
- }
- private void OnCloseClick(object sender, RoutedEventArgs e)
- {
- Ok = false;
- Close();
- }
- private void OnOKClick(object sender, RoutedEventArgs e)
- {
- SelectedAgent = (AgentInfoEx)Agents.SelectedItem;
- if (SelectedAgent == null)
- {
- MessageBox.Show(this, "请选择目标工作站", "错误", MessageBoxButton.OK, MessageBoxImage.Error);
- }
- else
- {
- Ok = true;
- Close();
- }
- }
- }
- }
|