Пример #1
0
        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;
        }
Пример #2
0
        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);
            }
        }
Пример #3
0
        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);
            }
        }
Пример #4
0
        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();
            }
        }