China Mobile SMS gateway cmpp3.0 C # source code: Event definition and Related tool Functions

Source: Internet
Author: User
Using system;
Using system. text;
Using system. runtime. interopservices;
Using system. Threading;
Using system. collections;
Using system. diagnostics;
Namespace tiray. SMS
{
// Event Parameter Definition
Public class smseventargs: eventargs
{
Sms_state m_state;
Object m_data;
Datetime m_dttime;

Public sms_state state
{
Get {return m_state ;}
Set {m_state = value ;}
}

Public Object Data
{
Get {return m_data ;}
Set {m_data = value ;}
}
Public datetime time
{
Get {return m_dttime ;}
Set {m_dttime = value ;}
}

}
// Event processing functions
Public Delegate void smseventhandler (Object sender, smseventargs E );
 
// Asynchronous Event Callback Function
Public Delegate void smsasyncevent (smseventargs E );

Public class Utility
{
Public static string decode (byte [] Buf, int startindex, int length, coding)
{
String STR = string. empty;
If (coding = coding. ASCII)
STR = system. Text. encoding. ASCII. getstring (BUF, startindex, length );

Else if (coding = coding. ucs2)
STR = system. Text. encoding. bigendianunicode. getstring (BUF, 0, length );
Else if (coding = coding. GBK)
STR = system. Text. unicodeencoding. getencoding ("gb2312"). getstring (BUF, startindex, length );
Return STR;
}
Public static byte [] encode (string STR, coding)
{
Byte [] Buf = NULL;
If (STR = NULL)
Return Buf;
If (coding = coding. ASCII)
Buf = system. Text. encoding. ASCII. getbytes (STR );
Else if (coding = coding. ucs2)
Buf = system. Text. encoding. bigendianunicode. getbytes (STR );
Else if (coding = coding. GBK)
Buf = system. Text. unicodeencoding. getencoding ("gb2312"). getbytes (STR );

Return Buf;

}
Public static uint32 countlength (string STR, coding)
{
Byte [] Buf = encode (STR, coding );
If (BUF! = NULL)
Return (uint32) BUF. length;
Else
Return 0;
}

Public static byte [] inttonetbytes (Object OBJ)
{
Byte [] bytes = NULL;
If (obj. GetType () = system. type. GetType ("system. uint32 "))
{
Uint32 val = (uint32) OBJ;
Bytes = bitconverter. getbytes (VAL );
}
If (obj. GetType () = system. type. GetType ("system. uint64 "))
{
Uint64 val = (uint64) OBJ;
Bytes = bitconverter. getbytes (VAL );
}

If (Bytes! = NULL)
System. array. Reverse (bytes );

Return bytes;

}
Public static object netbytestoint (byte [] bytes, int index, int length)
{
Array. Reverse (bytes, index, length );
If (length = 4)
Return bitconverter. touint32 (bytes, index );
Else if (length = 8)
Return bitconverter. touint64 (bytes, index );
Else
Return 0;
}
}

}

[To be continued]

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.