902 lines
24 KiB
C#
902 lines
24 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Collections;
|
|
using System.Threading;
|
|
using System.Net;
|
|
using System.Net.Sockets;
|
|
|
|
namespace SafeMobileLib
|
|
{
|
|
public enum AppType { SAFEDISPATCH = 00, SAFENET = 10 };
|
|
public enum CallType { ALLCALL = 101, PRIVATECALL = 102, GROUPCALL = 103, EMERGENCYCALL = 104 };
|
|
public enum CallStatus { INPROGRESS = 1, HANGTIME = 2, ENDED = 3 };
|
|
public enum DeviceType { RADIO = 0, SMARTPHONE = 1 };
|
|
|
|
public sealed class GroupType
|
|
{
|
|
|
|
public String displayedName { get; private set; }
|
|
public readonly String dbName;
|
|
public readonly int value;
|
|
|
|
public static readonly GroupType CATEGORY = new GroupType(0, "CATEGORY");
|
|
public static readonly GroupType RADIOTALK = new GroupType(1, "RADIOTALK");
|
|
public static readonly GroupType MOBILETALK = new GroupType(2, "MOBILETALK");
|
|
public static readonly GroupType UNKNOWN = new GroupType(11, "UNKNOWN");
|
|
|
|
private GroupType(int value, String dbValue)
|
|
{
|
|
this.dbName = dbValue;
|
|
this.value = value;
|
|
}
|
|
|
|
public override String ToString()
|
|
{
|
|
return displayedName;
|
|
}
|
|
|
|
public static void SetCategoryLanguageName(String name)
|
|
{
|
|
CATEGORY.displayedName = name;
|
|
}
|
|
|
|
public static void SetRadioTalkLanguageName(String name)
|
|
{
|
|
RADIOTALK.displayedName = name;
|
|
}
|
|
|
|
public static void SetMobileTalkLanguageName(String name)
|
|
{
|
|
MOBILETALK.displayedName = name;
|
|
}
|
|
|
|
public static GroupType FromValue(int value)
|
|
{
|
|
if (value == CATEGORY.value)
|
|
return CATEGORY;
|
|
else if (value == RADIOTALK.value)
|
|
return RADIOTALK;
|
|
else if (value == MOBILETALK.value)
|
|
return MOBILETALK;
|
|
|
|
return UNKNOWN;
|
|
}
|
|
|
|
public static GroupType FromDisplayedName(string displayedName)
|
|
{
|
|
displayedName = displayedName.ToLower();
|
|
|
|
if (displayedName.Equals(CATEGORY.displayedName.ToLower()))
|
|
return CATEGORY;
|
|
else if (displayedName.Equals(RADIOTALK.displayedName.ToLower()))
|
|
return RADIOTALK;
|
|
else if (displayedName.Equals(MOBILETALK.displayedName.ToLower()))
|
|
return MOBILETALK;
|
|
|
|
return UNKNOWN;
|
|
}
|
|
|
|
public static GroupType FromDbName(string dbName)
|
|
{
|
|
dbName = dbName.ToLower();
|
|
|
|
if (dbName.Equals(CATEGORY.dbName.ToLower()))
|
|
return CATEGORY;
|
|
else if (dbName.Equals(RADIOTALK.dbName.ToLower()))
|
|
return RADIOTALK;
|
|
else if (dbName.Equals(MOBILETALK.dbName.ToLower()))
|
|
return MOBILETALK;
|
|
|
|
return UNKNOWN;
|
|
}
|
|
|
|
}
|
|
|
|
public enum ContactType { USER = 0, GROUP = 1, UNIT = 2, GPS_ID = 3, RADIOGATEWAY = 4 };
|
|
public enum PriorityType { Low = 0, Normal = 1, High = 2, Critical = 3};
|
|
public enum GatewayType { Tier2Radio = 0, Tier3Radio = 1, Broadband = 2, Unknown = 3, SMCBridge = 4 };
|
|
public enum RefreshCommandReason { ModifiedUnitList = 1};
|
|
|
|
public enum Result_Codes_ENUM
|
|
{
|
|
SUCCESS = 0x0,
|
|
UNSUPPORTED_VERSION = 0x8,
|
|
SYNTAX_ERROR = 0xA,
|
|
PROTOCOL_ELEMENT_NOT_SUPPORTED = 0xB,
|
|
PROTOCOL_ELEMENT_VALUE_OUT_OF_RANGE = 0xD,
|
|
QUERY_INFO_NOT_ATTAINABLE = 0xF,
|
|
QUERY_INFO_NOT_CURRENTLY_ATTAINABLE = 0x10,
|
|
NO_SUCH_REQUEST = 0x15,
|
|
DUPLICATE_REQUEST_ID = 0x16,
|
|
REPORTING_WILL_STOP = 0x11
|
|
};
|
|
|
|
public enum Document_Identifiers_ENUM
|
|
{
|
|
Immediate_Location_Request = 0x04,
|
|
Immediate_Location_Request_NoCDT = 0x05,
|
|
Immediate_Location_Report = 0x06,
|
|
Immediate_Location_Report_NoCDT = 0x07,
|
|
Triggered_Location_Request = 0x08,
|
|
Triggered_Location_Request_NoCDT = 0x09,
|
|
Triggered_Location_Answer = 0x0A,
|
|
Triggered_Location_Answer_NoCDT = 0x0B,
|
|
Triggered_Location_Report = 0x0C,
|
|
Triggered_Location_Report_NoCDT = 0x0D,
|
|
Triggered_Location_Stop_Request = 0x0E,
|
|
Triggered_Location_Stop_Request_NoCDT = 0x0F,
|
|
Triggered_Location_Stop_Answer = 0x10,
|
|
Triggered_Location_Stop_Answer_NoCDT = 0x11,
|
|
Unsolicited_Location_Report = 0x12,
|
|
Unsolicited_Location_Report_NoCDT = 0x13,
|
|
Location_Protocol_Request_NoCDT = 0x14,
|
|
Location_Protocol_Report_NoCDT = 0x15
|
|
};
|
|
|
|
// -------------------------------------------------------------------
|
|
// ARS Service
|
|
// -------------------------------------------------------------------
|
|
public enum header_event
|
|
{
|
|
Unqualified_Event = 0x00,
|
|
Initial_Event = 0x01,
|
|
Refresh_Event = 0x02,
|
|
UNKNOWN = 0x03
|
|
}
|
|
|
|
// -------------------------------------------------------------------
|
|
// Location Service
|
|
// -------------------------------------------------------------------
|
|
|
|
|
|
public enum Common_Element_Tokens_ENUM
|
|
{
|
|
request_id = 0x22,
|
|
request_id1 = 0x23,
|
|
request_id2 = 0x24
|
|
};
|
|
public enum Query_Request_Messages_Tokens_ENUM
|
|
{
|
|
interval = 0x31,
|
|
oneshot_trigger = 0x33,
|
|
periodic_trigger = 0x34,
|
|
request_altitude = 0x54,
|
|
request_altitude_acc = 0x55,
|
|
request_altitude_acc1 = 0x56,
|
|
request_direction_hor = 0x57,
|
|
request_hor_acc = 0x5F,
|
|
request_hor_acc1 = 0x60,
|
|
request_lev_conf = 0x61,
|
|
request_protocol_version = 0x3F,
|
|
request_speed_hor = 0x62,
|
|
request_speed_vrt = 0x64,
|
|
require_max_info_age = 0x42,
|
|
require_altitude = 0x66,
|
|
require_altitude_acc = 0x67,
|
|
require_altitude_acc1 = 0x68,
|
|
require_direction_hor = 0x69,
|
|
require_hor_acc = 0x71,
|
|
require_hor_acc1 = 0x72,
|
|
require_lev_conf = 0x73,
|
|
require_speed_hor = 0x74,
|
|
require_speed_vrt = 0x76,
|
|
ret_info = 0x50,
|
|
ret_info1 = 0x51,
|
|
ret_info2 = 0x52,
|
|
ret_info3 = 0x53,
|
|
trg_condition = 0x4A,
|
|
SU_IPv4 = 0x26,
|
|
impl_spec_data = 0x40
|
|
};
|
|
|
|
public enum Report_Messages_Tokens_ENUM
|
|
{
|
|
circle_2d = 0x51,
|
|
circle_3d = 0x54,
|
|
circle_3d1 = 0x55,
|
|
direction_hor = 0x56,
|
|
info_time = 0x34,
|
|
info_time1 = 0x35,
|
|
lev_conf = 0x65,
|
|
point_2d = 0x66,
|
|
point_3d = 0x69,
|
|
point_3d1 = 0x6A,
|
|
protocol_version = 0x36,
|
|
result = 0x37,
|
|
result1 = 0x38,
|
|
result2 = 0x39,
|
|
speed_hor = 0x6C,
|
|
speed_vrt = 0x70,
|
|
SU_IPv4 = 0x26
|
|
};
|
|
|
|
public enum Attribute_Tokens_ENUM
|
|
{
|
|
result_code = 0x22,
|
|
result_code1 = 0x23,
|
|
ret_info_accuracy = 0x50,
|
|
ret_info_accuracy1 = 0x51,
|
|
ret_info_no_req_id = 0x52,
|
|
ret_info_no_req_id1 = 0x53,
|
|
ret_info_time = 0x54,
|
|
ret_info_time1 = 0x55
|
|
};
|
|
|
|
public enum MessageBusCmds
|
|
{
|
|
InitAllCall = 101,
|
|
InitAllCallResponse = 121,
|
|
InitPrivateCall = 102,
|
|
InitPrivateCallResponse = 122,
|
|
InitGroupCall = 103,
|
|
InitGroupCallResponse = 123,
|
|
EndAllCall = 111,
|
|
EndPrivateCall = 112,
|
|
EndPrivateCallResponse = 116,
|
|
EndGroupCall = 113,
|
|
EndGroupCallResponse = 117,
|
|
EndAllCallResponse = 115,
|
|
PollRequest = 154,
|
|
RadioEmergencyReceived = 138,
|
|
AppServerEmergency = 134,
|
|
EmergencyACK = 238,
|
|
RadioEnableDisableRequest = 150,
|
|
RadioEnableDisableStatusRequest = 151,
|
|
RadioEnableDisableStatusBroadcast = 250,
|
|
ARSReceived = 130,
|
|
LocationReceived = 131,
|
|
PollResponseReceived = 231,
|
|
SMSReceived = 132,
|
|
SubscriberGatewayUpdate = 139,
|
|
SendSMSRequest = 142,
|
|
SendSMSRequest2 = 143,
|
|
SendGroupSMSRequest = 144,
|
|
SendGroupSMSRequest2 = 145,
|
|
SmsSavedInDbAck = 232,
|
|
FieldRadioReceivedSmsAck = 242,
|
|
TelemetryRequest = 133,
|
|
TelemetryReceived = 233,
|
|
CallStatusBroadcast = 125,
|
|
ChannelQueryRequest = 94,
|
|
ChannelBroadcast = 124,
|
|
EndSipCallRequest = 220,
|
|
EndSipCallResponse = 222,
|
|
GatewayOn = 500,
|
|
GatewayStatusChanged = 501,
|
|
AppServerHeartbeat = 507,
|
|
RefreshDatabaseCommand = 209,
|
|
PollArsRequest = 149,
|
|
WebsocketStatusToMsgBus = 612
|
|
};
|
|
|
|
public enum RADIOTYPE
|
|
{
|
|
MOTO = 0,
|
|
HYT = 1,
|
|
HARRIS = 2,
|
|
ATLAS = 3,
|
|
UNKNOWN = 4,
|
|
TETRA = 5,
|
|
CONECTPLUS = 6,
|
|
REPEATER_TRBO = 7,
|
|
SIMOCO = 8,
|
|
LINX = 9,
|
|
LINXB = 10,
|
|
EXCERA = 11,
|
|
LISF = 12,
|
|
SAFENET = 99
|
|
}
|
|
|
|
public class Alarms
|
|
{
|
|
public rep_type type;
|
|
public DateTime time;
|
|
public String unitname;
|
|
public String descript;
|
|
|
|
public Alarms(rep_type _type, DateTime _time, String _unitname, String _descript)
|
|
{
|
|
type = _type;
|
|
time = _time;
|
|
unitname = _unitname;
|
|
descript = _descript;
|
|
}
|
|
}
|
|
|
|
public sealed class ARSStatus
|
|
{
|
|
|
|
private readonly String name;
|
|
private readonly int value;
|
|
|
|
public static readonly ARSStatus ON = new ARSStatus(1, "ON");
|
|
public static readonly ARSStatus OFF = new ARSStatus(0, "OFF");
|
|
|
|
private ARSStatus(int value, String name)
|
|
{
|
|
this.name = name;
|
|
this.value = value;
|
|
}
|
|
|
|
public override String ToString()
|
|
{
|
|
return name;
|
|
}
|
|
|
|
}
|
|
|
|
public sealed class IconTheme
|
|
{
|
|
|
|
private readonly String name;
|
|
private readonly int value;
|
|
|
|
public static readonly IconTheme CLASSIC = new IconTheme(1, "classic");
|
|
public static readonly IconTheme PIN = new IconTheme(2, "pin");
|
|
public static readonly IconTheme SQUARE = new IconTheme(3, "square");
|
|
|
|
private IconTheme(int value, String name)
|
|
{
|
|
this.name = name;
|
|
this.value = value;
|
|
}
|
|
|
|
public override String ToString()
|
|
{
|
|
return name;
|
|
}
|
|
|
|
public static IconTheme GetIconType(string iconType)
|
|
{
|
|
if (iconType.Equals("classic"))
|
|
return IconTheme.CLASSIC;
|
|
else if (iconType.Equals("pin"))
|
|
return IconTheme.PIN;
|
|
else
|
|
return IconTheme.SQUARE;
|
|
}
|
|
|
|
}
|
|
|
|
public class Definitions
|
|
{
|
|
public static string GetCallStatus4UI(int callStatus)
|
|
{
|
|
switch(callStatus)
|
|
{
|
|
case (int)CallStatus.INPROGRESS : return "In Progress";
|
|
case (int)CallStatus.HANGTIME: return "Hang Time";
|
|
case (int)CallStatus.ENDED: return "Ended";
|
|
default: return "Unknown";
|
|
}
|
|
}
|
|
|
|
public static string GetCallType4UI(int callType)
|
|
{
|
|
switch(callType)
|
|
{
|
|
case (int)CallType.ALLCALL : return "All Call";
|
|
case (int)CallType.PRIVATECALL: return "Private Call";
|
|
case (int)CallType.GROUPCALL: return "Group Call";
|
|
case (int)CallType.EMERGENCYCALL: return "Emergency Call";
|
|
default: return "Unknown";
|
|
}
|
|
}
|
|
}
|
|
|
|
public class dailyReport
|
|
{
|
|
private String Reptype;
|
|
public String reptype
|
|
{
|
|
get { return Reptype; }
|
|
set { Reptype = value; }
|
|
}
|
|
|
|
private String Email;
|
|
public String email
|
|
{
|
|
get { return Email; }
|
|
set { Email = value; }
|
|
}
|
|
|
|
private DateTime Datafrom;
|
|
public DateTime datafrom
|
|
{
|
|
get { return Datafrom; }
|
|
set { Datafrom = value; }
|
|
}
|
|
|
|
private DateTime Datato;
|
|
public DateTime datato
|
|
{
|
|
get { return Datato; }
|
|
set { Datato = value; }
|
|
}
|
|
|
|
private Int32 IntDatafrom;
|
|
public Int32 intdatafrom
|
|
{
|
|
get { return IntDatafrom; }
|
|
set { IntDatafrom = value; }
|
|
}
|
|
|
|
private Int32 IntDatato;
|
|
public Int32 intdatato
|
|
{
|
|
get { return IntDatato; }
|
|
set { IntDatato = value; }
|
|
}
|
|
|
|
private String Unitname;
|
|
public String unitname
|
|
{
|
|
get { return Unitname; }
|
|
set { Unitname = value; }
|
|
}
|
|
|
|
private String Zonename;
|
|
public String zonename
|
|
{
|
|
get { return Zonename; }
|
|
set { Zonename = value; }
|
|
}
|
|
|
|
private Int32 Idx;
|
|
public Int32 idx
|
|
{
|
|
get { return Idx; }
|
|
set { Idx = value; }
|
|
}
|
|
|
|
private String userName;
|
|
public String UserName
|
|
{
|
|
get { return userName; }
|
|
set { userName = value; }
|
|
}
|
|
|
|
}
|
|
|
|
public class SDRegistration
|
|
{
|
|
private string databaseIP;
|
|
public string DatabaseIP
|
|
{
|
|
get { return databaseIP; }
|
|
set { databaseIP = value; }
|
|
}
|
|
|
|
private string db_schema;
|
|
public string Db_schema
|
|
{
|
|
get { return db_schema; }
|
|
set { db_schema = value; }
|
|
}
|
|
|
|
private string db_user;
|
|
public string Db_user
|
|
{
|
|
get { return db_user; }
|
|
set { db_user = value; }
|
|
}
|
|
|
|
private string db_password;
|
|
public string Db_password
|
|
{
|
|
get { return db_password; }
|
|
set { db_password = value; }
|
|
}
|
|
|
|
private string db_port;
|
|
public string Db_port
|
|
{
|
|
get { return db_port; }
|
|
set { db_port = value; }
|
|
}
|
|
|
|
|
|
private string Ip;
|
|
public string ip
|
|
{
|
|
get { return Ip; }
|
|
set { Ip = value; }
|
|
}
|
|
|
|
private Boolean hasGps;
|
|
public Boolean gps
|
|
{
|
|
get { return hasGps; }
|
|
set { hasGps = value; }
|
|
}
|
|
|
|
private Boolean hasSms;
|
|
public Boolean sms
|
|
{
|
|
get { return hasSms; }
|
|
set { hasSms = value; }
|
|
}
|
|
|
|
private Boolean hasTicketing;
|
|
public Boolean ticketing
|
|
{
|
|
get { return hasTicketing; }
|
|
set { hasTicketing = value; }
|
|
}
|
|
|
|
private Boolean hasReports;
|
|
public Boolean reports
|
|
{
|
|
get { return hasReports; }
|
|
set { hasReports = value; }
|
|
}
|
|
|
|
private Boolean hasVoice;
|
|
public Boolean voice
|
|
{
|
|
get { return hasVoice; }
|
|
set { hasVoice = value; }
|
|
}
|
|
|
|
private Boolean hasRecordings;
|
|
public Boolean recordings
|
|
{
|
|
get { return hasRecordings; }
|
|
set { hasRecordings = value; }
|
|
}
|
|
|
|
private Boolean hasZones;
|
|
public Boolean zones
|
|
{
|
|
get { return hasZones; }
|
|
set { hasZones = value; }
|
|
}
|
|
|
|
private Boolean hasTelemetry;
|
|
public Boolean telemetry
|
|
{
|
|
get { return hasTelemetry; }
|
|
set { hasTelemetry = value; }
|
|
}
|
|
|
|
private Int16 mapType;
|
|
public Int16 map_type
|
|
{
|
|
get { return mapType; }
|
|
set { mapType = value; }
|
|
}
|
|
|
|
public String Map_TypeS;
|
|
public String MapTypeS
|
|
{
|
|
get { return Map_TypeS; }
|
|
set { Map_TypeS = value; }
|
|
}
|
|
|
|
public string MSG_BUS_IP, MSg_BUS_port, VoiceMessageBusPort;
|
|
public override bool Equals(object obj)
|
|
{
|
|
if (obj == null)
|
|
{
|
|
return false;
|
|
}
|
|
SDRegistration p = obj as SDRegistration;
|
|
if ((System.Object)p == null)
|
|
{
|
|
return false;
|
|
}
|
|
if (ip != p.ip)
|
|
{
|
|
return false;
|
|
}
|
|
if (gps != p.gps)
|
|
{
|
|
return false;
|
|
}
|
|
if (sms != p.sms)
|
|
{
|
|
return false;
|
|
}
|
|
if (ticketing != p.ticketing)
|
|
{
|
|
return false;
|
|
}
|
|
if (reports != p.reports)
|
|
{
|
|
return false;
|
|
}
|
|
if (voice != p.voice)
|
|
{
|
|
return false;
|
|
}
|
|
if (recordings != p.recordings)
|
|
{
|
|
return false;
|
|
}
|
|
if (zones != p.zones)
|
|
{
|
|
return false;
|
|
}
|
|
if (telemetry != p.telemetry)
|
|
{
|
|
return false;
|
|
}
|
|
if (map_type != p.map_type)
|
|
{
|
|
return false;
|
|
}
|
|
return true;
|
|
}
|
|
|
|
public override int GetHashCode()
|
|
{
|
|
return base.GetHashCode();
|
|
}
|
|
}
|
|
|
|
public class GatewayRegistration
|
|
{
|
|
private string Ip;
|
|
public string ip
|
|
{
|
|
get { return Ip; }
|
|
set { Ip = value; }
|
|
}
|
|
|
|
private string Id;
|
|
public string id
|
|
{
|
|
get { return Id; }
|
|
set { Id = value; }
|
|
}
|
|
}
|
|
|
|
public enum Status_for_tab
|
|
{
|
|
OFF = 0,
|
|
ON = 1,
|
|
GPS_ON = 2,
|
|
GPS_POOR = 3,
|
|
GPS_OFF = 4,
|
|
NOGPSFIX = 5,
|
|
ENABLE = 6,
|
|
DISABLE =7,
|
|
EMERG=8,
|
|
MADEOFF=9,
|
|
MADEON=10,
|
|
UNKNOW=11
|
|
};
|
|
|
|
|
|
public class VehicleStatus
|
|
{
|
|
public Int32 gps_poor;
|
|
public Int32 gps_off;
|
|
public Int32 made_off;
|
|
|
|
public Double lat = 0;
|
|
public Double lng = 0;
|
|
public DateTime lastArsTime;
|
|
public DateTime lastPositionTime;
|
|
|
|
private Status_for_tab _previousStatus = Status_for_tab.UNKNOW;
|
|
public Status_for_tab previousStatus
|
|
{
|
|
get { return _previousStatus; }
|
|
}
|
|
|
|
public Status_for_tab _curentStatus = Status_for_tab.UNKNOW;
|
|
public Status_for_tab curentStatus
|
|
{
|
|
get { return _curentStatus; }
|
|
set
|
|
{
|
|
_previousStatus = _curentStatus;
|
|
_curentStatus = value;
|
|
}
|
|
}
|
|
|
|
public VehicleStatus(Int32 _gps_poor, Int32 _gps_off,Int32 _made_off)
|
|
{
|
|
gps_off = _gps_off;
|
|
gps_poor = _gps_poor;
|
|
made_off = _made_off;
|
|
lastPositionTime = new DateTime(1970,1,1);
|
|
lastArsTime = new DateTime(1970, 1, 1);
|
|
}
|
|
}
|
|
|
|
public class IMEI_and_STAT
|
|
{
|
|
public String imei="";
|
|
public Status_for_tab veh_stat = Status_for_tab.UNKNOW;
|
|
|
|
public IMEI_and_STAT(String _imei, Status_for_tab _veh_stat)
|
|
{
|
|
imei = _imei;
|
|
veh_stat = _veh_stat;
|
|
}
|
|
}
|
|
|
|
public class DT
|
|
{
|
|
|
|
public static DateTime GetNetworkTime()
|
|
{
|
|
try
|
|
{
|
|
const string ntpServer = "time.nist.gov";//"pool.ntp.org";
|
|
var ntpData = new byte[48];
|
|
ntpData[0] = 0x1B; //LeapIndicator = 0 (no warning), VersionNum = 3 (IPv4 only), Mode = 3 (Client Mode)
|
|
|
|
var addresses = Dns.GetHostEntry(ntpServer).AddressList;
|
|
var ipEndPoint = new IPEndPoint(addresses[0], 123);
|
|
var socket = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);
|
|
socket.ReceiveTimeout = 3000;
|
|
|
|
socket.Connect(ipEndPoint);
|
|
socket.Send(ntpData);
|
|
socket.Receive(ntpData);
|
|
socket.Close();
|
|
|
|
ulong intPart = (ulong)ntpData[40] << 24 | (ulong)ntpData[41] << 16 | (ulong)ntpData[42] << 8 | (ulong)ntpData[43];
|
|
ulong fractPart = (ulong)ntpData[44] << 24 | (ulong)ntpData[45] << 16 | (ulong)ntpData[46] << 8 | (ulong)ntpData[47];
|
|
|
|
var milliseconds = (intPart * 1000) + ((fractPart * 1000) / 0x100000000L);
|
|
var networkDateTime = (new DateTime(1900, 1, 1)).AddMilliseconds((long)milliseconds);
|
|
|
|
return networkDateTime;
|
|
}
|
|
catch(Exception ex)
|
|
{
|
|
return DateTime.UtcNow;
|
|
}
|
|
}
|
|
}
|
|
|
|
public class SW_Subscriber
|
|
{
|
|
public int sc_id;
|
|
public string imei;
|
|
public string phone;
|
|
public string email;
|
|
public SW_Subscriber()
|
|
{
|
|
this.sc_id = 0;
|
|
this.imei = "";
|
|
this.phone = "";
|
|
this.email = "";
|
|
}
|
|
}
|
|
|
|
public class InterthreadMessageQueue<T>
|
|
{
|
|
private DateTime lastReadTime = DateTime.Now;
|
|
|
|
public DateTime LastReadTime
|
|
{
|
|
get { return lastReadTime; }
|
|
private set { lastReadTime = value; }
|
|
}
|
|
|
|
System.Collections.Generic.Queue<T> _queue = new
|
|
System.Collections.Generic.Queue<T>();
|
|
|
|
/// <summary>
|
|
/// Post a message to the queue.
|
|
/// </summary>
|
|
public void PostItem(T item)
|
|
{
|
|
|
|
lock (_queue)
|
|
{
|
|
_queue.Enqueue(item);
|
|
if (_queue.Count == 1)
|
|
Monitor.Pulse(_queue);
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Post a message to the queue.
|
|
/// </summary>
|
|
public void PostItems(List<T> items)
|
|
{
|
|
|
|
lock (_queue)
|
|
{
|
|
foreach(T item in items)
|
|
_queue.Enqueue(item);
|
|
|
|
if (_queue.Count == 1)
|
|
Monitor.Pulse(_queue);
|
|
}
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// Retrieve a message from the queue.
|
|
/// </summary>
|
|
/// <param name="maxWait">Number of milliseconds to block ifnothing is available. -1 means "block indefinitely"</param>
|
|
/// <returns>The next item in the queue, or default(T) if queue is empty</returns>
|
|
public T GetItem(int maxWait)
|
|
{
|
|
lock (_queue)
|
|
{
|
|
LastReadTime = DateTime.Now;
|
|
if (_queue.Count == 0)
|
|
{
|
|
if (maxWait == 0)
|
|
return default(T);
|
|
Monitor.Wait(_queue, maxWait);
|
|
if (_queue.Count == 0)
|
|
return default(T);
|
|
}
|
|
return _queue.Dequeue();
|
|
}
|
|
}
|
|
|
|
public T Peek(int maxWait)
|
|
{
|
|
lock (_queue)
|
|
{
|
|
if (_queue.Count == 0)
|
|
{
|
|
if (maxWait == 0)
|
|
return default(T);
|
|
Monitor.Wait(_queue, maxWait);
|
|
if (_queue.Count == 0)
|
|
return default(T);
|
|
}
|
|
return _queue.Peek();
|
|
}
|
|
}
|
|
|
|
public void Remove(T item)
|
|
{
|
|
lock (_queue)
|
|
{
|
|
if (_queue.Count != 0)
|
|
{
|
|
T itemPeek = _queue.Peek();
|
|
if (itemPeek.Equals(item))
|
|
{
|
|
_queue.Dequeue();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
public void Clear()
|
|
{
|
|
lock (_queue)
|
|
{
|
|
if (_queue.Count != 0)
|
|
{
|
|
_queue.Clear();
|
|
}
|
|
}
|
|
}
|
|
|
|
public List<T> ToList()
|
|
{
|
|
lock (_queue)
|
|
{
|
|
return _queue.ToList();
|
|
}
|
|
}
|
|
|
|
public int Count
|
|
{
|
|
get
|
|
{
|
|
lock (_queue)
|
|
{
|
|
return _queue.Count;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|