Ejemplo n.º 1
0
        public P_Episode[] ListEpisodes(P_User user)
        {
            P_Episode[] answer = null;

            ISession     session     = null;
            ITransaction transaction = null;

            try {
                session     = factory.OpenSession();
                transaction = session.BeginTransaction();

                //session.Lock(user, LockMode.None);
                session.Update(user);
                answer = new P_Episode[user.Episodes.Count];
                int i = 0;
                foreach (P_Episode e in user.Episodes)
                {
                    session.Update(e);
                    answer[i++] = e;
                }
                transaction.Commit();
            } catch {
                if (transaction != null)
                {
                    transaction.Rollback();
                    throw;
                }
            } finally {
                if (session != null)
                {
                    session.Close();
                }
            }
            return(answer);
        }
Ejemplo n.º 2
0
        public P_State[] ListStates(P_Episode episode)
        {
            P_State[] answer = null;

            ISession     session     = null;
            ITransaction transaction = null;

            try {
                session     = factory.OpenSession();
                transaction = session.BeginTransaction();

                session.Lock(episode, LockMode.None);
                answer = new P_State[episode.States.Count];
                int i = 0;
                foreach (P_State s in episode.States)
                {
                    session.Update(s);
                    answer[i++] = s;
                }
                transaction.Commit();
            } catch {
                if (transaction != null)
                {
                    transaction.Rollback();
                    throw;
                }
            } finally {
                if (session != null)
                {
                    session.Close();
                }
            }
            return(answer);
        }
Ejemplo n.º 3
0
 public virtual void AddEpisode(P_Episode episode)
 {
     episode.User = this;
     if (episodes == null)
     {
         episodes = new HashedSet();
     }
     episodes.Add(episode);
     if (openEpisode != null)
     {
         openEpisode.Close();
     }
     openEpisode = episode;
 }
Ejemplo n.º 4
0
        public int SetProblem(int userId, string problemName)
        {
            int answer = 0;

            ISession     session     = null;
            ITransaction transaction = null;

            try {
                session     = factory.OpenSession();
                transaction = session.BeginTransaction();

                P_User user = session.Load <P_User>(userId);

                // If the user has no open Episode, or if the open Episode is for a different problem, we need
                // to generate a new Episode
                if (user.OpenEpisode == null || user.OpenEpisode.Problem.Name != problemName)
                {
                    ICriteria criterion = session.CreateCriteria(typeof(P_Problem));
                    criterion.Add(Expression.Eq("Name", problemName));
                    P_Problem problem = criterion.UniqueResult <P_Problem>();

                    P_Episode episode = new P_Episode(problem);
                    user.AddEpisode(episode);
                    session.Save(problem);
                    session.Save(episode);
                    answer = problem.Id;
                }
                else
                {
                    // requested problem is already associate with the user's open episode, do nothing
                    answer = user.OpenEpisode.Problem.Id;
                }

                transaction.Commit();
            } catch {
                if (transaction != null)
                {
                    transaction.Rollback();
                    throw;
                }
            } finally {
                if (session != null)
                {
                    session.Close();
                }
            }
            return(answer);
        }
Ejemplo n.º 5
0
 public P_User(string emailAddr)
 {
     this.emailAddr   = emailAddr;
     this.lastLogin   = DateTime.Now;
     this.openEpisode = null;
 }