public void Start() { client = DCClient.Instance(Global.DC_DIR_SRVID, "global"); client.Srv(Global.DC_DIR_CLTSRVINFO_RPT, this.updateCltSrvInfo); client.Srv(Global.DC_DIR_CLTSRVINFO_QRY, this.queryCltSrvInfo); mngThread = new Thread(new ThreadStart(delegate() { while (!disposed) { try { Thread.Sleep(8000); } catch { break; } IEnumerator <List <StringAndTime> > srvInfoItor = cltSrvInfo.Values.GetEnumerator(); while (srvInfoItor.MoveNext()) { srvInfoItor.Current.RemoveAll((item) => { return((DateTime.Now.Ticks - item.LastRefresh) > (60 * 10000000)); }); } } } )); mngThread.IsBackground = true; mngThread.Start(); }
internal void Start() { IConfigSource cs = new IniConfigSource(System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "BizFileStore.ini")); IConfig c = cs.Configs["config"]; rootDir = c.Get("RootDir"); clt = DCClient.Instance("BizFileStore", "global"); clt.Srv("/filestore/genfilename", genfilename); clt.Srv("/filestore/appendfile", appendfile); clt.Srv("/filestore/savefile", savefile); clt.Srv("/filestore/readfile", readfile); }
internal void Start() { IConfigSource cs = new IniConfigSource(System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "BizSYSMAN.ini")); IConfig c = cs.Configs["config"]; dbConnStr = c.Get("DbConnectionString"); db = new DbNetData(dbConnStr); db.CloseConnectionOnError = false; db.Open(); clt = DCClient.Instance("BizSYSMAN", "global"); clt.Srv("/sysman/dic/list", dic_list); }
static void Main(string[] args) { DCClient client = DCClient.Instance("TESTSUB", "global"); //client.Sub("Status", "Service2", Program.display); client.Sub("0x0309", Program.display0309); //client.Sub("0x0304", Program.display0304); //client.Sub("0x0407", "001001RTMS00000001", Program.display0407); //client.Sub("20001", "001001DDCS00000001", Program.display); //client.Sub("20001", "001001WBFS00000001", Program.display); //client.Sub("20002", Program.display); //client.Sub<Signal>(displaySignal); //client.Sub("testObj", typeof(Signal2), displaySignal); }
internal void Start() { IConfigSource cs = new IniConfigSource(System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "BizMOBAPP.ini")); IConfig c = cs.Configs["config"]; dbConnStr = c.Get("DbConnectionString"); db = new DbNetData(dbConnStr); db.CloseConnectionOnError = false; db.Open(); clt = DCClient.Instance("BizMOBAPP", "global"); clt.Srv("/mobapp/manage/register", manage_register); clt.Srv("/mobapp/manage/login", manage_login); }
internal void Start() { IConfigSource cs = new IniConfigSource(System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "ContainerBiz.ini")); IConfig c = cs.Configs["config"]; //dbConnStr = c.Get("DbConnectionString"); //db = new DbNetData(dbConnStr); //db.CloseConnectionOnError = false; //db.Open(); clt = DCClient.Instance(c.Get("ServiceId"), "global"); System.Threading.Thread.Sleep(1000); //clt.Srv("/sysman/dic/list", dic_list); Dictionary <string, IBizSrv> bizs = this.getBizs(); foreach (string url in bizs.Keys) { //bizs[url].SetDb(db); //bizs[url].SetConfig(c); bizs[url].SetContext(new BizSrvContext(url, System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "ContainerBiz.ini"))); clt.Srv(url, bizs[url].RequestProc); DCLogger.LogInfo("注册接口{0},来源{1}", url, bizs[url].ToString()); } }
static void Main(string[] args) { DCClient client = DCClient.Instance("TESTACT", "global"); Random r = new Random(); while (true) { //string read = Console.ReadLine(); Thread.Sleep(r.Next(1000)); for (int i = 0; i < 10; i++) { try { string requet = string.Format("{0}+{1}", r.Next(10, 1000), r.Next(100, 1000)); ActResult ar = client.Act("Add?TESTACT", "TESTSRV", Encoding.Unicode.GetBytes(requet), 2); Console.WriteLine("{0}\t{1}", Encoding.Unicode.GetString(ar.ResultData), DateTime.Now); } catch (Exception e) { Console.WriteLine(e.Message); } } } }
static void Main(string[] args) { Random r = new Random(); int max = 0; Thread t1 = new Thread(() => { DCClient client = DCClient.Instance("TESTPUB", "global"); while (true) { client.Pub("0x0309", make0EEE()); Console.WriteLine("--0x0309--" + DateTime.Now.Second + "." + DateTime.Now.Millisecond); Thread.Sleep(10000); } } ); t1.Start(); //Thread t2 = new Thread(() => //{ // DCClient client = DCClient.Instance("TESTPUB", "global"); // while (true) // { // List<string> list = new List<string>(); // Signal sig = new Signal { Freq = (UInt64)r.Next(), Bw = (UInt32)r.Next(), TimeMark = DateTime.Now, Halo = "最无需思考的方法就是", List = new List<string>(new string[] { "asdfte", "satewr", "阿布才" }) }; // client.Pub<Signal>(sig); // Console.WriteLine("--Signal--" + DateTime.Now.Second + "." + DateTime.Now.Millisecond); // Thread.Sleep(2000); // } //} //); //t2.Start(); //Thread t3 = new Thread(() => //{ // DCClient client = DCClient.Instance("TESTPUB", "global"); // while (true) // { // List<string> list = new List<string>(); // Signal sig = new Signal { Freq = (UInt64)r.Next(), Bw = (UInt32)r.Next(), TimeMark = DateTime.Now, Halo = "最无需思考的方法就是", List = new List<string>(new string[] { "asdfte", "satewr", "阿布才" }) }; // client.Pub("testObj", sig); // Console.WriteLine("--Signal--" + DateTime.Now.Second + "." + DateTime.Now.Millisecond); // //Thread.Sleep(10); // } //} //); //t3.Start(); //Thread t2 = new Thread(() => //{ // DCClient client = DCClient.Instance("TESTPUB", "global"); // while (true) // { // client.Pub("0x0304", make0EEE()); // Console.WriteLine("--0x0304--" + DateTime.Now.Second + "." + DateTime.Now.Millisecond); // //Thread.Sleep(1); // } //} //); //t2.Start(); //Thread t3 = new Thread(() => //{ // DCClient client = DCClient.Instance("Service1", "global"); // while (true) // { // client.Pub("20002", Encoding.Unicode.GetBytes("Status Service1, timestamp " + DateTime.Now.Second + "." + DateTime.Now.Millisecond)); // Thread.Sleep(r.Next(10, 1000)); // } //} //); //t3.Start(); //Thread t4 = new Thread(() => //{ // DCClient client = DCClient.Instance("Service2", "global"); // while (true) // { // client.Pub("20002", Encoding.Unicode.GetBytes("Status Service2, timestamp " + DateTime.Now.Second + "." + DateTime.Now.Millisecond)); // Thread.Sleep(r.Next(10, 1000)); // } //} //); //t4.Start(); //Thread t5 = new Thread(() => //{ // DCClient client = DCClient.Instance("Service3", "global"); // while (true) // { // client.Pub("20002", Encoding.Unicode.GetBytes("Status Service3, timestamp " + DateTime.Now.Second + "." + DateTime.Now.Millisecond)); // Thread.Sleep(r.Next(10, 1000)); // } //} //); //t5.Start(); Console.ReadLine(); }
static void Main(string[] args) { DCClient client = DCClient.Instance("TESTSRV", "global"); client.Srv("Add", Program.add); }
public void Start() { clt = DCClient.Instance("BizSampleSrv", "global"); //clt.Srv("/veginfo/list", veginfoList); clt.Srv("/test/helloworld", helloworld); }
//private string lsnrUrl = "http://+:8080/"; //private string localMngPort = "8090"; public void Start() { IConfigSource cs = new IniConfigSource(System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "ConnectorRest.ini")); //lsnrUrl = cs.Configs["init"].Get("ListenPoint"); //localMngPort = cs.Configs["init"].Get("LocalManagePort"); lsnrThrd = new Thread(new ThreadStart(delegate() { // 检查系统是否支持 if (!HttpListener.IsSupported) { DCLogger.LogError("软件运行需要 Windows XP SP2 或 Server 2003 以上系统."); } // 注意前缀必须以 / 正斜杠结尾 string[] prefixes = cs.Configs["init"].Get("ListenPoint").Split(','); // 设置manifest UAC权限 foreach (string lsnrUrl in prefixes) { AddAddress(lsnrUrl); } // 创建监听器. HttpListener listener = new HttpListener(); // 增加监听的前缀. foreach (string lsnrUrl in prefixes) { listener.Prefixes.Add(lsnrUrl); } //开始监听 try { listener.Start(); } catch (Exception ex) { DCLogger.LogError(ex.Message); throw ex; } foreach (string lsnrUrl in prefixes) { DCLogger.LogInfo(string.Format("REST监听启动于:{0}", lsnrUrl)); } DCClient client = DCClient.Instance("ConnectorRest", "global"); long length = 0; Stopwatch watch = new Stopwatch(); watch.Start(); while (true) { try { // 注意: GetContext 方法将阻塞线程,直到请求到达 HttpListenerContext context = listener.GetContext(); // 取得请求对象 HttpListenerRequest request = context.Request; length += 1; if (watch.ElapsedMilliseconds > 10000) { DCLogger.LogInfo(string.Format("Connect Pressure:{0}requests/s\t{1}", length * 1000 / (watch.ElapsedMilliseconds), DateTime.Now)); length = 0; watch.Reset(); watch.Start(); } //if (request.RawUrl.Equals("/connector/stop")) // break; if (request.RawUrl.Equals("/helloworld")) { // 取得回应对象 HttpListenerResponse response = context.Response; byte[] ack = Encoding.UTF8.GetBytes("Hello World!"); response.ContentLength64 = ack.LongLength; response.ContentType = "text/plain; charset=UTF-8"; response.StatusCode = 200; // 输出回应内容 try { using (BinaryWriter writer = new System.IO.BinaryWriter(response.OutputStream)) { writer.Write(ack, 0, (int)response.ContentLength64); } } catch (Exception ex) { DCLogger.LogError(ex.Message); } continue; } if (request.ContentLength64 < 0 || request.ContentLength64 > 20000000) { string resp = string.Format("超长的Rest请求内容,长度{0}", request.ContentLength64); DCLogger.LogError(resp); // 取得回应对象 HttpListenerResponse response = context.Response; // 设置回应头部内容,长度,编码 response.ContentLength64 = resp.Length; response.ContentType = "text/plain; charset=UTF-8"; response.StatusCode = 500; // 输出回应内容 try { using (BinaryWriter writer = new BinaryWriter(response.OutputStream)) { writer.Write(Encoding.UTF8.GetBytes(resp)); } } catch (Exception ex) { DCLogger.LogError(ex.Message); } continue; } byte[] postData = getPostData(request); if (request.ContentLength64 > 0 && request.ContentLength64 <= 256) { DCLogger.LogTrace(string.Format( "{0}-->{1}:::{2}", request.RemoteEndPoint, request.RawUrl, Global.Encoding.GetString(postData) ) ); } else if (request.ContentLength64 > 256 && request.ContentLength64 <= 4096) { DCLogger.LogTrace(string.Format( "{0}-->{1}:::{2}", request.RemoteEndPoint, request.RawUrl, Global.Encoding.GetString(postData, 0, 256) + "..." ) ); } else { DCLogger.LogTrace(string.Format( "{0}-->{1}:::{2}", request.RemoteEndPoint, request.RawUrl, string.Format("{0} bytes long content.", request.ContentLength64) ) ); } //if (postData == null) //{ // HttpListenerResponse response = context.Response; // response.StatusCode = 404; // response.Close(); //} //else { try { client.Act(request.RawUrl, postData, (rst) => { // 取得回应对象 HttpListenerResponse response = context.Response; // 设置回应头部内容,长度,编码 int httpHeadInfoLength = BitConverter.ToInt32(rst.ResultData, 0); HttpHeadInfo httpHeadInfo = HttpHeadInfo.FromBytes(rst.ResultData, 4, httpHeadInfoLength); int rawBytesIndex = httpHeadInfoLength + 4; response.ContentLength64 = rst.ResultData.LongLength - rawBytesIndex; response.ContentType = httpHeadInfo.ContentType; response.StatusCode = (int)httpHeadInfo.StatusCode; // 输出回应内容 try { using (BinaryWriter writer = new System.IO.BinaryWriter(response.OutputStream)) { writer.Write(rst.ResultData, rawBytesIndex, (int)response.ContentLength64); } if (response.ContentType.Equals(HttpContentType.Json)) { if (response.ContentLength64 > 256) { DCLogger.LogTrace(string.Format( "{0}<--{1}:::{2}", request.RemoteEndPoint, request.RawUrl, Global.Encoding.GetString(rst.ResultData, rawBytesIndex, 256) + "..." ) ); } else { DCLogger.LogTrace(string.Format( "{0}<--{1}:::{2}", request.RemoteEndPoint, request.RawUrl, Global.Encoding.GetString(rst.ResultData, rawBytesIndex, (int)response.ContentLength64) ) ); } } } catch (Exception ex) { DCLogger.LogError(ex.Message); } } ); } catch (Exception ex) { DCLogger.LogError(ex.Message); // 取得回应对象 HttpListenerResponse response = context.Response; // 设置回应头部内容,长度,编码 response.ContentLength64 = ex.Message.Length; response.ContentType = "text/plain; charset=UTF-8"; response.StatusCode = 500; // 输出回应内容 try { using (BinaryWriter writer = new BinaryWriter(response.OutputStream)) { writer.Write(Encoding.UTF8.GetBytes(ex.Message)); } } catch (Exception ex2) { DCLogger.LogError(ex2.Message); } //response.Close(); } } } catch (ThreadAbortException) { break; } catch { } } // 关闭服务器 listener.Stop(); DCLogger.LogInfo(string.Format("REST监听关闭:{0}", prefixes)); DCClient.Dispose(client); } )); lsnrThrd.IsBackground = true; lsnrThrd.Start(); }