private void initCoolers() { // Get the list of existing coolers from our XML data file string coolersDataFile = Path.Combine(dataDir, "Coolers.xml"); string coolersSchemaFile = Path.Combine(schemaDir, "Coolers.xsd"); CoolerCollection coolers = new CoolerCollection(coolersDataFile, coolersSchemaFile); // Persist the list in the database ISession session = null; ITransaction transaction = null; try { session = factory.OpenSession(); transaction = session.BeginTransaction(); foreach (Cooler c in coolers) { P_Cooler p_cool = new P_Cooler(); p_cool.Name = c.Name; session.Save(p_cool); } transaction.Commit(); } catch { if (transaction != null) { transaction.Rollback(); } throw; } finally { if (session != null) { session.Close(); } } }
public P_Cooler[] ListAllCoolers() { ISession session = factory.OpenSession(); ICriteria criterion = session.CreateCriteria(typeof(P_Cooler)); System.Collections.IList coolerList = criterion.List(); P_Cooler[] answer = new P_Cooler[coolerList.Count]; for (int i = 0; i < coolerList.Count; i++) { answer[i] = (P_Cooler)coolerList[i]; } return(answer); }
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(); } } }