基线 SVN r240
SVN-Revision: r240
This commit is contained in:
@@ -0,0 +1,118 @@
|
||||
/******************************
|
||||
* 说明:上传Socket通讯
|
||||
* 创建人:龚宇超
|
||||
* 创建日期:2018-01-23
|
||||
* 修改人:
|
||||
* 修改日期:
|
||||
* 修改备注:
|
||||
* 版本:1.0.0.0
|
||||
******************************/
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Lskj.SocketService;
|
||||
|
||||
namespace Lskj.SocketClient
|
||||
{
|
||||
/// <summary>
|
||||
/// 上传Socket通讯协议
|
||||
/// </summary>
|
||||
class ClientUploadSocket : ClientBaseSocket
|
||||
{
|
||||
public ClientUploadSocket()
|
||||
: base()
|
||||
{
|
||||
_protocolFlag = ProtocolFlag.Upload;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// <para>说明:上传</para>
|
||||
/// <para>创建人:龚宇超</para>
|
||||
/// <para>创建日期:2018-01-24 </para>
|
||||
/// <para>修改人:</para>
|
||||
/// <para>修改日期:</para>
|
||||
/// <para>修改备注:</para>
|
||||
/// <para>版本:1.0</para>
|
||||
/// </summary>
|
||||
/// <param name="dirName">目录</param>
|
||||
/// <param name="fileName">文件</param>
|
||||
/// <param name="fileSize">文件大小</param>
|
||||
/// <returns><c>true</c> if XXXX, <c>false</c> otherwise.</returns>
|
||||
public bool DoUpload(string dirName, string fileName, ref long fileSize)
|
||||
{
|
||||
bool bConnect = ReConnectAndLogin(); //检测连接是否还在,如果断开则重连并登录
|
||||
if (!bConnect)
|
||||
return bConnect;
|
||||
try
|
||||
{
|
||||
_outgoingDataAssembler.Clear();
|
||||
_outgoingDataAssembler.AddRequest();
|
||||
_outgoingDataAssembler.AddCommand(ProtocolKey.Upload);
|
||||
_outgoingDataAssembler.AddValue(ProtocolKey.DirName, dirName);
|
||||
_outgoingDataAssembler.AddValue(ProtocolKey.FileName, fileName);
|
||||
_outgoingDataAssembler.AddValue(ProtocolKey.FileSize, fileSize);
|
||||
SendCommand();
|
||||
bool bSuccess = RecvCommand();
|
||||
if (bSuccess)
|
||||
{
|
||||
bSuccess = CheckErrorCode();
|
||||
if (bSuccess)
|
||||
{
|
||||
bSuccess = _incomingDataParser.GetValue(ProtocolKey.FileSize, ref fileSize);
|
||||
}
|
||||
return bSuccess;
|
||||
}
|
||||
else
|
||||
return false;
|
||||
}
|
||||
catch (Exception E)
|
||||
{
|
||||
//记录日志
|
||||
_errorString = E.Message;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public bool DoData(byte[] buffer, int offset, int count)
|
||||
{
|
||||
try
|
||||
{
|
||||
_outgoingDataAssembler.Clear();
|
||||
_outgoingDataAssembler.AddRequest();
|
||||
_outgoingDataAssembler.AddCommand(ProtocolKey.Data);
|
||||
SendCommand(buffer, offset, count);
|
||||
return true;
|
||||
}
|
||||
catch (Exception E)
|
||||
{
|
||||
//记录日志
|
||||
_errorString = E.Message;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public bool DoEof(Int64 fileSize)
|
||||
{
|
||||
try
|
||||
{
|
||||
_outgoingDataAssembler.Clear();
|
||||
_outgoingDataAssembler.AddRequest();
|
||||
_outgoingDataAssembler.AddCommand(ProtocolKey.Eof);
|
||||
SendCommand();
|
||||
bool bSuccess = RecvCommand();
|
||||
if (bSuccess)
|
||||
return CheckErrorCode();
|
||||
else
|
||||
return false;
|
||||
}
|
||||
catch (Exception E)
|
||||
{
|
||||
//记录日志
|
||||
_errorString = E.Message;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user