Beispiel #1
0
        /// <summary>
        /// 消息处理
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        public static void process(StateObject request)
        {
            //哈希表存放包体内容
            Hashtable _hashtable_Package = new Hashtable();
            string    UserId             = ""; //用户ID
            string    UserPwd            = ""; //用户密码


            try
            {
                if (request != null)
                {
                    #region 包体解析
                    short cmd1 = 0;    //主命令字
                    short cmd2 = 0;    //子命令字
                    cmd1 = OMSCmd.RspUserLogin;
                    cmd2 = ErrCommon.Success;
                    byte[]    ByteResult = null;
                    DataTable dt         = new DataTable();
                    Commonality.CommClass.ReadXML(request.receiveFileTemporarily, ref dt);

                    if (dt.Rows.Count <= 0)
                    {
                        cmd2 = -101;    //解包失败
                        //哈希表存放包体内容
                        Hashtable _hashtable_Package_Temp = new Hashtable();
                        _hashtable_Package_Temp.Add("1", request);    //...連結位置
                        _hashtable_Package_Temp.Add("2", cmd1);
                        _hashtable_Package_Temp.Add("3", cmd2);
                        ByteResult = null;
                        _hashtable_Package_Temp.Add("4", ByteResult);
                        ThreadPool.QueueUserWorkItem(new WaitCallback(CommonFunction.SendDatas), _hashtable_Package_Temp);
                        Commonality.ConsoleManage.Write(Commonality.ErrorLevel.Serious,
                                                        "KOIPMonitor>>RspUserLogin>>process>>", "消息体内容有误");
                        return;
                    }

                    UserId  = dt.Rows[0]["USERID"].ToString();
                    UserPwd = dt.Rows[0]["USERPWD"].ToString();
                    //UserId = Guid.NewGuid().ToString();
                    int    Ret   = -1;
                    string Roles = "";
                    int    RetID = 0;;
                    RspUserLogin.LoginVerification(UserId, UserPwd, ref Ret, ref Roles, ref RetID);
                    switch (Ret)
                    {
                    case -1:
                        cmd2 = -8010;
                        break;

                    case -2:
                        cmd2 = -8011;
                        break;

                    case 0:
                        if (CommClass.GetUserIsLogin(UserId) == 0)
                        {
                            cmd2 = ErrCommon.Success;
                        }
                        else
                        {
                            cmd2 = -8032;
                        }
                        CommClass.AddClientConnList(UserId, request);
                        //List表内容
                        List <Commonality.CommClass.TTable> ListTtable = new List <Commonality.CommClass.TTable>();
                        //Table属性内容
                        Commonality.CommClass.TTable Ttable = new Commonality.CommClass.TTable();
                        Ttable.FieldName  = "ROLES";
                        Ttable.FieldValue = Roles;
                        ListTtable.Add(Ttable);
                        Ttable.FieldName  = "ID";
                        Ttable.FieldValue = RetID.ToString();
                        ListTtable.Add(Ttable);
                        Commonality.CommClass.TableToByteArry(ListTtable, ref ByteResult);
                        break;
                    }


                    #endregion

                    Hashtable _hashtable_PackageArry = new Hashtable();
                    _hashtable_PackageArry.Add("1", request);    //...連結位置
                    _hashtable_PackageArry.Add("2", cmd1);
                    _hashtable_PackageArry.Add("3", cmd2);
                    _hashtable_PackageArry.Add("4", ByteResult);
                    ThreadPool.QueueUserWorkItem(new WaitCallback(CommonFunction.SendDatas), _hashtable_PackageArry);
                }
                else
                {
                    Commonality.ConsoleManage.Write(Commonality.ErrorLevel.Serious, "KOIPMonitor>>RspUserLogin>>process>>", "StateObject request==null");
                }
            }
            catch (Exception ex)
            {
                Commonality.ConsoleManage.Write(Commonality.ErrorLevel.Serious, "KOIPMonitor>>RspUserLogin>>process>>", ex.Message);
            }
            finally
            {
                //删除文件
                //if (!string.IsNullOrEmpty(request.receiveFileTemporarily))
                //    ThreadPool.QueueUserWorkItem(new WaitCallback(DiskIO.Del), request.receiveFileTemporarily);

                //GC.Collect();
            }
        }
        public static void ReceiveEvent(StateObject OmsState)
        {
            try
            {
                if (OmsState == null)
                {
                    return;
                }

                switch (OmsState.cmd1)
                {
                case  OMSCmd.RspServOpt:
                    RspServOpt.process(OmsState);
                    break;

                case  OMSCmd.UpDevState:
                    UpDevState.process(OmsState);
                    break;

                case OMSCmd.ReqGetServList:    //启动服务请求
                    if (CommClass.ISCONUP == "0")
                    {
                        RspGetServList.process(OmsState);    //启动服务回应
                    }
                    break;

                case OMSCmd.ReqServOpt:           //启动服务请求
                    ReqServOpt.process(OmsState); //启动服务回应
                    break;

                case OMSCmd.ReqGetServState:           //获取服务器状态请求
                    RspGetServState.process(OmsState); //获取服务器状态回应
                    break;

                case OMSCmd.ReqUserLogin:    //获取服务器状态请求
                    if (CommClass.ISCONUP == "0")
                    {
                        RspUserLogin.process(OmsState);    //获取服务器状态回应
                    }
                    break;

                case CommCmd.Handshake:    //握手
                    //byte[] ResultByte=null;
                    //CommonFunction.HandshakeByte(ref ResultByte);
                    //OmsState.Send(ResultByte);
                    CommonFunction.SendHandshake(OmsState);
                    break;

                case OMSCmd.DevTypeAdd:    //设备类型添加
                    if (CommClass.ISCONUP == "0")
                    {
                        DevTypeAdd.process(OmsState);
                    }
                    break;

                case OMSCmd.DevTypeDelete:    //设备类型删除
                    if (CommClass.ISCONUP == "0")
                    {
                        DevTypeDelete.process(OmsState);
                    }
                    break;

                case OMSCmd.DevTypeModify:    //设备类型修改
                    if (CommClass.ISCONUP == "0")
                    {
                        DevTypeModify.process(OmsState);
                    }
                    break;

                case OMSCmd.DevTypeQuery:    //设备类型查询
                    if (CommClass.ISCONUP == "0")
                    {
                        DevTypeQuery.process(OmsState);
                    }
                    break;

                case OMSCmd.DevInfoAdd:    //设备信息添加
                    if (CommClass.ISCONUP == "0")
                    {
                        DevInfoAdd.process(OmsState);
                    }
                    break;

                case OMSCmd.DevInfoDelete:    //设备信息删除
                    if (CommClass.ISCONUP == "0")
                    {
                        DevInfoDelete.process(OmsState);
                    }
                    break;

                case OMSCmd.DevInfoModify:    //设备信息修改
                    if (CommClass.ISCONUP == "0")
                    {
                        DevInfoModify.process(OmsState);
                    }
                    break;

                case OMSCmd.DevInfoQuery:    //设备信息查询
                    if (CommClass.ISCONUP == "0")
                    {
                        DevInfoQuery.process(OmsState);
                    }
                    break;

                case OMSCmd.UserInfoAdd:    //用户添加
                    if (CommClass.ISCONUP == "0")
                    {
                        UserInfoAdd.process(OmsState);
                    }
                    break;

                case OMSCmd.UserInfoDelete:    //用户删除
                    if (CommClass.ISCONUP == "0")
                    {
                        UserInfoDelete.process(OmsState);
                    }
                    break;

                case OMSCmd.UserInfoModify:    //用户修改
                    if (CommClass.ISCONUP == "0")
                    {
                        UserInfoModify.process(OmsState);
                    }
                    break;

                case OMSCmd.UserInfoQuery:    //用户查询
                    if (CommClass.ISCONUP == "0")
                    {
                        UserInfoQuery.process(OmsState);
                    }
                    break;

                case OMSCmd.ChangePwd:    //用户密码修改
                    if (CommClass.ISCONUP == "0")
                    {
                        ChangePwd.process(OmsState);
                    }
                    break;

                case OMSCmd.AlarmLogQuery:    //故障日志查询
                    if (CommClass.ISCONUP == "0")
                    {
                        AlarmLogQuery.process(OmsState);
                    }
                    break;

                case OMSCmd.AlarmLogClear:    //故障日志清除
                    if (CommClass.ISCONUP == "0")
                    {
                        AlarmLogClear.process(OmsState);
                    }
                    break;

                case OMSCmd.KOIPOnline:    //KOIP挂线查询
                    if (CommClass.ISCONUP == "0")
                    {
                        KOIPOnline.process(OmsState);
                    }
                    break;

                default:
                    break;
                }
            }
            catch (Exception ex)
            {
                Commonality.ConsoleManage.Write(Commonality.ErrorLevel.Serious, "KOIPMonitor>>tcpServer_ReceiveEvent>>KOIPMonitor  TCP 連接接收處理>>", ex.Message);
            }
            finally
            {
                if (!string.IsNullOrEmpty(OmsState.receiveFileTemporarily))
                {
                    ThreadPool.QueueUserWorkItem(new WaitCallback(DiskIO.Del), OmsState.receiveFileTemporarily);
                    //KdsState.workSocket.Close();
                    //KdsState.workSocket.Shutdown(System.Net.Sockets.SocketShutdown.Both);
                }
            }
        }