/// <summary> /// Dispose /// </summary> public void Dispose() { try { if (IOSocket != null) { IOSocket.Shutdown(SocketShutdown.Both); } _receiveArgs.Dispose(); _sendArgs.Dispose(); _sendBuffer.Clear(); _tempSBuffer.Clear(); _receiveBuffer.Clear(); _tempRBuffer.Clear(); _sendQueue.Clear(); _receiveQueue.Clear(); _isSending = false; _isReceiving = false; } catch (Exception) { // throws if client process has already closed, so it is not necessary to catch. } finally { if (IOSocket != null) { IOSocket.Close(); IOSocket = null; } } }
public void CreateCfgBytesFile(string path) { MoByteBuffer byteBuffer = new MoByteBuffer(ResDefine.CfgStreamMaxLen); MoByteBuffer tableBuffer = new MoByteBuffer(ResDefine.TabStreamMaxLen); for (int i = 0; i < _tables.Count; i++) { //写入行标记 byteBuffer.WriteShort(ResDefine.TabStreamHead); //清空缓存 tableBuffer.Clear(); //写入数据 IRow row = _tables[i].Row; for (int cellNum = row.FirstCellNum; cellNum < row.LastCellNum; cellNum++) { ICell cell = row.GetCell(cellNum); string value = GetTableCellValue(cell); HeadWrapper head = GetHead(cellNum); WriteCell(tableBuffer, head, value); } //检测数据大小有效性 int tabSize = tableBuffer.ReadableBytes(); if (tabSize == 0) { throw new Exception("Table size is zero."); } //写入到总缓存 byteBuffer.WriteInt(tabSize); byteBuffer.WriteBytes(tableBuffer.ReadBytes(tabSize)); } //创建文件 string filePath = GetSaveFileFullPath(path, ".bytes"); using (FileStream fs = new FileStream(filePath, FileMode.Create)) { byte[] data = byteBuffer.Buf; int length = byteBuffer.ReadableBytes(); fs.Write(data, 0, length); } }