static void ProccessMessagesAsync() { if (taskProccesSMSNotices == null || taskProccesSMSNotices.Status == TaskStatus.Running) { taskProccesSMSNotices = new Task(() => { cancellationTokenProccessSMSNotices = false; while (true) { if (!SMSNotices.IsEmpty) { foreach (Modem gsmModem in Modems.Where(s => s.IsFree).ToList()) { SMSNotice smsNotice; if (SMSNotices.TryDequeue(out smsNotice)) { gsmModem.SendMessage(smsNotice); } } Thread.Sleep(1000); } if (cancellationTokenProccessSMSNotices) { break; } } }); taskProccesSMSNotices.Start(); } }
//============================================================== #region SMS public static int SendSMS(SMSNotices newSmsNotice) { using (VedantaEntities ve = new VedantaEntities()) { if (newSmsNotice != null) { ve.AddToSMSNotices(newSmsNotice); return(ve.SaveChanges()); } return(0); } }
/// <summary> /// Send message /// </summary> /// <param name="message">message to sent</param> /// <returns>collection notices which must be perfomed</returns> public static IEnumerable <Notice> SendMessage(string message) { List <Notice> notices = new List <Notice>(); foreach (Contact contact in Contacts) { SMSNotice smsNotice = new SMSNotice(message, contact); notices.Add(smsNotice); SMSNotices.Enqueue(smsNotice); } //add EmailNotice return(notices); }
public ActionResult Notification(FormCollection form, SMSNotices newSMS) { if (!ModelState.IsValid) { ApplicationMessages msg = new ApplicationMessages("Message Sent failed.", MessageType.Faild); ViewData["Message"] = msg; return(View()); } string cell = string.Empty; if (newSMS.MobileNumber.Length > 10) { cell = "91" + newSMS.MobileNumber.Substring(newSMS.MobileNumber.Length - 10, 10); } else { if (newSMS.MobileNumber.Length == 10) { cell = "91" + newSMS.MobileNumber.Substring(0, 10); } } if (!string.IsNullOrEmpty(cell)) { ViewData["SendString"] = "http://199.189.250.157/smsclient/api.php?username=scan&password=27963108&source=senderid&dmobile=" + cell + "&message=" + newSMS.SMSText; if (MasterModels.SendSMS(newSMS) > 0) { ApplicationMessages msg1 = new ApplicationMessages("Message Sent successfully.", MessageType.Success); ViewData["Message"] = msg1; } else { ApplicationMessages msg = new ApplicationMessages("Message Sent failed.", MessageType.Faild); ViewData["Message"] = msg; } } else { ApplicationMessages msg = new ApplicationMessages("Invalid Mobile Number.", MessageType.Faild); ViewData["Message"] = msg; } return(View()); }