예제 #1
0
        // keep last 100 trends in a category
        public void Trend(string name, int value = 1, DateTime?actionDateUtc = null)
        {
            using (IDbConnection db = _factory.OpenDbConnection())
            {
                // add the latest
                var trend = new Trend {
                    Name = name, Value = value
                };

                if (actionDateUtc.HasValue)
                {
                    trend.ActionDateUTC = actionDateUtc.Value;
                }

                db.Insert <Trend>(trend);

                // do we need to remove any?
                long count = db.Count <Trend>(t => t.Name == name);
                if (count > MaxTrends)
                {
                    long toDelete = count - MaxTrends;
                    db.ExecuteNonQuery(string.Format("DELETE FROM Trend WHERE Id IN (SELECT TOP {0} Id FROM Trend ORDER BY ActionDateUTC ASC)", toDelete));
                }
            }
        }
예제 #2
0
        // keep last 100 trends in a category
        public void Trend(string name, int value = 1, DateTime? actionDateUtc = null)
        {
            using (IDbConnection db = _factory.OpenDbConnection())
            {
                // add the latest
                var trend = new Trend { Name = name, Value = value };

                if (actionDateUtc.HasValue)
                    trend.ActionDateUTC = actionDateUtc.Value;

                db.Insert<Trend>(trend);

                // do we need to remove any?
                long count = db.Count<Trend>(t => t.Name == name);
                if (count > MaxTrends)
                {
                    long toDelete = count - MaxTrends;
                    db.ExecuteNonQuery(string.Format("DELETE FROM Trend WHERE Id IN (SELECT TOP {0} Id FROM Trend ORDER BY ActionDateUTC ASC)", toDelete));
                }
            }
        }