public void finishWorks() { if (checkFinishTimer != null) { checkFinishTimer.Stop(); } if (queueItems != null && queueItems.Count > 0) { using (SMSPortalDBEntities db = new SMSPortalDBEntities()) { foreach (QueueItem item in queueItems) { var qp = (from x in db.Queue_Phone where x.TFId == item.queue_phone.TFId select x).FirstOrDefault(); qp.TFIsUnderProcess = false; db.Entry(qp).State = EntityState.Modified; } db.SaveChanges(); } } this.isQueueFinished = true; this.isUSSDFinished = true; }
public void onReadInbox(InboxPacket packet) { try { using (SMSPortalDBEntities db = new SMSPortalDBEntities()) { string dtFa = ""; try { dtFa = SMSPortalCross.Utils.Date.CompleteGregorianToPersian(packet.DtRecieved); } catch { } db.Inboxes.Add(new Inbox() { TFId = Guid.NewGuid(), TFSim_Id = this.simId, TFMessage = packet.Message, TFSenderNumber = packet.Number, TFDateTime = packet.DtRecieved, TFDateTimeFA = dtFa, TFIsRead = false }); db.SaveChanges(); } } catch { } }
public void onAutoDelivery(DeliveryPacket packet) { try { using (SMSPortalDBEntities db = new SMSPortalDBEntities()) { var sp = (from x in db.SendBox_Phone where x.Phone.TFNumber == packet.Number && !x.TFIsDelivered && x.TFGSM_Id == packet.Id select x).FirstOrDefault(); //if (sp == null) // sp = (from x in db.SendBox_Phone // where x.TFGSM_Id == packet.Id || x.TFGSM_Id == packet.Id - 1 // select x).FirstOrDefault(); if (sp != null) { if (!sp.TFIsDelivered) { sp.TFIsDelivered = true; sp.TFDateTimeSendGSM = packet.DtSend; sp.TFDateTimeSendGSMFA = SMSPortalCross.Utils.Date.CompleteGregorianToPersian(packet.DtSend); sp.TFDateTimeDelivery = packet.DtDeliver; sp.TFDateTimeDeliveryFA = SMSPortalCross.Utils.Date.CompleteGregorianToPersian(packet.DtDeliver); db.Entry(sp).State = EntityState.Modified; db.SaveChanges(); Logger.Show(string.Format("Sendbox_Phone with SP_Id: {0} is delivered", sp.TFId), ConsoleColor.Yellow); } else { Logger.Show(string.Format("SP_Id: {0} is already delivered", sp.TFId), ConsoleColor.Yellow); } } } } catch (Exception e) { Logger.ShowError(e.Message); } }
public void onUSSDRead(USSDPacket packet) { try { resetTimer(); using (SMSPortalDBEntities db = new SMSPortalDBEntities()) { Guid id = ussdItems[0].TFId; var ussd = (from x in db.USSDs where x.TFId == id select x).FirstOrDefault(); ussd.TFIsSent = true; ussd.TFReceive = packet.RequestAnswer; db.Entry(ussd).State = EntityState.Modified; db.SaveChanges(); } try { ussdItems.RemoveAt(0); } catch (Exception e) { Logger.ShowError(e.Message); } if (ussdItems.Count > 0) { sendUSSD(); } else { finishWorks(); } } catch (Exception e) { Logger.ShowError(e.Message); } }
public void PushBySchedule(User user, Guid _sendBoxId) { try { using (SMSPortalDBEntities db = new SMSPortalDBEntities()) { SendBox sendBox = (from x in db.SendBoxes where x.TFId == _sendBoxId select x).FirstOrDefault(); Queue queue = (from x in db.Queues where x.TFId == sendBox.TFQueue_Id select x).FirstOrDefault(); var lstQP = (from x in db.Queue_Phone where x.TFQueue_Id == queue.TFId && x.TFActive == false select x).ToList(); foreach (var q in lstQP) { q.TFActive = true; int scheduleType = (from x in db.Queues where x.TFId == queue.TFId select x.TFScheduleType).FirstOrDefault(); if (Enums.isOnceType(scheduleType)) { try { SMSPortalCross.Utils.Scheduler scheduler = new SMSPortalCross.Utils.Scheduler(); scheduler.removeSchedule(queue.TFId); } catch (Exception e) { Logger.Log(Messages.GSM_HANDLER_PUSH_BY_SCHEDULE, e); } } } db.SaveChanges(); } } catch (Exception e) { Logger.Log(Messages.GSM_HANDLER_PUSH_BY_SCHEDULE, e); } }
public void QueueMaker(User _user, Message _message, List <Phone> lstPhone, Enums.Schedule _ScheduleType, DateTime _dtSend) { try { Guid queue_id = Guid.NewGuid(); Queue queue = new Queue() { TFId = queue_id, TFMessage_Id = _message.TFId, TFScheduleType = (int)_ScheduleType, TFUser_Id = _user.TFId, TFDateTimeCreate = DateTime.Now, TFDateTimeCreateFA = SMSPortalCross.Utils.Date.CompleteGregorianToPersian(DateTime.Now), TFDateTimeRequest = _dtSend, TFDateTimeRequestFA = SMSPortalCross.Utils.Date.CompleteGregorianToPersian(_dtSend), TFEnable = true }; SendBox sendBox = new SendBox() { TFId = Guid.NewGuid(), TFMessage_Id = _message.TFId, TFUser_Id = _user.TFId, TFQueue_Id = queue_id, TFDateTimeCreate = DateTime.Now, TFDateTimeCreateFA = SMSPortalCross.Utils.Date.CompleteGregorianToPersian(DateTime.Now), }; using (SMSPortalDBEntities db = new SMSPortalDBEntities()) { db.Queues.Add(queue); db.SendBoxes.Add(sendBox); db.SaveChanges(); } AddQueuePhone(_user, queue, sendBox, lstPhone, _ScheduleType, _dtSend); } catch (Exception e) { Logger.Log(Messages.GSM_HANDLER_QUEUE_MAKER, e); } }
public void AddQueuePhone(User _user, Queue _queue, SendBox _sendBox, List <Phone> lstPhone, Enums.Schedule _scheduleType, DateTime _dtSend) { try { using (SMSPortalDBEntities db = new SMSPortalDBEntities()) { db.Configuration.AutoDetectChangesEnabled = false; string message = (from x in db.Messages where x.TFId == _queue.TFMessage_Id select x.TFContent).FirstOrDefault(); foreach (Phone phone in lstPhone) { Guid qp_Id = Guid.NewGuid(); Queue_Phone qp = new Queue_Phone() { TFId = qp_Id, TFPhone_Id = phone.TFId, TFQueue_Id = _queue.TFId, TFIsUnderProcess = false, TFActive = Enums.getDefultActiveState((int)_scheduleType), TFEnable = true, TFError = false }; db.Queue_Phone.Add(qp); } db.SaveChanges(); if (_scheduleType != Enums.Schedule.None) { SMSPortalCross.Utils.Scheduler scheduler = new SMSPortalCross.Utils.Scheduler(); scheduler.makeNewSchedule(_queue.TFId, _user.TFId, _sendBox.TFId, Global.File_Scheduler, _scheduleType, _dtSend); } } } catch (Exception e) { Logger.Log(Messages.GSM_HANDLER_ADD_QUEUE_PHONE, e); } }
public void onAutoId(RegisterationPacket packet) { try { using (SMSPortalDBEntities db = new SMSPortalDBEntities()) { var qp = (from x in db.Queue_Phone where x.Phone.TFNumber == packet.Number && x.TFQueue_Id == queueId select x).FirstOrDefault(); // if queue or queue phone is deleted by user during send process 'q' can be null. // So, it must be checked wheter the value of q is null or not. if (qp != null) { var sendBox = (from x in db.SendBoxes where x.TFQueue_Id == queueId select x).FirstOrDefault(); db.SendBox_Phone.Add(new SendBox_Phone { TFId = Guid.NewGuid(), TFPhone_Id = qp.TFPhone_Id, TFSendBox_Id = sendBox.TFId, TFSim_Id = simId, TFGSM_Id = packet.Id, TFDateTimeSend = DateTime.Now, TFDateTimeSendFA = SMSPortalCross.Utils.Date.CompleteGregorianToPersian(DateTime.Now), TFIsDelivered = false }); db.SaveChanges(); int scheduleType = (from x in db.Queues where x.TFId == queueId select x.TFScheduleType).FirstOrDefault(); if (Enums.isOnceType(scheduleType)) { db.Queue_Phone.Remove(qp); Logger.Show(string.Format("Queue_Phone with QP_Id: {0} has been removed", qp.TFId), ConsoleColor.Yellow); } else { qp.TFActive = false; db.Entry(qp).State = EntityState.Modified; Logger.Show(string.Format("Queue_Phone with QP_Id: {0} has been deactived", qp.TFId), ConsoleColor.Yellow); } var _qp = queueItems.FirstOrDefault(x => x.queue_phone.TFId == qp.TFId); if (_qp != null) { queueItems.Remove(_qp); } else { Logger.ShowError(string.Format("Invalid Queue_Phone Id: {0}", qp.TFId)); Logger.Log(Messages.CONNECTOR_ON_SEND, new Exception("Invalid Queue_Phone Id")); } } db.SaveChanges(); if (queueItems.Count != 0) { resetTimer(); } else { finishWorks(); } } } catch (Exception e) { Logger.Log(Messages.CONNECTOR_ON_SEND, e); resetTimer(); } }