78 lines
2.0 KiB
C#
78 lines
2.0 KiB
C#
using Godot;
|
|
using System;
|
|
using System.Linq;
|
|
using BITKit;
|
|
using IDIS.Models;
|
|
using IDIS.Services;
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
|
|
namespace IDIS;
|
|
public partial class IDIS_Query : EntityComponent
|
|
{
|
|
[ExportCategory(nameof(UXContainer))]
|
|
[Export] private UXContainer queryContainer;
|
|
[Export] private UXContainer titleBarContainer;
|
|
|
|
[ExportCategory(nameof(Label))]
|
|
[Export] private Label logLabel;
|
|
|
|
[ExportCategory(nameof(NodeBuilder))]
|
|
[Export] private NodeBuilder contentBuilder;
|
|
|
|
//private IDIS_TemplateService _templateService;
|
|
private IDIS_Service _service;
|
|
|
|
public override void OnStart()
|
|
{
|
|
//_templateService = Entity.ServiceProvider.GetRequiredService<IDIS_TemplateService>();
|
|
_service = Entity.ServiceProvider.GetRequiredService<IDIS_Service>();
|
|
|
|
queryContainer.button.Pressed += () =>
|
|
{
|
|
Query(queryContainer.lineEdit.Text);
|
|
};
|
|
|
|
titleBarContainer.Hide();
|
|
}
|
|
|
|
private async void Query(string handle)
|
|
{
|
|
try
|
|
{
|
|
titleBarContainer.Hide();
|
|
var response = await _service.QueryAsync(handle);
|
|
contentBuilder.Clear();
|
|
await BITApp.SwitchToMainThread();
|
|
if (response.TryAs<IDIS_Data>(out var data) is false)
|
|
throw new InvalidOperationException(response.Message);
|
|
|
|
titleBarContainer.Show();
|
|
|
|
foreach (var x in data.IdData.OrderBy(x=>x.Index).Reverse())
|
|
{
|
|
var container = contentBuilder.Build<HBoxContainer>();
|
|
|
|
var nameLabel = container.Create<Label>();
|
|
var valueLabel = container.Create<Label>();
|
|
|
|
nameLabel.SizeFlagsHorizontal = Control.SizeFlags.ExpandFill;
|
|
valueLabel.SizeFlagsHorizontal = Control.SizeFlags.ExpandFill;
|
|
|
|
nameLabel.Text = x.Name;
|
|
valueLabel.Text = x.RealVal;
|
|
}
|
|
logLabel.Hide();
|
|
|
|
titleBarContainer.labels[0].Text = data.TitleBarInfo.Handle;
|
|
titleBarContainer.labels[1].Text =$"查询次数:{data.TitleBarInfo.Count}次";
|
|
}
|
|
catch (InvalidOperationException e)
|
|
{
|
|
await BITApp.SwitchToMainThread();
|
|
logLabel.Show();
|
|
logLabel.Text = e.Message;
|
|
}
|
|
|
|
}
|
|
}
|