コード例 #1
0
        public ESBServer(int port)
            : base(port)
        {
            ServerModeNeedLogin = false;

            if (!string.IsNullOrWhiteSpace(ManagerWebPortStr))
            {
                var manport = int.Parse(ManagerWebPortStr);

                Net.HTTP.Server.HttpServer manhttpserver = new Net.HTTP.Server.HttpServer(new Net.HTTP.Server.Server(manport));
                manhttpserver.Handlers.Add(new Net.HTTP.Server.RESTfulApiHandlerBase(Net.HTTP.Server.HMethod.GET, "/esb/index", new List <string>()
                {
                }, new DefaultHander(this)));
            }
        }
コード例 #2
0
            public bool Process(Net.HTTP.Server.HttpServer server, Net.HTTP.Server.HttpRequest request, Net.HTTP.Server.HttpResponse response, Dictionary <string, string> param)
            {
                StringBuilder sb = new StringBuilder();

                sb.Append(@"<style type=""text/css"">
        table{
            border:solid 1px lightblue; width:100%;
        }
        th{
            height:30px;
        }

        td{
            border-top:dashed 1px #ccc;
            height:22px;
        }

    </style>
                ");
                sb.AppendFormat("当前时间:{0}<br/><br/>", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
                var servicelist = _esb.ServiceContainer.Select(p => p).ToList();

                sb.AppendFormat("当前注册了{0}个服务实例<br/>", servicelist.Count);
                if (servicelist.Count > 0)
                {
                    sb.AppendFormat("<table>");
                    sb.AppendFormat("<tr><th>服务号</th><th>服务实例</th></tr>");
                    foreach (var gp in servicelist.GroupBy(p => p.ServiceNo))
                    {
                        sb.AppendFormat("<tr>");
                        sb.AppendFormat("<td>{0}</td>", gp.Key);
                        sb.Append("<td>");
                        sb.Append("<table>");
                        sb.Append("<tr><th>ID</th><th>服务器地址</th><th>TCP直连</th><th>UDP直连</th></tr>");
                        foreach (var item in gp)
                        {
                            if (DateTime.Now.Subtract(item.Session.LastSessionTime).TotalMinutes > 1)
                            {
                                lock (this._esb.ServiceContainer)
                                {
                                    _esb.ServiceContainer.Remove(item);
                                }
                            }

                            sb.AppendFormat("<tr><td>{0}</td><td>{1}:{2}</td><td>{3}</td><td>{4}</td></tr>", item.Session.SessionID, item.Session.IPAddress, item.Session.Port,
                                            item.RedirectTcpIps == null ? "" : (string.Join(",", item.RedirectTcpIps) + ":" + item.RedirectTcpPort),
                                            item.RedirectUdpIps == null ? "" : (string.Join(",", item.RedirectUdpIps) + ":" + item.RedirectUdpPort));
                        }
                        sb.Append("</table>");
                        sb.Append("</td>");
                        sb.AppendFormat("</tr>");
                    }
                    sb.AppendFormat("</table>");
                }

                //客户端
                sb.Append("<br/>");
                var clients = _esb.GetConnectedList().Select(p => p).ToList();

                sb.AppendFormat("当前连接了{0}个客户端", clients.Count);
                sb.Append("<table>");
                sb.Append("<tr>");
                sb.AppendFormat("<th>clientid</th><th>地址</th><th>连接时间</th><th>上次心跳时间</th><th>连接时长(分钟)</th><th>发送字节</th><th>接收字节</th>");
                sb.Append("</tr>");
                HashSet <string> clienthash = new HashSet <string>();

                foreach (var item in clients)
                {
                    if (!clienthash.Contains(item.Key))
                    {
                        clienthash.Add(item.Key);
                    }

                    sb.AppendFormat("<tr><td>{0}</td><td>{1}:{2}</td><td>{3}</td><td>{4}</td><td>{5}</td><td>{6}</td><td>{7}</td></tr>", item.Key, item.Value.IPAddress, item.Value.Port,
                                    item.Value.ConnectTime.ToString("yyyy-MM-dd HH:mm:ss"),
                                    item.Value.LastSessionTime.ToString("yyyy-MM-dd HH:mm:ss"), Math.Round(item.Value.LastSessionTime.Subtract(item.Value.ConnectTime).TotalMinutes, 3),
                                    item.Value.BytesSend, item.Value.BytesRev);
                }
                if (clients.Count > 0)
                {
                    sb.AppendFormat("<tr><td colspan='5'>{0}</td><td>{1}kb</td><td>{2}kb</td></tr>", "合计", (clients.Sum(p => p.Value.BytesSend) / 1024), (clients.Sum(p => p.Value.BytesRev) / 1024));
                }
                sb.Append("</table>");

                //客户端
                sb.Append("<br/>");
                clients = _esb.ClientSessionList.Select(p => p).ToList();
                sb.AppendFormat("当前活跃{0}个客户端", clients.Count);
                sb.Append("<table>");
                sb.Append("<tr>");
                sb.AppendFormat("<th>任务ID</th><th>clientid</th><th>地址</th><th>连接时间</th><th>上次心跳时间</th><th>连接时长(分钟)</th><th>发送字节</th><th>接收字节</th>");
                sb.Append("</tr>");
                foreach (var item in clients)
                {
                    if (!clienthash.Contains(item.Value.SessionID))
                    {
                        lock (_esb.ClientSessionList)
                        {
                            _esb.ClientSessionList.Remove(item.Key);
                        }
                    }

                    sb.AppendFormat("<tr><td>{0}</td><td>{1}</td><td>{2}:{3}</td><td>{4}</td><td>{5}</td><td>{6}</td><td>{7}</td><td>{8}</td></tr>", item.Key, item.Value.SessionID, item.Value.IPAddress, item.Value.Port,
                                    item.Value.ConnectTime.ToString("yyyy-MM-dd HH:mm:ss"),
                                    item.Value.LastSessionTime.ToString("yyyy-MM-dd HH:mm:ss"), Math.Round(item.Value.LastSessionTime.Subtract(item.Value.ConnectTime).TotalMinutes, 3),
                                    item.Value.BytesSend, item.Value.BytesRev);
                }
                sb.Append("</table>");

                response.Content = sb.ToString();
                return(true);
            }