










public interface IT服务端 { int 端口 { get; set; } int WebApi端口 { get; set; } void 添加对象(string 对象名称, Func<M对象> 获取对象); void 删除对象(string 对象名称); void 开启(); event Action<IPEndPoint> 客户端已连接; event Action<IPEndPoint> 客户端已断开; List<IPEndPoint> 客户端列表 { get; } void 关闭(); void 触发事件(string 对象名, string 事件名, Dictionary<string, string> 实参 = null, List<IPEndPoint> 地址列表 = null); } public interface IT客户端 { IPEndPoint 设备地址 { get; } void 连接(IPEndPoint 设备地址); void 断开(); bool 连接正常 { get; } /// <summary> /// true:主动断开,false:被动断开 /// </summary> event Action<bool> 已断开; bool 自动重连 { get; set; } event Action 已连接; M对象列表查询结果 查询可访问对象(); M对象明细查询结果 查询对象明细(string 对象名称); string 查询属性值(string 对象名, string 属性名, int 超时毫秒 = 3000); string 执行方法(string 对象名, string 方法名, Dictionary<string,string> 参数列表 = null, int 超时毫秒 = 3000); void 订阅事件(string 对象名, string 事件名, Action<Dictionary<string, string>> 处理方法); void 注销事件(string 对象名, string 事件名, Action<Dictionary<string, string>> 处理方法); /// <summary> /// 通常用于调试 /// </summary> event Action<M接收事件> 收到了事件; } public class M对象 { public string 名称 { get { return 概要.名称; } set { 概要.名称 = value; } } public string 分类 { get { return 概要.分类; } set { 概要.分类 = value; } } public E角色 角色 { get { return 概要.角色; } set { 概要.角色 = value; } } internal M对象概要 概要 { get; set; } internal M对象明细查询结果 明细 { get; set; } /// <summary> /// 字典中的键string:方法名; 值:方法; 方法中的string:返回值 /// </summary> Dictionary<string, Func<Dictionary<string, string>, string>> _所有方法 = new Dictionary<string, Func<Dictionary<string, string>, string>>(); /// <summary> /// 字典中的键string:方法名; 值:方法; 方法中的string:返回值 /// </summary> Dictionary<string, Func<Dictionary<string, string>, IPEndPoint, string>> _所有方法_带地址 = new Dictionary<string, Func<Dictionary<string, string>, IPEndPoint, string>>(); /// <summary> /// 字典中的键string:属性名; 值:属性值计算方法 /// </summary> Dictionary<string, Func<string>> _所有属性方法 = new Dictionary<string, Func<string>>(); public M对象(string __名称, string __分类) { this.概要 = new M对象概要(__名称, __分类); this.明细 = new M对象明细查询结果(); } public void 添加属性(string __名称, Func<string> __计算值, E角色 __角色 = E角色.开发, M元数据 __元数据 = null) { this.角色 = this.角色 | __角色; this.明细.属性列表.Add(new M属性(__名称, __元数据, __角色)); _所有属性方法[__名称] = __计算值; } public void 添加方法(string __名称, Func<Dictionary<string, string>, string> __执行方法, E角色 __角色 = E角色.开发, List<M形参> __参数列表 = null, M元数据 __返回值元数据 = null) { this.角色 = this.角色 | __角色; _所有方法[__名称] = __执行方法; this.明细.方法列表.Add(new M方法(__名称, __参数列表, __返回值元数据, __角色)); } public void 添加方法(string __名称, Func<Dictionary<string, string>, IPEndPoint, string> __执行方法, E角色 __角色 = E角色.开发, List<M形参> __参数列表 = null, M元数据 __返回值元数据 = null) { this.角色 = this.角色 | __角色; _所有方法_带地址[__名称] = __执行方法; this.明细.方法列表.Add(new M方法(__名称, __参数列表, __返回值元数据, __角色)); } internal string 执行方法(string __名称, Dictionary<string, string> __参数列表, IPEndPoint __来源) { if (_所有方法.ContainsKey(__名称)) { return _所有方法[__名称].Invoke(__参数列表); } if (_所有方法_带地址.ContainsKey(__名称)) { return _所有方法_带地址[__名称].Invoke(__参数列表, __来源); } throw new ApplicationException("执行方法失败: 无此方法"); } internal string 计算属性(string __属性名称) { if (_所有属性方法.ContainsKey(__属性名称)) { return _所有属性方法[__属性名称](); } throw new ApplicationException("计算属性失败: 无此属性"); } public void 添加事件(string __名称, E角色 __角色 = E角色.开发, List<M形参> __参数列表 = null) { this.角色 = this.角色 | __角色; this.明细.事件列表.Add(new M事件(__名称, __参数列表, __角色)); } }
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。