最新评论
Re:幻灯片会场管理 BLoodMaster 2012-05-25 12:32
//版本信息响应
case CmdTypePro.SpeechVersionRes:
res.SpeechVersionResStruct = new SpeechVersionRes();
res.SpeechVersionResStruct.SpeechVersionList = new List<SpeechVersionStruct>();
for (int index = 0; index < preAnalyze.DataBody.Length; )
{
index = tag.Decode(preAnalyze.DataBody, index);
switch (tag.TagType)
{
case TagTypePro.SpeechVersion:
byte[] tmp = tag.StreamDatagram;
SpeechVersionStruct tmpSpeech = new SpeechVersionStruct();
for (int indexInner = 0; indexInner < tmp.Length; )
{
TagLV tagTmp = new TagLV();
indexInner = tagTmp.Decode(tmp, indexInner);
switch (tagTmp.TagType)
{
case TagTypePro.SpeechVersionName:
tmpSpeech.SpeechVersionName = tag.StrValue;
break;
default://如果出现其他tag值,则数据包存在问题
res.ErrorType = ErrorTypePro.NotLegal;
return res;
}
}
res.SpeechVersionResStruct.SpeechVersionList.Add(tmpSpeech);
break;
default:
res.ErrorType = ErrorTypePro.NotLegal;
return res;
}
}
break;
case CmdTypePro.Unknow:
default:
res.ErrorType = ErrorTypePro.UnknowCMD;
break;
}
return res;
}
#endregion
#region 检查数据包 成员
/// <summary>
///检查数据包是否完整,如果存在完整包,则返回数据包的开始位置
/// </summary>
/// <param name="m_pDataStream"></param>
/// <returns></returns>
public int AnalyzDatagram(byte[] m_pDataStream, out int size)
{
Datagram datagram = new Datagram();
return datagram.AnalyzDatagram(m_pDataStream,out size);
}
#endregion
}
}
Re:幻灯片会场管理 BLoodMaster 2012-05-25 12:31
//演讲信息响应
case CmdTypePro.SpeechAllRes:
res.SpeechAllResStruct = new SpeechAllRes();
res.ScheduleReqStruct.SpeechList = new List<SpeeachStruct>();
for (int index = 0; index < preAnalyze.DataBody.Length; )
{
index = tag.Decode(preAnalyze.DataBody, index);
switch (tag.TagType)
{
case TagTypePro.SpeechTotal:
byte[] tmp = tag.StreamDatagram;
SpeeachStruct tmpSpeech = new SpeeachStruct();
for (int indexInner = 0; indexInner < tmp.Length; )
{
TagLV tagTmp = new TagLV();
indexInner = tagTmp.Decode(tmp, indexInner);
switch (tagTmp.TagType)
{
case TagTypePro.SpeakerName:
tmpSpeech.SpeakerName = tag.StrValue;
break;
case TagTypePro.SpeakerUnit:
tmpSpeech.SpeakerUnit = tag.StrValue;
break;
case TagTypePro.SpeechBatch:
tmpSpeech.SpeechBatch = tag.StrValue;
break;
case TagTypePro.SpeechStartTime:
tmpSpeech.SpeechStartTime = Convert.ToDateTime(tag.StrValue);
break;
case TagTypePro.SpeechEndTime:
tmpSpeech.SpeechEndTime = Convert.ToDateTime(tag.StrValue);
break;
case TagTypePro.SpeechTitle:
tmpSpeech.SpeechTitle = tag.StrValue;
break;
default://如果出现其他tag值,则数据包存在问题
res.ErrorType = ErrorTypePro.NotLegal;
return res;
}
}
res.ScheduleReqStruct.SpeechList.Add(tmpSpeech);
break;
default:
res.ErrorType = ErrorTypePro.NotLegal;
return res;
}
}
break;
//版本信息请求
case CmdTypePro.SpeechVersionReq:
res.SpeechVersionReqStruct = new SpeechVersionReq();
for (int index = 0; index < preAnalyze.DataBody.Length; )
{
index = tag.Decode(preAnalyze.DataBody, index);
switch (tag.TagType)
{
case TagTypePro.SpeechBatch:
res.SpeechVersionReqStruct.SpeechBatch = tag.StrValue;
break;
default://如果出现其他tag值,则数据包存在问题
res.ErrorType = ErrorTypePro.NotLegal;
return res;
}
}
break;
Re:幻灯片会场管理 BLoodMaster 2012-05-25 12:31
//文件请求响应
case CmdTypePro.FileRes:
res.FileResStruct = new FileRes();
for (int index = 0; index < preAnalyze.DataBody.Length; )
{
index = tag.Decode(preAnalyze.DataBody, index);
switch (tag.TagType)
{
case TagTypePro.FileRes:
res.FileResStruct.IsSuccess = tag.StrValue == ConstantVar.FileTransferSuccess;
break;
default://如果出现其他tag值,则数据包存在问题
res.ErrorType = ErrorTypePro.NotLegal;
return res;
}
}
break;
//演讲信息请求
case CmdTypePro.SpeechAllReq:
res.SpeechAllReqStruct = new SpeechAllReq();
for (int index = 0; index < preAnalyze.DataBody.Length; )
{
index = tag.Decode(preAnalyze.DataBody, index);
switch (tag.TagType)
{
case TagTypePro.Account:
res.SpeechAllReqStruct.SpeakerAccount = tag.StrValue;
break;
default://如果出现其他tag值,则数据包存在问题
res.ErrorType = ErrorTypePro.NotLegal;
return res;
}
}
break;
Re:幻灯片会场管理 BLoodMaster 2012-05-25 11:48
//日程信息分发响应
case CmdTypePro.ScheduleDistRes:
res.ScheduleResStruct = new ScheduleRes();
for (int index = 0; index < preAnalyze.DataBody.Length; )
{
index = tag.Decode(preAnalyze.DataBody, index);
switch (tag.TagType)
{
case TagTypePro.ScheduleRes:
res.ScheduleResStruct.IsSuccess = tag.StrValue == ConstantVar.ScheduleSuccess;
break;
default://如果出现其他tag值,则数据包存在问题
res.ErrorType = ErrorTypePro.NotLegal;
return res;
}
}
break;
//文件传输请求,后续部分为文件内容相关信息
case CmdTypePro.FileReq:
res.FileReqStruct = new FileReq();
for (int index = 0; index < preAnalyze.DataBody.Length; )
{
index = tag.Decode(preAnalyze.DataBody, index);
switch (tag.TagType)
{
case TagTypePro.BatchInfo:
res.FileReqStruct.SpeechBatch = tag.StrValue;
break;
case TagTypePro.FileType:
switch (tag.StrValue)
{
case ConstantVar.PPT:
res.FileReqStruct.FileType = TransferFileTypePro.PPT;
break;
case ConstantVar.IMAGE:
res.FileReqStruct.FileType = TransferFileTypePro.IMAGE;
break;
case ConstantVar.FLV:
default:
res.FileReqStruct.FileType = TransferFileTypePro.FLV;
break;
}
break;
case TagTypePro.IsFolder:
res.FileReqStruct.IsFolder = tag.StrValue == ConstantVar.IsFolder;
break;
case TagTypePro.CurrPath:
res.FileReqStruct.CurrPath = tag.StrValue;
break;
case TagTypePro.FileName:
res.FileReqStruct.FileName = tag.StrValue;
break;
case TagTypePro.TotalBagCount:
res.FileReqStruct.TotalBagCount = Convert.ToInt32(tag.StrValue);
break;
case TagTypePro.CurrBagID:
res.FileReqStruct.CurrBagID = Convert.ToInt32(tag.StrValue);
break;
case TagTypePro.HasNextBag:
res.FileReqStruct.HasNextBag = tag.StrValue == ConstantVar.HasNextBag;
break;
case TagTypePro.FileContent:
res.FileReqStruct.FileContent = tag.StreamDatagram;
break;
default://如果出现其他tag值,则数据包存在问题
res.ErrorType = ErrorTypePro.NotLegal;
return res;
}
}
break;
Re:幻灯片会场管理 BLoodMaster 2012-05-25 11:48
//演讲者信息分发响应
case CmdTypePro.SpeakerDistRes:
res.SpeakerResStruct = new SpeakerRes();
for (int index = 0; index < preAnalyze.DataBody.Length; )
{
index = tag.Decode(preAnalyze.DataBody, index);
switch (tag.TagType)
{
case TagTypePro.SpeakerRes:
res.SpeakerResStruct.IsSuccess = tag.StrValue == ConstantVar.SpeakerSuccess;
break;
default://如果出现其他tag值,则数据包存在问题
res.ErrorType = ErrorTypePro.NotLegal;
return res;
}
}
break;
//日程信息,其中tag值为TagTypePro.Schedule,数据部分为TLV结构,包含演讲者姓名、演讲者单位、演讲批次、开始时间、结束时间、演讲主题
case CmdTypePro.ScheduleDistReq:
res.ScheduleReqStruct = new ScheduleReq();
res.ScheduleReqStruct.SpeechList = new List<SpeeachStruct>();
for (int index = 0; index < preAnalyze.DataBody.Length; )
{
index = tag.Decode(preAnalyze.DataBody, index);
switch (tag.TagType)
{
case TagTypePro.ScheduleTotal:
byte[] tmp = tag.StreamDatagram;
SpeeachStruct tmpSpeech = new SpeeachStruct();
for (int indexInner = 0; indexInner < tmp.Length;)
{
TagLV tagTmp = new TagLV();
indexInner = tagTmp.Decode(tmp, indexInner);
switch (tagTmp.TagType)
{
case TagTypePro.SpeakerName:
tmpSpeech.SpeakerName = tag.StrValue;
break;
case TagTypePro.SpeakerUnit:
tmpSpeech.SpeakerUnit = tag.StrValue;
break;
case TagTypePro.SpeechBatch:
tmpSpeech.SpeechBatch = tag.StrValue;
break;
case TagTypePro.SpeechStartTime:
tmpSpeech.SpeechStartTime = Convert.ToDateTime(tag.StrValue);
break;
case TagTypePro.SpeechEndTime:
tmpSpeech.SpeechEndTime = Convert.ToDateTime(tag.StrValue);
break;
case TagTypePro.SpeechTitle:
tmpSpeech.SpeechTitle = tag.StrValue;
break;
default://如果出现其他tag值,则数据包存在问题
res.ErrorType = ErrorTypePro.NotLegal;
return res;
}
}
res.ScheduleReqStruct.SpeechList.Add(tmpSpeech);
break;
default:
res.ErrorType = ErrorTypePro.NotLegal;
return res;
}
}
break;
Re:幻灯片会场管理 BLoodMaster 2012-05-25 11:47
//机器码响应
case CmdTypePro.KeyRes:
res.MachineResStruct = new MachineRes();
for (int index = 0; index < preAnalyze.DataBody.Length; )
{
index = tag.Decode(preAnalyze.DataBody, index);
switch (tag.TagType)
{
case TagTypePro.MachineKeyRes:
res.MachineResStruct.IsSuccess = tag.StrValue == ConstantVar.MachineSuccess;
break;
default://如果出现其他tag值,则数据包存在问题
res.ErrorType = ErrorTypePro.NotLegal;
return res;
}
}
break;
//鉴权请求
case CmdTypePro.AuthReq:
res.AuthReqStruct = new AuthReq();
for (int index = 0; index < preAnalyze.DataBody.Length;)
{
index = tag.Decode(preAnalyze.DataBody, index);
switch (tag.TagType)
{
case TagTypePro.Account:
res.AuthReqStruct.UserName = tag.StrValue;
break;
case TagTypePro.Pwd:
res.AuthReqStruct.UserPwd = tag.StrValue;
break;
default://如果出现其他tag值,则数据包存在问题
res.ErrorType = ErrorTypePro.NotLegal;
return res;
}
}
break;
//鉴权结果响应
case CmdTypePro.AuthRes:
res.AuthResStruct = new AuthRes();
for (int index = 0; index < preAnalyze.DataBody.Length; )
{
index = tag.Decode(preAnalyze.DataBody, index);
switch (tag.TagType)
{
case TagTypePro.AuthRes:
res.AuthResStruct.IsSuccess = tag.StrValue == ConstantVar.AuthSuccess;
break;
default://如果出现其他tag值,则数据包存在问题
res.ErrorType = ErrorTypePro.NotLegal;
return res;
}
}
break;
//演讲者信息分发请求
case CmdTypePro.SpeakerDistReq:
res.SpeakerReqStruct = new SpeakerReq();
for (int index = 0; index < preAnalyze.DataBody.Length; )
{
index = tag.Decode(preAnalyze.DataBody, index);
switch (tag.TagType)
{
case TagTypePro.SpeakerName:
res.SpeakerReqStruct.SpeakerName = tag.StrValue;
break;
case TagTypePro.SpeakerUnit:
res.SpeakerReqStruct.SpeakerUnit = tag.StrValue;
break;
case TagTypePro.SpeakerImage:
res.SpeakerReqStruct.SpeakerImagePath = tag.StrValue;
break;
default://如果出现其他tag值,则数据包存在问题
res.ErrorType = ErrorTypePro.NotLegal;
return res;
}
}
break;
Re:幻灯片会场管理 BLoodMaster 2012-05-25 11:46
/// <summary>
/// 解包
/// </summary>
/// <param name="m_pDatagram"></param>
/// <returns></returns>
public AnalyzeStruct Decode(byte[] m_pDatagram)
{
AnalyzeStruct res = new AnalyzeStruct();
//初步解包,得到数据部分
Datagram preAnalyze = new Datagram();
preAnalyze.Decode(m_pDatagram);
//数据包非法
if (preAnalyze.ErrorType != ErrorTypePro.None)
{
res.ErrorType = preAnalyze.ErrorType;
return res;
}
res.ErrorType = ErrorTypePro.None;
res.CmdType = preAnalyze.CmdType;
res.ProtocolType = preAnalyze.ProtocolType;
//解压数据部分
TagLV tag = new TagLV();
switch (res.CmdType)
{
//心跳
case CmdTypePro.HeartBeat:
res.HeartBeatStruct = new HeartBeat();
for (int index = 0; index < preAnalyze.DataBody.Length; )
{
index = tag.Decode(preAnalyze.DataBody, index);
switch (tag.TagType)
{
case TagTypePro.HeartBeat:
res.HeartBeatStruct.LastBeat = DateTime.Now;
break;
default://如果出现其他tag值,则数据包存在问题
res.ErrorType = ErrorTypePro.NotLegal;
return res;
}
}
break;
//机器码请求
case CmdTypePro.KeyReq:
res.MachineReqStruct = new MachineReq();
for (int index = 0; index < preAnalyze.DataBody.Length; )
{
index = tag.Decode(preAnalyze.DataBody, index);
switch (tag.TagType)
{
case TagTypePro.MachineKey:
res.MachineReqStruct.MachineKey = tag.StrValue;
break;
default://如果出现其他tag值,则数据包存在问题
res.ErrorType = ErrorTypePro.NotLegal;
return res;
}
}
break;
Re:幻灯片会场管理 BLoodMaster 2012-05-25 11:42
/// <summary>
/// 所有版本信息响应
/// </summary>
/// <param name="m_pRes"></param>
/// <returns></returns>
public byte[] SpeechVersionRes(SpeechVersionRes m_pRes)
{
//获取数据部分
TagLV tag = new TagLV();
byte[] tmp = new byte[0];
//所有演讲信息
for (int i = 0; i < m_pRes.SpeechVersionList.Count; i++)
{
//版本名称
tag.StrValue = m_pRes.SpeechVersionList[i].SpeechVersionName;
tag.TagType = TagTypePro.SpeechVersionName;
byte[] tmp0 = tag.Encode();
tmp = CombineArray(tmp, tmp0);
}
tag.TagType = TagTypePro.SpeechVersion;
tag.StreamDatagram = tmp;
tmp = tag.Encode();
//拼接数据部分
byte[] bodyArray = CombineArray(tmp);
//封装协议
Datagram datagram = new Datagram();
datagram.ProtocolType = ProtocolTypePro.Command;
datagram.CmdType = CmdTypePro.KeyReq;
datagram.DataBody = bodyArray;
byte[] resPro = datagram.Encode();
return resPro;
}
#endregion
#region 解码方法 成员
Re:幻灯片会场管理 BLoodMaster 2012-05-25 11:42
/// <summary>
/// 所有演讲信息响应
/// </summary>
/// <param name="m_pRes"></param>
/// <returns></returns>
public byte[] SpeechAllRes(SpeechAllRes m_pRes)
{
//获取数据部分
TagLV tag = new TagLV();
byte[] tmp = new byte[0];
//所有演讲信息
for (int i = 0; i < m_pRes.SpeechList.Count; i++)
{
//演讲批次
tag.StrValue = m_pRes.SpeechList[i].SpeechBatch;
tag.TagType = TagTypePro.SpeechBatch;
byte[] tmp0 = tag.Encode();
//演讲者姓名
tag.StrValue = m_pRes.SpeechList[i].SpeakerName;
tag.TagType = TagTypePro.SpeakerName;
byte[] tmp1 = tag.Encode();
//演讲者单位
tag.StrValue = m_pRes.SpeechList[i].SpeakerUnit;
tag.TagType = TagTypePro.SpeakerUnit;
byte[] tmp2 = tag.Encode();
//演讲主题
tag.StrValue = m_pRes.SpeechList[i].SpeechTitle;
tag.TagType = TagTypePro.SpeechTitle;
byte[] tmp3 = tag.Encode();
//演讲开始时间
tag.StrValue = m_pRes.SpeechList[i].SpeechStartTime.ToString("YYYY-MM-DD HH:mm:SS");
tag.TagType = TagTypePro.SpeechStartTime;
byte[] tmp4 = tag.Encode();
//演讲结束时间
tag.StrValue = m_pRes.SpeechList[i].SpeechEndTime.ToString("YYYY-MM-DD HH:mm:SS");
tag.TagType = TagTypePro.SpeechEndTime;
byte[] tmp5 = tag.Encode();
tmp = CombineArray(tmp, tmp0, tmp1, tmp2, tmp3, tmp4, tmp5);
}
tag.TagType = TagTypePro.ScheduleTotal;
tag.StreamDatagram = tmp;
tmp = tag.Encode();
//拼接数据部分
byte[] bodyArray = CombineArray(tmp);
//封装协议
Datagram datagram = new Datagram();
datagram.ProtocolType = ProtocolTypePro.Command;
datagram.CmdType = CmdTypePro.KeyReq;
datagram.DataBody = bodyArray;
byte[] resPro = datagram.Encode();
return resPro;
}
/// <summary>
/// 所有版本信息请求
/// </summary>
/// <param name="m_pReq"></param>
/// <returns></returns>
public byte[] SpeechVersionReq(SpeechVersionReq m_pReq)
{
//获取数据部分
TagLV tag = new TagLV();
tag.TagType = TagTypePro.SpeechBatch;
tag.StrValue = m_pReq.SpeechBatch;
byte[] resArray = tag.Encode();
//拼接数据部分
byte[] bodyArray = CombineArray(resArray);
//封装协议
Datagram datagram = new Datagram();
datagram.ProtocolType = ProtocolTypePro.Command;
datagram.CmdType = CmdTypePro.KeyReq;
datagram.DataBody = bodyArray;
byte[] resPro = datagram.Encode();
return resPro;
}
Re:幻灯片会场管理 BLoodMaster 2012-05-25 11:42
/// <summary>
/// 文件传输请求
/// </summary>
/// <param name="m_pReq"></param>
/// <returns></returns>
public byte[] EncodeFileTranferReq(FileReq m_pReq)
{
//获取数据部分
TagLV tag = new TagLV();
//当前包号
tag.StrValue = m_pReq.CurrBagID.ToString();
tag.TagType = TagTypePro.CurrBagID;
byte[] tmp0 = tag.Encode();
//当前路径
tag.StrValue = m_pReq.CurrPath;
tag.TagType = TagTypePro.CurrPath;
byte[] tmp1 = tag.Encode();
//文件内容
tag.StreamDatagram = m_pReq.FileContent;
tag.TagType = TagTypePro.FileContent;
byte[] tmp2 = tag.Encode();
//文件名称
tag.StrValue = m_pReq.FileName;
tag.TagType = TagTypePro.FileName;
byte[] tmp3 = tag.Encode();
//是否存在下一个包
tag.StrValue = m_pReq.HasNextBag ? ConstantVar.HasNextBag : ConstantVar.NotHasNextBag;
tag.TagType = TagTypePro.HasNextBag;
byte[] tmp4 = tag.Encode();
//是否为文件夹
tag.StrValue = m_pReq.IsFolder ? ConstantVar.IsFolder : ConstantVar.NotFolder;
tag.TagType = TagTypePro.IsFolder;
byte[] tmp5 = tag.Encode();
//演讲批次
tag.StrValue = m_pReq.SpeechBatch;
tag.TagType = TagTypePro.SpeechBatch;
byte[] tmp6 = tag.Encode();
//总报数
tag.StrValue = m_pReq.TotalBagCount.ToString();
tag.TagType = TagTypePro.TotalBagCount;
byte[] tmp7 = tag.Encode();
//传输类型
switch (m_pReq.FileType)
{
case TransferFileTypePro.PPT:
tag.StrValue = ConstantVar.PPT;
break;
case TransferFileTypePro.FLV:
tag.StrValue = ConstantVar.FLV;
break;
case TransferFileTypePro.IMAGE:
tag.StrValue = ConstantVar.IMAGE;
break;
default:
tag.StrValue = ConstantVar.PPT;
break;
}
tag.TagType = TagTypePro.FileType;
byte[] tmp8 = tag.Encode();
//拼接数据部分
byte[] bodyArray = CombineArray(tmp0, tmp1, tmp2, tmp3, tmp4, tmp5, tmp6, tmp7, tmp8);
//封装协议
Datagram datagram = new Datagram();
datagram.ProtocolType = ProtocolTypePro.FileTransfer;
datagram.CmdType = CmdTypePro.KeyReq;
datagram.DataBody = bodyArray;
byte[] resPro = datagram.Encode();
return resPro;
}
/// <summary>
/// 文件传输响应
/// </summary>
/// <param name="m_pRes"></param>
/// <returns></returns>
public byte[] EncodeFileTransferRes(FileRes m_pRes)
{
//获取数据部分
TagLV tag = new TagLV();
tag.StrValue = m_pRes.IsSuccess ? ConstantVar.FileTransferSuccess : ConstantVar.FileTransferFailed;
tag.TagType = TagTypePro.FileRes;
byte[] resArray = tag.Encode();
//拼接数据部分
byte[] bodyArray = CombineArray(resArray);
//封装协议
Datagram datagram = new Datagram();
datagram.ProtocolType = ProtocolTypePro.FileTransfer;
datagram.CmdType = CmdTypePro.KeyReq;
datagram.DataBody = bodyArray;
byte[] resPro = datagram.Encode();
return resPro;
}
/// <summary>
/// 所有演讲信息请求
/// </summary>
/// <param name="m_pReq"></param>
/// <returns></returns>
public byte[] SpeechAllReq(SpeechAllReq m_pReq)
{
//获取数据部分
TagLV tag = new TagLV();
tag.TagType = TagTypePro.Account;
tag.StrValue = m_pReq.SpeakerAccount;
byte[] resArray = tag.Encode();
//拼接数据部分
byte[] bodyArray = CombineArray(resArray);
//封装协议
Datagram datagram = new Datagram();
datagram.ProtocolType = ProtocolTypePro.Command;
datagram.CmdType = CmdTypePro.KeyReq;
datagram.DataBody = bodyArray;
byte[] resPro = datagram.Encode();
return resPro;
}
Re:幻灯片会场管理 BLoodMaster 2012-05-25 11:42
/// <summary>
/// 日程安排信息分发请求
/// </summary>
/// <param name="m_pReq"></param>
/// <returns></returns>
public byte[] EncodeScheduleReq(ScheduleReq m_pReq)
{
//获取数据部分
TagLV tag = new TagLV();
byte[] tmp = new byte[6];
//所有演讲信息
for (int i = 0; i < m_pReq.SpeechList.Count; i++)
{
//演讲批次
tag.StrValue = m_pReq.SpeechList[i].SpeechBatch;
tag.TagType = TagTypePro.SpeechBatch;
byte[] tmp0 = tag.Encode();
//演讲者姓名
tag.StrValue = m_pReq.SpeechList[i].SpeakerName;
tag.TagType = TagTypePro.SpeakerName;
byte[] tmp1 = tag.Encode();
//演讲者单位
tag.StrValue = m_pReq.SpeechList[i].SpeakerUnit;
tag.TagType = TagTypePro.SpeakerUnit;
byte[] tmp2 = tag.Encode();
//演讲主题
tag.StrValue = m_pReq.SpeechList[i].SpeechTitle;
tag.TagType = TagTypePro.SpeechTitle;
byte[] tmp3 = tag.Encode();
//演讲开始时间
tag.StrValue = m_pReq.SpeechList[i].SpeechStartTime.ToString("YYYY-MM-DD HH:mm:SS");
tag.TagType = TagTypePro.SpeechStartTime;
byte[] tmp4 = tag.Encode();
//演讲结束时间
tag.StrValue = m_pReq.SpeechList[i].SpeechEndTime.ToString("YYYY-MM-DD HH:mm:SS");
tag.TagType = TagTypePro.SpeechEndTime;
byte[] tmp5 = tag.Encode();
tmp = CombineArray(tmp, tmp0, tmp1, tmp2, tmp3, tmp4, tmp5);
}
tag.TagType = TagTypePro.ScheduleTotal;
tag.StreamDatagram = tmp;
//拼接数据部分
byte[] bodyArray = tag.Encode();
//封装协议
Datagram datagram = new Datagram();
datagram.ProtocolType = ProtocolTypePro.Command;
datagram.CmdType = CmdTypePro.KeyReq;
datagram.DataBody = bodyArray;
byte[] resPro = datagram.Encode();
return resPro;
}
/// <summary>
/// 日程安排信息分发响应
/// </summary>
/// <param name="m_pStrKey"></param>
/// <returns></returns>
public byte[] EncodeScheduleRes(SpeakerRes m_pRes)
{
//获取数据部分
TagLV tag = new TagLV();
tag.StrValue = m_pRes.IsSuccess ? ConstantVar.ScheduleSuccess : ConstantVar.ScheduleFailed;
tag.TagType = TagTypePro.ScheduleRes;
byte[] resArray = tag.Encode();
//拼接数据部分
byte[] bodyArray = CombineArray(resArray);
//封装协议
Datagram datagram = new Datagram();
datagram.ProtocolType = ProtocolTypePro.Command;
datagram.CmdType = CmdTypePro.KeyReq;
datagram.DataBody = bodyArray;
byte[] resPro = datagram.Encode();
return resPro;
}
Re:幻灯片会场管理 BLoodMaster 2012-05-25 11:41
//心跳无需响应,如果网络出问题,客户端会在发送心跳包时感知
/// <summary>
/// 上传机器标识请求
/// </summary>
/// <param name="m_pStrKey"></param>
/// <returns></returns>
public byte[] EncodeUploadMachineKeyReq(MachineReq m_pReq)
{
//获取数据部分
TagLV tag = new TagLV();
tag.StrValue = m_pReq.MachineKey;
tag.TagType = TagTypePro.MachineKey;
byte[] keyArray = tag.Encode();
//拼接数据部分
byte[] bodyArray = CombineArray(keyArray);
//封装协议
Datagram datagram = new Datagram();
datagram.ProtocolType = ProtocolTypePro.Command;
datagram.CmdType = CmdTypePro.KeyReq;
datagram.DataBody = bodyArray;
byte[] resPro = datagram.Encode();
return resPro;
}
/// <summary>
/// 上传机器标识响应
/// </summary>
/// <param name="m_pStrKey"></param>
/// <returns></returns>
public byte[] EncodeUploadMachineKeyRes(MachineRes m_pRes)
{
//获取数据部分
TagLV tag = new TagLV();
tag.StrValue = m_pRes.IsSuccess ? ConstantVar.MachineSuccess : ConstantVar.MachineFailed;
tag.TagType = TagTypePro.MachineKeyRes;
byte[] resArray = tag.Encode();
//拼接数据部分
byte[] bodyArray = CombineArray(resArray);
//封装协议
Datagram datagram = new Datagram();
datagram.ProtocolType = ProtocolTypePro.Command;
datagram.CmdType = CmdTypePro.KeyReq;
datagram.DataBody = bodyArray;
byte[] resPro = datagram.Encode();
return resPro;
}
/// <summary>
/// 演讲者信息分发请求
/// </summary>
/// <param name="m_pReq"></param>
/// <returns></returns>
public byte[] EncodeSpeakerReq(SpeakerReq m_pReq)
{
//获取数据部分
TagLV tag = new TagLV();
tag.StrValue = m_pReq.SpeakerName;
tag.TagType = TagTypePro.SpeakerName;
byte[] nameArray = tag.Encode();
tag.StrValue = m_pReq.SpeakerImagePath;
tag.TagType = TagTypePro.SpeakerImage;
byte[] imageArray = tag.Encode();
tag.StrValue = m_pReq.SpeakerUnit;
tag.TagType = TagTypePro.SpeakerUnit;
byte[] unitArray = tag.Encode();
//拼接数据部分
byte[] bodyArray = CombineArray(nameArray, imageArray, unitArray);
//封装协议
Datagram datagram = new Datagram();
datagram.ProtocolType = ProtocolTypePro.Command;
datagram.CmdType = CmdTypePro.KeyReq;
datagram.DataBody = bodyArray;
byte[] resPro = datagram.Encode();
return resPro;
}
/// <summary>
/// 演讲者信息分发响应
/// </summary>
/// <param name="m_pStrKey"></param>
/// <returns></returns>
public byte[] EncodeSpeakerRes(SpeakerRes m_pRes)
{
//获取数据部分
TagLV tag = new TagLV();
tag.StrValue = m_pRes.IsSuccess ? ConstantVar.SpeakerSuccess : ConstantVar.SpeakerFailed;
tag.TagType = TagTypePro.SpeakerRes;
byte[] resArray = tag.Encode();
//拼接数据部分
byte[] bodyArray = CombineArray(resArray);
//封装协议
Datagram datagram = new Datagram();
datagram.ProtocolType = ProtocolTypePro.Command;
datagram.CmdType = CmdTypePro.KeyReq;
datagram.DataBody = bodyArray;
byte[] resPro = datagram.Encode();
return resPro;
}
Re:幻灯片会场管理 BLoodMaster 2012-05-25 11:41
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace PPT.Protocol
{
/// <summary>
/// 协议类的管理类,唯一对外的接口
/// </summary>
public class ProtocolManager
{
#region 私有方法 成员
/// <summary>
/// 将多个数组拼接为一个数组
/// </summary>
/// <param name="m_pArray"></param>
/// <returns></returns>
private byte[] CombineArray(params object[] m_pArray)
{
if (m_pArray.Length == 0)
return new byte[0];
if (m_pArray.Length == 1)
return (byte[])m_pArray[0];
byte[][] temp = new byte[m_pArray.Length][];
for (int i = 0; i < m_pArray.Length; i++)
{
temp[i] = (byte[])m_pArray[i];
}
List<byte> res = new List<byte>();
for (int i = 0; i < temp.Length; i++)
{
for (int j = 0; j < temp[i].Length; j++)
{
res.Add(temp[i][j]);
}
}
return res.ToArray();
}
#endregion
#region 编码方法 成员
/// <summary>
/// 鉴权请求编码
/// </summary>
/// <param name="m_pReq"></param>
/// <returns></returns>
public byte[] EncodeAuthReq(AuthReq m_pReq)
{
//获取数据部分
TagLV tag = new TagLV();
tag.StrValue = m_pReq.UserName;
tag.TagType = TagTypePro.Account;
byte[] accountArray = tag.Encode();
tag.StrValue = m_pReq.UserPwd;
tag.TagType = TagTypePro.Pwd;
byte[] pwdArray = tag.Encode();
//拼接数据部分
byte[] bodyArray = CombineArray(accountArray, pwdArray);
//封装协议
Datagram datagram = new Datagram();
datagram.ProtocolType = ProtocolTypePro.Command;
datagram.CmdType = CmdTypePro.AuthReq;
datagram.DataBody = bodyArray;
byte[] resPro = datagram.Encode();
return resPro;
}
/// <summary>
/// 鉴权结果
/// </summary>
/// <param name="m_pRes"></param>
/// <returns></returns>
public byte[] EncodeAuthRes(AuthRes m_pRes)
{
//获取数据部分
TagLV tag = new TagLV();
tag.StrValue = m_pRes.IsSuccess ? ConstantVar.AuthSuccess : ConstantVar.AuthFail;
tag.TagType = TagTypePro.AuthRes;
byte[] authArray = tag.Encode();
//拼接数据部分
byte[] bodyArray = CombineArray(authArray);
//封装协议
Datagram datagram = new Datagram();
datagram.ProtocolType = ProtocolTypePro.Command;
datagram.CmdType = CmdTypePro.AuthReq;
datagram.DataBody = bodyArray;
byte[] resPro = datagram.Encode();
return resPro;
}
/// <summary>
/// 心跳
/// </summary>
/// <returns></returns>
public byte[] EncodeHeartBeatReq()
{
//获取数据部分
TagLV tag = new TagLV();
tag.StrValue = "";
tag.TagType = TagTypePro.HeartBeat;
byte[] beatArray = tag.Encode();
//拼接数据部分
byte[] bodyArray = CombineArray(beatArray);
//封装协议
Datagram datagram = new Datagram();
datagram.ProtocolType = ProtocolTypePro.Command;
datagram.CmdType = CmdTypePro.HeartBeat;
datagram.DataBody = bodyArray;
byte[] resPro = datagram.Encode();
return resPro;
}
Re:幻灯片会场管理 BLoodMaster 2012-05-25 11:36
case (int)TagTypePro.FileName:
TagType = TagTypePro.FileName;
StrValue = System.Text.UTF8Encoding.UTF8.GetString(m_pStream, 6 + m_pIndex, iLen);
break;
case (int)TagTypePro.TotalBagCount:
TagType = TagTypePro.TotalBagCount;
StrValue = System.Text.UTF8Encoding.UTF8.GetString(m_pStream, 6 + m_pIndex, iLen);
break;
case (int)TagTypePro.CurrBagID:
TagType = TagTypePro.CurrBagID;
StrValue = System.Text.UTF8Encoding.UTF8.GetString(m_pStream, 6 + m_pIndex, iLen);
break;
case (int)TagTypePro.HasNextBag:
TagType = TagTypePro.HasNextBag;
StrValue = System.Text.UTF8Encoding.UTF8.GetString(m_pStream, 6 + m_pIndex, iLen);
break;
case (int)TagTypePro.FileContent:
TagType = TagTypePro.FileContent;
StreamDatagram = new byte[iLen];
StreamDatagram = SubArray(m_pStream, 6 + m_pIndex, iLen);
break;
case (int)TagTypePro.FileRes:
TagType = TagTypePro.FileRes;
StrValue = System.Text.UTF8Encoding.UTF8.GetString(m_pStream, 6 + m_pIndex, iLen);
break;
default:
TagType = TagTypePro.Unknow;
ErrorType = ErrorTypePro.UnknowTag;
break;
}
return m_pIndex + 6 + iLen;
}
#endregion
}
}
Re:幻灯片会场管理 BLoodMaster 2012-05-25 11:36
case (int)TagTypePro.AuthRes:
TagType = TagTypePro.AuthRes;
StrValue = System.Text.UTF8Encoding.UTF8.GetString(m_pStream, 6 + m_pIndex, iLen);
break;
case (int)TagTypePro.SpeakerRes:
TagType = TagTypePro.SpeakerRes;
StrValue = System.Text.UTF8Encoding.UTF8.GetString(m_pStream, 6 + m_pIndex, iLen);
break;
case (int)TagTypePro.ScheduleRes:
TagType = TagTypePro.ScheduleRes;
StrValue = System.Text.UTF8Encoding.UTF8.GetString(m_pStream, 6 + m_pIndex, iLen);
break;
case (int)TagTypePro.MachineKeyRes:
TagType = TagTypePro.MachineKeyRes;
StreamDatagram = SubArray(m_pStream, 6 + m_pIndex, iLen);
break;
case (int)TagTypePro.SpeechTotal:
TagType = TagTypePro.SpeechTotal;
StreamDatagram = SubArray(m_pStream, 6 + m_pIndex, iLen);
break;
case (int)TagTypePro.SpeechVersion:
TagType = TagTypePro.MachineKeyRes;
StreamDatagram = SubArray(m_pStream, 6 + m_pIndex, iLen);
break;
case (int)TagTypePro.ScheduleTotal:
TagType = TagTypePro.ScheduleTotal;
StreamDatagram = SubArray(m_pStream, 6 + m_pIndex, iLen);
break;
case (int)TagTypePro.SpeechVersionName:
TagType = TagTypePro.SpeechVersionName;
StrValue = System.Text.UTF8Encoding.UTF8.GetString(m_pStream, 6 + m_pIndex, iLen);
break;
//文件传输部分
case (int)TagTypePro.BatchInfo:
TagType = TagTypePro.BatchInfo;
StrValue = System.Text.UTF8Encoding.UTF8.GetString(m_pStream, 6 + m_pIndex, iLen);
break;
case (int)TagTypePro.FileType:
TagType = TagTypePro.FileType;
StrValue = System.Text.UTF8Encoding.UTF8.GetString(m_pStream, 6 + m_pIndex, iLen);
break;
case (int)TagTypePro.IsFolder:
TagType = TagTypePro.IsFolder;
StrValue = System.Text.UTF8Encoding.UTF8.GetString(m_pStream, 6 + m_pIndex, iLen);
break;
case (int)TagTypePro.CurrPath:
TagType = TagTypePro.CurrPath;
StrValue = System.Text.UTF8Encoding.UTF8.GetString(m_pStream, 6 + m_pIndex, iLen);
break;
Re:幻灯片会场管理 BLoodMaster 2012-05-25 11:36
/// <summary>
/// 根据tag值解码
/// </summary>
/// <param name="m_pStream"></param>
/// <returns>下次解包位置</returns>
public int Decode(byte[] m_pStream, int m_pIndex)
{
//重置标志位
ErrorType = ErrorTypePro.None;
TagType = TagTypePro.Unknow;
StrValue = "";
StreamDatagram = new byte[0];
//TLV数据长度不合法
if (m_pStream.Length < 6 + m_pIndex)
{
ErrorType = ErrorTypePro.NotComplete;
return -1;
}
int iTag = m_pStream[0 + m_pIndex] + m_pStream[1 + m_pIndex] * 256;
int iLen = m_pStream[2 + m_pIndex] * 1
+ m_pStream[3 + m_pIndex] * 256
+ m_pStream[4 + m_pIndex] * 256 * 256
+ m_pStream[5 + m_pIndex] * 256 * 256 * 256;
//TLV长度不合法
if (m_pStream.Length < iLen + 6 + m_pIndex)
{
ErrorType = ErrorTypePro.NotComplete;
return -1;
}
//解码
//获取值value,此处编码均为UTF-8编码
//此处代码放置在switch中的原因是为了考虑程序的扩展性,TLV的V部分不一定均为UTF8编码的字符串
//res.StrValue = System.Text.UTF8Encoding.UTF8.GetString(m_pStream, 6, iLen);
switch (iTag)
{
//命令交互部分
case (int)TagTypePro.Account:
TagType = TagTypePro.Account;
StrValue = System.Text.UTF8Encoding.UTF8.GetString(m_pStream, 6 + m_pIndex, iLen);
break;
case (int)TagTypePro.Pwd:
TagType = TagTypePro.Pwd;
StrValue = System.Text.UTF8Encoding.UTF8.GetString(m_pStream, 6 + m_pIndex, iLen);
break;
case (int)TagTypePro.SpeakerName:
TagType = TagTypePro.SpeakerName;
StrValue = System.Text.UTF8Encoding.UTF8.GetString(m_pStream, 6 + m_pIndex, iLen);
break;
case (int)TagTypePro.SpeakerUnit:
TagType = TagTypePro.SpeakerUnit;
StrValue = System.Text.UTF8Encoding.UTF8.GetString(m_pStream, 6 + m_pIndex, iLen);
break;
case (int)TagTypePro.SpeakerImage:
TagType = TagTypePro.SpeakerImage;
StrValue = System.Text.UTF8Encoding.UTF8.GetString(m_pStream, 6 + m_pIndex, iLen);
break;
case (int)TagTypePro.SpeechBatch:
TagType = TagTypePro.SpeechBatch;
StrValue = System.Text.UTF8Encoding.UTF8.GetString(m_pStream, 6 + m_pIndex, iLen);
break;
case (int)TagTypePro.SpeechStartTime:
TagType = TagTypePro.SpeechStartTime;
StrValue = System.Text.UTF8Encoding.UTF8.GetString(m_pStream, 6 + m_pIndex, iLen);
break;
case (int)TagTypePro.SpeechEndTime:
TagType = TagTypePro.SpeechEndTime;
StrValue = System.Text.UTF8Encoding.UTF8.GetString(m_pStream, 6 + m_pIndex, iLen);
break;
case (int)TagTypePro.SpeechTitle:
TagType = TagTypePro.SpeechTitle;
StrValue = System.Text.UTF8Encoding.UTF8.GetString(m_pStream, 6 + m_pIndex, iLen);
break;
case (int)TagTypePro.MachineKey:
TagType = TagTypePro.MachineKey;
StrValue = System.Text.UTF8Encoding.UTF8.GetString(m_pStream, 6 + m_pIndex, iLen);
break;
case (int)TagTypePro.HeartBeat:
TagType = TagTypePro.HeartBeat;
StrValue = System.Text.UTF8Encoding.UTF8.GetString(m_pStream, 6 + m_pIndex, iLen);
break;
Re:幻灯片会场管理 BLoodMaster 2012-05-25 11:35
case TagTypePro.IsFolder:
tmpHead[0] = ((int)TagTypePro.IsFolder) / 256;
tmpHead[1] = ((int)TagTypePro.IsFolder) % 256;
tmpContent = System.Text.UTF8Encoding.UTF8.GetBytes(StrValue);
break;
case TagTypePro.CurrPath:
tmpHead[0] = ((int)TagTypePro.CurrPath) / 256;
tmpHead[1] = ((int)TagTypePro.CurrPath) % 256;
tmpContent = System.Text.UTF8Encoding.UTF8.GetBytes(StrValue);
break;
case TagTypePro.FileName:
tmpHead[0] = ((int)TagTypePro.FileName) / 256;
tmpHead[1] = ((int)TagTypePro.FileName) % 256;
tmpContent = System.Text.UTF8Encoding.UTF8.GetBytes(StrValue);
break;
case TagTypePro.TotalBagCount:
tmpHead[0] = ((int)TagTypePro.TotalBagCount) / 256;
tmpHead[1] = ((int)TagTypePro.TotalBagCount) % 256;
tmpContent = System.Text.UTF8Encoding.UTF8.GetBytes(StrValue);
break;
case TagTypePro.CurrBagID:
tmpHead[0] = ((int)TagTypePro.CurrBagID) / 256;
tmpHead[1] = ((int)TagTypePro.CurrBagID) % 256;
tmpContent = System.Text.UTF8Encoding.UTF8.GetBytes(StrValue);
break;
case TagTypePro.HasNextBag:
tmpHead[0] = ((int)TagTypePro.HasNextBag) / 256;
tmpHead[1] = ((int)TagTypePro.HasNextBag) % 256;
tmpContent = System.Text.UTF8Encoding.UTF8.GetBytes(StrValue);
break;
case TagTypePro.FileContent:
tmpHead[0] = ((int)TagTypePro.FileContent) / 256;
tmpHead[1] = ((int)TagTypePro.FileContent) % 256;
//此处不进行编码,外部直接将文件流的信息写入此字段
tmpContent = StreamDatagram;
break;
case TagTypePro.FileRes:
tmpHead[0] = ((int)TagTypePro.FileRes) / 256;
tmpHead[1] = ((int)TagTypePro.FileRes) % 256;
tmpContent = System.Text.UTF8Encoding.UTF8.GetBytes(StrValue);
break;
//无效tag值,直接返回
case TagTypePro.Unknow:
default:
return new byte[0];
}
int iLen = tmpContent.Length;
tmpHead[2] = (byte)(iLen % 256);
tmpHead[3] = (byte)(iLen / 256 % 256);
tmpHead[4] = (byte)(iLen / 256 / 256 % 256);
tmpHead[5] = (byte)(iLen / 256 / 256 / 256 % 256);
byte[] res = new byte[iLen + 6];
//TAG 与 LENGTH 赋值
for (int i = 0; i < 6; i++)
{
res[i] = tmpHead[i];
}
//VALUE 赋值
for (int i = 0; i < tmpContent.Length; i++)
{
tmpHead[i + 6] = tmpContent[i];
}
return res;
}
Re:幻灯片会场管理 BLoodMaster 2012-05-25 11:34
case TagTypePro.AuthRes:
tmpHead[0] = ((int)TagTypePro.AuthRes) / 256;
tmpHead[1] = ((int)TagTypePro.AuthRes) % 256;
tmpContent = System.Text.UTF8Encoding.UTF8.GetBytes(StrValue);
break;
case TagTypePro.SpeakerRes:
tmpHead[0] = ((int)TagTypePro.SpeakerRes) / 256;
tmpHead[1] = ((int)TagTypePro.SpeakerRes) % 256;
tmpContent = System.Text.UTF8Encoding.UTF8.GetBytes(StrValue);
break;
case TagTypePro.ScheduleRes:
tmpHead[0] = ((int)TagTypePro.ScheduleRes) / 256;
tmpHead[1] = ((int)TagTypePro.ScheduleRes) % 256;
tmpContent = System.Text.UTF8Encoding.UTF8.GetBytes(StrValue);
break;
case TagTypePro.MachineKeyRes:
tmpHead[0] = ((int)TagTypePro.MachineKeyRes) / 256;
tmpHead[1] = ((int)TagTypePro.MachineKeyRes) % 256;
tmpContent = System.Text.UTF8Encoding.UTF8.GetBytes(StrValue);
break;
case TagTypePro.ScheduleTotal:
tmpHead[0] = ((int)TagTypePro.ScheduleTotal) / 256;
tmpHead[1] = ((int)TagTypePro.ScheduleTotal) % 256;
tmpContent = StreamDatagram;
break;
case TagTypePro.SpeechTotal:
tmpHead[0] = ((int)TagTypePro.SpeechTotal) / 256;
tmpHead[1] = ((int)TagTypePro.SpeechTotal) % 256;
tmpContent = StreamDatagram;
break;
case TagTypePro.SpeechVersion:
tmpHead[0] = ((int)TagTypePro.SpeechVersion) / 256;
tmpHead[1] = ((int)TagTypePro.SpeechVersion) % 256;
tmpContent = StreamDatagram;
break;
case TagTypePro.SpeechVersionName:
tmpHead[0] = ((int)TagTypePro.SpeechVersion) / 256;
tmpHead[1] = ((int)TagTypePro.SpeechVersion) % 256;
tmpContent = System.Text.UTF8Encoding.UTF8.GetBytes(StrValue);
break;
//文件传输部分
case TagTypePro.BatchInfo:
tmpHead[0] = ((int)TagTypePro.BatchInfo) / 256;
tmpHead[1] = ((int)TagTypePro.BatchInfo) % 256;
tmpContent = System.Text.UTF8Encoding.UTF8.GetBytes(StrValue);
break;
case TagTypePro.FileType:
tmpHead[0] = ((int)TagTypePro.FileType) / 256;
tmpHead[1] = ((int)TagTypePro.FileType) % 256;
tmpContent = System.Text.UTF8Encoding.UTF8.GetBytes(StrValue);
break;
Re:幻灯片会场管理 BLoodMaster 2012-05-25 11:33
#region 公有方法 成员
/// <summary>
/// tag值编码
/// </summary>
/// <returns>TLV编码结果</returns>
public byte[] Encode()
{
byte[] tmpHead = new byte[6];//tag值为两个字节,长度为四个字节
byte[] tmpContent;
//获取tag值
switch (TagType)
{
//命令交互部分
case TagTypePro.Account:
tmpHead[0] = ((int)TagTypePro.Account) / 256;
tmpHead[1] = ((int)TagTypePro.Account) % 256;
tmpContent = System.Text.UTF8Encoding.UTF8.GetBytes(StrValue);
break;
case TagTypePro.Pwd:
tmpHead[0] = ((int)TagTypePro.Pwd) / 256;
tmpHead[1] = ((int)TagTypePro.Pwd) % 256;
tmpContent = System.Text.UTF8Encoding.UTF8.GetBytes(StrValue);
break;
case TagTypePro.SpeakerName:
tmpHead[0] = ((int)TagTypePro.SpeakerName) / 256;
tmpHead[1] = ((int)TagTypePro.SpeakerName) % 256;
tmpContent = System.Text.UTF8Encoding.UTF8.GetBytes(StrValue);
break;
case TagTypePro.SpeakerUnit:
tmpHead[0] = ((int)TagTypePro.SpeakerUnit) / 256;
tmpHead[1] = ((int)TagTypePro.SpeakerUnit) % 256;
tmpContent = System.Text.UTF8Encoding.UTF8.GetBytes(StrValue);
break;
case TagTypePro.SpeakerImage:
tmpHead[0] = ((int)TagTypePro.SpeakerImage) / 256;
tmpHead[1] = ((int)TagTypePro.SpeakerImage) % 256;
tmpContent = System.Text.UTF8Encoding.UTF8.GetBytes(StrValue);
break;
case TagTypePro.SpeechBatch:
tmpHead[0] = ((int)TagTypePro.SpeechBatch) / 256;
tmpHead[1] = ((int)TagTypePro.SpeechBatch) % 256;
tmpContent = System.Text.UTF8Encoding.UTF8.GetBytes(StrValue);
break;
case TagTypePro.SpeechStartTime:
tmpHead[0] = ((int)TagTypePro.SpeechStartTime) / 256;
tmpHead[1] = ((int)TagTypePro.SpeechStartTime) % 256;
tmpContent = System.Text.UTF8Encoding.UTF8.GetBytes(StrValue);
break;
case TagTypePro.SpeechEndTime:
tmpHead[0] = ((int)TagTypePro.SpeechEndTime) / 256;
tmpHead[1] = ((int)TagTypePro.SpeechEndTime) % 256;
tmpContent = System.Text.UTF8Encoding.UTF8.GetBytes(StrValue);
break;
case TagTypePro.SpeechTitle:
tmpHead[0] = ((int)TagTypePro.SpeechTitle) / 256;
tmpHead[1] = ((int)TagTypePro.SpeechTitle) % 256;
tmpContent = System.Text.UTF8Encoding.UTF8.GetBytes(StrValue);
break;
case TagTypePro.MachineKey:
tmpHead[0] = ((int)TagTypePro.MachineKey) / 256;
tmpHead[1] = ((int)TagTypePro.MachineKey) % 256;
tmpContent = System.Text.UTF8Encoding.UTF8.GetBytes(StrValue);
break;
case TagTypePro.HeartBeat:
tmpHead[0] = ((int)TagTypePro.HeartBeat) / 256;
tmpHead[1] = ((int)TagTypePro.HeartBeat) % 256;
tmpContent = new byte[0];//心跳包无value部分
break;
Re:幻灯片会场管理 BLoodMaster 2012-05-25 11:31
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
namespace PPT.Protocol
{
/// <summary>
/// Tag值的编解码
/// </summary>
class TagLV
{
#region 私有方法 成员
/// <summary>
/// 截取子数组
/// </summary>
/// <param name="m_resource"></param>
/// <param name="m_index"></param>
/// <param name="m_count"></param>
/// <returns></returns>
public byte[] SubArray(byte[] m_resource, int m_index, int m_count)
{
if (m_resource.Length < m_index + m_count)
return new byte[0];
byte[] res = new byte[m_count];
for (int i = 0; i < m_count; i++)
{
res[i] = m_resource[i + m_index];
}
return res;
}
#endregion
#region 公有属性 成员
/// <summary>
/// 数据包错误类型,仅在解包时需要读取该标志位
/// </summary>
public ErrorTypePro ErrorType { set; get; }
/// <summary>
/// tag值类型,存储需要编码或解码后的tag值
/// </summary>
public TagTypePro TagType { set; get; }
/// <summary>
/// 字符串值,存储需要编码或解码后的字符串值
/// </summary>
public string StrValue { set; get; }
/// <summary>
/// 文件流,用于传输文件时使用,存储需要编码或解码后的文件流
/// </summary>
public byte[] StreamDatagram { set; get; }
#endregion