예제 #1
0
        public override void ExecuteCommand(ChatSession session, BinaryRequestInfo requestInfo)
        {
            session.Logger.DebugFormat("Cmd: EditProfile, RemoteEndPoint: {0}", session.RemoteEndPoint);
            string content = Encoding.UTF8.GetString(requestInfo.Body, 0, requestInfo.Body.Length);

            session.Logger.DebugFormat("消息内容:{0}", content);

            ResultInfo result = null;

            try
            {
                //解析Json字符串
                var user = JConverter.Deserialize <User>(content);

                result = BizManager.AutofacBootstrapper.Resolve <IUserBiz>().UpdateUser(user);
            }
            catch (Exception ex)
            {
                result = new ResultInfo(ex);
            }

            ArraySegmentWrapper segmentWrapper = new ArraySegmentWrapper(Constants.EDIT_PROFILE_RESPONSE_KEY, JConverter.SerializeToBytes(result));

            session.SendData(session, segmentWrapper.Wrapper());
        }
예제 #2
0
        public void Deserialize <T>(T value)
        {
            var json = JsonConvert.SerializeObject(value);

            _converter
            .Deserialize <T>(json)
            .Should().BeEquivalentTo(value);
        }
예제 #3
0
        public long Velo()
        {
            long stub = 0;

            foreach (var element in _dataset)
            {
                var deserialized = _converter.Deserialize <BigObject>(element);
                stub += deserialized.Int;
            }

            return(stub);
        }
예제 #4
0
        private void DataAnalyze(string cmd, string msg)
        {
            JsonDict           json  = null;
            JsonDictCollection jsons = null;

            switch (cmd)
            {
            case Constants.CONNECTED_RESPONSE_KEY:
                //建立连接响应报文
                var res1 = JConverter.Deserialize <ResultInfo>(msg);
                this.ConnectedCallbackHandler?.Invoke(res1);
                break;

            case Constants.SIGNIN_RESPONSE_KEY:
                //用户登录响应报文
                var res2 = JConverter.Deserialize <ResultInfo <User> >(msg);
                this.SignInCallbackHandler?.Invoke(res2);
                break;

            case Constants.SIGNUP_RESPONSE_KEY:
                //用户注册
                var res3 = JConverter.Deserialize <ResultInfo>(msg);
                this.SignUpCallbackHandler?.Invoke(res3);
                break;

            case Constants.ONLINE_LIST_RESPONSE_KEY:
                //获取在线用户列表
                var res4 = JConverter.Deserialize <ResultInfo <IEnumerable <User> > >(msg);
                this.GetOnlineListCallbackHandler?.Invoke(res4);
                break;

            case Constants.TALK_RESPONSE_KEY:
                //对话
                var res5 = JConverter.Deserialize <ResultInfo <Message> >(msg);
                this.TalkCallbackHandler?.Invoke(res5);
                break;

            case Constants.SEARCH_USER_RESPONSE_KEY:
                //搜索用户
                var res6 = JConverter.Deserialize <ResultInfo <IEnumerable <User> > >(msg);
                this.SearchUserCallbackHandler?.Invoke(res6);
                break;

            case Constants.SAVE_CONTACTS_RESPONSE_KEY:
                //保存通讯录
                var res7 = JConverter.Deserialize <ResultInfo>(msg);
                this.SaveContactsCallbackHandler?.Invoke(res7);
                break;

            case Constants.GET_CONTACTS_RESPONSE_KEY:
                //获取通讯录
                var res8 = JConverter.Deserialize <ResultInfo <IEnumerable <Contacts> > >(msg);
                this.GetContactsCallbackHandler?.Invoke(res8);
                break;

            case Constants.EDIT_PROFILE_RESPONSE_KEY:
                //修改个人资料
                var res9 = JConverter.Deserialize <ResultInfo>(msg);
                this.EditProfileCallbackHandler?.Invoke(res9);
                break;

            case Constants.UPLOAD_AVATAR_RESPONSE_KEY:
                //上传头像
                var res10 = JConverter.Deserialize <ResultInfo>(msg);
                this.UploadAvatarCallbackHandler?.Invoke(res10);
                break;

            case Constants.DOWNLOAD_AVATAR_RESPONSE_KEY:
                //下载头像
                var res11 = JConverter.Deserialize <ResultInfo <Tuple <long, byte[]> > >(msg);
                this.DownloadAvatarCallbackHandler?.Invoke(res11);
                break;

            case Constants.NOTIFY_ONLINE_RESPONSE_KEY:
            case Constants.NOTIFY_OFFLINE_RESPONSE_KEY:
                this.GetOnlineList();
                break;

            default:
                var res99 = new ReceivedRes()
                {
                    FromUser = "******", ToUser = "******", Content = msg
                };
                this.ReceivedCallbackHandler?.Invoke(res99);
                break;
            }
        }
예제 #5
0
        public void Deserialize_Array_Objects(Boo[] array)
        {
            var json = JsonConvert.SerializeObject(array);

            var deserialized = _converter.Deserialize <Boo[]>(json);

            for (var i = 0; i < array.Length; i++)
            {
                var element             = array[i];
                var deserializedElement = deserialized[i];

                Assert.Equal(element.Bool, deserializedElement.Bool);
                Assert.Equal(element.Double, deserializedElement.Double);
                Assert.Equal(element.Float, deserializedElement.Float);
                Assert.Equal(element.Int, deserializedElement.Int);
            }
        }