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 QueueMaker(Guid Sim_Id) { this.Sim_Id = Sim_Id; SIM sim = null; using (SMSPortalDBEntities db = new SMSPortalDBEntities()) { sim = (from x in db.SIMs where x.TFId == Sim_Id select x).FirstOrDefault(); } Logger.Show(string.Format("Working SIM: {0}", sim.TFNumber), ConsoleColor.Magenta); if (sim != null) { connector = new Connector(Sim_Id, sim.TFPort); try { aTimer = new System.Timers.Timer(10000); aTimer.Elapsed += OnTimedEvent; aTimer.AutoReset = true; aTimer.Enabled = true; aTimer.Start(); } catch (Exception e) { Logger.Log(Messages.CONNECTOR_MAIN, e); } } }
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 onGSMSendingError() { try { resetTimer(); Logger.ShowError("Error Occured... try re-active numbers by skipping current number"); try { using (SMSPortalDBEntities db = new SMSPortalDBEntities()) { } } catch { } Thread.Sleep(5000); AbstractPacket packetToSend = new ActivationPacket(sim_number); packetToSend.Cmd = AbstractPacket.READ_CMD; byte[] byteToSend = packetToSend.toRaw(); networkManager.Send(byteToSend); } catch (Exception e) { Logger.ShowError(e.Message); } }
public void onMessageTextWrite() { try { resetTimer(); using (SMSPortalDBEntities db = new SMSPortalDBEntities()) { Guid qp_id = queueItems[0].queue_phone.TFId; string number = (from x in db.Queue_Phone where x.TFId == qp_id select x.Phone.TFNumber).FirstOrDefault(); AbstractPacket packetToSend = new RegisterationPacket(sim_number, number, 0); Logger.Show(packetToSend.ToString(), ConsoleColor.White); byte[] byteToSend = packetToSend.toRaw(); networkManager.Send(byteToSend); } } catch (Exception e) { Logger.ShowError(e.Message); } }
private List <USSD> getUSSDItems() { try { using (SMSPortalDBEntities db = new SMSPortalDBEntities()) { var q = (from x in db.USSDs where x.TFSim_Id == Sim_Id && !x.TFIsSent select x).ToList(); return(q); } } catch { } return(null); }
private void btnGetSim_Click(object sender, EventArgs e) { using (SMSPortalDBEntities db = new SMSPortalDBEntities()) { var q = (from x in db.SIMs select new { x.TFId, x.TFNumber, x.TFPort, }).ToList(); grdSim.DataSource = q; } }
public void registerQueue(List <QueueItem> queueItems, Guid queueId) { resetTimer(); this.isQueueFinished = false; Console.ResetColor(); try { this.queueId = queueId; this.queueItems = queueItems; using (SMSPortalDBEntities db = new SMSPortalDBEntities()) { try { message = (from x in db.Queues where x.TFId == queueId select x.Message.TFContent).FirstOrDefault(); if (Encoding.BigEndianUnicode.GetBytes(message).Length > SMSTextPacket.MESSAGE_TEXT_COUNTER) { Logger.ShowError(string.Format("Message could not be more than {0} bytes", SMSTextPacket.MESSAGE_TEXT_COUNTER)); return; } start = 0; finish = queueItems.Count() - 1; AbstractPacket packetToSend = new SMSTextPacket(sim_number, message); byte[] byteToSend = packetToSend.toRaw(); networkManager.Send(byteToSend); } catch (IndexOutOfRangeException e1) { Logger.ShowError(string.Format("Message could not be more than {0} bytes", SMSTextPacket.MESSAGE_TEXT_COUNTER)); } } } catch (Exception e) { Logger.ShowError(e.Message); } }
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); } }
/// <summary> /// Itterate on gridview numbers based on registeration answer of modem and register new number /// After all numbers are registered, activation of numbers will be done /// </summary> /// <param name="registeredPacket">Registerd packet (answer of modem)</param> public void onWriteNumberRegister(RegisterationPacket registeredPacket) { try { resetTimer(); int cIndex = registeredPacket.Index + 1; byte[] byteToSend = null; AbstractPacket packetToSend = null; if (cIndex < queueItems.Count) { using (SMSPortalDBEntities db = new SMSPortalDBEntities()) { Guid qp_id = queueItems[cIndex].queue_phone.TFId; string number = (from x in db.Queue_Phone where x.TFId == qp_id select x.Phone.TFNumber).FirstOrDefault(); packetToSend = new RegisterationPacket(sim_number, number, cIndex); Logger.Show(packetToSend.ToString(), ConsoleColor.White); byteToSend = packetToSend.toRaw(); networkManager.Send(byteToSend); } } else { Logger.Show("All numbers are registered", ConsoleColor.White); packetToSend = new ActivationPacket(sim_number, start, finish); byteToSend = packetToSend.toRaw(); networkManager.Send(byteToSend); } } catch (Exception e) { Logger.ShowError(e.Message); } }
public List <QueueItem> getQueueItems() { List <QueueItem> queueItems = new List <QueueItem>(); SqlConnection connection = null; SqlCommand command = null; SqlDataReader reader = null; try { connection = new SqlConnection(ConfigurationManager.ConnectionStrings["SMSPortalLowLevelConnection"].ConnectionString); connection.Open(); string query = "UPDATE Queue_Phone " + "SET TFIsUnderProcess = 1 " + "OUTPUT INSERTED.TFId " + "WHERE TFId IN " + "( " + "SELECT TOP 20 TFId " + "FROM Queue_Phone WHERE TFQueue_Id in " + "( " + "SELECT TFId FROM Queue where Queue.TFUser_Id in" + "( " + "select TFUser_Id from SIM_User where TFSIM_Id = @simId" + ") " + "and TFEnable = 1" + ") " + "and TFIsUnderProcess = 0 and TFEnable = 1 and TFActive = 1 and TFError = 0" + ")"; command = new SqlCommand(query, connection); command.Parameters.Add(new SqlParameter("simId", Sim_Id)); reader = command.ExecuteReader(); using (SMSPortalDBEntities db = new SMSPortalDBEntities()) { while (reader.Read()) { Guid QP_id = Guid.Parse(reader["TFId"].ToString()); QueueItem item = new QueueItem() { queue_phone = (from x in db.Queue_Phone where x.TFId == QP_id select x).FirstOrDefault(), }; item.sendBox = (from x in db.SendBoxes where x.TFQueue_Id == item.queue_phone.TFQueue_Id select x).FirstOrDefault(); queueItems.Add(item); } } } catch (Exception e) { Logger.Log(Messages.CONNECTOR_GET_QUEUE_ITEM, e); } finally { if (reader != null) { reader.Dispose(); reader.Close(); } if (command != null) { command.Dispose(); } if (connection != null) { connection.Dispose(); connection.Close(); } } return(queueItems); }
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(); } }