using Serein.Library;
using Serein.Library.Api;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
namespace Serein.NodeFlow.Tool
{
internal class ToCSharpCodeHelper
{
///
/// 运行环境
///
private readonly IFlowEnvironment env;
///
/// 环境中已加载的所有节点
///
private readonly List nodes;
///
/// 获取流程启动时在不同时间点需要自动实例化的类型
///
private readonly Dictionary> autoRegisterTypes;
///
/// 初始化方法
///
private readonly List initMethods;
///
/// 加载时方法
///
private readonly List loadingMethods;
///
/// 结束时方法
///
private readonly List exitMethods;
///
/// 开始运行(需要准备好方法信息)
///
/// 运行环境
/// 环境中已加载的所有节点
/// 获取流程启动时在不同时间点需要自动实例化的类型
/// 初始化方法
/// 加载时方法
/// 结束时方法
///
public ToCSharpCodeHelper(IFlowEnvironment env,
List nodes,
Dictionary> autoRegisterTypes,
List initMethods,
List loadingMethods,
List exitMethods)
{
this.env = env;
this.nodes = nodes;
this.autoRegisterTypes = autoRegisterTypes;
this.initMethods = initMethods;
this.loadingMethods = loadingMethods;
this.exitMethods = exitMethods;
}
public string ToCode()
{
StringBuilder sb = new StringBuilder();
// 确认命名空间
sb.AppendLine($"using System;");
sb.AppendLine($"using System.Linq;");
sb.AppendLine($"using System.Threading;");
sb.AppendLine($"using System.Threading.Tasks;");
sb.AppendLine($"using System.Collections.Concurrent;");
sb.AppendLine($"using System.Collections.Generic;");
sb.AppendLine($"using Serein.Library;");
sb.AppendLine($"using Serein.Library.Api;");
sb.AppendLine($"using Serein.NodeFlow;");
sb.AppendLine(
"""
using System;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using System.Collections.Concurrent;
using System.Collections.Generic;
using Serein.Library;
using Serein.Library.Api;
using Serein.NodeFlow;
// 这里添加引用
namespace NodeToCode
{
class Program
{
private readonly IFlowEnvironment env; // 流程运行环境
""" +
DefineVariableCode() + // 这里定义变量
"""
public void Main(string[] args)
{
""" +
MainOfCSharpCode() + // 这里初始化运行环境
"""
}
""" +
BusinessOfCSharpCode() + // 流程逻辑代码
"""
}
}
"""
);
//sb.AppendLine($"public {returnType} {methodName}({parmasStr})");
//sb.AppendLine($"{{");
//sb.AppendLine($"}}");
return "";
}
public void Main(string[] args) {
var plcLoginControl = ioc.Get();
var networkLoginControl = ioc.Get();
if(nodeModel.)
plcLoginControl.Init("", networkLoginControl.Func("",""))
foreach (var md in ffMd)
{
Execution(md);
}
plcLoginControl.Init("129.123.41.21",123);
}
public void Execution(Action action)
{
}
public object Execution(Func