//here we determine if the installer should skip this step... public override bool Completed() { bool retval = false; try { IInstallerUtility m_Installer = BusinessLogic.Application.SqlHelper.Utility.CreateInstaller(); retval = m_Installer.IsLatestVersion; m_Installer = null; } catch { // this step might fail due to missing connectionstring return(false); } return(retval); }
public static string installOrUpgrade() { Helper.setProgress(5, "Opening database connection...", ""); IInstallerUtility m_Installer = BusinessLogic.Application.SqlHelper.Utility.CreateInstaller(); // Build the new connection string //DbConnectionStringBuilder connectionStringBuilder = CreateConnectionString(); Helper.setProgress(5, "Connecting...", ""); // Try to connect to the database Exception error = null; try { ISqlHelper sqlHelper = DataLayerHelper.CreateSqlHelper(GlobalSettings.DbDSN); m_Installer = sqlHelper.Utility.CreateInstaller(); if (!m_Installer.CanConnect) { throw new Exception("The installer cannot connect to the database."); } else { Helper.setProgress(20, "Connection opened", ""); } } catch (Exception ex) { error = new Exception("Database connection initialisation failed.", ex); Helper.setProgress(-5, "Database connection initialisation failed.", error.Message); return(error.Message); } if (m_Installer.CanConnect) { if (m_Installer.IsLatestVersion) { Helper.setProgress(90, "Refreshing content cache", ""); library.RefreshContent(); Helper.setProgress(100, "Database is up-to-date", ""); } else { if (m_Installer.IsEmpty) { Helper.setProgress(35, "Installing tables...", ""); //do install m_Installer.Install(); Helper.setProgress(100, "Installation completed!", ""); m_Installer = null; library.RefreshContent(); return("installed"); } //else if (m_Installer.CurrentVersion == DatabaseVersion.None || m_Installer.CanUpgrade) { //Helper.setProgress(35, "Updating database tables...", ""); //m_Installer.Install(); // library.RefreshContent(); // return "installed"; // } else if (m_Installer.CurrentVersion == DatabaseVersion.None || m_Installer.CanUpgrade) { Helper.setProgress(35, "Updating database tables...", ""); m_Installer.Install(); Helper.setProgress(100, "Upgrade completed!", ""); m_Installer = null; library.RefreshContent(); return("upgraded"); } } } return("no connection;"); }