static void Main(string[] args) { ServerConnection connection = null; try { connection = new ServerConnection(); connection.ServerInstance = Configuration.ServerName; var server = new Server(connection); EnableMixedAuthenticationMode(server); var database = CreateDatabaseIfNotExists(server); var path = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location); var backupFilePath = Path.Combine(path, Configuration.BackupFileName); try { Console.WriteLine("Restoring database from backup {0}", backupFilePath); server.RestoreDatabase(Configuration.DatabaseName, backupFilePath); } catch { Console.WriteLine("Backup Restore Failed. Creating database from tests"); System.Data.Entity.Database.SetInitializer(new DatabaseContextInitializer()); using (var context = new DatabaseContext()) { context.Database.Initialize(true); } } CreateLoginIfNotExists(server, database); DeployPackage(); CreateWebSiteIfNotExists(); PostInstallConfiguration(); } catch (Exception ex) { ConsoleHelper.WriteLine(ConsoleColor.Magenta, string.Format("{0}\n{1}", ex.Message, ex.StackTrace)); } finally { if(connection != null) connection.Disconnect(); Console.WriteLine("Press any key to exit"); Console.ReadKey(); } }