Hi. Good day
This is my code in C#
while (SMSMessages.Count != 0)
{
String SMSMessage;
if (SMSMessages.TryDequeue(out SMSMessage))
{
string[] nummsg = SMSMessage.Split(';');
ConsoleWriteLine("Waiting for message to send...");
IAsyncResult result;
Action action = () =>
{
_smsreadyNotifier1.WaitOne();
};
result = action.BeginInvoke(null, null);
if (result.AsyncWaitHandle.WaitOne(20000))
{
string TaskID = null;
if (nummsg[1].Contains("Service Ref. No.:"))
{
TaskID = nummsg[1].Split('J')[0].Substring(18).Trim();
//ConsoleWriteLine("Send SMS TaskID: " + TaskID);
updateStatus(TaskID, "Sending Message...");
sms.setTaskID(TaskID);
}
Thread.Sleep(1000);
sms.SendSMS(nummsg[0], nummsg[1]);
Thread.Sleep(2000);
}
else
{
string TaskID = null;
if (nummsg[1].Contains("Service Ref. No.:"))
{
TaskID = nummsg[1].Split('J')[0].Substring(18).Trim();
//ConsoleWriteLine("Send SMS TaskID: " + TaskID);
updateStatus(TaskID, "Sending Message...");
sms.setTaskID(TaskID);
}
Thread.Sleep(1000);
sms.SendSMS(nummsg[0], nummsg[1]);
Thread.Sleep(2000);
}
}
}
So where does the SMSMessages method came from? Here is the code:
public override void handleGETRequest (HttpProcessor p)
{
p.writeSuccess();
if((!p.http_url.Equals("/favicon.ico")) && (p.http_request.Equals("/sms"))){
Uri myUri = new Uri("http://localhost"+p.http_url);
string num = HttpUtility.ParseQueryString(myUri.Query).Get("num");
string msg = HttpUtility.ParseQueryString(myUri.Query).Get("msg").Replace("%3A", ":");
if (msg.Length > 140)
{
string[] msgchunks = SplitIntoChunks(msg, 140);
foreach (string chunks in msgchunks) {
Program.ServerInstance.SMSMessages.Enqueue(num + ";" + chunks);
}
}
else
{
Program.ServerInstance.SMSMessages.Enqueue(num + ";" + msg);
}
Program.ServerInstance.runbgworker();
SqlConnection myConnection = Program.ServerInstance.myConnection;
}
}
Next, the "msg" itself where the .Split Method should have split for me to get the taskID. To be clear, here the Javascript code where msg is added:
function(taskID){
var msg = 'Service Ref. No.%3A '+taskID+
';J.O. No.%3A '+document.getElementById('JONumber').value+
';SRF No.%3A '+document.getElementById('SRFNumber').value+
';Client%3A '+cname+
';Site%3A '+sname+
';Date%3A '+document.getElementById('datepicker').value+
';Time%3A '+document.getElementById('Departure').value.split(':').join('%3A')+' to '+document.getElementById('Arrival').value.split(':').join('%3A')+
';Verification Code%3A '+captcha+
';Objectives%3A '+document.getElementById('Objectives').value;
//togglepanel('addpanel', 0);
if (taskID !== undefined) {
sendsms(phone, msg);
updatetable();
}
}
My question:
1) Do I miss anything? I need to split the "msg" for me to get the taskID which is needed for my program.
2) Do I have the right method of splitting the "msg" to get "Service Ref. No.:"? If not, what other way can i split the "msg" so that i could get the "Service Re. No.:"?