private static void __CJNetFrameworkSerialzetionToolCompile()
        {
            RuntimeTypeModel rtCSProtocolSerializeTypSet = TypeModel.Create();
            List <Type>      CSProtocolSerializeTypSet   = JsonSerializtionFactory.CreateSpecializationSerializeTypeSet();

            foreach (Type typeItem in CSProtocolSerializeTypSet)
            {
                rtCSProtocolSerializeTypSet.Add(typeItem, true);
            }
            rtCSProtocolSerializeTypSet.Compile("CJNet_SerializeTool", "CJNet_SerializeTool.dll");

            //RuntimeTypeModel rtMiddlewareProtocolSerializeTypSet = TypeModel.Create();
            //List<Type> MiddlewareSerializeTypSet = Middleware.Middleware.JsonSerializtionFactory.CreateSpecializationSerializeTypeSet();
            //foreach (Type typeItem in MiddlewareSerializeTypSet)
            //{
            //    rtMiddlewareProtocolSerializeTypSet.Add(typeItem, true);
            //}
            //rtMiddlewareProtocolSerializeTypSet.Compile("CJNet_MiddlewareProtocolSerializeTool", "CJNet_MiddlewareProtocolSerializeTool.dll");
        }
Exemple #2
0
        protected virtual void Client_MessageRecevied(object sender, MessageEventArgs e)
        {
            string    sourMessageid = e.Message.MessageId;
            byte      oprCodec;
            Hashtable parmMap;

            ServerOprInfoFilter(((ScsRawDataMessage)e.Message).MessageData, out oprCodec, out parmMap);
            switch (oprCodec)
            {
            case (int)ServerOprCodec.P2pTransport:
            {
                byte         oprFaildCodec;
                AppErrorInfo ret = _server.Send(_token, parmMap["Token"] as string, parmMap["Content"] as byte[], out oprFaildCodec);
                if (AppErrorInfo.APP_SUCESS == ret)
                {
                    //Reply Suc
                    byte[] sucReply = new byte[1];
                    sucReply[0] = (byte)ClientHeadCodec.P2pTransport_ReplySucess;
                    _client.SendMessage(new ScsRawDataMessage(sucReply, sourMessageid));

                    string logInfo = "{"
                                     + "ret:" + "P2pTransport => APP_SUCESS" + " , "
                                     + "info:"
                                     + "{"
                                     + "from_detail:" + this.Detail
                                     + "from_token:" + this.Token + ","
                                     + "to_token:" + parmMap["Token"]
                                     + "}"
                                     + "}";
                    _server.__AddLogItem(logInfo);
                }
                else
                {
                    switch (oprFaildCodec)
                    {
                    case (byte)P2pTransportFaildCodec.Target_UNCONNECT:
                    {
                        //向源头打回错误报文
                        byte[] erroReply = new byte[2];
                        erroReply[0] = (byte)ClientHeadCodec.P2pTransport_ReplyFaild;
                        erroReply[1] = (byte)P2pTransportFaildCodec.Target_UNCONNECT;
                        _client.SendMessage(new ScsRawDataMessage(erroReply, sourMessageid));

                        string logInfo = "{"
                                         + "ret:" + "P2pTransport => Target_UNCONNECT" + " , "
                                         + "info:"
                                         + "{"
                                         + "from_detail:" + this.Detail
                                         + "from_token:" + this.Token + ","
                                         + "to_token:" + parmMap["Token"]
                                         + "}"
                                         + "}";
                        _server.__AddLogItem(logInfo);
                        break;
                    }

                    case (byte)P2pTransportFaildCodec.Token_UNPARSE:
                    {
                        //向源头打回错误报文
                        byte[] erroReply = new byte[2];
                        erroReply[0] = (byte)ClientHeadCodec.P2pTransport_ReplyFaild;
                        erroReply[1] = (byte)P2pTransportFaildCodec.Token_UNPARSE;
                        _client.SendMessage(new ScsRawDataMessage(erroReply, sourMessageid));

                        string logInfo = "{"
                                         + "ret:" + "P2pTransport => Token_UNPARSE" + " , "
                                         + "info:"
                                         + "{"
                                         + "from_detail:" + this.Detail
                                         + "from_token:" + this.Token + ","
                                         + "to_token:" + parmMap["Token"]
                                         + "}"
                                         + "}";
                        _server.__AddLogItem(logInfo);
                        break;
                    }

                    default:
                    {
                        string logInfo = "{"
                                         + "ret:" + "P2pTransport => default:错误码分支未实现" + " , "
                                         + "info:"
                                         + "{"
                                         + "from_detail:" + this.Detail
                                         + "from_token:" + this.Token + ","
                                         + "to_token:" + parmMap["Token"]
                                         + "}"
                                         + "}";
                        _server.__AddLogItem(logInfo);
                        return;
                    }
                    }
                }
                break;
            }

            case (int)ServerOprCodec.CreateGroup:
            {
                string gropDetail = parmMap["GroupDetail"] as string;
                if (false == string.IsNullOrEmpty(gropDetail))
                {
                    string       token;
                    byte         oprFaildCodec;
                    AppErrorInfo ret = _server.CreateGroup(gropDetail, out token, out oprFaildCodec);
                    if (AppErrorInfo.APP_SUCESS == ret)
                    {
                        byte [] sucReply = new byte[1 + ConstData.tokenLength];
                        sucReply[0] = (byte)ClientHeadCodec.CreateGroup_ReplySucess;
                        Buffer.BlockCopy(Encoding.ASCII.GetBytes(token), 0, sucReply, 1, ConstData.tokenLength);
                        _client.SendMessage(new ScsRawDataMessage(sucReply, sourMessageid));

                        string logInfo = "{"
                                         + "ret:" + "CreateGroup => APP_SUCESS" + " , "
                                         + "info:"
                                         + "{"
                                         + "from_detail:" + this.Detail
                                         + "from_token:" + this.Token + ","
                                         + "group_detail:" + gropDetail
                                         + "group_token:" + token
                                         + "}"
                                         + "}";
                        _server.__AddLogItem(logInfo);
                    }
                    else
                    {
                        switch (oprFaildCodec)
                        {
                        case (byte)CreateGroupFaildCodec.Detail_REPEAT:
                        {
                            byte[] errorReply = new byte[2];
                            errorReply[0] = (byte)ClientHeadCodec.CreateGroup_ReplyFaild;
                            errorReply[1] = (byte)CreateGroupFaildCodec.Detail_REPEAT;
                            _client.SendMessage(new ScsRawDataMessage(errorReply, sourMessageid));

                            string logInfo = "{"
                                             + "ret:" + "CreateGroup => Detail_REPEAT" + " , "
                                             + "info:"
                                             + "{"
                                             + "from_detail:" + this.Detail
                                             + "from_token:" + this.Token + ","
                                             + "group_detail:" + gropDetail
                                             + "}"
                                             + "}";
                            _server.__AddLogItem(logInfo);
                            break;
                        }

                        default:
                        {
                            string logInfo = "{"
                                             + "ret:" + "CreateGroup => default:错误码分支未实现" + " , "
                                             + "info:"
                                             + "{"
                                             + "from_detail:" + this.Detail
                                             + "from_token:" + this.Token + ","
                                             + "group_detail:" + gropDetail
                                             + "}"
                                             + "}";
                            _server.__AddLogItem(logInfo);
                            return;
                        }
                        }
                    }
                }
                else
                {
                    //空名称视为非法detail
                    byte[] errorReply = new byte[2];
                    errorReply[0] = (byte)ClientHeadCodec.CreateGroup_ReplyFaild;
                    errorReply[1] = (byte)CreateGroupFaildCodec.Detail_REPEAT;
                    _client.SendMessage(new ScsRawDataMessage(errorReply, sourMessageid));

                    string logInfo = "{"
                                     + "ret:" + "CreateGroup => Detail_NULL" + " , "
                                     + "info:"
                                     + "{"
                                     + "from_detail:" + this.Detail
                                     + "from_token:" + this.Token + ","
                                     + "group_detail:" + gropDetail
                                     + "}"
                                     + "}";
                    _server.__AddLogItem(logInfo);
                }
                break;
            }

            case (int)ServerOprCodec.JoinGroup:
            {
                string       token           = parmMap["Token"] as string;
                byte         listOrRadioFlag = Byte.Parse(parmMap["ClientState"].ToString());
                byte         oprFaildCodec;
                AppErrorInfo ret = _server.JoinGroup(this, token, listOrRadioFlag, out oprFaildCodec);
                if (AppErrorInfo.APP_SUCESS == ret)
                {
                    byte[] sucReply = new byte[1];
                    sucReply[0] = (byte)ClientHeadCodec.JoinGroup_ReplySucess;
                    _client.SendMessage(new ScsRawDataMessage(sucReply, sourMessageid));

                    string logInfo = "{"
                                     + "ret:" + "JoinGroup => APP_SUCESS" + " , "
                                     + "info:"
                                     + "{"
                                     + "from_detail:" + this.Detail
                                     + "from_token:" + this.Token + ","
                                     + "group_token:" + token
                                     + "}"
                                     + "}";
                    _server.__AddLogItem(logInfo);
                }
                else
                {
                    switch (oprFaildCodec)
                    {
                    case (byte)JoinGroupFaildCodec.Client_REPEAT: { break; }

                    case (byte)JoinGroupFaildCodec.Group_INEXISTANCE: { break; }

                    default:
                    {
                        string logInfo1 = "{"
                                          + "ret:" + "CreateGroup => default:错误码分支未实现" + " , "
                                          + "info:"
                                          + "{"
                                          + "from_detail:" + this.Detail
                                          + "from_token:" + this.Token + ","
                                          + "group_token:" + token
                                          + "}"
                                          + "}";
                        _server.__AddLogItem(logInfo1);
                        return;
                    }
                    }
                    byte[] errorReply = new byte[1 + 1];
                    errorReply[0] = (byte)ClientHeadCodec.JoinGroup_ReplyFaild;
                    errorReply[1] = (byte)oprFaildCodec;
                    _client.SendMessage(new ScsRawDataMessage(errorReply, sourMessageid));

                    string logInfo2 = "{"
                                      + "ret:" + "JoinGroup => JoinGroup_ReplyFaild" + " , "
                                      + "info:"
                                      + "{"
                                      + "from_detail:" + this.Detail
                                      + "from_token:" + this.Token + ","
                                      + "group_token:" + token
                                      + "}"
                                      + "}";
                    _server.__AddLogItem(logInfo2);
                }
                break;
            }

            case (int)ServerOprCodec.ExitGroup:
            {
                string       token = parmMap["Token"] as string;
                byte         oprFaildCodec;
                AppErrorInfo ret = _server.ExitGroup(this, token, out oprFaildCodec);
                if (AppErrorInfo.APP_SUCESS == ret)
                {
                    byte [] sucReply = new byte [1];
                    sucReply[0] = (byte)ClientHeadCodec.ExitGroup_ReplySucess;
                    _client.SendMessage(new ScsRawDataMessage(sucReply, sourMessageid));
                }
                else
                {
                    switch (oprFaildCodec)
                    {
                    case (byte)ExitGroupFaildCodec.Client_UNBELONG: { break; }

                    case (byte)ExitGroupFaildCodec.Group_INEXISTANCE: { break; }

                    default:
                    {
                        throw new NotImplementedException();
                    }
                    }
                    byte[] errorReply = new byte[1 + 1];
                    errorReply[0] = (byte)ClientHeadCodec.ExitGroup_ReplyFaild;
                    errorReply[1] = (byte)oprFaildCodec;
                    _client.SendMessage(new ScsRawDataMessage(errorReply, sourMessageid));
                }
                break;
            }

            case (int)ServerOprCodec.RadioTransport:
            {
                List <string> tokens  = parmMap["Tokens"] as List <string>;
                byte[]        content = parmMap["Content"] as byte[];
                foreach (string gropToken in tokens)
                {
                    byte         oprFaildCodec;
                    AppErrorInfo ret = _server.SendRadioMessage(this, gropToken, content, out oprFaildCodec);
                    if (AppErrorInfo.APP_SUCESS == ret)
                    {
                        byte[] sucReply = new byte[1];
                        sucReply[0] = (byte)ClientHeadCodec.RadioTransport_ReplySucess;
                        _client.SendMessage(new ScsRawDataMessage(sucReply, sourMessageid));
                    }
                    else
                    {
                        switch (oprFaildCodec)
                        {
                        case (byte)RadioTransportFaildCodec.Trans_FORBIDDEN: { break; }

                        case (byte)RadioTransportFaildCodec.Client_UNBELONG: { break; }

                        case (byte)RadioTransportFaildCodec.Group_INEXISTANCE: { break; }

                        default:
                        {
                            throw new NotImplementedException();
                        }
                        }
                        byte[] errorReply = new byte[2];
                        errorReply[0] = (byte)ClientHeadCodec.RadioTransport_ReplyFaild;
                        errorReply[1] = (byte)oprFaildCodec;
                        _client.SendMessage(new ScsRawDataMessage(errorReply, sourMessageid));
                    }
                }
                break;
            }

            case (int)ServerOprCodec.GroupOnlineList:
            {
                List <Group> grops = Server.Groups;
                List <CSCommunicateClass.GroupInfo> jsonGrops = new List <CSCommunicateClass.GroupInfo>();
                foreach (Group grop in grops)
                {
                    string token  = grop.Token;
                    string detail = grop.Detail;

                    CSCommunicateClass.GroupInfo gropInfoInst = new CSCommunicateClass.GroupInfo(token, detail);
                    jsonGrops.Add(gropInfoInst);
                }
                byte[] bytJson = JsonSerializtionFactory.JSON <CSCommunicateClass.GroupInfo>(jsonGrops);

                byte [] replyInfo = new byte [1 + bytJson.Length];
                replyInfo[0] = (byte)ClientHeadCodec.GetOnlineGroup_ReplySucess;
                Buffer.BlockCopy(bytJson, 0, replyInfo, 1, bytJson.Length);

                _client.SendMessage(new ScsRawDataMessage(replyInfo, sourMessageid));
                break;
            }

            case (int)ServerOprCodec.GroupClientOnlineList:
            {
                string       gropToken = parmMap["Token"] as string;
                Group        gropInst;
                AppErrorInfo ret = _server.GetGroup(gropToken, out gropInst);
                if (AppErrorInfo.APP_SUCESS == ret)
                {
                    byte oprFaildCodec;
                    List <CSCommunicateClass.ClientInfo> jsonList;
                    AppErrorInfo ret2 = gropInst.GetOnlineClient(_token, out oprFaildCodec, out jsonList);
                    if (AppErrorInfo.APP_SUCESS == ret2)
                    {
                        byte[] bytJson = JsonSerializtionFactory.JSON <CSCommunicateClass.ClientInfo>(jsonList);

                        byte [] replyInfo = new byte [1 + bytJson.Length];
                        replyInfo[0] = (byte)ClientHeadCodec.GetGroupClient_ReplySucess;
                        Buffer.BlockCopy(bytJson, 0, replyInfo, 1, bytJson.Length);

                        _client.SendMessage(new ScsRawDataMessage(replyInfo, sourMessageid));
                    }
                    else
                    {
                        byte [] errorReply = new byte [2];
                        errorReply[0] = (byte)ClientHeadCodec.GetGroupClient_ReplyFaild;
                        errorReply[1] = (byte)oprFaildCodec;
                        _client.SendMessage(new ScsRawDataMessage(errorReply, sourMessageid));
                    }
                }
                else
                {
                    if (null == gropInst)
                    {
                        byte [] errorReply = new byte [2];
                        errorReply[0] = (byte)ClientHeadCodec.GetGroupClient_ReplyFaild;
                        errorReply[1] = (byte)GetGoupClientFaildCodec.Group_INEXISTENCE;
                        _client.SendMessage(new ScsRawDataMessage(errorReply, sourMessageid));
                    }
                }
                break;
            }

            case (int)ServerOprCodec.ClientCancle:
            {
                byte[] sucReplyInfo = new byte[1];
                sucReplyInfo[0] = (byte)ClientHeadCodec.ClientCancle_ReplySucess;
                _client.SendMessage(new ScsRawDataMessage(sucReplyInfo, sourMessageid));
                this.Cancle();
                break;
            }

            default:
            {
                break;
            }
            }
        }