/************************************************************************************ * * Umbraco Data Layer * MIT Licensed work * ©2008 Ruben Verborgh * ***********************************************************************************/ using System; using System.Resources; using umbraco.DataLayer.Utility.Installer; using System.Diagnostics; namespace SqlCE4Umbraco { /// /// Database installer for an SQL Server data source. /// public class SqlCEInstaller : DefaultInstallerUtility { #region Private Constants /// The latest database version this installer supports. private const DatabaseVersion LatestVersionSupported = DatabaseVersion.Version4_1; /// The specifications to determine the database version. private static readonly VersionSpecs[] m_VersionSpecs = new VersionSpecs[] { new VersionSpecs("id","umbracoNode", "-21", DatabaseVersion.Version4_1), new VersionSpecs("action","umbracoAppTree",DatabaseVersion.Version4), new VersionSpecs("description","cmsContentType",DatabaseVersion.Version3), new VersionSpecs("id","sysobjects",DatabaseVersion.None) }; #endregion #region Public Properties /// /// Gets a value indicating whether the installer can upgrade the data source. /// /// /// true if the installer can upgrade the data source; otherwise, false. /// /// Empty data sources can't be upgraded, just installed. public override bool CanUpgrade { get { return false; } } #endregion #region Protected Properties /// /// Gets the version specification for evaluation by DetermineCurrentVersion. /// Only first matching specification is taken into account. /// /// The version specifications. protected override VersionSpecs[] VersionSpecs { get { return m_VersionSpecs; } } #endregion #region Public Constructors /// /// Initializes a new instance of the class. /// /// The SQL helper. public SqlCEInstaller(SqlCEHelper sqlHelper) : base(sqlHelper, LatestVersionSupported) { } #endregion #region DefaultInstaller Members /// /// Returns the sql to do a full install /// protected override string FullInstallSql { get { return SqlCEResources.Total; } } /// /// Returns the sql to do an upgrade /// protected override string UpgradeSql { get { string upgradeFile = string.Format("{0}_Upgrade", CurrentVersion.ToString()); return SqlCEResources.ResourceManager.GetString(upgradeFile); } } // We need to override this as the default way of detection a db connection checks for systables that doesn't exist // in a CE db protected override DatabaseVersion DetermineCurrentVersion() { DatabaseVersion version = base.DetermineCurrentVersion(); if (version != DatabaseVersion.Unavailable) { return version; } // verify connection try { if (SqlCeApplicationBlock.VerifyConnection(base.SqlHelper.ConnectionString)) return DatabaseVersion.None; } catch (Exception e) { Trace.WriteLine(e.ToString()); } return DatabaseVersion.Unavailable; } #endregion } }