|
|
@@ -1,9 +1,11 @@
|
|
|
using Microsoft.AspNetCore.Http;
|
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
+using System.IO;
|
|
|
using YSAI.Core.data;
|
|
|
using YSAI.Core.@enum;
|
|
|
using YSAI.Core.@interface.only;
|
|
|
using YSAI.Core.@interface.unify;
|
|
|
+using YSAI.Core.reflection;
|
|
|
using YSAI.Manage.Core.@base;
|
|
|
using YSAI.Opc.ua.client;
|
|
|
using YSAI.Unility;
|
|
|
@@ -18,13 +20,21 @@ namespace YSAI.Manage.Core
|
|
|
protected override string LogHead => "[ ManageOperate 操作 ]";
|
|
|
protected override string ClassName => "ManageOperate";
|
|
|
/// <summary>
|
|
|
- /// 配置路径
|
|
|
+ /// 转发配置路径
|
|
|
/// </summary>
|
|
|
- private readonly string configPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "config//AMConfig.json");
|
|
|
+ private readonly string RelayConfigPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "config//RelayConfig.json");
|
|
|
/// <summary>
|
|
|
- /// 实例文件路径
|
|
|
+ /// 转发实例文件路径
|
|
|
/// </summary>
|
|
|
- private readonly string samplePath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "config//Sample.json");
|
|
|
+ private readonly string RelaySamplePath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "config//RelaySample.json");
|
|
|
+ /// <summary>
|
|
|
+ /// 数采配置路径
|
|
|
+ /// </summary>
|
|
|
+ private readonly string DaqConfigPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "config//DaqConfig.json");
|
|
|
+ /// <summary>
|
|
|
+ /// 数采实例文件路径
|
|
|
+ /// </summary>
|
|
|
+ private readonly string DaqSamplePath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "config//DaqSample.json");
|
|
|
/// <summary>
|
|
|
/// 配置数据
|
|
|
/// </summary>
|
|
|
@@ -50,31 +60,45 @@ namespace YSAI.Manage.Core
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- public IActionResult Sample()
|
|
|
+ public IActionResult Sample(LibType LType)
|
|
|
{
|
|
|
- try
|
|
|
- {
|
|
|
- Address address = JsonTool.StringToJsonEntity<Address>(FileTool.FileToString(samplePath));
|
|
|
- AddressManage addressManage = new AddressManage();
|
|
|
- addressManage.SN = address.SN;
|
|
|
- addressManage.AddressArray = address.AddressArray;
|
|
|
- addressManage.CreationTime = DateTime.Now.ToLocalTime();
|
|
|
- addressManage.DType = DaqType.OpcUa;
|
|
|
- addressManage.InstanceParam = new OpcUaClientData.Basics() { Name = $"OpcUa", UserName = "123", Password = "123", ServerUrl = "opc.tcp://127.0.0.1:4840", SamplingInterval = 100 };
|
|
|
- return new FileContentResult(System.Text.Encoding.Default.GetBytes(new List<AddressManage> { addressManage, addressManage, addressManage, addressManage, addressManage, addressManage }.ToJson().JsonFormatting()), "application/octet-stream");
|
|
|
- }
|
|
|
- catch (Exception ex)
|
|
|
+ switch (LType)
|
|
|
{
|
|
|
- throw new NotImplementedException("实例获取异常:" + ex.Message);
|
|
|
+ case LibType.Daq:
|
|
|
+ try
|
|
|
+ {
|
|
|
+ Address address = JsonTool.StringToJsonEntity<Address>(FileTool.FileToString(DaqSamplePath));
|
|
|
+ AddressManage addressManage = new AddressManage();
|
|
|
+ addressManage.SN = address.SN;
|
|
|
+ addressManage.AddressArray = address.AddressArray;
|
|
|
+ addressManage.CreationTime = DateTime.Now.ToLocalTime();
|
|
|
+ addressManage.DType = DaqType.OpcUa;
|
|
|
+ addressManage.InstanceParam = new OpcUaClientData.Basics() { Name = $"OpcUa", UserName = "123", Password = "123", ServerUrl = "opc.tcp://127.0.0.1:4840", SamplingInterval = 100 };
|
|
|
+ return new FileContentResult(System.Text.Encoding.Default.GetBytes(new List<AddressManage> { addressManage, addressManage, addressManage, addressManage, addressManage, addressManage }.ToJson().JsonFormatting()), "application/octet-stream");
|
|
|
+ }
|
|
|
+ catch (Exception ex)
|
|
|
+ {
|
|
|
+ throw new NotImplementedException("数采示例获取异常:" + ex.Message);
|
|
|
+ }
|
|
|
+ case LibType.Relay:
|
|
|
+ try
|
|
|
+ {
|
|
|
+ return new FileContentResult(System.Text.Encoding.Default.GetBytes(FileTool.FileToString(RelaySamplePath).JsonFormatting()), "application/octet-stream");
|
|
|
+ }
|
|
|
+ catch (Exception ex)
|
|
|
+ {
|
|
|
+ throw new NotImplementedException("转发示例获取异常:" + ex.Message);
|
|
|
+ }
|
|
|
}
|
|
|
+ throw new NotImplementedException("示例获取失败");
|
|
|
}
|
|
|
|
|
|
- public Task<IActionResult> SampleAsync()
|
|
|
+ public Task<IActionResult> SampleAsync(LibType LType)
|
|
|
{
|
|
|
- return Task.Run(() => Sample());
|
|
|
+ return Task.Run(() => Sample(LType));
|
|
|
}
|
|
|
|
|
|
- public OperateResult Setting(IFormFile? ConfigFile)
|
|
|
+ public OperateResult Setting(IFormFile? ConfigFile, LibType LType)
|
|
|
{
|
|
|
//开始记录运行时间
|
|
|
Depart("Setting");
|
|
|
@@ -84,19 +108,38 @@ namespace YSAI.Manage.Core
|
|
|
{
|
|
|
return Break("Setting", false, "请选择要上传的文件");
|
|
|
}
|
|
|
- if (!System.IO.File.Exists(configPath))
|
|
|
- {
|
|
|
- OperateResult operateResult = Update(ConfigFile);
|
|
|
- if (operateResult.State)
|
|
|
- {
|
|
|
- return Break("Setting", operateResult.State);
|
|
|
- }
|
|
|
- return Break("Setting", operateResult.State, operateResult.Message.Split(')')[1]);
|
|
|
- }
|
|
|
- else
|
|
|
+ switch (LType)
|
|
|
{
|
|
|
- return Break("Setting", false, "配置文件已存在,请执行修改配置接口");
|
|
|
+ case LibType.Daq:
|
|
|
+ if (!System.IO.File.Exists(DaqConfigPath))
|
|
|
+ {
|
|
|
+ OperateResult operateResult = Update(ConfigFile, LType);
|
|
|
+ if (operateResult.State)
|
|
|
+ {
|
|
|
+ return Break("Setting", operateResult.State);
|
|
|
+ }
|
|
|
+ return Break("Setting", operateResult.State, operateResult.Message.Split(')')[1]);
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ return Break("Setting", false, "配置文件已存在,请执行修改配置接口");
|
|
|
+ }
|
|
|
+ case LibType.Relay:
|
|
|
+ if (!System.IO.File.Exists(RelayConfigPath))
|
|
|
+ {
|
|
|
+ OperateResult operateResult = Update(ConfigFile, LType);
|
|
|
+ if (operateResult.State)
|
|
|
+ {
|
|
|
+ return Break("Setting", operateResult.State);
|
|
|
+ }
|
|
|
+ return Break("Setting", operateResult.State, operateResult.Message.Split(')')[1]);
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ return Break("Setting", false, "配置文件已存在,请执行修改配置接口");
|
|
|
+ }
|
|
|
}
|
|
|
+ return Break("Setting", false, $"设置配置失败");
|
|
|
}
|
|
|
catch (Exception ex)
|
|
|
{
|
|
|
@@ -104,12 +147,12 @@ namespace YSAI.Manage.Core
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- public Task<OperateResult> SettingAsync(IFormFile? ConfigFile)
|
|
|
+ public Task<OperateResult> SettingAsync(IFormFile? ConfigFile, LibType LType)
|
|
|
{
|
|
|
- return Task.Run(() => Setting(ConfigFile));
|
|
|
+ return Task.Run(() => Setting(ConfigFile, LType));
|
|
|
}
|
|
|
|
|
|
- public OperateResult Update(IFormFile? ConfigFile)
|
|
|
+ public OperateResult Update(IFormFile? ConfigFile, LibType LType)
|
|
|
{
|
|
|
//开始记录运行时间
|
|
|
Depart("Update");
|
|
|
@@ -120,10 +163,53 @@ namespace YSAI.Manage.Core
|
|
|
return Break("Update", false, "请选择要上传的文件");
|
|
|
}
|
|
|
//判断文件夹是否存在,不存在则创建
|
|
|
- FileTool.GetPathFolderPath(configPath, true);
|
|
|
- using (var stream = System.IO.File.Create(configPath))
|
|
|
+ FileTool.GetPathFolderPath(DaqConfigPath, true);
|
|
|
+ FileTool.GetPathFolderPath(RelayConfigPath, true);
|
|
|
+
|
|
|
+ //数据转换
|
|
|
+ StreamReader reader = new StreamReader(ConfigFile.OpenReadStream());
|
|
|
+ //Json内容
|
|
|
+ string jsonContent = reader.ReadToEnd();
|
|
|
+
|
|
|
+ switch (LType)
|
|
|
{
|
|
|
- ConfigFile.CopyToAsync(stream).Wait();
|
|
|
+ case LibType.Daq:
|
|
|
+
|
|
|
+ List<AddressManage>? addressManage = null;
|
|
|
+ //json转换
|
|
|
+ try
|
|
|
+ {
|
|
|
+ addressManage = JsonTool.StringToJsonEntity<List<AddressManage>>(jsonContent);
|
|
|
+ }
|
|
|
+ catch { }
|
|
|
+
|
|
|
+ if (addressManage != null)
|
|
|
+ {
|
|
|
+ FileTool.StringToFile(DaqConfigPath, jsonContent);
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ return Break("Update", false, $"[ {LType.ToString()} ] 文件内容错误");
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ case LibType.Relay:
|
|
|
+ ReflectionData.Basics? reflectionData = null;
|
|
|
+ //json转换
|
|
|
+ try
|
|
|
+ {
|
|
|
+ reflectionData = JsonTool.StringToJsonEntity<ReflectionData.Basics>(jsonContent);
|
|
|
+ }
|
|
|
+ catch { }
|
|
|
+
|
|
|
+ if (reflectionData != null)
|
|
|
+ {
|
|
|
+ FileTool.StringToFile(RelayConfigPath, jsonContent);
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ return Break("Update", false, $"[ {LType.ToString()} ] 文件内容错误");
|
|
|
+ }
|
|
|
+ break;
|
|
|
}
|
|
|
|
|
|
//当配置更新时,底层统一管理将被释放
|
|
|
@@ -138,20 +224,19 @@ namespace YSAI.Manage.Core
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- public Task<OperateResult> UpdateAsync(IFormFile? ConfigFile)
|
|
|
+ public Task<OperateResult> UpdateAsync(IFormFile? ConfigFile, LibType LType)
|
|
|
{
|
|
|
- return Task.Run(() => Update(ConfigFile));
|
|
|
+ return Task.Run(() => Update(ConfigFile, LType));
|
|
|
}
|
|
|
|
|
|
public OperateResult Init()
|
|
|
{
|
|
|
if (baseOperate == null)
|
|
|
{
|
|
|
-
|
|
|
try
|
|
|
{
|
|
|
//配置赋值
|
|
|
- AManages = JsonTool.StringToListJsonEntity<AddressManage>(FileTool.FileToString(configPath));
|
|
|
+ AManages = JsonTool.StringToListJsonEntity<AddressManage>(FileTool.FileToString(DaqConfigPath));
|
|
|
if (baseOperate != null)
|
|
|
{
|
|
|
baseOperate.Dispose();
|