示例#1
0
        /// <summary>
        /// 处理用户类型消息
        /// </summary>
        private void DealWithUserMessage(NetworkStream stream, FirstMessageBag firstMsgBag)
        {
            if (DisposeUserMethod.RegistUser(
                    firstMsgBag.UserName,
                    firstMsgBag.UserPassport,
                    firstMsgBag.FilesCount,
                    firstMsgBag.SiteName,
                    firstMsgBag.SiteId,
                    out _Total, out _userFilePath, out _projectName, out _changedProjName, out _action))
            {
                //此信息写入日志
                _publisherID        = firstMsgBag.UserName;
                _projectID          = firstMsgBag.SiteId;
                _softwareVersion    = firstMsgBag.SdVersion;
                _projectSavedPath   = Path.Combine(AnyFilePath.SdSiteFilePath, _userFilePath);
                _projectBuildedPath = Path.Combine(AnyFilePath.SdWebFilePath, _userFilePath);

                //向客户端发送消息,表明验证是否成功
                SendResponseMessage(stream, MessageType.User, string.Empty, 1);
                _isRealUser = true;
                GetMessage();
            }
            else
            {
                SendResponseMessage(stream, MessageType.User, string.Empty, 0);
                DisposeUserMethod.DeleteUser();
            }
        }
示例#2
0
        /// <summary>
        /// 解析客户端发过来的消息包
        /// </summary>
        /// <param name="bag"></param>
        private void AnalyzeClientMessage(NetworkStream stream, MessageBag bag)
        {
            LogService.WriteServerRunLog(LogLevel.Info, "解析来自" + _publisherIP + "的不同类型的消息包");

            MessageType type = (MessageType)bag.Head.Type;

            switch (type)
            {
            case MessageType.User:
                if (bag.Head.State == 1)     //处理客户端传来的第一个消息包
                {
                    FirstMessageBag firstBag = (FirstMessageBag)bag;
                    DealWithUserMessage(stream, firstBag);
                }
                else if (bag.Head.State == 2)      //用户退出,用户切换
                {
                    string getUserId = Encoding.UTF8.GetString(bag.BytesBody);

                    if (CommonService.RecordUserDic.ContainsKey(getUserId))
                    {
                        CommonService.RecordUserDic.Remove(getUserId);
                    }
                }
                else if (bag.Head.State == 3)      //由CGI发送的UserID
                {
                    DealWithCGIMessage(stream, bag);
                }
                break;

            case MessageType.File:
                FileMessageBag fileBag = (FileMessageBag)bag;
                DealWithFileMessage(stream, fileBag);
                break;

            default:
                Debug.Fail("未知在MessageType:" + type);
                break;
            }
        }