Example #1
0
        public static void IncrementHourlyCounter(ISession session, int count)
        {
            DateTime utcnow  = DateTime.UtcNow;
            DateTime hournow = utcnow.Date.AddHours(utcnow.Hour);

            HourlyCounter counter = (HourlyCounter)session.CreateCriteria(typeof(HourlyCounter))
                                    .Add(Expression.Eq("DateTime", hournow))
                                    .UniqueResult();

            if (counter == null)
            {
                counter              = new HourlyCounter();
                counter.DateTime     = hournow;
                counter.RequestCount = 0;
            }

            counter.RequestCount += count;
            session.Save(counter);
        }
Example #2
0
        public static List <TransitCounter> GetSummaryHourly(ISession session)
        {
            List <TransitCounter> result = new List <TransitCounter>();
            DateTime now = DateTime.UtcNow;
            DateTime ts  = now.AddHours(-24);

            while (ts <= now)
            {
                DateTime      ts_current = new DateTime(ts.Year, ts.Month, ts.Day, ts.Hour, 0, 0);
                HourlyCounter c          = (HourlyCounter)session.CreateCriteria(typeof(HourlyCounter))
                                           .Add(Expression.Eq("DateTime", ts_current))
                                           .UniqueResult();

                result.Add((c == null) ? new TransitCounter(ts_current, 0) : new TransitCounter(c.DateTime, c.RequestCount));
                ts = ts.AddHours(1);
            }

            return(result);
        }
Example #3
0
 public HourlyCounterTest()
 {
     mHourlyCounter              = new HourlyCounter();
     mHourlyCounter.DateTime     = DateTime.UtcNow;
     mHourlyCounter.RequestCount = 10;
 }