Exemplo n.º 1
0
        /// <summary>
        /// Looks for a file named DatabaseDefaults.sql.  If it exists it runs it.  The purpose of this file is to create default data in the database.  This will only be ran one time on initial creation of the database.
        /// </summary>
        private InstallResult BuildDatabaseDefaults()
        {
            OnBeforeDatabaseDefaults(EventArgs.Empty);
            InstallResult result = new InstallResult();

            Logger.Info("Creating initial database defaults from {0}.", INITIAL_DATABASE_DEFAULTS_FILENAME);

            var script = UpdateScript.FromScriptName(INITIAL_DATABASE_DEFAULTS_FILENAME, ExecutingAssembly);

            if (script.FileContents == null)
            {
                string message = string.Format("Initial database defaults file {0} could not be found.  Database schema creation was successful but the defaults were not loaded into the database.  This will cause a problem with login and other initial date the database is expecting.  Try to to run it again in SQL manager if possible.", script.FullNamespaceName);
                Logger.Error(message);
                result.Success = false;
                result.SetMessage(message);
                return(result);
            }

            var dbCreateResuls = RunSingleScript(script);

            if (dbCreateResuls.Status == SchemaChange.Status_Failed)
            {
                string message = string.Format("Building the initial database defaults for this database has failed. There was a problem while running the update file {0}. Here is the error: {1}. This will cause a problem with login and other initial date the database is expecting.  Try to to run it again in SQL manager if possible.", script.Name, dbCreateResuls.ScriptErrors);
                Logger.Error(message);
                result.Success = false;
                result.SetMessage(message);
            }

            Logger.Info("Initial database defaults created!");

            OnAfterDatabaseDefaults(EventArgs.Empty);
            return(result);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Looks for the file named DatabaseBaseline.sql and runs it on a blank database.
        /// </summary>
        private InstallResult BuildInitialSchema()
        {
            OnBeforeInitialSchema(EventArgs.Empty);

            InstallResult result = new InstallResult();

            Logger.Info("Creating initial database schema from {0}.", INITIAL_DATABASE_SCHEMA_FILENAME);

            var script = UpdateScript.FromScriptName(INITIAL_DATABASE_SCHEMA_FILENAME, ExecutingAssembly);

            if (script.FileContents == null)
            {
                string message = string.Format("The initial schema creation for this database has failed. The {0} file could not be found at {1}.", INITIAL_DATABASE_SCHEMA_FILENAME, script.FullNamespaceName);
                Logger.Error(message);
                result.Success = false;
                result.SetMessage(message);
                return(result);
            }

            var dbCreateResuls = RunSingleScript(script);

            if (dbCreateResuls.Status == SchemaChange.Status_Failed)
            {
                string message = string.Format("The initial schema creation for this database has failed. There was a problem while running the update file {0}. Here is the error: {1} ", script.Name, dbCreateResuls.ScriptErrors);
                Logger.Error(message);
                result.Success = false;
                result.SetMessage(message);
            }

            Logger.Info("Initial database schema created!");

            OnAfterInitialSchema(EventArgs.Empty);
            return(result);
        }
Exemplo n.º 3
0
        private static InstallResult PerformSingleUpdateFromAppInfoFile(string appInfoFilePath, string folderNameToUpdate, string connectionString)
        {
            var appInfo = Amie.AppInfo.LoadFromFile(appInfoFilePath);
            var result  = new InstallResult();

            //get the [folder] to update
            var folder = appInfo.AppFolderFromName(folderNameToUpdate);

            if (folder == null)
            {
                result.Success = false;
                result.SetMessage("Update failed: the app to udpate with the name {0} was not found in the AppInfo.json file.  An AppFolder configuration is required to update this product.", folderNameToUpdate);
                return(result);
            }

            Amiedater a = new Amiedater(folder);

            if (folder.Type.Name == AppInfo.AppFolderType.Service.Name)
            {
                result = a.PerformServiceUpdate(connectionString);
            }
            else if (folder.Type.Name == AppInfo.AppFolderType.Web.Name)
            {
                result = a.PerformWebUpdate(connectionString);
            }
            else
            {
                //Must be a resource, such as a command line program or something.  We don't know where the old one is installed but we know where the new one is so at least we can update the connection string....
                result = a.PerformResouceUpdate(connectionString);
            }

            return(result);
        }
Exemplo n.º 4
0
        public static InstallResult DeployFullUpdate(System.Reflection.Assembly executingAssembly)
        {
            InstallResult result = new InstallResult();

            try
            {
                ShowAppStartInfo();

                if (File.Exists(AppInfoFilePath))
                {
                    result = PerformUpdateFromAppInfoFile(AppInfoFilePath, executingAssembly);
                }
                else
                {
                    result.Success = false;
                    result.Message = string.Format("The AppInfoFile was not found at {0} so Amie does not know what to do.", AppInfoFilePath);
                }
            }
            catch (Exception ex)
            {
                result.Success = false;
                result.SetMessage("Software update failed. {0}", ex.ToString());
            }
            return(result);
        }
Exemplo n.º 5
0
        private static InstallResult RunUpdateCommand(string updateExeLocation)
        {
            var result = new InstallResult();

            Process p = new Process();

            FileInfo fileInfo = new FileInfo(updateExeLocation);

            try
            {
                p.StartInfo.FileName  = fileInfo.FullName;
                p.StartInfo.Arguments = "fullupdate";
                //Makes the working directory of TrafficUpdate the actual working directory instead of where this service is running.
                p.StartInfo.UseShellExecute  = false;
                p.StartInfo.WorkingDirectory = fileInfo.DirectoryName;
                p.Start();

                p.WaitForExit(int.MaxValue);

                result.Message = "Update ran successfully.";
            }
            catch (Exception ex)
            {
                result.Success = false;
                result.SetMessage("Update failed. {0}.", ex.ToString());
            }

            return(result);
        }
Exemplo n.º 6
0
        private InstallResult CallInstallUtil(string[] installUtilArguments)
        {
            var result = new InstallResult();

            Process proc = new Process();

            proc.StartInfo.FileName               = Path.Combine(InstallUtilPath, "installutil.exe");
            proc.StartInfo.Arguments              = String.Join(" ", installUtilArguments);
            proc.StartInfo.WindowStyle            = ProcessWindowStyle.Hidden;
            proc.StartInfo.RedirectStandardOutput = true;
            proc.StartInfo.UseShellExecute        = false;

            proc.Start();
            string outputResult = proc.StandardOutput.ReadToEnd();

            proc.WaitForExit();

            //  ---check result---
            if (proc.ExitCode != 0)
            {
                result.SetMessage("Error with the service.  Here is the error {0}", outputResult);
                Logger.Error("Error with the service.  Here is the error {0}", outputResult);
                //installResult.Success = false;
                //installResult.Message = outputResult;
                result.Success = false;
            }

            return(result);
        }
Exemplo n.º 7
0
        private InstallResult UninstallOldService()
        {
            var result = new InstallResult();

            //Another way to do it if InstallUtil.exe is not installed on the system, but I could never get it to work 2/21/2015.  Can be used to call install as well without the /u
            //System.Configuration.Install.ManagedInstallerClass.InstallHelper(new string[] { Assebly.GetExecutingAsseembly().Location });

            //Attempt to uninstall from installed location.  If this does not work then use the update location to try uninstall. If this is already installed it should not matter.
            try
            {
                //Old Service does not exist
                if (FolderToUpdate.Service == null)
                {
                    return(result);
                }

                Logger.Info("Uninstalling Service at {0}", FolderToUpdate.InstalledPath);
                result = CallInstallUtil(new string[] { "/u", "/LogFile=UninstallTrafficService.log", FolderToUpdate.InstalledPath });
            }
            catch (Exception)
            {
                try
                {
                    Logger.Info("Uninstalling the service from the installed location {0} failed. Is possible the old files were removed. So we are trying at the update location {1}.", FolderToUpdate.InstalledPath, FolderToUpdate.UpdatePath);
                    result = CallInstallUtil(new string[] { "/u", "/LogFile=UninstallTrafficService.log", FolderToUpdate.UpdatePath });
                }
                catch (Exception ex)
                {
                    result.Success = false;
                    result.SetMessage("Uninstalling the old service failed. Installation was stopped.  Here is the error {0}.", ex.Message);
                }
            }
            return(result);
        }
Exemplo n.º 8
0
        internal InstallResult CopyConfigSettings(string source, string destination)
        {
            var result = new InstallResult();

            if (!File.Exists(source))
            {
                result.Success = false;
                result.SetMessage("The source configuration file {0} could not be found.", source);
                return(result);
            }

            if (!File.Exists(destination))
            {
                result.Success = false;
                result.SetMessage("The destination configuration file {0} could not be found.", destination);
                return(result);
            }

            ExeConfigurationFileMap installedConfigFile = new ExeConfigurationFileMap();

            installedConfigFile.ExeConfigFilename = source;             //_info.WebConfigPathInstalled;
            Configuration configInstalled = ConfigurationManager.OpenMappedExeConfiguration(installedConfigFile, ConfigurationUserLevel.None);

            ExeConfigurationFileMap updateConfigFile = new ExeConfigurationFileMap();

            updateConfigFile.ExeConfigFilename = destination;             //_info.WebConfigPathUpdate;
            Configuration configUpdate = ConfigurationManager.OpenMappedExeConfiguration(updateConfigFile, ConfigurationUserLevel.None);

            foreach (KeyValueConfigurationElement appSetting in configInstalled.AppSettings.Settings)
            {
                if (configUpdate.AppSettings.Settings[appSetting.Key] != null)
                {
                    configUpdate.AppSettings.Settings[appSetting.Key].Value = appSetting.Value;
                }
            }

            configUpdate.ConnectionStrings.ConnectionStrings[FolderToUpdate.ConnectionStringName].ConnectionString = FolderToUpdate.ConnectionString.ConnectionString;

            configUpdate.Save(ConfigurationSaveMode.Modified);
            Logger.Info("Copy Config Settings: Done");
            return(result);
        }
Exemplo n.º 9
0
        internal InstallResult PerformServiceUpdate(string connectionString = "")
        {
            var result = new InstallResult();

            Logger.Info("Updating service {0} at {1}", FolderToUpdate.ServiceName, FolderToUpdate.UpdatePath);

            //Install new service
            if (FolderToUpdate.Service == null)
            {
                result = InstallNewService();

                if (result.Success)
                {
                    if (connectionString == "")
                    {
                        Logger.Error("The connection string was not passed into the arguments when the update started. The new service was installed but the connection string to the database was not set.");
                    }

                    result = SetConnectionString(FolderToUpdate.InstalledConfigPath, connectionString);

                    StartService();
                }

                Logger.Info("Servied install finished!");
                return(result);
            }

            //Update existing service
            if (StopService())
            {
                CopyConfigSettings(FolderToUpdate.InstalledConfigPath, FolderToUpdate.UpdateConfigPath);

                result = UninstallOldService();

                if (result.Success)
                {
                    result = InstallNewService();
                }

                //If this fails, don't error, just keep moving on, nothing to see here.
                StartService();

                Logger.Info(FolderToUpdate.ServiceName + " Service update finshed!");
            }
            else
            {
                Logger.Error("The service {0} could not be stopped.", FolderToUpdate.ServiceName);
                result.Success = false;
                result.SetMessage("Installation failed. The service {0} could not be stopped.", FolderToUpdate.ServiceName);
            }

            return(result);
        }
Exemplo n.º 10
0
        public static InstallResult DepolyDatabaseUpdateOnly(string connectionString, System.Reflection.Assembly executingAssembly)
        {
            InstallResult result = new InstallResult();

            try
            {
                ShowAppStartInfo();
                result = PerformDatabaseUpdate(connectionString, executingAssembly);
            }
            catch (Exception ex)
            {
                result.Success = false;
                result.SetMessage("Database update failed. {0}", ex.ToString());
            }
            return(result);
        }
Exemplo n.º 11
0
        internal InstallResult PerformResouceUpdate(string connectionString)
        {
            var result = new InstallResult();

            try
            {
                SetConnectionString(FolderToUpdate.UpdateConfigPath, connectionString);
            }
            catch (Exception ex)
            {
                result.Success = false;
                result.SetMessage("Updating the configuration file of the Resource config file {0} failed.  Here is the error {1}.", FolderToUpdate.UpdatePath, ex.Message);
            }

            return(result);
        }
Exemplo n.º 12
0
        internal InstallResult PerformWebUpdate(string connectionString = "")
        {
            var result = new InstallResult();

            try
            {
                //update existing web
                Logger.Info("Updating web app {0}", FolderToUpdate.WebApplicationName);

                Logger.Info("Creating application pool: {0}", FolderToUpdate.WebApplicationPoolName);
                IISHelper.CreateApplicationPool(FolderToUpdate.WebApplicationPoolName);

                Logger.Info("Creating application {0} in website {1}", FolderToUpdate.WebApplicationName, FolderToUpdate.WebSite.Name);
                IISHelper.ChangeApplicationPath(FolderToUpdate.WebSite.Name, FolderToUpdate.WebApplicationName, FolderToUpdate.UpdatePath);

                Logger.Info("Setting Application Pool {0} in application {1}", FolderToUpdate.WebApplicationPoolName, FolderToUpdate.WebApplicationName);
                IISHelper.SetApplicationApplicationPool(FolderToUpdate.WebSite.Name, FolderToUpdate.WebApplicationName, FolderToUpdate.WebApplicationPoolName);

                //install new web
                if (FolderToUpdate.WebApplication == null)
                {
                    if (connectionString == "")
                    {
                        Logger.Error("The connection string was not passed into the arguments when the update started. The install was successfull but the connection string was not updated.");
                    }
                    else
                    {
                        result = SetConnectionString(FolderToUpdate.InstalledConfigPath, connectionString);
                    }
                }
                else
                {
                    //In an update we don't copy anything or move anything except settings. Wherever the installer(human) puts the folder is where it will live. We just keep moving the path of the web and path of the service to the new spot.
                    result = CopyConfigSettings(FolderToUpdate.InstalledConfigPath, FolderToUpdate.UpdateConfigPath);
                }

                Logger.Info(FolderToUpdate.Name + " Update Finished!");
            }
            catch (Exception ex)
            {
                Logger.Info(FolderToUpdate.Name + " Web Update Failed.  Here is the error {0}.", ex.Message);
                result.Success = false;
                result.SetMessage("Web update failed. Here is the error {0}.", ex.Message);
            }
            return(result);
        }
Exemplo n.º 13
0
        private InstallResult SetConnectionString(string configFilePath, string connectionString)
        {
            var result = new InstallResult();

            try
            {
                ExeConfigurationFileMap updateConfigFile = new ExeConfigurationFileMap();
                updateConfigFile.ExeConfigFilename = configFilePath;
                Configuration configUpdate = ConfigurationManager.OpenMappedExeConfiguration(updateConfigFile, ConfigurationUserLevel.None);
                configUpdate.ConnectionStrings.ConnectionStrings[FolderToUpdate.ConnectionStringName].ConnectionString = connectionString;
                configUpdate.Save(ConfigurationSaveMode.Modified);
            }
            catch (Exception ex)
            {
                result.Success = false;
                result.SetMessage("Setting the connection string to {0} failed.  The error is {1}.", configFilePath, ex.Message);
            }
            return(result);
        }
Exemplo n.º 14
0
        public static InstallResult DeployUpdate(string folderNameToUpdate, string connectionString)
        {
            InstallResult result = new InstallResult();

            try
            {
                if (File.Exists(AppInfoFilePath))
                {
                    result = PerformSingleUpdateFromAppInfoFile(AppInfoFilePath, folderNameToUpdate, connectionString);
                }
                else
                {
                    result.Success = false;
                    result.Message = string.Format("The AppInfoFile was not found at {0} so Amie does not know what to do.", AppInfoFilePath);
                }
            }
            catch (Exception ex)
            {
                result.Success = false;
                result.SetMessage("Software update failed. {0}", ex.ToString());
            }
            return(result);
        }