Ejemplo n.º 1
0
 public List <Device> GetOfflineDevices()
 {
     using (var context = new DeviceHiveContext())
     {
         return(context.Devices
                .Include(e => e.Network)
                .Include(e => e.DeviceClass)
                .Where(e => e.DeviceClass.OfflineTimeout != null)
                .Where(d => !context.DeviceNotifications.Any(n => n.Device == d &&
                                                             EntityFunctions.AddSeconds(n.Timestamp, d.DeviceClass.OfflineTimeout) >= DateTime.UtcNow))
                .ToList());
     }
 }
Ejemplo n.º 2
0
        private StatusData.Status GetCurrentStatus(int counterId, double minThreshold, double maxThreshold)
        {
            var stat = _context.Results
                       .Where(c => c.DeviceCounter.Id == counterId)
                       .Where(t => t.LogDate <= DateTime.Now && t.LogDate >= EntityFunctions.AddSeconds(DateTime.Now, -30))
                       .Where(t => t.LogDate <= DateTime.Now)
                       .FirstOrDefault();

            if (stat != null)
            {
                return(GetStatus(minThreshold, maxThreshold, stat.AverageRead, stat.DeviceCounter.Device.Name));
            }

            return(StatusData.Status.Green);
        }
Ejemplo n.º 3
0
        public void TimeAddSeconds()
        {
            TimeSpan time = stored.Add(TimeSpan.FromSeconds(-1));

#if !EFOLD
            var q = this.Entities
                    .Where(x =>
                           DbFunctions.AddSeconds(x.Time, -1) == time);
#else
            var q = this.Entities
                    .Where(x =>
                           EntityFunctions.AddSeconds(x.Time, -1) == time);
#endif

            q.Should().NotBeEmpty();
        }
        public void DateTimeAddSeconds()
        {
            DateTime date = stored.AddSeconds(-1);

#if !EFOLD
            var q = this.Entities
                    .Where(x =>
                           DbFunctions.AddSeconds(x.DateTime, -1) == date);
#else
            var q = this.Entities
                    .Where(x =>
                           EntityFunctions.AddSeconds(x.DateTime, -1) == date);
#endif

            q.Should().NotBeEmpty();
        }
Ejemplo n.º 5
0
        public void DateTimeOffsetAddSeconds()
        {
            DateTimeOffset offset = stored.AddSeconds(-1);

#if !EFOLD
            var q = this.Entities
                    .Where(x =>
                           DbFunctions.AddSeconds(x.Offset, -1) == offset);
#else
            var q = this.Entities
                    .Where(x =>
                           EntityFunctions.AddSeconds(x.Offset, -1) == offset);
#endif

            q.Should().NotBeEmpty();
        }
Ejemplo n.º 6
0
        // Логируем все наши запросы в основную таблицу логов
        public int CountRequests(RequestDelimeter delimeter, string ip)
        {
            int sec = 0;

            switch (delimeter)
            {
            case RequestDelimeter.Minute:
                sec = DateTime.Now.Second * -1;
                break;

            case RequestDelimeter.Hour:
                sec = (DateTime.Now.Minute * 60 + DateTime.Now.Second) * -1;
                break;

            case RequestDelimeter.Day:
                sec = (((DateTime.Now.Hour * 60 * 60) + (DateTime.Now.Minute * 60)) + DateTime.Now.Second) * -1;
                break;
            }

            return(dbLog.SearchSparePartsLog.Count(x => x.AcctgID.Equals(ip) && EntityFunctions.AddSeconds(DateTime.Now, sec) < x.SearchDate && x.Source == 1));
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Monitors the CDRs table for records that are using real-time call control and are within the limit that requires them to
        /// re-reserve credit.
        /// </summary>
        private void MonitorCDRs()
        {
            try
            {
                Thread.CurrentThread.Name = RTCC_THREAD_NAME;

                logger.Debug("RTCC Core Starting Monitor CDRs thread.");

                while (!m_exit)
                {
                    using (var db = new SIPSorceryEntities())
                    {
                        try
                        {
                            // Try and reserve credit on in progress calls.
                            DateTime reservationDue = DateTime.Now.AddSeconds(m_reserveDueSeconds);

                            var rtccReservationDue = (from rtcc in db.RTCCs1.Include("cdr")
                                                      where rtcc.AccountCode != null && rtcc.SecondsReserved != null && rtcc.SecondsReserved > 0 && rtcc.ReservationError == null && rtcc.ReconciliationResult == null &&
                                                      rtcc.cdr.HungupTime == null && rtcc.cdr.AnsweredAt != null && rtcc.cdr.AnsweredStatus >= 200 && rtcc.cdr.AnsweredStatus <= 299 &&
                                                      EntityFunctions.AddSeconds(rtcc.cdr.AnsweredAt, rtcc.SecondsReserved) <= reservationDue
                                                      orderby rtcc.cdr.AnsweredAt
                                                      select rtcc).Take(NUMBER_CDRS_PER_ROUNDTRIP);

                            while (rtccReservationDue.Count() > 0)
                            {
                                foreach (RTCC rtcc in rtccReservationDue)
                                {
                                    Log_External(new SIPMonitorConsoleEvent(SIPMonitorServerTypesEnum.RTCC, SIPMonitorEventTypesEnum.DialPlan, "Reserving credit for call " + rtcc.cdr.Dst + ".", rtcc.cdr.Owner));

                                    // Attempt to re-reserve the next chunk of credit for the call.
                                    m_customerAccountDataLayer.ReserveCredit(m_reservationAmountSeconds, rtcc.ID);
                                }
                            }
                        }
                        //catch (ReflectionTypeLoadException ex)
                        //{
                        //    StringBuilder sb = new StringBuilder();
                        //    foreach (Exception exSub in ex.LoaderExceptions)
                        //    {
                        //        sb.AppendLine(exSub.Message);
                        //        if (exSub is FileNotFoundException)
                        //        {
                        //            FileNotFoundException exFileNotFound = exSub as FileNotFoundException;
                        //            if (!string.IsNullOrEmpty(exFileNotFound.FusionLog))
                        //            {
                        //                sb.AppendLine("Fusion Log:");
                        //                sb.AppendLine(exFileNotFound.FusionLog);
                        //            }
                        //        }
                        //        sb.AppendLine();
                        //    }
                        //    string errorMessage = sb.ToString();
                        //    logger.Error(errorMessage);
                        //}
                        catch (Exception monitorExcp)
                        {
                            logger.Error("Exception MonitorCDRs Credit Reservation. " + monitorExcp);
                            logger.Error("InnerException MonitorCDRs Credit Reservation. " + monitorExcp.InnerException);
                        }

                        try
                        {
                            // Terminate any calls that have reached their time limit.
                            DateTime now = DateTime.Now;
                            var      rtccTerminationDue = (from rtcc in db.RTCCs1.Include("cdr")
                                                           where !rtcc.IsHangingUp && rtcc.AccountCode != null && rtcc.cdr.HungupTime == null && rtcc.cdr.AnsweredAt != null && rtcc.SecondsReserved != null &&
                                                           rtcc.cdr.AnsweredStatus >= 200 && rtcc.cdr.AnsweredStatus <= 299 && EntityFunctions.AddSeconds(rtcc.cdr.AnsweredAt, rtcc.SecondsReserved) <= now && !rtcc.IsHangingUp &&
                                                           rtcc.ReconciliationResult == null
                                                           orderby rtcc.cdr.AnsweredAt
                                                           select rtcc).Take(NUMBER_CDRS_PER_ROUNDTRIP);

                            while (rtccTerminationDue.Count() > 0)
                            {
                                foreach (RTCC rtcc in rtccTerminationDue)
                                {
                                    Log_External(new SIPMonitorConsoleEvent(SIPMonitorServerTypesEnum.RTCC, SIPMonitorEventTypesEnum.DialPlan, "Terminating call due to reservation limit being reached " + rtcc.cdr.Dst + ".", rtcc.cdr.Owner));

                                    m_customerAccountDataLayer.SetCDRIsHangingUp(rtcc.ID);

                                    var dialogue = m_sipDialoguePersistor.Get(x => x.CDRId == rtcc.CDRID, null, 0, 1).FirstOrDefault();
                                    if (dialogue != null)
                                    {
                                        m_sipDialogueManager.CallHungup(dialogue.SIPDialogue, "RTCC time limit reached", true);
                                    }
                                    else
                                    {
                                        Log_External(new SIPMonitorConsoleEvent(SIPMonitorServerTypesEnum.RTCC, SIPMonitorEventTypesEnum.Warn, "A dialogue could not be found when terminating a call due to reservation limit being reached.", rtcc.cdr.Owner));
                                    }
                                }
                            }
                        }
                        catch (Exception monitorExcp)
                        {
                            logger.Error("Exception RTCCCore MonitorCDRs Call Termination. " + monitorExcp.Message);
                        }
                    }

                    Thread.Sleep(1000);
                }

                logger.Warn("RTCCCore MonitorCDRs thread stopping.");
            }
            catch (Exception excp)
            {
                logger.Error("Exception RTCCCore MonitorCDRs. " + excp.Message);
            }
        }