public static void Delete(work_group obj) { string tsql = string.Format("delete from work_group where T1ID ={0}", obj.T1ID); //执行 db.Execute(tsql); }
public static void Save(work_group[] objs) { string tsql = string.Empty; DBSQLite.SQLite.TransactionExecute te = new DBSQLite.SQLite.TransactionExecute(Sqlite); int maxid = db.GetMaxID("work_group", "T1ID") + 1; for (int i = 0; i < objs.Length; i++) { work_group obj = objs[i]; if (obj.T1ID == 0) { //新增 obj.T1ID = maxid + i; tsql = string.Format("insert into work_group(T1ID,T1INIP,T1INPORT,T1OUTIP,T1OUTPORT,T1NAME,T1MAXNUM,T1STARTTIME,T1STOPTIME,T1SINGLEMAX) values({0},'{1}',{2},'{3}',{4},'{5}',{6},'{7}','{8}',{9})", obj.T1ID, obj.T1INIP.Replace("'", "''"), obj.T1INPORT, obj.T1OUTIP.Replace("'", "''"), obj.T1OUTPORT, obj.T1NAME.Replace("'", "''"), obj.T1MAXNUM, obj.T1STARTTIME.Replace("'", "''"), obj.T1STOPTIME.Replace("'", "''"), obj.T1SINGLEMAX); } else { tsql = string.Format("update work_group set T1ID ={0} , T1INIP ='{1}' , T1INPORT ={2} , T1OUTIP ='{3}' , T1OUTPORT ={4} , T1NAME ='{5}' , T1MAXNUM ={6} , T1STARTTIME ='{7}' , T1STOPTIME ='{8}' , T1SINGLEMAX ={9} where T1ID ={0}", obj.T1ID, obj.T1INIP.Replace("'", "''"), obj.T1INPORT, obj.T1OUTIP.Replace("'", "''"), obj.T1OUTPORT, obj.T1NAME.Replace("'", "''"), obj.T1MAXNUM, obj.T1STARTTIME.Replace("'", "''"), obj.T1STOPTIME.Replace("'", "''"), obj.T1SINGLEMAX, obj.T1ID); } //执行 te.Execute(tsql); } //提交 te.TransactionSubmit(); }
// Private Methods (8) private static List <work_group> load_maps_cfg() { string maps_cfg = ConfigurationManager.AppSettings["portmaps"]; if (string.IsNullOrEmpty(maps_cfg)) { throw new Exception("配置文件错误: 缺少PortMap配置"); } string[] tmp1 = maps_cfg.Split(new[] { ';' }, StringSplitOptions.RemoveEmptyEntries); if (tmp1.Length == 0) { throw new Exception("配置文件错误: 缺少PortMap配置"); } List <work_group> rtn = new List <work_group>(); foreach (string tmp2 in tmp1) { string[] tmp3 = tmp2.Split(new[] { '|' }); if (tmp3.Length != 2) { throw new Exception("配置文件错误: 每组PortMap配置必须为2个节点"); } work_group rtn_item = new work_group { _id = ++_id_plus }; for (int i = 0; i != 2; ++i) { string[] tmp4 = tmp3[i].Split(new[] { ':' }, StringSplitOptions.RemoveEmptyEntries); if (tmp4.Length != 2) { throw new Exception("配置文件错误: IP节点格式错误"); } IPAddress ip = IPAddress.Any; if (i == 0 && tmp4[0] != "*" && !IPAddress.TryParse(tmp4[0], out ip)) { throw new Exception("配置文件错误: IP节点格式错误"); } ushort port; if (!ushort.TryParse(tmp4[1], out port)) { throw new Exception("配置文件错误: IP节点格式错误"); } if (i == 0) { rtn_item._point_in = new IPEndPoint(ip, port); } if (i == 1) { rtn_item._point_out_host = tmp4[0]; rtn_item._point_out_port = port; } } rtn.Add(rtn_item); } return(rtn); }
public static work_group Load(int pT1ID) { string tsql = string.Format("select T1ID,T1INIP,T1INPORT,T1OUTIP,T1OUTPORT,T1NAME,T1MAXNUM,T1STARTTIME,T1STOPTIME,T1SINGLEMAX from work_group where T1ID ={0}", pT1ID); var dt = db.GetDataTable(tsql); if (dt.Rows.Count == 0) { return(null); } DataRow dr = dt.Rows[0]; work_group obj = Load(dr); return(obj); }
public static work_group Load(DataRow dr) { work_group obj = new work_group(); obj.T1ID = dr["T1ID"] != DBNull.Value ? Convert.ToInt32(dr["T1ID"]) : 0; obj.T1INIP = dr["T1INIP"] != DBNull.Value ? Convert.ToString(dr["T1INIP"]) : string.Empty; obj.T1INPORT = dr["T1INPORT"] != DBNull.Value ? Convert.ToInt32(dr["T1INPORT"]) : 0; obj.T1OUTIP = dr["T1OUTIP"] != DBNull.Value ? Convert.ToString(dr["T1OUTIP"]) : string.Empty; obj.T1OUTPORT = dr["T1OUTPORT"] != DBNull.Value ? Convert.ToInt32(dr["T1OUTPORT"]) : 0; obj.T1NAME = dr["T1NAME"] != DBNull.Value ? Convert.ToString(dr["T1NAME"]) : string.Empty; obj.T1MAXNUM = dr["T1MAXNUM"] != DBNull.Value ? Convert.ToInt32(dr["T1MAXNUM"]) : 0; obj.T1STARTTIME = dr["T1STARTTIME"] != DBNull.Value ? Convert.ToString(dr["T1STARTTIME"]) : string.Empty; obj.T1STOPTIME = dr["T1STOPTIME"] != DBNull.Value ? Convert.ToString(dr["T1STOPTIME"]) : string.Empty; obj.T1SINGLEMAX = dr["T1SINGLEMAX"] != DBNull.Value ? Convert.ToInt32(dr["T1SINGLEMAX"]) : 0; return(obj); }
private static void on_local_connected(IAsyncResult ar) { object[] ar_arr = ar.AsyncState as object[]; Socket sock_svr = ar_arr[0] as Socket; work_group work = (work_group)ar_arr[1]; ++_stat_info[work._id]._connect_cnt; Socket sock_cli = sock_svr.EndAccept(ar); sock_svr.BeginAccept(on_local_connected, ar.AsyncState); Socket sock_cli_remote = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); try { sock_cli_remote.Connect(work._point_out_host, work._point_out_port); } catch (Exception exp) { _l4n.Warn(exp.Message); try { sock_cli.Shutdown(SocketShutdown.Both); sock_cli_remote.Shutdown(SocketShutdown.Both); sock_cli.Close(); sock_cli_remote.Close(); } catch (Exception) { } --_stat_info[work._id]._connect_cnt; return; } Thread t_send = new Thread(new ParameterizedThreadStart(recv_and_send_caller)) { IsBackground = true }; Thread t_recv = new Thread(new ParameterizedThreadStart(recv_and_send_caller)) { IsBackground = true }; t_send.Start(new object[] { sock_cli, sock_cli_remote, work._id, true }); t_recv.Start(new object[] { sock_cli_remote, sock_cli, work._id, false }); t_send.Join(); t_recv.Join(); --_stat_info[work._id]._connect_cnt; }
public static void Save(work_group obj) { string tsql = string.Empty; if (obj.T1ID == 0) { //新增 int maxid = db.GetMaxID("work_group", "T1ID") + 1; obj.T1ID = maxid; tsql = string.Format("insert into work_group(T1ID,T1INIP,T1INPORT,T1OUTIP,T1OUTPORT,T1NAME,T1MAXNUM,T1STARTTIME,T1STOPTIME,T1SINGLEMAX) values({0},'{1}',{2},'{3}',{4},'{5}',{6},'{7}','{8}',{9})", obj.T1ID, obj.T1INIP.Replace("'", "''"), obj.T1INPORT, obj.T1OUTIP.Replace("'", "''"), obj.T1OUTPORT, obj.T1NAME.Replace("'", "''"), obj.T1MAXNUM, obj.T1STARTTIME.Replace("'", "''"), obj.T1STOPTIME.Replace("'", "''"), obj.T1SINGLEMAX); } else { tsql = string.Format("update work_group set T1ID ={0} , T1INIP ='{1}' , T1INPORT ={2} , T1OUTIP ='{3}' , T1OUTPORT ={4} , T1NAME ='{5}' , T1MAXNUM ={6} , T1STARTTIME ='{7}' , T1STOPTIME ='{8}' , T1SINGLEMAX ={9} where T1ID ={0}", obj.T1ID, obj.T1INIP.Replace("'", "''"), obj.T1INPORT, obj.T1OUTIP.Replace("'", "''"), obj.T1OUTPORT, obj.T1NAME.Replace("'", "''"), obj.T1MAXNUM, obj.T1STARTTIME.Replace("'", "''"), obj.T1STOPTIME.Replace("'", "''"), obj.T1SINGLEMAX, obj.T1ID); } //执行 db.Execute(tsql); }
private static void map_start(work_group work) { Socket sock_svr = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); bool start_error = false; try { sock_svr.Bind(work._point_in); sock_svr.Listen(10); sock_svr.BeginAccept(on_local_connected, new object[] { sock_svr, work }); } catch (Exception exp) { _l4n.Error(exp.Message); start_error = true; } finally { _stat_info.Add(work._id, new stat_obj(work._point_in.ToString(), work._point_out_host + ":" + work._point_out_port, !start_error, 0, 0, 0)); } }
// Private Methods (8) private static List<work_group> load_maps_cfg() { string maps_cfg = ConfigurationManager.AppSettings["portmaps"]; if (string.IsNullOrEmpty(maps_cfg)) throw new Exception("配置文件错误: 缺少PortMap配置"); string[] tmp1 = maps_cfg.Split(new[] { ';' }, StringSplitOptions.RemoveEmptyEntries); if (tmp1.Length == 0) throw new Exception("配置文件错误: 缺少PortMap配置"); List<work_group> rtn = new List<work_group>(); foreach (string tmp2 in tmp1) { string[] tmp3 = tmp2.Split(new[] { '|' }); if (tmp3.Length != 2) throw new Exception("配置文件错误: 每组PortMap配置必须为2个节点"); work_group rtn_item = new work_group { _id = ++_id_plus }; for (int i = 0; i != 2; ++i) { string[] tmp4 = tmp3[i].Split(new[] { ':' }, StringSplitOptions.RemoveEmptyEntries); if (tmp4.Length != 2) throw new Exception("配置文件错误: IP节点格式错误"); IPAddress ip = IPAddress.Any; if (i == 0 && tmp4[0] != "*" && !IPAddress.TryParse(tmp4[0], out ip)) throw new Exception("配置文件错误: IP节点格式错误"); ushort port; if (!ushort.TryParse(tmp4[1], out port)) throw new Exception("配置文件错误: IP节点格式错误"); if (i == 0) rtn_item._point_in = new IPEndPoint(ip, port); if (i == 1) { rtn_item._point_out_host = tmp4[0]; rtn_item._point_out_port = port; } } rtn.Add(rtn_item); } return rtn; }