Beispiel #1
0
        public static List <TransitCounter> GetSummaryMonthly(ISession session)
        {
            List <TransitCounter> result = new List <TransitCounter>();
            DateTime now = DateTime.UtcNow;
            DateTime ts  = now.AddMonths(-12);

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

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

            return(result);
        }
Beispiel #2
0
        public static void IncrementMonthlyCounter(ISession session, int count)
        {
            DateTime utcnow = DateTime.UtcNow.Date;

            utcnow = utcnow.AddDays(1 - utcnow.Day);

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

            if (counter == null)
            {
                counter              = new MonthlyCounter();
                counter.DateTime     = utcnow;
                counter.RequestCount = 0;
            }

            counter.RequestCount += count;
            session.Save(counter);
        }
Beispiel #3
0
 public MonthlyCounterTest()
 {
     mMonthlyCounter              = new MonthlyCounter();
     mMonthlyCounter.DateTime     = DateTime.UtcNow;
     mMonthlyCounter.RequestCount = 10;
 }