Ejemplo n.º 1
0
        private void initMaterials()
        {
            // Get the list of existing materials from our XML data file
            string materialsDataFile      = Path.Combine(dataDir, "Materials.xml");
            string materialsSchemaFile    = Path.Combine(schemaDir, "Materials.xsd");
            MaterialsCollection materials = new MaterialsCollection(materialsDataFile, materialsSchemaFile);

            // Persist the list in the database
            ISession     session     = null;
            ITransaction transaction = null;

            try {
                session     = factory.OpenSession();
                transaction = session.BeginTransaction();
                foreach (Material m in materials)
                {
                    P_Material p_mat = new P_Material();
                    p_mat.Name = m.Name;
                    session.Save(p_mat);
                }
                transaction.Commit();
            } catch {
                if (transaction != null)
                {
                    transaction.Rollback();
                }
                throw;
            } finally {
                if (session != null)
                {
                    session.Close();
                }
            }
        }
Ejemplo n.º 2
0
        public P_Material[] ListAllMaterials()
        {
            ISession  session   = factory.OpenSession();
            ICriteria criterion = session.CreateCriteria(typeof(P_Material));

            System.Collections.IList materialsList = criterion.List();
            P_Material[]             answer        = new P_Material[materialsList.Count];
            for (int i = 0; i < materialsList.Count; i++)
            {
                answer[i] = (P_Material)materialsList[i];
            }
            return(answer);
        }
Ejemplo n.º 3
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();
                }
            }
        }