?? commandfactory.cs
字號:
using System;
using System.Collections.Generic;
using System.Text;
using System.Net.Sockets;
using JeasonZhao.Sms.SGIP.Command;
using JeasonZhao.Sms.SGIP;
using JeasonZhao.Sms.BaseModule;
namespace JeasonZhao.Sms.SGIP
{
public class CommandFactory
{
private static uint m_nSequence = UInt32.MinValue;
public static uint GetNewMsgSequence()
{
if (m_nSequence + 1 >= UInt32.MaxValue)
{
m_nSequence = UInt32.MinValue;
}
else
{
m_nSequence++;
}
return m_nSequence;
}
/// <summary>
/// 取得反饋使用的報文類型
/// </summary>
/// <param name="cmd"></param>
/// <returns></returns>
public static Commands GetRespCommand(Commands cmd)
{
switch (cmd)
{
case Commands.Bind:
return Commands.Bind_Resp;
case Commands.Deliver:
return Commands.Deliver_Resp;
case Commands.Submit:
return Commands.Submit_Resp;
case Commands.Unbind:
return Commands.Unbind_Resp;
case Commands.Report:
return Commands.Report_Resp;
}
return Commands.Unbind_Resp;
}
public static BaseCommand Read(Socket sock, DelegateSocketInformation message)
{
if (null == sock)
{
return null;
}
BaseCommand baseCommand = new BaseCommand(Commands.Bind);
baseCommand.DebugHandler = message;
baseCommand.ReadHeader(sock);
BaseCommand cmd = null;
switch (baseCommand.Command)
{
case Commands.Bind:
cmd = new Bind();
break;
case Commands.Bind_Resp:
cmd = new Bind_Resp();
break;
case Commands.Deliver:
cmd = new Deliver();
break;
case Commands.Deliver_Resp:
cmd = new Deliver_Resp();
break;
case Commands.Submit:
cmd = new Submit();
break;
case Commands.Submit_Resp:
cmd = new Submit_Resp();
break;
case Commands.Unbind:
cmd = new Unbind();
break;
case Commands.Unbind_Resp:
cmd = new Unbind_Resp();
break;
case Commands.Report:
cmd = new Report();
break;
case Commands.Report_Resp:
cmd = new Report_Resp();
break;
}
if (null != cmd)
{
cmd.DebugHandler = message;
cmd.CopyHeader(baseCommand);
cmd.ReadBody(sock);
}
return cmd;
}
public static bool Send(Socket sock, BaseCommand cmd, DelegateSocketInformation mmm)
{
if (null == sock)
{
return false;
}
cmd.DebugHandler = mmm;
return cmd.SendPackage(sock);
}
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -