C#插件化架构(Plugin Architecture)或 可插拔架构,根据产品类型编码的不同自动路由到目标函数,而无需为每个产品都编码相应的代码!!

using HttpServer;

using MySql.Data.MySqlClient.Memcached;

using Newtonsoft.Json;

using Newtonsoft.Json.Linq;

using NPOI.SS.Formula.Functions;

using NPOI.SS.UserModel;

using Org.BouncyCastle.Bcpg;

using System;

using System.Collections;

using System.Collections.Generic;

using System.Data;

using System.Data.Entity.Core.Metadata.Edm;

using System.Diagnostics;

using System.Diagnostics.Contracts;

using System.IO;

using System.Linq;

using System.Net;

using System.Net.Sockets;

using System.Reflection;

using System.Runtime.InteropServices;

using System.Threading;

using System.Web.Http.Results;

using System.Web.Http.Tracing;

//using MySql.Data.MySqlClient.Memcached;

using static ai_light_server.adminQueryServices;

namespace ai_light_server

{

public partial class Work

{

public static string get_a_config_value_in_Codes_Dirs(string prodtype, string config_name)

{

// 获取当前程序的程序集

Assembly assembly = Assembly.GetExecutingAssembly();

Type\[\] types = assembly.GetTypes();

string ret_str = "";

foreach (Type type in types)

{

// 获取所有静态字段

FieldInfo\[\] fields = type.GetFields(BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic);

foreach (FieldInfo field in fields)

{

if (field.IsStatic) // 确保是静态字段

{

if (field.Name == "my_prodtype")

{

if (((int)field.GetValue(null)).ToString() == prodtype)

{

foreach (FieldInfo field002 in fields)

{

if (field002.Name == "class_is_a_Config")

{

if (((int)field002.GetValue(null)) == 1)

{

foreach (FieldInfo field003 in fields)

{

if (field003.Name == config_name)

{

return field003.GetValue(null).ToString();

}

}

break;

}

}

}

break;

}

}

}

}

}

return "";

}

public static void test1()

{

if (get_a_config_value_in_Codes_Dirs("33333".ToString(), "class_is_a_Config") == "1")

{

call_a_function_in_Codes_Dirs("33333".ToString(), "jiaoshi", new object\[\] { "111", new ctrl_works_item() { fail_msg="123456"} });

}

}

public static object call_a_function_in_Codes_Dirs(string prodtype, string func_name,params object\[\] parms_in)

{

// 获取当前程序的程序集

Assembly assembly = Assembly.GetExecutingAssembly();

Type\[\] types = assembly.GetTypes();

string ret_str = "";

foreach (Type type in types)

{

// 获取所有静态字段

FieldInfo\[\] fields = type.GetFields(BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic);

foreach (FieldInfo field in fields)

{

if (field.IsStatic) // 确保是静态字段

{

if (field.Name == "my_prodtype")

{

if (((int)field.GetValue(null)).ToString() == prodtype)

{

MethodInfo\[\] methods1 = type.GetMethods();

foreach (MethodInfo method1 in methods1)

{

if(method1.Name== func_name)

{

if (method1.IsStatic)

{

return method1.Invoke(null,parms_in);

}

else

{

object instance1 = Activator.CreateInstance(type,null);

return method1.Invoke(instance1, parms_in);

}

}

}

}

}

}

}

}

return null;

}

static void get_all_class_names()

{

// 获取当前程序的程序集

Assembly assembly = Assembly.GetExecutingAssembly();

Type\[\] types = assembly.GetTypes();

string classnames = "========================================================================\r\n";

foreach (Type type in types)

{

// classnames += (type.FullName + "\r\n");

// 获取所有静态字段

FieldInfo\[\] fields = type.GetFields(BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic);

foreach (FieldInfo field in fields)

{

if (field.IsStatic) // 确保是静态字段

{

if(field.Name== "my_prodtype")

{

classnames += (type.FullName + "\r\n");

if ((int)field.GetValue(null) == 33333)

{

classnames += ("----------------------------------\r\n");

classnames += ( "my_prodtype==33333\r\n");

classnames += ("----------------------------------\r\n");

}

}

}

}

}

tools1.fvdou_append_error_to_log_txtH("classnames", classnames);

}

}

}

==========================================================

using HttpServer;

using Newtonsoft.Json;

using Newtonsoft.Json.Linq;

using NPOI;

using NPOI.HSSF.Model;

using NPOI.HSSF.UserModel;

using NPOI.HSSF.UserModel;

using NPOI.HSSF.Util;

using NPOI.POIFS.Crypt.Dsig;

using NPOI.SS.Formula.Functions;

using NPOI.SS.UserModel;

using NPOI.XSSF.UserModel;

using NPOI.XWPF.UserModel;

using System;

using System.Collections;

using System.Collections.Generic;

using System.Data;

using System.Diagnostics;

using System.IO;

using System.Linq;

using System.Runtime.Serialization;

using System.ServiceModel;

using System.ServiceModel.Activation;

using System.ServiceModel.Web;

using System.Text;

using System.Threading;

using System.Web.UI.WebControls;

using static ai_light_server.adminQueryServices;

namespace ai_light_server

{

public class lib_1_33333

{

public static int my_prodtype = 33333;

public static string jiaoshi(string netgate_id, ctrl_works_item cur_task, byte mod_addr) //返回1=ok,返回0=超时,返回-1=网关不在线

{

return Work.jiaoshi_comm1(netgate_id, cur_task, mod_addr);

}

public static string ctrl_mod(string Name1, int switch_ctrl_enable,int tiaoguang_ctrl_enable,string netgate_id, ctrl_works_item cur_task, byte mod_addr,int wait_time_ms_1,int is_changjing_cmd_优先于面板主动发包) //返回1=ok,返回0=超时,返回-1=网关不在线

{

return Work.ctrl_mod_comm(Name1, switch_ctrl_enable, tiaoguang_ctrl_enable, netgate_id, cur_task, mod_addr, wait_time_ms_1, is_changjing_cmd_优先于面板主动发包);

}

}

}

======================================================

using HttpServer;

using Newtonsoft.Json;

using Newtonsoft.Json.Linq;

using NPOI;

using NPOI.HSSF.Model;

using NPOI.HSSF.UserModel;

using NPOI.HSSF.UserModel;

using NPOI.HSSF.Util;

using NPOI.POIFS.Crypt.Dsig;

using NPOI.SS.Formula.Functions;

using NPOI.SS.UserModel;

using NPOI.XSSF.UserModel;

using NPOI.XWPF.UserModel;

using System;

using System.Collections;

using System.Collections.Generic;

using System.Data;

using System.Diagnostics;

using System.IO;

using System.Linq;

using System.Runtime.Serialization;

using System.ServiceModel;

using System.ServiceModel.Activation;

using System.ServiceModel.Web;

using System.Text;

using System.Threading;

using System.Web.UI.WebControls;

using static ai_light_server.adminQueryServices;

namespace ai_light_server

{

public class lib_1_config_33333

{

public static int my_prodtype = 33333 ;

public static int class_is_a_Config = 1;

public static string is_can_Mod_Jiaoshi = "1";

public static string is_a_light_ctrl_Mod = "1";

}

}

==============================================

int prodtype = int.Parse(rttb1_1_tiaoguangs.Rowsy"prodtype".ToString());

int huilu_num = int.Parse(rttb1_1_tiaoguangs.Rowsy"huilu_num".ToString());

byte mod_addr = byte.Parse(rttb1_1_tiaoguangs.Rowsy"modbus_addr".ToString());

string Name1 = rttb1_1_tiaoguangs.Rowsy"Name".ToString();

online_state_info drv1 = adminQueryServices.get_drv(rttb1_1_tiaoguangs.Rowsy"id_str".ToString());

int wait_time_ms_1 = 6000;

if (drv1 != null)

{

if (drv1.is_online == -1 || drv1.is_online == 1)

{

wait_time_ms_1 = 8000;

}

else

{

wait_time_ms_1 = 3000;

}

}

Ext_prodtype_list_info extprodtype1 = Work.ref_this.Get_prod_type_info_by_prodtype1(prodtype.ToString());

if (extprodtype1 != null && extprodtype1.V2_JiaGou_Ver == 2)

{

if (get_a_config_value_in_Codes_Dirs(prodtype.ToString(), "is_a_light_ctrl_Mod") != "1")

{

if (Work.G_use_chs_0_or_english_1 == 0)

cur_task.works_msg += "" + Name1 + "mod无法控制...\n<br>";

if (Work.G_use_chs_0_or_english_1 == 1)

cur_task.works_msg += "" + Name1 + "mod is not a ctrl_able mod ...\n<br>";

}

else

{

string is_ok = call_a_function_in_Codes_Dirs(prodtype.ToString(), "ctrl_mod", new object\[\] {Name1, switch_ctrl_enable, tiaoguang_ctrl_enable, item11netgate, cur_task, mod_addr, wait_time_ms_1, is_changjing_cmd_优先于面板主动发包 }).ToString();

/*

if (is_ok == "0" || is_ok == "-1")

{

if (is_ok == "0")

{

if (Work.G_use_chs_0_or_english_1 == 0)

cur_task.works_msg += "校时" + Name1 + "mod时无返回数据...\n<br>";

if (Work.G_use_chs_0_or_english_1 == 1)

cur_task.works_msg += "time calibration for " + Name1 + "mod, No data return ...\n<br>";

}

else

{

if (Work.G_use_chs_0_or_english_1 == 0)

cur_task.works_msg += "" + item11netgate + "网关不在线...\n<br>";

if (Work.G_use_chs_0_or_english_1 == 1)

cur_task.works_msg += "" + item11netgate + "gateway not online...\n<br>";

}

}

else

{

if (Work.G_use_chs_0_or_english_1 == 0)

cur_task.works_msg += "控制" + Name1 + "mod时ok...\n<br>";

if (Work.G_use_chs_0_or_english_1 == 1)

cur_task.works_msg += "ctrl for " + Name1 + "mod ok! ...\n<br>";

}*/

}

}

相关推荐
牛哇网络工作室3 小时前
UnityHDRP写实数字人全流程基础5—语音输入和语音识别
android·unity·c#·游戏引擎·aigc·语音识别·xcode
资源大佬星 课it7 小时前
升级版,重学C++,重构你的C++知识体系资源下载
重构
zlinear数据采集卡14 小时前
数据采集卡从入门到精通(9):分辨率与精度——16位卡不等于1/65536的精度
开发语言·数据库·fpga开发·开源·c#
深澈Vincel16 小时前
我用 C# + WebView2 做了一个针对“流氓软件”的“一键清理工具“:架构实践与踩坑记录
c#
zlinear数据采集卡17 小时前
数据采集卡从入门到精通(7):流水线型ADC——级级接力,高速与高精的平衡术
开发语言·arm开发·嵌入式硬件·fpga开发·c#
kingwebo'sZone18 小时前
C# 根据公式计算的方法
开发语言·c#
阿部多瑞 ABU19 小时前
告别手工核图:基于 .NET + MuPDFCore 的 CAD 等轴测 PDF 材料表提取与新旧版本对比实战
后端·算法·ui·pdf·c#
条形码D19 小时前
DRG综合管理分析系统-目前已经支持CHS-DRG3.0
c#·drg·3.0分组器·drg分组器·chs-drg3.0分组器
百胜软件@百胜软件1 天前
从“人找货”到“货找人”:「胜券商品」如何用AI重构配补调
人工智能·重构
Alex Gram2 天前
数据库同步工具PanguSync图文教程
java·mysql·postgresql·sqlserver·c#·数据库同步软件·数据库同步工具