public NamedCounterTest() { CounterTest counter = new CounterTest(); AddDependentObject(counter); mNamedCounter = new NamedCounter(); mNamedCounter.Name = Guid.NewGuid().ToString(); mNamedCounter.Counter = counter.Counter; }
public void IncrementNamedCounter(string ticket, string name, int count) { using (DBlog.Data.Hibernate.Session.OpenConnection(GetNewConnection())) { ISession session = DBlog.Data.Hibernate.Session.Current; ITransaction t = session.BeginTransaction(); try { NamedCounter counter = session.CreateCriteria(typeof(NamedCounter)) .Add(Expression.Eq("Name", name)) .UniqueResult<NamedCounter>(); if (counter == null) { counter = new NamedCounter(); counter.Name = name; counter.Counter = new Counter(); counter.Counter.Count = 1; counter.Counter.Created = DateTime.UtcNow; session.Save(counter.Counter); session.Save(counter); } else { counter.Counter.Count += count; session.Save(counter.Counter); } session.Flush(); t.Commit(); } catch { t.Rollback(); } } }