/// <summary> 数据第二层分配中心;把数据归类 </summary> internal void codeManage(StateBase stateOne, StateCode statecode) { if (statecode == null || stateOne == null) { return; } StateCode stateCode = null; switch (statecode.State) { case PasswordCode._commonCode: //普通数据信息;抛给普通Code去处理 stateCode = EncryptionDecrypt.deciphering(statecode.DateByte, stateOne); CommonCodeManage(stateOne, stateCode); break; case PasswordCode._bigDateCode: //抛给分包Code去处理 stateCode = EncryptionDecryptSeparateDate.FileDecrypt(statecode.DateByte, stateOne); CommonCodeManage(stateOne, stateCode); break; case PasswordCode._fileCode: //抛给文件处理器去处理;如果返回null就不用发送了 byte[] haveDate = FileStart.ReceiveDateTO(statecode.DateByte, stateOne); if (haveDate != null) { Send(stateOne, haveDate); } break; } }
/// <summary> 当引擎非正常原因自动断开的时候触发此事件 P1=断开原因 </summary> internal void OnEngineLost(string str) { if (this.EngineLost != null) { EngineTool.EventInvoket(() => { this.EngineLost(str); }); FileStart.FileStopAll();//文件处理那里中断所有的文件 } }
/// <summary> 对文件进行续传 </summary> internal void FileContinue(StateBase stateOne, int fileLable) { byte[] haveDate = FileStart.FileContinue(fileLable, stateOne); if (haveDate == null) { throw new Exception("文件不存在或状态不在暂停状态"); } Send(stateOne, haveDate); }
/// <summary> 当引擎完全关闭释放资源的时候触发此事件 </summary> internal void OnEngineClose() { if (this.EngineClose != null && _engineStart == true) { _engineStart = false; EngineTool.EventInvoket(() => { this.EngineClose(); }); FileStart.FileStopAll();//文件处理那里中断所有的文件 } }
/// <summary> 关闭相连的scoket以及关联的TcpState,释放所有的资源 </summary> private void socketRemove(TcpState stateOne, string str) { if (stateOne == null) { return; } stateOne.WorkSocket.Close(); if (state.Remove(stateOne)) //当没有登录的时候断掉,不触发下面的事件 { EngineTool.EventInvoket(() => { Disconnection(stateOne.IpEndPoint, str); }); //当客户端断掉的时候触发此事件 FileOperate(stateOne.IpEndPoint.ToString() + "已经断开"); //记录 FileStart.FileStopITxBase(stateOne); } stateOne = null; }