⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 commandfactory.cs

📁 短信串口通信 于短信网关通信协议的封装 C#实现的类库
💻 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 + -