/// <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(); } }
/// <summary> /// 监听并处理客户端请求 /// </summary> public void Listen() { ///读取配置文件,获取端口号 Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None); string serverPort = config.AppSettings.Settings["ServerPort"].Value; Port = Convert.ToInt32(serverPort); ///初始化PathService SimplusD.PathService.Initialize(Application.StartupPath); try { ///初始化Tcp服务端 _listener = new TcpListener(IPAddress.Any, Port); _listener.Start(); while (true) { ///接收客户端请求 TcpClient tcpClient = _listener.AcceptTcpClient(); ///启动一个线程来处理这此客户端请求 ClientThread clientThread = new ClientThread(tcpClient); clientThread._publisherIP = ((IPEndPoint)tcpClient.Client.RemoteEndPoint).Address.ToString(); Thread thread = new Thread(new ThreadStart(clientThread.ThreadCallback)); thread.Start(); LogService.WriteServerRunLog(LogLevel.Info, "接收来自" + clientThread._publisherIP + "一个请求,线程启动"); } } catch (Exception e) { ExceptionService.WriteExceptionLog(e); MessageService.Show(e.Message); Application.Exit(); } }
/// <summary> /// 保存文件 /// </summary> /// <param name="fileContent"></param> /// <returns></returns> private bool FileSave(byte[] fileContent, string fileUrl) { try { ///保存到临时文件夹 ///modified by zhangling on 2008年6月12日 string _fileUrl = Path.Combine(AnyFilePath.GetTempFolderAbsolutePath(_userFilePath), fileUrl); FileService.FileSave(fileContent, _fileUrl); ///接收到的文件数+1 _fileCount += 1; ///总结接收文件的字节数 _uploadFileBytesAmount += fileContent.Length; return(true); } catch (Exception e) { ExceptionService.WriteExceptionLog(e); return(false); } }
//SdsiteXmlDocument sdsiteDocument; /// <summary> /// 开始生成网站 /// </summary> /// <returns></returns> public bool StartBuild(string partPath, string projName) { string sdPath = AnyFilePath.GetSdsitesFolderAbsolutePath(partPath); string buildPath = AnyFilePath.GetWebAbsolutePath(partPath); toHtmlHelperObj = new ToHtmlHelper(sdPath, buildPath); resStartPath = sdPath + @"Root\" + @"Resource"; resToPath = buildPath + @"\Resource"; buildFile = new BuildFile(); buildFile.SdsiteDocument = toHtmlHelperObj.SdsiteXmlDocument; buildFile.ToHtmlHelperObj = toHtmlHelperObj; FolderXmlElement channelRootEle = toHtmlHelperObj.SdsiteXmlDocument.RootChannel; //string sdPath = AnyFilePath.GetSdsitesFolderAbsolutePath(partPath) + projName + ".sdsite"; ////打开网站 //this.sdsiteDocument = new SdsiteXmlDocument(sdPath); //this.sdsiteDocument.Load(); //buildFile = new BuildFile(); //buildFile.SdsiteDocument = this.sdsiteDocument; //buildFile.BuildFilePath = partPath; //FolderXmlElement channelRootEle = this.sdsiteDocument.RootChannel; try { SearchAndProcess(channelRootEle); return(true); } catch (Exception Ex) { ExceptionService.WriteExceptionLog(Ex); return(false); } }