Exemplo n.º 1
0
 /// <summary>
 /// 已断开
 /// </summary>
 /// <param name="host"></param>
 public static void OnDisconnect(string host)
 {
     if (R.Tx.Hosts.Contains(host))
     {
         R.Tx.Hosts.Remove(host);
         TxHostMapTool.DelHost(host);
         R.MainUI.UIConnectCount(R.Tx.Hosts.Count);
     }
 }
Exemplo n.º 2
0
        /// <summary>
        /// 运行消息
        /// </summary>
        /// <param name="host"></param>
        /// <param name="model"></param>
        public static void ExecuteMessage(string host, TcpDataModel model)
        {
            if (R.Tx.Hosts.Contains(host))
            {
                switch (model.Type)
                {
                //应答信息
                case 20001000:     /* 普通应答 */
                    R.Tx.TcppServer.Write(host, 20001000, "~");
                    break;

                //系统状态
                case 20002000:                   /* 系统状态 */
                {
                    TxConvertHelper.Send(model); //转发给上游服务
                    string data   = Json.Byte2Object <string>(model.Data);
                    var    status = Json.String2Object <SystemStatusModel>(data);

                    R.Store.AddSystemStatus(status);
                    TxHostMapTool.AddHost(host, $"{status.IP}");
                    R.MainUI.systemListControl1.AddOrUpdate(status);
                    R.MainUI.txConsoleControl1.Write(host, model.Type, $"{Json.Byte2Object<string>(model.Data)}");
                    break;
                }

                //服务信息
                case 20003000:                   /* 服务状态 */
                {
                    TxConvertHelper.Send(model); //转发给上游服务
                    string data   = Json.Byte2Object <string>(model.Data);
                    var    status = Json.String2Object <ProjectStatusModel>(data);

                    R.Store.AddProjectStatus(status);
                    R.MainUI.projectListControl1.AddOrUpdate(status);
                    R.MainUI.txConsoleControl1.Write(host, model.Type, $"{data}");
                    break;
                }

                //程序更新
                case 90001000:
                {
                    Task.Factory.StartNew(() =>
                        {
                            try
                            {
                                string fire = Json.Byte2Object <string>(model.Data);
                                if (File.Exists(R.AppointFile))
                                {
                                    byte[] data = BinaryFileTool.read(R.AppointFile);
                                    R.Tx.TcppServer.Write(host, 90002000, data);
                                }
                            }
                            catch { }
                        });
                }
                break;

                case 90002000: { } break;

                default:
                    R.MainUI.txConsoleControl1.Write(host, model.Type, $"{model.Data.Length}");
                    break;
                }
            }
        }