Ejemplo n.º 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();
            }
        }
Ejemplo n.º 2
0
 /// <summary>
 /// 发送无消息体的消息到客户端
 /// </summary>
 /// <param name="type"></param>
 private void ResponseMessage(NetworkStream stream, MessageType type, int state)
 {
     try
     {
         MessageHead head   = new MessageHead((int)type, 0, state);
         MessageBag  bag    = new MessageBag(head);
         byte[]      buffer = bag.ToBytes();
         stream.Write(buffer, 0, buffer.Length);
     }
     catch (Exception e)
     {
         ExceptionService.WriteExceptionLog(e);
         DisposeUserMethod.DeleteUser();
         Client.Client.Close();
     }
 }
Ejemplo n.º 3
0
        /// <summary>
        /// 处理文件类型消息
        /// </summary>
        private void DealWithFileMessage(NetworkStream stream, FileMessageBag fileMsgBag)
        {
            //处理直接发送file包的情况(未经过用户验证)
            if (!_isRealUser)
            {
                return;
            }

            ///将当前上传文件加入待显示的字典
            string fileUrl = fileMsgBag.FileUrl;

            DisposeUserMethod.SetUserCurrentFile(fileUrl);

            ///接收文件
            byte[] fileContent = fileMsgBag.FileBody;

            if (FileSave(fileContent, fileUrl))
            {
                /// 向客户端发送文件url,表示此文件接收成功
                SendResponseMessage(stream, MessageType.FileReceive, fileUrl, 2);

                /// 还没接收完,继续接收
                if (_fileCount != _Total)
                {
                    GetMessage();
                }
                /// 接收完全,返回OK
                else
                {
                    //此信息写入日志
                    _receivedTime = DateTime.Now.ToString() + "." + DateTime.Now.Millisecond.ToString();


                    ///给客户端发送OK消息,表示所有文件接收完成
                    SendResponseMessage(stream, MessageType.FileReceive, string.Empty, 1);

                    LogService.WriteServerRunLog(LogLevel.Info, "来自" + _publisherIP + "的所有文件接收完成,开始整理接收的网站");

                    //将接收到的文件复制到相应的位置
                    DisposeSdsite disposeSdsite = new DisposeSdsite();

                    if (!disposeSdsite.ExecuteSdsite(_userFilePath, _projectName))
                    {
                        SendResponseMessage(stream, MessageType.FileTidy, string.Empty, 0);
                        return;
                    }
                    LogService.WriteServerRunLog(LogLevel.Info, "来自" + _publisherIP + "的sdsite文件已整理完毕,开始生成可浏览的网站");

                    //接收完毕,开始生成
                    //try
                    //{
                    //    //初始一下当前网站的根路径
                    //    string initPath = AnyFilePath.GetWebAbsolutePath(_userFilePath);
                    //    ToHtmlDirectoryService.InitializePath(initPath);

                    //    BuildSite buildSite = new BuildSite();

                    //    if (!buildSite.StartBuild(_userFilePath, _projectName))
                    //    {
                    //        SendResponseMessage(stream, MessageType.SiteBuild, string.Empty, 0);
                    //        return;
                    //    }
                    //}
                    //catch (Exception e)
                    //{
                    //    ExceptionService.WriteExceptionLog(e);
                    //    SendResponseMessage(stream, MessageType.SiteBuild, string.Empty, 0);
                    //    return;
                    //}

                    LogService.WriteServerRunLog(LogLevel.Info, "来自" + _publisherIP + "的sdsite文件,其网站生成完毕");

                    //此信息写入日志
                    _buildedTime = DateTime.Now.ToString() + "." + DateTime.Now.Millisecond.ToString();


                    //生成成功   返回消息;不管网站是否有同名,都将返回一个值(空,或是新网站名,或是原本的网站名)
                    SendResponseMessage(stream, MessageType.SiteBuild, _changedProjName, 1);

                    DisposeUserMethod.DeleteUser();
                    Client.Client.Close();

                    RecordLogToTable();

                    RecordInfoToTable(disposeSdsite);
                }
            }
        }