Example #1
0
        public override bool Execute(params string[] args)
        {
            string actionsList = null;

            Console.WriteLine("Found connection string: " + sys.Settings.SqlConnectionString);

            if (sys.Settings.SqlConnectionString == "...")
            {
                Console.WriteLine("Failed: please enter a connection string for the content database in web.config");
                return(false);
            }

            try
            {
                var pdb = new PreloadDb();
                actionsList = (string)pdb.EnsureCoreDb();
            }
            catch (Exception ex)
            {
                if (ex.Message.Contains("transient failure") || ex.Message.Contains("failed on Open"))
                {
                    Console.WriteLine("The database may not yet exist: please ensure it is created:\n" + ex.ToString());
                }
                else
                {
                    Console.WriteLine(ex.ToString());
                }

                return(false);
            }

            Console.WriteLine("Initialised Successfully: " + (actionsList ?? "no actions taken"));
            return(true);
        }
Example #2
0
        /// <summary>
        /// Called in order to check that a given database schema change record is present, to ensure
        /// the database schema fits the requirements of the module
        /// </summary>
        /// <param name="changePresent">The string describing the change to check for</param>
        /// <returns></returns>
        protected bool VerifyDbState(string changePresent)
        {
            bool verified = false;

            if (LyniconModuleManager.Instance.SkipDbStateCheck)
            {
                return(true);
            }
            try
            {
                var db = new PreloadDb();
                verified = db.DbChanges.Any(dbc => dbc.Change == changePresent);
                if (!verified)
                {
                    log.Warn("Failed to verify database in correct state for: " + changePresent);
                }
            }
            catch (Exception ex)
            {
                log.Fatal("Failed to connect to database", ex);
                throw new Exception("Failed to connect to database", ex);
            }
            return(verified);
        }