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]