Ejemplo n.º 1
0
        public static void Update <CounterType, TotalType>(ISession session, SortedDictionary <DateTime, TotalType> dict,
                                                           GetTimestampCounter <CounterType, TotalType> getTimestampcounter,
                                                           SetTimestampCounter <CounterType, TotalType> setTimestampcounter)
            where CounterType : IDbObject, new()
        {
            IEnumerator <CounterType> counterenumerator = session.CreateQuery(string.Format("FROM {0}", typeof(CounterType).Name))
                                                          .Enumerable <CounterType>().GetEnumerator();

            while (counterenumerator.MoveNext())
            {
                UpdateOrDelete <CounterType, TotalType>(session, dict, counterenumerator.Current,
                                                        getTimestampcounter, setTimestampcounter);
            }

            SortedDictionary <DateTime, TotalType> .Enumerator remainingenumerator = dict.GetEnumerator();
            while (remainingenumerator.MoveNext())
            {
                CounterType counter             = new CounterType();
                TimestampCounter <TotalType> tc = new TimestampCounter <TotalType>(
                    remainingenumerator.Current.Key,
                    remainingenumerator.Current.Value);
                setTimestampcounter(counter, tc);
                session.Save(counter);
            }
        }
Ejemplo n.º 2
0
        private List <TransitSummarizedCounter> GetSummary <CounterType, TotalType>(
            GetDt getfirst, GetDt getnext,
            GetTimestampCounter <CounterType, TotalType> gettimestampcounter,
            GetSummarizedCounter <TotalType> getsummarizedcounter)
        {
            List <TransitSummarizedCounter> result = new List <TransitSummarizedCounter>();
            DateTime now = DateTime.UtcNow;
            DateTime ts  = getfirst(now);

            while (ts <= now)
            {
                DateTime    ts_current = new DateTime(ts.Year, ts.Month, ts.Day, 0, 0, 0);
                CounterType c          = Session.CreateCriteria(typeof(CounterType))
                                         .Add(Expression.Eq("Timestamp", ts_current))
                                         .UniqueResult <CounterType>();

                TransitSummarizedCounter tsc = null;
                if (c == null)
                {
                    tsc = new TransitSummarizedCounter(ts_current, 0);
                }
                else
                {
                    TimestampCounter <TotalType> tc = gettimestampcounter(c);
                    tsc = getsummarizedcounter(tc);
                }

                result.Add(tsc);
                ts = getnext(ts);
            }

            return(result);
        }
Ejemplo n.º 3
0
        public static void UpdateOrDelete <CounterType, TotalType>(ISession session, SortedDictionary <DateTime, TotalType> dict, CounterType instance,
                                                                   GetTimestampCounter <CounterType, TotalType> getTimestampcounter,
                                                                   SetTimestampCounter <CounterType, TotalType> setTimestampcounter)
        {
            TotalType total = default(TotalType);
            TimestampCounter <TotalType> tc = getTimestampcounter(instance);

            if (dict.TryGetValue(tc.Timestamp, out total))
            {
                if (!total.Equals(tc.Total))
                {
                    tc.Total = total;
                    setTimestampcounter(instance, tc);
                    session.Save(instance);
                }
                dict.Remove(tc.Timestamp);
            }
            else
            {
                session.Delete(instance);
            }
        }