83 lines
2.6 KiB
C#
83 lines
2.6 KiB
C#
using MoviconHub.App.Com;
|
|
using MoviconHub.App.Models;
|
|
using System;
|
|
using System.Configuration;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace MoviconHub.App.Services
|
|
{
|
|
public static class ApiHelper
|
|
{
|
|
private static ApiService _apiService;
|
|
private static ApiConfig _apiConfig;
|
|
|
|
/// <summary>
|
|
/// 初始化API帮助类
|
|
/// </summary>
|
|
public static void Initialize()
|
|
{
|
|
//_apiConfig = ApiConfig.LoadConfig();
|
|
//string baseUrl = $"http://{_apiConfig.ServerAddress}:{_apiConfig.ServerPort}/";
|
|
string baseUrl = ConfigurationManager.AppSettings["ApiBaseUrl"];
|
|
if (string.IsNullOrWhiteSpace(baseUrl))
|
|
{
|
|
baseUrl = "http://172.16.3.203:8000";
|
|
}
|
|
_apiService = new ApiService(baseUrl);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 获取部件信息
|
|
/// </summary>
|
|
/// <param name="partQrCodeId">二维码零件ID</param>
|
|
/// <param name="deviceCode">设备编码</param>
|
|
/// <returns>部件信息</returns>
|
|
public static async Task<PartInfoResponse> GetPartInfoAsync(string partQrCodeId, string deviceCode)
|
|
{
|
|
if (_apiService == null)
|
|
{
|
|
Initialize();
|
|
}
|
|
//当前不需要设备条码
|
|
return await _apiService.GetPartInfoAsync(partQrCodeId, deviceCode);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 获取测试数据
|
|
/// </summary>
|
|
/// <param name="partQrCodeId">二维码零件ID</param>
|
|
/// <param name="deviceCode">设备编码</param>
|
|
/// <returns>测试数据</returns>
|
|
public static async Task<TestDataResponse> GetTestDataAsync(string partQrCodeId, string deviceCode)
|
|
{
|
|
if (_apiService == null)
|
|
{
|
|
Initialize();
|
|
}
|
|
return await _apiService.GetTestDataAsync(partQrCodeId, deviceCode);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 更新服务器配置
|
|
/// </summary>
|
|
/// <param name="serverAddress">服务器地址</param>
|
|
/// <param name="port">端口号</param>
|
|
public static void UpdateServerConfig(string serverAddress, int port)
|
|
{
|
|
if (_apiService == null || _apiConfig == null)
|
|
{
|
|
Initialize();
|
|
}
|
|
|
|
_apiConfig.ServerAddress = serverAddress;
|
|
_apiConfig.ServerPort = port;
|
|
_apiConfig.SaveConfig();
|
|
|
|
_apiService.ConfigureServerAddress(serverAddress, port);
|
|
}
|
|
}
|
|
}
|