diff --git a/FlowEdit/FlowEdit (sqlsugar).7z b/FlowEdit/FlowEdit (sqlsugar).7z
deleted file mode 100644
index 06184e8..0000000
Binary files a/FlowEdit/FlowEdit (sqlsugar).7z and /dev/null differ
diff --git a/FlowStartTool/FlowEnv.cs b/FlowStartTool/FlowEnv.cs
index 7186fa9..7faf082 100644
--- a/FlowStartTool/FlowEnv.cs
+++ b/FlowStartTool/FlowEnv.cs
@@ -35,14 +35,20 @@ namespace Serein.FlowStartTool
// this.window = window;
//}
- Env = new FlowEnvironmentDecorator(uIContextOperation);
+ Env = new FlowEnvironmentDecorator();
+ Env.SetUIContextOperation(uIContextOperation);
Env.LoadProject(new FlowEnvInfo { Project = flowProjectData }, fileDataPath); // 加载项目
- // 获取环境输出
- Env.OnEnvOut += (infoType, value) =>
+ if(Env is IFlowEnvironmentEvent @event)
{
- Console.WriteLine($"{DateTime.Now} [{infoType}] : {value}{Environment.NewLine}");
- };
+ // 获取环境输出
+ @event.OnEnvOut += (infoType, value) =>
+ {
+ Console.WriteLine($"{DateTime.Now} [{infoType}] : {value}{Environment.NewLine}");
+ };
+ }
+
+
await Env.StartRemoteServerAsync(7525); // 启动 web socket 监听远程请求
diff --git a/Library.Core/DbSql/DBSync.cs b/Library.Core/DbSql/DBSync.cs
deleted file mode 100644
index c8abbbc..0000000
--- a/Library.Core/DbSql/DBSync.cs
+++ /dev/null
@@ -1,606 +0,0 @@
-using SqlSugar;
-using System.ComponentModel;
-using System.Net.Sockets;
-using System.Reflection;
-
-namespace Serein.DbSql
-{
- public enum DBSyncStart
- {
- ///
- /// 无需同步
- ///
- [Description("无需同步")]
- NotNeed,
- ///
- /// 同步成功
- ///
- [Description("同步成功")]
- SyncSuccess,
- ///
- /// 同步失败
- ///
- [Description("同步失败")]
- SyncFailure,
- ///
- /// 连接异常
- ///
- [Description("配置/连接异常")]
- NetworkError,
- ///
- /// 没有同步事件
- ///
- [Description("没有同步事件,请使用 DBSync.SetSyncDataEvent() 方法设置同步事件")]
- NoEvent,
- }
- public enum DBSyncExType
- {
- [Description("连接异常")]
- ConnectError,
- [Description("读写异常")]
- CrudError,
- [Description("同步异常")]
- SyncError,
- }
-
- public class DBSyncConfig
- {
- public DBSyncConfig(ConnectionConfig primaryDBConfig,
- ConnectionConfig secondaryDBConfig)
- {
- PrimaryDBConfig = primaryDBConfig;
- SecondaryDBConfig = secondaryDBConfig;
- }
- ///
- /// 主数据库IP
- ///
- //private string Host { get; }
- ///
- /// 主数据库端口
- ///
- //private int Port { get; }
- ///
- /// 主数据库配置
- ///
- private ConnectionConfig PrimaryDBConfig { get; }
- ///
- /// 从数据库配置
- ///
- private ConnectionConfig SecondaryDBConfig { get; }
-
- public override string ToString()
- {
- return $"[主数据库配置]{PrimaryDBConfig.ConnectionString}" + Environment.NewLine +
- $"[从数据库配置]{SecondaryDBConfig.ConnectionString}" + Environment.NewLine;
- }
-
- ///
- /// 检查网络状态
- ///
- ///
- public bool GetNetworkState()
- {
- var isOpen = DBSync.IsPortOpen(); // 数据库基类获取网络状态
- if (!isOpen)
- {
- DBSync.SetIsNeedSyncData(true); // 远程数据库查询失败,尝试本地数据库
- }
- return isOpen;
- }
-
- ///
- /// 返回从数据库
- ///
- ///
- public SqlSugarClient GetSecondaryDB()
- {
- DBSync.SyncEvent.Wait();
- return new SqlSugarClient(SecondaryDBConfig);
- }
-
- ///
- /// 返回主数据库
- ///
- ///
- ///
- public SqlSugarClient GetPrimaryDB()
- {
- try
- {
- // 等待同步事件
- DBSync.SyncEvent.Wait();
- // 检查主数据库连接状态
- if (!DBSync.IsPortOpen()) // 返回主数据库检测网络状态
- {
- // Console.WriteLine($"主数据库无法连接,IP:{IP},端口:{Port}");
- DBSync.SetIsNeedSyncData(true); // 网络不可达
-
- return null;
-
- }
-
- // 检查是否需要同步数据
- /*if (DBSync.GetIsNeedSyncData())
- {
- var syncState = DBSync.StartSyncDataBase();
- if (syncState != DBSyncStart.SyncSuccess && syncState != DBSyncStart.NotNeed)
- {
- // Console.WriteLine($"获取读写客户端前,尝试同步时发生异常:{DBSync.GetDescription(syncState)}");
- return null;
- }
- }*/
-
- // 返回主数据库客户端
- return new SqlSugarClient(PrimaryDBConfig);
- }
- catch // (Exception ex)
- {
- // Console.WriteLine($"发生异常:{ex.Message}");
-
- return null;
-
- }
- }
-
-
- }
-
- ///
- /// 数据库同步异常
- ///
- public class DBSyncException : Exception
- {
- public DBSyncExType ExceptionType { get; private set; }
-
- public DBSyncException(DBSyncExType exceptionType)
- {
- ExceptionType = exceptionType;
- }
-
- public DBSyncException(DBSyncExType exceptionType, string message) : base(message)
- {
- ExceptionType = exceptionType;
- }
-
- public DBSyncException(DBSyncExType exceptionType, string message, Exception innerException) : base(message, innerException)
- {
- ExceptionType = exceptionType;
- }
- public override string ToString()
- {
- return $"异常: {ExceptionType}: {GetDescription(ExceptionType)}. Message: {Message}";
- }
- public static string GetDescription(DBSyncExType value)
- {
-
- FieldInfo field = value.GetType().GetField(value.ToString());
-
-
-
- DescriptionAttribute attribute = (DescriptionAttribute)field.GetCustomAttribute(typeof(DescriptionAttribute));
-
-
- return attribute == null ? value.ToString() : attribute.Description;
- }
-
- }
-
-
- ///
- /// 远程、本地数据库同步
- ///
- public static class DBSync
- {
- ///
- /// 主数据库配置
- ///
-
- private static ConnectionConfig PrimaryConfig { get; set; }
-
- ///
- /// 从数据库配置
- ///
-
- private static ConnectionConfig SecondaryConfig { get; set; }
-
- ///
- /// 主数据库IP
- ///
-
- private static string Host { get; set; }
-
- ///
- /// 主数据库端口
- ///
- private static int Port { get; set; }
- ///
- /// 同步数据事件(远程数据库,本地数据库,是否执行成功)
- ///
-
- private static Func SyncDataEvent { get; set; }
-
-
- private static Action StateChangeEvent { get; set; }
-
- ///
- /// 数据库设置锁
- ///
- //private static object DBSetLock { get; set; } = new object();
- ///
- /// 是否需要同步数据
- ///
- private static bool IsNeedSyncData { get; set; } = false;
- ///
- /// 等待次数(执行了多少次操作后才尝试进行同步,设置为0容易影响性能)
- ///
- private static int WaitCount { get; set; } = 10;
-
- ///
- /// 客户端获取计数
- ///
- private static int CrudDBGetCount { get; set; } = 0;
- ///
- /// 同步端获取计数
- ///
- private static int SyncDBGetCount { get; set; } = 0;
-
-
- //public static ManualResetEventSlim SyncEvent { get; } = new ManualResetEventSlim(true); // 同步事件
- ///
- /// 远程本地同步阻塞事件
- ///
- public static FifoManualResetEvent SyncEvent { get; } = new FifoManualResetEvent(true);
- ///
- /// 数据同步锁
- ///
- private static object SyncLock { get; } = new object();
- ///
- /// 是否需要同步数据读写锁
- ///
- private static readonly ReaderWriterLockSlim NeedSyncStateLock = new ReaderWriterLockSlim();
-
- ///
- /// 是否断开过,true=断开过,false=没有断开过
- /// 设置为 false 时自动检测网络情况,只有在网络正常的情况下才能成功设置为 true
- ///
- ///
- public static void SetIsNeedSyncData(bool value)
- {
- if (value == IsNeedSyncData)
- {
- return;
- }
- //Console.WriteLine("变更数据库");
- // 写入锁
- NeedSyncStateLock.EnterWriteLock();
- try
- {
- if (value)
- {
- IsNeedSyncData = true;
- return;
- }
- IsNeedSyncData = !IsPortOpen(); // 变更 是否同步 属性时获取网络状态
- }
- finally
- {
- NeedSyncStateLock.ExitWriteLock();
- StateChangeEvent?.Invoke(IsNeedSyncData);
- }
- }
- public static bool GetIsNeedSyncData()
- {
- // 读取锁
- NeedSyncStateLock.EnterReadLock();
- try
- {
- return IsNeedSyncData; //是否需要同步数据
- }
- finally
- {
- NeedSyncStateLock.ExitReadLock();
- }
- }
-
-
-
- ///
- /// 配置主数据库
- ///
- public static void PrimaryConnect(DbType dbType, string host, int port, string dbName, string user, string password)
- {
- Host = host;
- Port = port;
- PrimaryConfig = GetConnectionConfig(dbType, host, port.ToString(), dbName, user, password);
-
- /*SyncEvent.Wait();
-
- if (true || IsPortOpen(host, port))
- {
- // 目标端口打通时才会更改数据库配置
- lock (DBSetLock)
- {
- Host = host;
- Port = port;
- PrimaryConfig = GetConnectionConfig(dbType, host, port.ToString(), dbName, user, password);
- }
- }
- else
- {
- throw new DBSyncException(DBSyncExType.ConnectError, $"主数据库配置失败,无法连接,目标配置:IP:{host},端口:{port},目标库名:{dbName},账户:{user}");
- }*/
- }
- ///
- /// 配置从数据库
- ///
- public static void SecondaryConnect(DbType dbType, string host, int port, string dbName, string user, string password)
- {
- SecondaryConfig = GetConnectionConfig(dbType, host, port.ToString(), dbName, user, password);
-
- /*if (IsPortOpen(host, port))
- {
- lock (DBSetLock)
- {
- SecondaryConfig = GetConnectionConfig(dbType, host, port.ToString(), dbName, user, password);
- }
- }
- else
- {
- throw new DBSyncException(DBSyncExType.ConnectError, $"从数据库配置失败,无法连接,目标配置:{host},端口:{port},目标库名:{dbName},账户:{user}");
- }*/
- }
-
- ///
- /// 尝试执行一次数据同步
- ///
- public static bool SyncData()
- {
- SetIsNeedSyncData(true);
- var state = StartSyncDataBase(true); // 手动同步
- return state == DBSyncStart.SyncSuccess || state == DBSyncStart.NotNeed;
- }
-
-
-
- ///
- /// 设置同步事件与等待次数。
- ///
- /// 同步事件(需要手动同步数据)
- /// 等待次数(执行了多少次操作后才尝试进行同步,设置为0容易影响性能)
- public static void SetSyncEvent(Func syncDataEvent, int waitCount = 0)
- {
- SyncDataEvent = syncDataEvent;
- WaitCount = waitCount;
- }
- ///
- /// 设置状态变化事件
- ///
- ///
- ///
- public static void SetStateChangeEvent(Action stateChangeEvent)
- {
- StateChangeEvent = stateChangeEvent;
- }
-
- ///
- /// 获取数据库配置(不推荐使用在除了Repository的地方外部调用)
- ///
- ///
- public static DBSyncConfig GetSyncSqlConfig()
- {
- /*SyncEvent.Wait();
- */
-
- if (GetIsNeedSyncData())
- {
- _ = Task.Run(() => StartSyncDataBase()); // new了一个RepositoryBase时尝试同步数据
- }
-
- lock (SyncLock)
- {
- CrudDBGetCount++;
- //Console.WriteLine($"获取客户端:{CrudDBGetCount}");
- return new DBSyncConfig(PrimaryConfig, SecondaryConfig);
- }
- }
-
- public static void ReSetCrudDb()
- {
- CrudDBGetCount--;
- Task.Run(() => StartSyncDataBase()); // 释放数据库连接时尝试同步数据
-
- /*if (GetIsNeedSyncData())
- {
-
- }*/
- // Console.WriteLine($"释放客户端:{CrudDBGetCount}");
- }
-
- public static DBSyncStart StartSyncDataBase(bool isAtOnce = false)
- {
- /*if (!isAtOnce && WaitCount > 0)
- {
- WaitCount--;
- return DBSyncStart.NotNeed;
- }*/
-
- SyncEvent.Reset(); // 锁定线程,保证只有一个线程进入该方法
-
- if (!GetIsNeedSyncData())
- {
- SyncEvent.Set();
- return DBSyncStart.NotNeed;
- }
-
- if (!IsPortOpen()) // 同步时获取网络状态
- {
- SetIsNeedSyncData(true);
- SyncEvent.Set();
- return DBSyncStart.NetworkError;
- }
-
-
-
- if (SyncDataEvent == null)
- {
- SyncEvent.Set();
- return DBSyncStart.NoEvent;
- }
-
-
- lock (SyncLock) // 同步锁,避免其它符合进入条件的线程执行多次同步
- {
- if (!GetIsNeedSyncData())
- {
- SyncEvent.Set();
- return DBSyncStart.NotNeed;
- }
- Console.WriteLine("网络检测OK,准备同步数据");
- try
- {
- bool isSuccess = SyncDataEvent.Invoke(new SqlSugarClient(PrimaryConfig), new SqlSugarClient(SecondaryConfig));
- SetIsNeedSyncData(!isSuccess);
-
- if (isSuccess)
- {
- return DBSyncStart.SyncSuccess;
- }
- else
- {
- return DBSyncStart.SyncFailure;
- }
- }
- catch (Exception ex)
- {
- // 记录异常日志
- Console.WriteLine($"同步数据时发生异常: {ex.Message}");
- return DBSyncStart.SyncFailure;
- }
- finally
- {
- SyncEvent.Set(); // 释放同步事件,以防止其他线程一直被阻塞
- }
- }
-
- }
-
-
- public static string GetDescription(DBSyncStart value)
- {
-
- FieldInfo field = value.GetType().GetField(value.ToString());
-
-
-
- DescriptionAttribute attribute = (DescriptionAttribute)field.GetCustomAttribute(typeof(DescriptionAttribute));
-
-
- return attribute == null ? value.ToString() : attribute.Description;
- }
-
- ///
- /// 检测目标地址是否打通
- ///
- /// ip地址
- /// 端口号
- /// 超时时间
- ///
- public static bool IsPortOpen(string ip, int port, int timeout = 300)
- {
- using (var client = new TcpClient())
- {
- var result = client.ConnectAsync(ip, port);
- try
- {
- var open = result.Wait(timeout);
- return open;
- }
- catch (SocketException)
- {
- return false;
- }
- }
- }
- ///
- /// 检测目标地址是否打通:主数据库IP和端口是否打通(true通,false断)
- ///
- /// 超时时间
- ///
- public static bool IsPortOpen(int timeout = 300)
- {
- string ip = Host;
- int port = Port;
- using (var client = new TcpClient())
- {
- bool isOpen = true;
- try
- {
- var result = client.ConnectAsync(ip, port);
- isOpen = result.Wait(timeout);
- if (!isOpen)
- {
- //Console.WriteLine($"连接超时{ip},{port}");
- }
- return isOpen;
- }
- catch
- {
- isOpen = false;
- return isOpen;
- }
- finally
- {
- //Console.WriteLine("网络检测:" + isOpen);
- }
- }
- }
-
- ///
- /// 返回数据库连接串
- ///
- /// 数据库类型
- /// 服务器IP地址
- /// 数据库名
- /// 登录账户
- /// 登录密码
- private static ConnectionConfig GetConnectionConfig(DbType dbType, string host, string port, string dbName, string name, string password)
- {
- ConnectionConfig config;
- string ConnectionString;
- switch (dbType)
- {
- case DbType.MySql:
- ConnectionString = $"Server={host};DataBase={dbName};Port={port};UserId={name};Password={password};Persist Security Info=True;Allow Zero Datetime=True;Character Set=utf8;";
- config = new ConnectionConfig()
- {
- ConnectionString = ConnectionString,//连接符字串
- DbType = DbType.MySql,
- IsAutoCloseConnection = true,
- InitKeyType = InitKeyType.Attribute //从实体特性中读取主键自增列信息
- };
-
- break;
- case DbType.SqlServer:
- ConnectionString = $"Server={host},{port};DataBase={dbName};uid={name};pwd={password}";
- config = new ConnectionConfig()
- {
- ConnectionString = ConnectionString,//连接符字串
- DbType = DbType.SqlServer,
- IsAutoCloseConnection = true,
- InitKeyType = InitKeyType.Attribute //从实体特性中读取主键自增列信息
- };
- break;
- default:
-
- config = null;
-
- break;
- }
-
- return config;
-
-
- }
- }
-
-}
diff --git a/Library.Core/DbSql/FifoManualResetEvent.cs b/Library.Core/DbSql/FifoManualResetEvent.cs
deleted file mode 100644
index ca9a8f4..0000000
--- a/Library.Core/DbSql/FifoManualResetEvent.cs
+++ /dev/null
@@ -1,71 +0,0 @@
-namespace Serein.DbSql
-{
- ///
- /// 线程阻塞
- ///
- public class FifoManualResetEvent
- {
- private readonly object lockObj = new object();
- ///
- /// 让线程按进入时间顺序调用
- ///
- private readonly Queue waitQueue = new Queue();
- private bool isSet;
-
- public bool IsSet { get => isSet; set => isSet = value; }
-
- public FifoManualResetEvent(bool initialState = false)
- {
- IsSet = initialState;
- }
-
- ///
- /// 等待解锁
- ///
- public void Wait()
- {
- lock (lockObj)
- {
- if (IsSet)
- {
- // 获取到了发送的信号,线程开始重新执行
- return;
- }
-
- var currentThread = Thread.CurrentThread;
- waitQueue.Enqueue(currentThread);
-
- while (!IsSet || waitQueue.Peek() != currentThread)
- {
- Monitor.Wait(lockObj);
- }
-
- waitQueue.Dequeue();
- }
- }
-
- ///
- /// 发送信号
- ///
- public void Set()
- {
- lock (lockObj)
- {
- IsSet = true;
- Monitor.PulseAll(lockObj);
- }
- }
-
- ///
- /// 锁定当前线程
- ///
- public void Reset()
- {
- lock (lockObj)
- {
- IsSet = false;
- }
- }
- }
-
-}
diff --git a/Library.Core/DbSql/IRepositoryBase.cs b/Library.Core/DbSql/IRepositoryBase.cs
deleted file mode 100644
index 1df6707..0000000
--- a/Library.Core/DbSql/IRepositoryBase.cs
+++ /dev/null
@@ -1,19 +0,0 @@
-using System.Linq.Expressions;
-
-namespace Serein.DbSql
-{
- public interface IRepositoryBase where TEntity : class, new()
- {
- TEntity GetModelByID(dynamic ID);
-
- int Add(TEntity Model);
-
- int Update(TEntity Model);
-
- bool DeleteByID(dynamic ID);
-
- bool Delete(Expression> where);
-
- int UpdateColumns(TEntity model, Expression> expression);
- }
-}
diff --git a/Library.Core/DbSql/RepositoryBase.cs b/Library.Core/DbSql/RepositoryBase.cs
deleted file mode 100644
index 0cd8253..0000000
--- a/Library.Core/DbSql/RepositoryBase.cs
+++ /dev/null
@@ -1,877 +0,0 @@
-
-using Serein.DbSql;
-using Newtonsoft.Json.Converters;
-using Newtonsoft.Json;
-using SqlSugar;
-using System.Data;
-using System.Linq.Expressions;
-using Serein.Tool;
-
-namespace Serein.Helper
-{
-
- // public class RepositoryBase : DataBase, IRepositoryBase where TEntity : class, new()
- public class RepositoryBase : IRepositoryBase where TEntity : class, new()
- {
- public bool isHaveErr;
-
- public string ErrMsg = "";
-
- public string filterName = "SubSystemName";
- ~RepositoryBase()
- {
- DBSync.ReSetCrudDb();
- }
- public RepositoryBase()
- {
- }
- ///
- /// 是否优先使用本地数据库
- ///
- public bool IsUseLoaclDB = false;
-
-
- #region 数据库操作 泛型抽象方法
-
- #region 优先查询 主数据库
-
- ///
- /// 无状态数据操作(查询)泛型抽象方法
- ///
- ///
- ///
- ///
- ///
- public virtual T SyncExecuteRead(Func func)
- {
- var syncSqlConfig = DBSync.GetSyncSqlConfig(); // 基类获取数据库配置
- if (IsUseLoaclDB)
- {
- var secondaryDB = syncSqlConfig.GetSecondaryDB();
- return func.Invoke(secondaryDB); // 尝试查询本地数据库
- }
-
-
- if (syncSqlConfig.GetNetworkState()) // 网络检测
- {
- try
- {
- var primaryDB = syncSqlConfig.GetPrimaryDB();
- if (primaryDB != null)
- {
- return func.Invoke(primaryDB); // 尝试查询本地数据库
- }
- else
- {
- Console.WriteLine("远程数据库不可用");
- }
- }
- catch(Exception ex)
- {
- DBSync.SetIsNeedSyncData(true); // 网络不可达
- Console.WriteLine(ex.ToString());
- }
- }
-
- try
- {
- var secondaryDB = syncSqlConfig.GetSecondaryDB();
- return func.Invoke(secondaryDB); // 尝试查询本地数据库
- }
- catch
- {
- throw new DBSyncException(DBSyncExType.CrudError, $"主从数据库不可用。\r\n {syncSqlConfig.ToString()} ");
- }
- }
- ///
- /// 无状态数据操作(查询)泛型抽象方法
- ///
- ///
- ///
- ///
- ///
- public virtual T SyncExecuteRead(Func, T> func)
- {
- var syncSqlConfig = DBSync.GetSyncSqlConfig(); // 基类获取数据库配置
-
- if (IsUseLoaclDB)
- {
- var secondaryDB = syncSqlConfig.GetSecondaryDB().GetSimpleClient();
- return func.Invoke(secondaryDB); // 尝试查询本地数据库
- }
-
- if (syncSqlConfig.GetNetworkState()) // 网络检测
- {
- try
- {
- var primaryDB = syncSqlConfig.GetPrimaryDB()?.GetSimpleClient();
- if (primaryDB != null)
- {
- return func.Invoke(primaryDB); // 尝试查询远程数据库
- }
- else
- {
- Console.WriteLine("远程数据库不可用");
- }
- }
- catch (Exception ex)
- {
- DBSync.SetIsNeedSyncData(true); // 网络不可达
- Console.WriteLine(ex.ToString());
- }
- }
-
- try
- {
- var secondaryDB = syncSqlConfig.GetSecondaryDB().GetSimpleClient();
- return func.Invoke(secondaryDB); // 尝试查询本地数据库
- }
- catch
- {
- throw new DBSyncException(DBSyncExType.CrudError, $"主从数据库不可用。\r\n {syncSqlConfig.ToString()} ");
- }
- }
-
- #endregion
-
-
- #region 优先查询 从数据库 (已注释)
- /* ///
- /// 无状态数据操作(查询)泛型抽象方法
- ///
- ///
- ///
- ///
- ///
- public virtual T ExecuteSyncOperation(Func func)
- {
- DBSync.SyncEvent.Wait();
- var secondaryDB = SyncSqlConfig.GetSecondaryDB();
-
- try
- {
- return func.Invoke(secondaryDB); // 优先尝试查询本地数据库
- }
- catch
- {
- try
- {
- var primaryDB = SyncSqlConfig.GetPrimaryDB();
- if (primaryDB != null)
- {
- if (SyncSqlConfig.GetNetworkState()) // 网络检测
- {
- DBSync.SyncEvent.Wait();
- return func.Invoke(primaryDB); // 尝试查询远程数据库
- }
- else
- {
- throw new DBSyncException(DBSyncExType.CrudError, "网络不可达,无法查询远程数据库。");
- }
- }
- else
- {
- throw new DBSyncException(DBSyncExType.CrudError, "远程数据库不可用。");
- }
- }
- catch
- {
- throw new DBSyncException(DBSyncExType.CrudError, $"远程数据库查询失败。\r\n {SyncSqlConfig.ToString()} ");
- }
- }
- }
-
- ///
- /// 无状态数据操作(查询)泛型抽象方法
- ///
- ///
- ///
- ///
- ///
- public virtual T ExecuteSyncOperation(Func, T> func)
- {
- DBSync.SyncEvent.Wait();
-
- var secondaryDB = SyncSqlConfig.GetSecondaryDB().GetSimpleClient();
-
- try
- {
- return func.Invoke(secondaryDB); // 优先尝试查询本地数据库
- }
- catch
- {
- // 本地数据库查询失败,尝试远程数据库
- try
- {
- var primaryDB = SyncSqlConfig.GetPrimaryDB()?.GetSimpleClient();
- if (primaryDB != null)
- {
- if (SyncSqlConfig.GetNetworkState()) // 网络检测
- {
- DBSync.SyncEvent.Wait();
- return func.Invoke(primaryDB); // 尝试查询远程数据库
- }
- else
- {
- throw new DBSyncException(DBSyncExType.CrudError, "网络不可达,无法查询远程数据库。");
- }
- }
- else
- {
- throw new DBSyncException(DBSyncExType.CrudError, "远程数据库不可用。");
- }
- }
- catch
- {
- throw new DBSyncException(DBSyncExType.CrudError, $"远程数据库查询失败。\r\n {SyncSqlConfig.ToString()} ");
- }
- }
- }
- */
- #endregion
-
- #region 增加、更新、删除 操作泛型方法
- ///
- /// 有状态数据操作(更新、增加、删除)泛型抽象方法,优先操作本地数据库,操作远程数据库失败时调用DBSync.SetIsNeedSyncData(true);
- ///
- ///
- ///
- ///
- ///
- ///
- public virtual T SyncExecuteCUD(Func func)
- {
- var syncSqlConfig = DBSync.GetSyncSqlConfig(); // 基类获取数据库配置
- var secondaryDB = syncSqlConfig.GetSecondaryDB();
- try
- {
- var secondaryResult = func.Invoke(secondaryDB); // 本地数据库操作
- if (IsUseLoaclDB)
- {
- return secondaryResult;
- }
- if (syncSqlConfig.GetNetworkState()) // 网络检测
- {
- var primaryDB = syncSqlConfig.GetPrimaryDB();
- if(primaryDB != null)
- {
- var primaryResult = func.Invoke(primaryDB); // 远程数据库操作
- return primaryResult;
- }
- else
- {
- Console.WriteLine("远程数据库不可用");
- }
- }
- return secondaryResult;
- }
- catch (Exception ex)
- {
- Console.WriteLine("主从数据库不可用:" + ex.ToString());
- DBSync.SetIsNeedSyncData(true);
- throw new DBSyncException(DBSyncExType.CrudError, $"主从数据库不可用。\r\n {syncSqlConfig.ToString()} ");
- }
- }
-
- public virtual T SyncExecuteCUD(Func, T> func)
- {
- var syncSqlConfig = DBSync.GetSyncSqlConfig(); // 基类获取数据库配置
- var secondaryDB = syncSqlConfig.GetSecondaryDB().GetSimpleClient();
-
- try
- {
- var secondaryResult = func.Invoke(secondaryDB); // 本地数据库操作
- if (IsUseLoaclDB)
- {
- return secondaryResult;
- }
- if (syncSqlConfig.GetNetworkState()) // 网络检测
- {
- var primaryDB = syncSqlConfig.GetPrimaryDB().GetSimpleClient();
- if(primaryDB != null)
- {
- var primaryResult = func.Invoke(primaryDB); // 远程数据库操作
- return primaryResult;
- }
- else
- {
- Console.WriteLine("远程数据库不可用");
- }
- }
- return secondaryResult;
- }
- catch (Exception ex)
- {
- Console.WriteLine("主从数据库不可用:" + ex.ToString());
- DBSync.SetIsNeedSyncData(true);
- throw new DBSyncException(DBSyncExType.CrudError, $"主从数据库不可用。\r\n {syncSqlConfig.ToString()} ");
- }
- }
-
-
- #endregion
-
-
- public TEntity SyncRead(Func func)
- {
- return SyncExecuteRead(func);
- }
-
- public bool SyncRead(Func func)
- {
- return SyncExecuteRead(func);
- }
-
- public List SyncRead(Func> func)
- {
- return SyncExecuteRead(func);
- }
-
-
- ///
- /// 查询返回实体
- ///
- public TEntity SyncRead(Func, TEntity> func)
- {
- return SyncExecuteRead(func);
- }
-
- ///
- /// 查询返回实体列表
- ///
- public List SyncRead(Func, List> func)
- {
- return SyncExecuteRead(func);
- }
-
- public TEntity SyncCUD(Func func)
- {
- return SyncExecuteCUD(func);
- }
-
- public int SyncCUD(Func func)
- {
- return SyncExecuteCUD(func);
- }
-
- public bool SyncCUD(Func func)
- {
- return SyncExecuteCUD(func);
- }
-
- public TEntity SyncSimpleCUD(Func, TEntity> func)
- {
-
- return SyncExecuteCUD(func);
- }
-
- public int SyncSimpleCUD(Func, int> func)
- {
- return SyncExecuteCUD(func);
- }
-
- public bool SyncSimpleCUD(Func, bool> func)
- {
- return SyncExecuteCUD(func);
- }
-
-
- #endregion
-
-
-
-
- public virtual TEntity GetModelByID(dynamic ID)
- {
- return SyncRead(db => db.GetById(ID));
- }
-
- public virtual TEntity GetModel(Expression> where)
- {
- try
- {
- return SyncRead(db => db.Queryable().Where(where).First()); //db.GetSingle(where));
- // GetSingle结果不能大于1
- }
- catch (Exception ex)
- {
-
- isHaveErr = true;
- ErrMsg = ex.Message;
-
- return null;
-
- }
- }
-
-
- public virtual int Add(TEntity model)
- {
- try
- {
- return SyncCUD(db => db.Insertable(model).ExecuteCommand());
- }
- catch (Exception ex)
- {
- isHaveErr = true;
- ErrMsg = ex.Message;
- return 0;
- }
- }
-
-
- public virtual int AddAndReturnIndex(TEntity model)
- {
- try
- {
- return SyncCUD(db => db.Insertable(model).ExecuteReturnIdentity());
- }
- catch (Exception ex)
- {
- isHaveErr = true;
- ErrMsg = ex.Message;
- return 0;
- }
- }
-
-
- public virtual bool Exist(Expression> where)
- {
- try
- {
- return SyncRead(db => db.Queryable().Where(where).Take(1).Any());
- }
- catch (Exception ex)
- {
- isHaveErr = true;
- ErrMsg = ex.Message;
- return false;
- }
- }
-
-
- public int AddOrUpdate(TEntity model, string keyValue)
- {
- if (keyValue == "")
- {
- try
- {
- return SyncCUD(db => db.Insertable(model).ExecuteCommand());
- }
- catch (Exception ex)
- {
- isHaveErr = true;
- ErrMsg = ex.Message;
- return 0;
- }
- }
- return SyncCUD(db => db.Updateable(model).ExecuteCommand());
- }
-
-
- public virtual int Update(TEntity model)
- {
- return SyncCUD(db => db.Updateable(model).ExecuteCommand());
- }
-
-
- public virtual int UpdateColumns(TEntity model, Expression> expression)
- {
- //DatabaseSync.StartcaControls();
- try
- {
- return SyncCUD(db => db.Updateable(model).UpdateColumns(expression).ExecuteCommand());
- }
- catch (Exception ex)
- {
- isHaveErr = true;
- ErrMsg = ex.Message;
- return 0;
- }
- }
-
-
- public virtual bool DeleteByID(dynamic ID)
- {
-
- //SyncCUD(db => db.Updateable().RemoveDataCache().ExecuteCommand());
- return SyncSimpleCUD(db => (bool)db.DeleteById(ID));
- }
-
-
- public virtual bool Delete(Expression> where)
- {
- return SyncSimpleCUD(db => db.Delete(where));
- }
-
-
-
- public virtual string GetPageList(Pagination pagination, Expression> where = null)
-
- {
- //DatabaseSync.StartcaControls();
- return new
- {
- rows = GetList(pagination, where),
- total = pagination.total,
- page = pagination.page,
- records = pagination.records
- }.ToJson();
- }
-
-
- public virtual TEntity GetSingle(Expression> expression)
- {
- //DatabaseSync.StartcaControls();
- return SyncRead(db => db.Queryable().Filter(filterName, isDisabledGobalFilter: true).Single(expression));
- }
-
-
-
- public virtual List GetTop(int Top, Expression> expression, OrderByType _OrderByType = OrderByType.Asc, Expression> where = null, string selstr = "*")
-
- {
- return SyncRead(db => db.Queryable().Select(selstr).WhereIF(where != null, where)
- .Take(Top)
- .OrderBy(expression, _OrderByType)
- .Filter(filterName, isDisabledGobalFilter: true)
- .ToList());
- }
-
- ///
- /// 排序表达式所用的键,排序方式,搜索条件
- ///
- ///
- ///
- ///
- ///
-
- public virtual TEntity GetFirst(Expression> OrderExpression, OrderByType _OrderByType = OrderByType.Asc, Expression> where = null)
-
- {
- return SyncRead(db => db.Queryable().Filter(filterName, isDisabledGobalFilter: true).WhereIF(where != null, where)
- .OrderBy(OrderExpression, _OrderByType)
- .First());
- }
-
-
- public virtual List GetList(Pagination pagination, Expression> where = null)
-
- {
- int totalNumber = 0;
- List result = SyncRead(db => db.Queryable().WhereIF(where != null, where).OrderBy(pagination.sidx + " " + pagination.sord)
- .Filter(filterName, isDisabledGobalFilter: true)
- .ToPageList(pagination.page, pagination.rows, ref totalNumber));
- pagination.records = totalNumber;
- return result;
- }
-
-
-
- public virtual List GetList(Expression> where = null)
-
- {
- return SyncRead(db => db.Queryable().WhereIF(where != null, where).Filter(filterName, isDisabledGobalFilter: true)
- .ToList());
- }
-
- public virtual List GetList()
- {
- return SyncRead(db => db.Queryable().ToList());
- }
-
-
-
-
- public virtual DataTable GetDataTable(Expression> where = null, Pagination pagination = null)
-
-
- {
- if (pagination != null)
- {
- return DataHelper.ListToDataTable(GetList(pagination, where));
- }
- return DataHelper.ListToDataTable(GetList(where));
- }
-
- public virtual void UseFilter(SqlFilterItem item)
- {
- SyncCUD(db =>
- {
- db.QueryFilter.Remove(item.FilterName);
- db.QueryFilter.Add(item);
- return 0;
- });
- filterName = item.FilterName;
- }
-
-
- public virtual void ClearFilter()
- {
- SyncCUD(db =>
- {
- db.QueryFilter.Clear();
- return 0;
- });
-
-
- filterName = null;
-
- }
-
-
-
-
-
-
-
-
- /* public void ReSetConnStr(string constr, SqlSugar.DbType _dbtype)
- {
- db = DBHelper.CreateDB(constr, _dbtype);
- Sclient = db.GetSimpleClient();
- }
-
-
- public virtual TEntity GetModelByID(dynamic ID)
- {
- return Sclient.GetById(ID);
- }
-
-
- public virtual TEntity GetModel(Expression> where)
- {
- try
- {
- return Sclient.GetSingle(where);
- }
- catch (Exception ex)
- {
- isHaveErr = true;
- ErrMsg = ex.Message;
- return null;
- }
- }
-
-
- public virtual int Add(TEntity model)
- {
- try
- {
- return db.Insertable(model).ExecuteCommand();
- }
- catch (Exception ex)
- {
- isHaveErr = true;
- ErrMsg = ex.Message;
- return 0;
- }
- }
-
-
- public virtual int AddAndReturnIndex(TEntity model)
- {
- try
- {
- return db.Insertable(model).ExecuteReturnIdentity();
- }
- catch (Exception ex)
- {
- isHaveErr = true;
- ErrMsg = ex.Message;
- return 0;
- }
- }
-
-
- public virtual bool Exist(Expression> where)
- {
- return db.Queryable().Where(where).Take(1).Any();
- }
-
-
- public int AddOrUpdate(TEntity model, string Keyvale)
- {
- if (Keyvale == "")
- {
- return db.Insertable(model).ExecuteCommand();
- }
- return db.Updateable(model).ExecuteCommand();
- }
-
-
- public virtual int Update(TEntity model)
- {
- return db.Updateable(model).ExecuteCommand();
- }
-
-
- public virtual int UpdateColumns(TEntity model, Expression> expression)
- {
- return db.Updateable(model).UpdateColumns(expression).ExecuteCommand();
- }
-
-
- public virtual bool DeleteByID(dynamic ID)
- {
- db.Updateable().RemoveDataCache().ExecuteCommand();
- return Sclient.DeleteById(ID);
- }
-
-
- public virtual bool Delete(Expression> where)
- {
- return Sclient.Delete(where);
- }
-
-
- public virtual string GetPageList(Pagination pagination, Expression> where = null)
- {
- return new
- {
- rows = GetList(pagination, where),
- total = pagination.total,
- page = pagination.page,
- records = pagination.records
- }.ToJson();
- }
-
-
- public virtual TEntity GetSingle(Expression> expression)
- {
- return db.Queryable().Filter(filterName, isDisabledGobalFilter: true).Single(expression);
- }
-
-
- public virtual List GetTop(int Top, Expression> expression, OrderByType _OrderByType = OrderByType.Asc, Expression> where = null, string selstr = "*")
- {
- return db.Queryable().Select(selstr).WhereIF(where != null, where)
- .Take(Top)
- .OrderBy(expression, _OrderByType)
- .Filter(filterName, isDisabledGobalFilter: true)
- .ToList();
- }
-
-
- public virtual TEntity GetFirst(Expression> OrderExpression, OrderByType _OrderByType = OrderByType.Asc, Expression> where = null)
- {
- return db.Queryable().Filter(filterName, isDisabledGobalFilter: true).WhereIF(where != null, where)
- .OrderBy(OrderExpression, _OrderByType)
- .First();
- }
-
- public virtual List GetList(Pagination pagination, Expression> where = null)
- {
- int totalNumber = 0;
- List result = db.Queryable().WhereIF(where != null, where).OrderBy(pagination.sidx + " " + pagination.sord)
- .Filter(filterName, isDisabledGobalFilter: true)
- .ToPageList(pagination.page, pagination.rows, ref totalNumber);
- pagination.records = totalNumber;
- return result;
- }
-
-
- public virtual List GetList(Expression> where = null)
- {
- return db.Queryable().WhereIF(where != null, where).Filter(filterName, isDisabledGobalFilter: true)
- .ToList();
- }
-
- public virtual List GetList()
- {
- return db.Queryable().ToList();
- }
-
-
- public virtual DataTable GetDataTable(Expression> where = null, Pagination pagination = null)
- {
- if (pagination != null)
- {
- return DataHelper.ListToDataTable(GetList(pagination, where));
- }
- return DataHelper.ListToDataTable(GetList(where));
- }
-
- public virtual void UseFilter(SqlFilterItem item)
- {
- db.QueryFilter.Remove(item.FilterName);
- db.QueryFilter.Add(item);
- filterName = item.FilterName;
- }
-
-
- public virtual void ClearFilter()
- {
- db.QueryFilter.Clear();
- filterName = null;
- }
-
- public void BeginTran()
- {
- db.Ado.BeginTran();
- }
-
- public void CommitTran()
- {
- db.Ado.CommitTran();
- }
-
- public void RollbackTran()
- {
- db.Ado.RollbackTran();
- }*/
- }
- public class Pagination
- {
- ///
- /// 每页行数
- ///
- public int rows { get; set; }
-
- ///
- /// 当前页
- ///
- public int page { get; set; }
-
- ///
- /// /排序列
- ///
-
- public string sidx { get; set; }
-
-
- ///
- /// 排序类型
- ///
-
- public string sord { get; set; }
-
-
- ///
- /// 总记录数
- ///
- public int records { get; set; }
-
- ///
- /// 总页数
- ///
- public int total
- {
- get
- {
- if (records > 0)
- {
- if (records % rows != 0)
- {
- return records / rows + 1;
- }
-
- return records / rows;
- }
- return 0;
- }
- }
- }
-
-
-}
diff --git a/Library.Core/Serein.Library.Core.csproj b/Library.Core/Serein.Library.Core.csproj
deleted file mode 100644
index 0658f6b..0000000
--- a/Library.Core/Serein.Library.Core.csproj
+++ /dev/null
@@ -1,68 +0,0 @@
-
-
-
- 1.0.16
- net8.0
- enable
- enable
- D:\Project\C#\DynamicControl\SereinFlow\.Output
- Library
- True
- SereinFow
- Net8运行时需要添加的依赖
- README.md
- https://github.com/fhhyyp/serein-flow
- MIT
- True
- true
- latest
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- True
- \
-
-
- True
- \
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/Library.Framework/DynamicContext.cs b/Library.Framework/DynamicContext.cs
deleted file mode 100644
index 5ff508d..0000000
--- a/Library.Framework/DynamicContext.cs
+++ /dev/null
@@ -1,188 +0,0 @@
-using Serein.Library.Api;
-using System;
-using System.Collections.Concurrent;
-using System.Collections.Generic;
-
-namespace Serein.Library.Framework.NodeFlow
-{
-
-
- ///
- /// 动态流程上下文
- ///
- public class DynamicContext : IDynamicContext
- {
- public DynamicContext(/*ISereinIOC sereinIoc,*/ IFlowEnvironment flowEnvironment)
- {
- // SereinIoc = sereinIoc;
- Env = flowEnvironment;
- RunState = RunState.Running;
- }
-
- private readonly string _guid = global::System.Guid.NewGuid().ToString();
- string IDynamicContext.Guid => _guid;
-
- ///
- /// 运行环境
- ///
- public IFlowEnvironment Env { get; }
-
- ///
- /// 运行状态
- ///
- public RunState RunState { get; set; } = RunState.NoStart;
-
- ///
- /// 用来在当前流程上下文间传递数据
- ///
- //public Dictionary ContextShareData { get; } = new Dictionary();
- public object Tag { get; set; }
-
- ///
- /// 当前节点执行完成后,设置该属性,让运行环境判断接下来要执行哪个分支的节点。
- ///
- public ConnectionInvokeType NextOrientation { get; set; }
-
- ///
- /// 运行时异常信息
- ///
- public Exception ExceptionOfRuning { get; set; }
-
- ///
- /// 每个上下文分别存放节点的当前数据
- ///
- private readonly ConcurrentDictionary dictNodeFlowData = new ConcurrentDictionary();
-
- private readonly ConcurrentDictionary dictPreviousNodes = new ConcurrentDictionary();
-
- ///
- /// 设置运行时上一节点
- ///
- /// 当前节点
- /// 上一节点
- public void SetPreviousNode(NodeModelBase currentNodeModel, NodeModelBase PreviousNode)
- {
- dictPreviousNodes.AddOrUpdate(currentNodeModel, (n1) => PreviousNode, (n1, n2) => PreviousNode);
- }
-
- ///
- /// 获取当前节点的运行时上一节点
- ///
- ///
- ///
- public NodeModelBase GetPreviousNode(NodeModelBase currentNodeModel)
- {
- if (dictPreviousNodes.TryGetValue(currentNodeModel, out var node))
- {
- return node;
- }
- else
- {
- return null;
- }
- }
-
- ///
- /// 获取节点当前数据
- ///
- ///
- public object GetFlowData(string nodeGuid)
- {
- if (dictNodeFlowData.TryGetValue(nodeGuid, out var data))
- {
- return data;
- }
- else
- {
- return null;
- }
- }
-
- ///
- /// 添加或更新当前节点数据
- ///
- /// 节点
- /// 新的数据
- public void AddOrUpdate(string nodeGuid, object flowData)
- {
- // this.dictNodeFlowData.TryGetValue(nodeGuid, out var oldFlowData);
- this.dictNodeFlowData.AddOrUpdate(nodeGuid, n1 => flowData, (n1, n2)=> flowData);
- }
-
- ///
- /// 上一节点数据透传到下一节点
- ///
- ///
- public object TransmissionData(NodeModelBase nodeModel)
- {
- if (dictPreviousNodes.TryGetValue(nodeModel, out var previousNode)) // 首先获取当前节点的上一节点
- {
- if (dictNodeFlowData.TryGetValue(previousNode.Guid, out var data)) // 其次获取上一节点的数据
- {
- return data;
- //AddOrUpdate(nodeModel.Guid, data); // 然后作为当前节点的数据记录在上下文中
- }
- }
- return null;
- }
-
-
- ///
- /// 结束流程
- ///
- public void Exit()
- {
- foreach (var nodeObj in dictNodeFlowData.Values)
- {
- if (nodeObj is null)
- {
- continue;
- }
- else
- {
- if (typeof(IDisposable).IsAssignableFrom(nodeObj?.GetType()) && nodeObj is IDisposable disposable)
- {
- disposable?.Dispose();
- }
- }
- }
-
- if (Tag != null && typeof(IDisposable).IsAssignableFrom(Tag?.GetType()) && Tag is IDisposable tagDisposable)
- {
- tagDisposable?.Dispose();
- }
- this.Tag = null;
- this.dictNodeFlowData?.Clear();
- RunState = RunState.Completion;
- }
- // public NodeRunCts NodeRunCts { get; set; }
- // public ISereinIOC SereinIoc { get; }
- //public Task CreateTimingTask(Action action, int time = 100, int count = -1)
- //{
- // if(NodeRunCts == null)
- // {
- // NodeRunCts = Env.IOC.Get();
- // }
- // // 使用局部变量,避免捕获外部的 `action`
- // Action localAction = action;
-
- // return Task.Run(async () =>
- // {
- // for (int i = 0; i < count && !NodeRunCts.IsCancellationRequested; i++)
- // {
- // await Task.Delay(time);
- // if (NodeRunCts.IsCancellationRequested) { break; }
- // //if (FlowEnvironment.IsGlobalInterrupt)
- // //{
- // // await FlowEnvironment.GetOrCreateGlobalInterruptAsync();
- // //}
- // // 确保对局部变量的引用
- // localAction?.Invoke();
- // }
-
- // // 清理引用,避免闭包导致的内存泄漏
- // localAction = null;
- // });
- //}
- }
-}
diff --git a/Library.Framework/FlipflopContext.cs b/Library.Framework/FlipflopContext.cs
deleted file mode 100644
index c4a9e2c..0000000
--- a/Library.Framework/FlipflopContext.cs
+++ /dev/null
@@ -1,83 +0,0 @@
-using Serein.Library.Api;
-using Serein.Library.Utils;
-using System;
-using System.Threading.Tasks;
-
-namespace Serein.Library.Framework.NodeFlow
-{
- public static class FlipflopFunc
- {
- ///
- /// 传入触发器方法的返回类型,尝试获取Task[Flipflop[]] 中的泛型类型
- ///
- //public static Type GetFlipflopInnerType(Type type)
- //{
- // // 检查是否为泛型类型且为 Task<>
- // if (type.IsGenericType && type.GetGenericTypeDefinition() == typeof(Task<>))
- // {
- // // 获取 Task<> 的泛型参数类型,即 Flipflop<>
- // var innerType = type.GetGenericArguments()[0];
-
- // // 检查泛型参数是否为 Flipflop<>
- // if (innerType.IsGenericType && innerType.GetGenericTypeDefinition() == typeof(FlipflopContext<>))
- // {
- // // 获取 Flipflop<> 的泛型参数类型,即 T
- // var flipflopInnerType = innerType.GetGenericArguments()[0];
-
- // // 返回 Flipflop<> 中的具体类型
- // return flipflopInnerType;
- // }
- // }
- // // 如果不符合条件,返回 null
- // return null;
- //}
-
- public static bool IsTaskOfFlipflop(Type type)
- {
- // 检查是否为泛型类型且为 Task<>
- if (type.IsGenericType && type.GetGenericTypeDefinition() == typeof(Task<>))
- {
- // 获取 Task<> 的泛型参数类型
- var innerType = type.GetGenericArguments()[0];
- if (innerType.IsGenericType && type.GetGenericTypeDefinition() == typeof(IFlipflopContext<>))
- {
- var flipflop = type.GetGenericArguments()[0];
- return true;
- }
-
- //// 检查泛型参数是否为 Flipflop<>
- //if (innerType == typeof(FlipflopContext))
- ////if (innerType.IsGenericType && innerType.GetGenericTypeDefinition() == typeof(FlipflopContext<>))
- //{
- // return true;
- //}
- }
-
- return false;
- }
- }
-
- ///
- /// 触发器上下文
- ///
- public class FlipflopContext : IFlipflopContext
- {
- public FlipflopStateType State { get; set; }
-
- public TriggerDescription Type { get; set; }
- public TResult Value { get; set; }
-
- public FlipflopContext(FlipflopStateType ffState)
- {
- State = ffState;
- }
-
- public FlipflopContext(FlipflopStateType ffState, TResult value)
- {
- State = ffState;
- Value = value;
- }
- }
-
-
-}
diff --git a/Library.Framework/Properties/AssemblyInfo.cs b/Library.Framework/Properties/AssemblyInfo.cs
deleted file mode 100644
index c3ce276..0000000
--- a/Library.Framework/Properties/AssemblyInfo.cs
+++ /dev/null
@@ -1,38 +0,0 @@
-using System.Resources;
-using System.Reflection;
-using System.Runtime.CompilerServices;
-using System.Runtime.InteropServices;
-
-// 有关程序集的一般信息由以下
-// 控制。更改这些特性值可修改
-// 与程序集关联的信息。
-[assembly: AssemblyTitle("Serein.Library.Framework")]
-[assembly: AssemblyDescription("")]
-[assembly: AssemblyConfiguration("")]
-[assembly: AssemblyCompany("")]
-[assembly: AssemblyProduct("Serein.Library.Framework")]
-[assembly: AssemblyCopyright("Copyright © 2024")]
-[assembly: AssemblyTrademark("")]
-[assembly: AssemblyCulture("")]
-
-// 将 ComVisible 设置为 false 会使此程序集中的类型
-//对 COM 组件不可见。如果需要从 COM 访问此程序集中的类型
-//请将此类型的 ComVisible 特性设置为 true。
-[assembly: ComVisible(false)]
-
-// 如果此项目向 COM 公开,则下列 GUID 用于类型库的 ID
-[assembly: Guid("73b272e8-222d-4d08-a030-f1e1db70b9d1")]
-
-// 程序集的版本信息由下列四个值组成:
-//
-// 主版本
-// 次版本
-// 生成号
-// 修订号
-//
-//可以指定所有这些值,也可以使用“生成号”和“修订号”的默认值
-//通过使用 "*",如下所示:
-// [assembly: AssemblyVersion("1.0.*")]
-[assembly: AssemblyVersion("1.0.1.4")]
-[assembly: AssemblyFileVersion("1.0.1.5")]
-[assembly: NeutralResourcesLanguage("")]
diff --git a/Library.Framework/Serein.Library.Framework.csproj b/Library.Framework/Serein.Library.Framework.csproj
deleted file mode 100644
index 332ba9c..0000000
--- a/Library.Framework/Serein.Library.Framework.csproj
+++ /dev/null
@@ -1,67 +0,0 @@
-
-
-
-
- Debug
- AnyCPU
- {73B272E8-222D-4D08-A030-F1E1DB70B9D1}
- Library
- Properties
- Serein.Library.Framework
- Serein.Library.Framework
- v4.6.2
- 512
- true
-
-
-
- true
- full
- false
- ..\.Output\Debug\librarynet462\
- DEBUG;TRACE
- prompt
- 4
-
-
- pdbonly
- true
- ..\.Output\Release\librarynet462\
- TRACE
- prompt
- 4
- ..\.Output\Release\librarynet462\Serein.Library.Framework.xml
-
-
-
- ..\packages\Newtonsoft.Json.13.0.3\lib\net45\Newtonsoft.Json.dll
-
-
-
-
- ..\packages\System.ValueTuple.4.5.0\lib\net461\System.ValueTuple.dll
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- {5e19d0f2-913a-4d1c-a6f8-1e1227baa0e3}
- Serein.Library
-
-
-
-
\ No newline at end of file
diff --git a/Library.Framework/packages.config b/Library.Framework/packages.config
deleted file mode 100644
index c34824f..0000000
--- a/Library.Framework/packages.config
+++ /dev/null
@@ -1,5 +0,0 @@
-
-
-
-
-
\ No newline at end of file
diff --git a/Library/Api/IFlowEnvironment.cs b/Library/Api/IFlowEnvironment.cs
index 84f6091..43e404f 100644
--- a/Library/Api/IFlowEnvironment.cs
+++ b/Library/Api/IFlowEnvironment.cs
@@ -710,7 +710,6 @@ namespace Serein.Library.Api
///
void WriteLine(InfoType type, string message, InfoClass @class = InfoClass.Trivial);
-
///
/// 加载项目文件
///
@@ -960,6 +959,11 @@ namespace Serein.Library.Api
///
bool TryGetDelegateDetails(string assemblyName, string methodName, out DelegateDetails del);
+ ///
+ /// 提供设置UI上下文的能力
+ ///
+ ///
+ void SetUIContextOperation(UIContextOperation uiContextOperation);
///
/// 开始运行
diff --git a/Library/Enums/NodeType.cs b/Library/Enums/NodeType.cs
index 90f211e..fdd5047 100644
--- a/Library/Enums/NodeType.cs
+++ b/Library/Enums/NodeType.cs
@@ -12,6 +12,7 @@ namespace Serein.Library
///
public enum NodeType
{
+
///
/// 初始化,流程启动时执行(不生成节点)
/// 可以异步等待
@@ -28,6 +29,7 @@ namespace Serein.Library
///
Exit,
+
///
/// 触发器节点,必须为标记在可异步等待的方法,建议与继承了 FlowTriggerk<TEnum> 的实例对象搭配使用
/// 方法返回值必须为Task<IFlipflopContext<TResult>>,若为其它返回值,将不会创建节点。
diff --git a/Library/FlowNode/ContainerFlowEnvironment.cs b/Library/FlowNode/ContainerFlowEnvironment.cs
new file mode 100644
index 0000000..840b7ac
--- /dev/null
+++ b/Library/FlowNode/ContainerFlowEnvironment.cs
@@ -0,0 +1,384 @@
+using Serein.Library.Api;
+using Serein.Library.Utils;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace Serein.Library
+{
+
+ ///
+ /// 不提供流程操作能力,仅提供容器功能
+ ///
+
+ public class ContainerFlowEnvironment : IFlowEnvironment, ISereinIOC
+ {
+ ///
+ /// 本地运行环境缓存的持久化实例
+ ///
+ private Dictionary PersistennceInstance { get; } = new Dictionary();
+ public ContainerFlowEnvironment()
+ {
+
+ }
+
+ private ISereinIOC sereinIOC => this;
+ public ISereinIOC IOC => sereinIOC;
+
+ public string EnvName => throw new NotImplementedException();
+
+ public bool IsGlobalInterrupt => throw new NotImplementedException();
+
+ public bool IsControlRemoteEnv => throw new NotImplementedException();
+
+ public InfoClass InfoClass { get => throw new NotImplementedException(); set => throw new NotImplementedException(); }
+ public RunState FlowState { get => throw new NotImplementedException(); set => throw new NotImplementedException(); }
+ public RunState FlipFlopState { get => throw new NotImplementedException(); set => throw new NotImplementedException(); }
+
+ public IFlowEnvironment CurrentEnv => this;
+
+ public UIContextOperation UIContextOperation { get; set; }
+
+ ///
+ /// 设置在UI线程操作的线程上下文
+ ///
+ ///
+ public void SetUIContextOperation(UIContextOperation uiContextOperation)
+ {
+ this.UIContextOperation = uiContextOperation;
+ }
+
+ public void ActivateFlipflopNode(string nodeGuid)
+ {
+ throw new NotImplementedException();
+ }
+
+ public Task ChangeParameter(string nodeGuid, bool isAdd, int paramIndex)
+ {
+ throw new NotImplementedException();
+ }
+
+ public Task ConnectArgSourceNodeAsync(string fromNodeGuid, string toNodeGuid, JunctionType fromNodeJunctionType, JunctionType toNodeJunctionType, ConnectionArgSourceType argSourceType, int argIndex)
+ {
+ throw new NotImplementedException();
+ }
+
+ public Task ConnectInvokeNodeAsync(string fromNodeGuid, string toNodeGuid, JunctionType fromNodeJunctionType, JunctionType toNodeJunctionType, ConnectionInvokeType invokeType)
+ {
+ throw new NotImplementedException();
+ }
+
+ public Task<(bool, RemoteMsgUtil)> ConnectRemoteEnv(string addres, int port, string token)
+ {
+ throw new NotImplementedException();
+ }
+
+ public Task CreateNodeAsync(NodeControlType nodeType, PositionOfUI position, MethodDetailsInfo methodDetailsInfo = null)
+ {
+ throw new NotImplementedException();
+ }
+
+ public Task ExitFlowAsync()
+ {
+ throw new NotImplementedException();
+ }
+
+ public void ExitRemoteEnv()
+ {
+ throw new NotImplementedException();
+ }
+
+ public Task GetEnvInfoAsync()
+ {
+ throw new NotImplementedException();
+ }
+
+ public Task GetProjectInfoAsync()
+ {
+ throw new NotImplementedException();
+ }
+
+ public Task