Example #1
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);
        }
Example #2
0
        /// <summary>
        /// Save the given state into the user's open episode.
        /// N.B. We're assuming that the user is logged in and has an open episode
        /// </summary>
        /// <param name="user"></param>
        /// <param name="state"></param>
        public void SetState(int userId, P_State state)
        {
            ISession     session     = null;
            ITransaction transaction = null;

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

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

                user.OpenEpisode.AddState(state);
                session.Save(state);

                transaction.Commit();
            } catch {
                if (transaction != null)
                {
                    transaction.Rollback();
                    throw;
                }
            } finally {
                if (session != null)
                {
                    session.Close();
                }
            }
        }
Example #3
0
        public P_State RandomState()
        {
            P_State answer = P_State.RandomState();

            answer.Cooler   = (P_Cooler)chooseRandom(coolerList);
            answer.Material = (P_Material)chooseRandom(materialList);
            return(answer);
        }
Example #4
0
 public virtual void AddState(P_State state)
 {
     if (!isOpen)
     {
         throw new Exception("Attempt to add new state to a closed Episode");
     }
     state.Episode = this;
     states.Add(state);
 }
Example #5
0
        public void SetState(int userId, State rawState)
        {
            ISession     session     = null;
            ITransaction transaction = null;

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

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

                ICriteria criterion = session.CreateCriteria(typeof(P_Cooler));
                criterion.Add(Expression.Eq("Name", rawState.coolerName));
                P_Cooler cooler = criterion.UniqueResult <P_Cooler>();

                criterion = session.CreateCriteria(typeof(P_Material));
                criterion.Add(Expression.Eq("Name", rawState.materialName));
                P_Material material = criterion.UniqueResult <P_Material>();

                P_State state = new P_State(rawState.length, rawState.crossSection, rawState.powerFactor, rawState.inputPower, rawState.cost, rawState.stressLimit, rawState.temperature, rawState.cooledLength, rawState.isValidSolution);
                state.Cooler   = cooler;
                state.Material = material;

                user.OpenEpisode.AddState(state);
                session.Save(state);

                transaction.Commit();
            } catch {
                if (transaction != null)
                {
                    transaction.Rollback();
                    throw;
                }
            } finally {
                if (session != null)
                {
                    session.Close();
                }
            }
        }