public MainForm(HardwareSessionManager hsm) { session = hsm; InitializeComponent(); // populate everything with the proper data from state updateState(); }
static void Main() { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); // First log in LoginForm lf = new LoginForm(); if (!lf.isLoginSuccess()) { Environment.Exit(-1); } String connectionString = Properties.Settings.Default.Database; String sessionFile = Properties.Settings.Default.SessionFile; OleDbConnection connection = null; try { connection = new OleDbConnection(connectionString); } catch (Exception e) { HardwareUtil.log(LogLevel.error, e.Message); } // Inject the retrieved session manager into the application and try to read from ms access db HardwareSessionManager savedSession = new HardwareSessionManager(); try { savedSession.retrieveState(connection); } catch (Exception e) { // we catch exception and log it but we don't tell the user HardwareUtil.log(LogLevel.error, e.Message); // and fall back to using file based persistence if (File.Exists(sessionFile)) { savedSession.retrieveState(sessionFile); } } // we run the app MainForm f = new MainForm(savedSession); Application.Run(f); // try to save changes to db try { f.session.saveState(connection); } catch (Exception e) { // if that fails write to file and log error HardwareUtil.log(LogLevel.error, e.Message); f.session.saveState(sessionFile); } }
public MainForm() { session = new HardwareSessionManager(); InitializeComponent(); updateState(); }