|
|
@@ -1,5 +1,4 @@
|
|
|
using Newtonsoft.Json.Linq;
|
|
|
-using StackExchange.Redis;
|
|
|
using System;
|
|
|
using System.Collections.Concurrent;
|
|
|
using System.Collections.Generic;
|
|
|
@@ -13,6 +12,7 @@ using System.Text;
|
|
|
using System.Text.RegularExpressions;
|
|
|
using System.Threading.Tasks;
|
|
|
using YSAI.Core.data;
|
|
|
+using YSAI.Core.@enum;
|
|
|
using YSAI.Core.@interface.unify;
|
|
|
using YSAI.Unility;
|
|
|
|
|
|
@@ -156,6 +156,11 @@ namespace YSAI.DaqManage
|
|
|
//检索
|
|
|
Search();
|
|
|
|
|
|
+ //创建文件
|
|
|
+ if (!Directory.Exists(basics.LibFolder))
|
|
|
+ {
|
|
|
+ Directory.CreateDirectory(basics.LibFolder);
|
|
|
+ }
|
|
|
//文件夹监控
|
|
|
watcherLibFolder = new FileSystemWatcher(basics.LibFolder);
|
|
|
//监控的配置
|
|
|
@@ -167,11 +172,15 @@ namespace YSAI.DaqManage
|
|
|
//启动监听
|
|
|
watcherLibFolder.EnableRaisingEvents = true;
|
|
|
|
|
|
-
|
|
|
+ //创建文件
|
|
|
+ if (!Directory.Exists(basics.LibConfigFolder))
|
|
|
+ {
|
|
|
+ Directory.CreateDirectory(basics.LibConfigFolder);
|
|
|
+ }
|
|
|
//文件夹监视
|
|
|
watcherLibConfigFolder = new FileSystemWatcher(basics.LibConfigFolder);
|
|
|
//监控的配置
|
|
|
- watcherLibConfigFolder.Filter = ".*.Config-*.json";
|
|
|
+ watcherLibConfigFolder.Filter = basics.ConfigWatcherFormat;
|
|
|
//当文件夹中新增文件
|
|
|
watcherLibConfigFolder.Created += delegate (object sender, FileSystemEventArgs e) { Watcher_Created(sender, e, 1); };
|
|
|
//当文件夹中删除文件
|
|
|
@@ -195,17 +204,17 @@ namespace YSAI.DaqManage
|
|
|
private void Watcher_Deleted(object sender, FileSystemEventArgs e, int Type)
|
|
|
{
|
|
|
//程序集SN
|
|
|
- string TypeSN = string.Empty;
|
|
|
+ string TypeIocSN = string.Empty;
|
|
|
switch (Type)
|
|
|
{
|
|
|
case 0:
|
|
|
OnEventHandler?.Invoke(this, new EventResult(true, $"{e.Name} 文件被删除,移除此库程序集,并移除所有实例"));
|
|
|
//程序集SN
|
|
|
- TypeSN = e.Name.Replace(".dll", string.Empty);
|
|
|
+ TypeIocSN = e.Name.Replace(".dll", string.Empty);
|
|
|
|
|
|
foreach (var item in InstanceIoc)
|
|
|
{
|
|
|
- if (item.Key.Contains(TypeSN))
|
|
|
+ if (item.Key.Contains(TypeIocSN))
|
|
|
{
|
|
|
InstanceIoc[item.Key].Dispose();
|
|
|
if (InstanceIoc.Remove(item.Key, out _))
|
|
|
@@ -221,7 +230,7 @@ namespace YSAI.DaqManage
|
|
|
|
|
|
foreach (var item in TypeIoc)
|
|
|
{
|
|
|
- if (item.Key.Contains(TypeSN))
|
|
|
+ if (item.Key.Contains(TypeIocSN))
|
|
|
{
|
|
|
if (TypeIoc.Remove(item.Key, out _))
|
|
|
{
|
|
|
@@ -236,31 +245,26 @@ namespace YSAI.DaqManage
|
|
|
break;
|
|
|
case 1:
|
|
|
OnEventHandler?.Invoke(this, new EventResult(true, $"{e.Name} 文件被删除,移除对应配置实例"));
|
|
|
+ //实例的SN
|
|
|
+ string InstanceIocSN = e.Name.Replace(basics.ConfigReplaceFormat, string.Empty);
|
|
|
//程序集SN
|
|
|
- TypeSN = e.Name.Split('-')[0].Replace(".Config", string.Empty);
|
|
|
- //分割
|
|
|
- string[] strs = e.Name.Split('-');
|
|
|
- if (strs.Length > 1)
|
|
|
+ TypeIocSN = InstanceIocSN.Replace($".{InstanceIocSN.Split('.')[InstanceIocSN.Split('.').Length - 1]}", string.Empty);
|
|
|
+ if (InstanceIoc.ContainsKey(InstanceIocSN))
|
|
|
{
|
|
|
- //获取配置实例SN
|
|
|
- string SN = $"{TypeSN}:{e.Name.Split('-')[1].Split('.')[0]}";
|
|
|
- if (InstanceIoc.ContainsKey(SN))
|
|
|
+ InstanceIoc[InstanceIocSN].Dispose();
|
|
|
+ if (InstanceIoc.Remove(InstanceIocSN, out _))
|
|
|
{
|
|
|
- InstanceIoc[SN].Dispose();
|
|
|
- if (InstanceIoc.Remove(SN, out _))
|
|
|
- {
|
|
|
- OnEventHandler?.Invoke(this, new EventResult(true, $"{e.Name} 移除配置实例成功"));
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- OnEventHandler?.Invoke(this, new EventResult(false, $"{e.Name} 移除配置实例失败"));
|
|
|
- }
|
|
|
+ OnEventHandler?.Invoke(this, new EventResult(true, $"{e.Name} 移除配置实例成功"));
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
- OnEventHandler?.Invoke(this, new EventResult(false, $"{e.Name} 移除配置实例失败 {TypeSN} 实例不存在"));
|
|
|
+ OnEventHandler?.Invoke(this, new EventResult(false, $"{e.Name} 移除配置实例失败"));
|
|
|
}
|
|
|
}
|
|
|
+ else
|
|
|
+ {
|
|
|
+ OnEventHandler?.Invoke(this, new EventResult(false, $"{e.Name} 移除配置实例失败 {TypeIocSN} 实例不存在"));
|
|
|
+ }
|
|
|
break;
|
|
|
}
|
|
|
}
|
|
|
@@ -303,31 +307,26 @@ namespace YSAI.DaqManage
|
|
|
srdPreview.Close();
|
|
|
srdPreview.Dispose();
|
|
|
|
|
|
- //获取程序集SN
|
|
|
- string TypeSN = e.Name.Split('-')[0].Replace(".Config", string.Empty);
|
|
|
- //分割
|
|
|
- string[] strs = e.Name.Split('-');
|
|
|
- if (strs.Length > 1)
|
|
|
+ //实例的SN
|
|
|
+ string InstanceIocSN = e.Name.Replace(basics.ConfigReplaceFormat, string.Empty);
|
|
|
+ //程序集SN
|
|
|
+ string TypeIocSN = InstanceIocSN.Replace($".{InstanceIocSN.Split('.')[InstanceIocSN.Split('.').Length - 1]}", string.Empty);
|
|
|
+ //判断是否存在此程序集SN
|
|
|
+ if (TypeIoc.ContainsKey(TypeIocSN))
|
|
|
{
|
|
|
- //获取配置实例SN
|
|
|
- string SN = $"{TypeSN}:{strs[1].Split('.')[0]}";
|
|
|
- //判断是否存在此程序集SN
|
|
|
- if (TypeIoc.ContainsKey(TypeSN))
|
|
|
+ if (!InstanceIoc.ContainsKey(InstanceIocSN))
|
|
|
{
|
|
|
- if (!InstanceIoc.ContainsKey(SN))
|
|
|
- {
|
|
|
- ConfigCreateInstance(TypeIoc[TypeSN], temp);
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- OnEventHandler?.Invoke(this, new EventResult(false, $" {e.Name} 此配置实例已存在"));
|
|
|
- }
|
|
|
+ ConfigCreateInstance(TypeIoc[TypeIocSN], temp);
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
- OnEventHandler?.Invoke(this, new EventResult(false, $" {e.Name} 新增对应配置创建实例失败 {TypeSN} 程序集不存在"));
|
|
|
+ OnEventHandler?.Invoke(this, new EventResult(false, $" {e.Name} 此配置实例已存在"));
|
|
|
}
|
|
|
}
|
|
|
+ else
|
|
|
+ {
|
|
|
+ OnEventHandler?.Invoke(this, new EventResult(false, $" {e.Name} 新增对应配置创建实例失败 {TypeIocSN} 程序集不存在"));
|
|
|
+ }
|
|
|
fs.Close();
|
|
|
fs.Dispose();
|
|
|
}
|
|
|
@@ -432,23 +431,35 @@ namespace YSAI.DaqManage
|
|
|
//获取结构参数
|
|
|
JObject? jsonObject = Newtonsoft.Json.JsonConvert.DeserializeObject<JObject>(content);
|
|
|
//获取唯一标识符
|
|
|
- string SN = $"{type.FullName}.{jsonObject[basics.LibConfigSNKey]}";
|
|
|
+ string InstanceIocSN = $"{type.FullName}.{jsonObject[basics.LibConfigSNKey]}";
|
|
|
//获取实例
|
|
|
IDaq? instance = CreateInstance(type, new object[] { jsonObject }) as IDaq;
|
|
|
//实例不为空
|
|
|
if (instance != null)
|
|
|
{
|
|
|
//把这个实例添加到容器中
|
|
|
- InstanceIoc.TryAdd(SN, instance);
|
|
|
+ InstanceIoc.TryAdd(InstanceIocSN, instance);
|
|
|
//事件注册
|
|
|
instance.OnEvent += Instance_OnEvent;
|
|
|
- //抛出信息
|
|
|
- OnEventHandler?.Invoke(this, new EventResult(true, $"{SN} 实例创建成功"));
|
|
|
+
|
|
|
+ //自动打开
|
|
|
+ if (basics.AutoOn)
|
|
|
+ {
|
|
|
+ //执行打开方法
|
|
|
+ OperateResult operateResult = instance.On();
|
|
|
+ //抛出信息
|
|
|
+ OnEventHandler?.Invoke(this, new EventResult(operateResult.State, $"{InstanceIocSN} 实例创建成功,自动打开{(operateResult.State ? "成功" : "失败")}"));
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ //抛出信息
|
|
|
+ OnEventHandler?.Invoke(this, new EventResult(true, $"{InstanceIocSN} 实例创建成功"));
|
|
|
+ }
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
//抛出信息
|
|
|
- OnEventHandler?.Invoke(this, new EventResult(false, $"{SN} 实例创建失败"));
|
|
|
+ OnEventHandler?.Invoke(this, new EventResult(false, $"{InstanceIocSN} 实例创建失败"));
|
|
|
}
|
|
|
}
|
|
|
/// <summary>
|
|
|
@@ -591,7 +602,7 @@ namespace YSAI.DaqManage
|
|
|
}
|
|
|
catch (Exception ex)
|
|
|
{
|
|
|
- return Break("Dispose", false,ex.Message);
|
|
|
+ return Break("Dispose", false, ex.Message);
|
|
|
}
|
|
|
}
|
|
|
/// <summary>
|
|
|
@@ -603,6 +614,19 @@ namespace YSAI.DaqManage
|
|
|
{
|
|
|
return Task.Run(() => Dispose(SN));
|
|
|
}
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// 实例列表
|
|
|
+ /// </summary>
|
|
|
+ /// <returns>实例数组</returns>
|
|
|
+ public List<string>? InstanceList()
|
|
|
+ {
|
|
|
+ if (InstanceIoc != null)
|
|
|
+ {
|
|
|
+ return InstanceIoc.Keys.ToList();
|
|
|
+ }
|
|
|
+ return null;
|
|
|
+ }
|
|
|
/// <summary>
|
|
|
/// 移除实例
|
|
|
/// </summary>
|
|
|
@@ -785,6 +809,7 @@ namespace YSAI.DaqManage
|
|
|
{
|
|
|
return Task.Run(() => UnSubscribe(address, SN));
|
|
|
}
|
|
|
+
|
|
|
/// <summary>
|
|
|
/// 打开
|
|
|
/// </summary>
|
|
|
@@ -819,6 +844,55 @@ namespace YSAI.DaqManage
|
|
|
}
|
|
|
}
|
|
|
/// <summary>
|
|
|
+ /// 打开所有
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="SN">实例的唯一标识符</param>
|
|
|
+ /// <returns>统一出参</returns>
|
|
|
+ public Task<OperateResult> OnAllAsync()
|
|
|
+ {
|
|
|
+ return Task.Run(() => OnAll());
|
|
|
+ }
|
|
|
+ /// <summary>
|
|
|
+ /// 打开所有
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="SN">实例的唯一标识符</param>
|
|
|
+ /// <returns>统一出参</returns>
|
|
|
+ public OperateResult OnAll()
|
|
|
+ {
|
|
|
+ Depart("OnAll");
|
|
|
+ try
|
|
|
+ {
|
|
|
+ if (InstanceIoc != null && InstanceIoc.Count > 0)
|
|
|
+ {
|
|
|
+ List<string> FailMessage = new List<string>();
|
|
|
+ foreach (var item in InstanceIoc)
|
|
|
+ {
|
|
|
+ OperateResult operateResult = item.Value.On();
|
|
|
+ if (!operateResult.State)
|
|
|
+ {
|
|
|
+ FailMessage.Add(operateResult.Message);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (FailMessage.Count > 0)
|
|
|
+ {
|
|
|
+ return Break("OnAll", false, $"存在{FailMessage.Count}个异常信息,请查看RData", FailMessage, ResultType.All);
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ return Break("OnAll", true);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ return Break("OnAll", false, "实例为空");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ catch (Exception ex)
|
|
|
+ {
|
|
|
+ return Break("OnAll", false, ex.Message);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ /// <summary>
|
|
|
/// 关闭
|
|
|
/// </summary>
|
|
|
/// <param name="SN">实例的唯一标识符</param>
|
|
|
@@ -851,5 +925,54 @@ namespace YSAI.DaqManage
|
|
|
return Break("Off", false, ex.Message);
|
|
|
}
|
|
|
}
|
|
|
+ /// <summary>
|
|
|
+ /// 关闭所有
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="SN">实例的唯一标识符</param>
|
|
|
+ /// <returns>统一出参</returns>
|
|
|
+ public Task<OperateResult> OffAllAsync()
|
|
|
+ {
|
|
|
+ return Task.Run(() => OffAll());
|
|
|
+ }
|
|
|
+ /// <summary>
|
|
|
+ /// 关闭所有
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="SN">实例的唯一标识符</param>
|
|
|
+ /// <returns>统一出参</returns>
|
|
|
+ public OperateResult OffAll()
|
|
|
+ {
|
|
|
+ Depart("OffAll");
|
|
|
+ try
|
|
|
+ {
|
|
|
+ if (InstanceIoc != null && InstanceIoc.Count > 0)
|
|
|
+ {
|
|
|
+ List<string> FailMessage = new List<string>();
|
|
|
+ foreach (var item in InstanceIoc)
|
|
|
+ {
|
|
|
+ OperateResult operateResult = item.Value.Off();
|
|
|
+ if (!operateResult.State)
|
|
|
+ {
|
|
|
+ FailMessage.Add(operateResult.Message);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (FailMessage.Count > 0)
|
|
|
+ {
|
|
|
+ return Break("OffAll", false, $"存在{FailMessage.Count}个异常信息,请查看RData", FailMessage, ResultType.All);
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ return Break("OffAll", true);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ return Break("OffAll", false, "实例为空");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ catch (Exception ex)
|
|
|
+ {
|
|
|
+ return Break("OffAll", false, ex.Message);
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
}
|