Esempio n. 1
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);
        }
Esempio n. 2
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);
        }
Esempio n. 3
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);
        }
Esempio 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);
        }
Esempio n. 5
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);
        }
Esempio n. 6
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);
        }
Esempio n. 7
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);
        }
Esempio n. 8
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);
        }
Esempio n. 9
0
        private InstallResult BuildNewDatabase()
        {
            InstallResult result = new InstallResult();

            result = BuildInitialSchema();
            if (!result.Success)
            {
                return(result);
            }

            result = BuildDatabaseDefaults();

            return(result);
        }
Esempio 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);
        }
Esempio 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);
        }
Esempio 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);
        }
Esempio n. 13
0
        private static InstallResult PerformUpdateFromAppInfoFile(string appInfoFilePath, System.Reflection.Assembly executingAssembly)
        {
            var appInfo = Amie.AppInfo.LoadFromFile(appInfoFilePath);
            var result  = new InstallResult();

            string connectionString = GetConnectionString(appInfo);

            if (string.IsNullOrEmpty(connectionString))
            {
                result.Success = false;
                result.Message = "Update failed the connection string was not found.";
                return(result);
            }

            DBUpdater dbUpdate = new DBUpdater(executingAssembly);

            result = dbUpdate.UpdateFromConnectionString(connectionString);

            if (!result.Success)
            {
                return(result);
            }

            foreach (var item in appInfo.AppFolders)
            {
                Amiedater a = new Amiedater(item);

                if (item.Type.Name == AppInfo.AppFolderType.Web.Name)
                {
                    result = a.PerformWebUpdate();
                }
                else if (item.Type.Name == AppInfo.AppFolderType.Service.Name)
                {
                    result = a.PerformServiceUpdate();
                }
                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);
        }
Esempio n. 14
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);
        }
Esempio n. 15
0
        public static InstallResult SendUpdateTrigger(HttpPostedFileBase file)
        {
            InstallResult result = new InstallResult();

            try
            {
                //Check to make sure its a zip file.
                if (!file.FileName.EndsWith(".zip"))
                {
                    result.Success = false;
                    result.Message = "The update file must be a zip file.";
                    return(result);
                }

                //Read the bytes out of the files
                byte[] fileBytes;
                using (var reader = new System.IO.BinaryReader(file.InputStream))
                {
                    fileBytes = reader.ReadBytes(file.ContentLength);
                }

                //Create the update setings
                UpdateSettings settings = new UpdateSettings();
                settings.Key        = AppSettings.PrivateKey;
                settings.UpdateFile = fileBytes;

                //Send the command to the server.
                Amie.Client.AsyncClient client = new Amie.Client.AsyncClient();
                client.StartClient(AppSettings.TCPClientAddress, AppSettings.TCPClientPort);
                byte[] bytesToSend = UpdateSettings.Serialize(settings);
                client.SendBytes(bytesToSend, true);

                //TODO: Need to buffer server response and send it back to the calling function....
                return(result);
            }
            catch (Exception ex)
            {
                result.Success = false;
                result.Message = ex.ToString();
                return(result);
            }
        }
Esempio n. 16
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);
        }
Esempio n. 17
0
        internal InstallResult RunDatabaseTests()
        {
            InstallResult result = new InstallResult();

            Logger.Info("Connection string check...");
            if (string.IsNullOrEmpty(ConnectionString.ConnectionString))
            {
                result.Success = false;
                result.Message = "Database connection string missing.";
                return(result);
            }

            if (!TestDatabaseConnection().Success)
            {
                result.Success = false;
                result.Message = "Connection to the database failed.";
                return(result);
            }

            Logger.Info("Connection string looks good.");
            return(result);
        }
Esempio n. 18
0
        private InstallResult TestDatabaseConnection()
        {
            InstallResult result = new InstallResult();
            var           con    = new SqlConnection(ConnectionString.ConnectionString);

            try
            {
                con.Open();
                result.Success = true;
                return(result);
            }
            catch (Exception ex)
            {
                result.Message = ex.ToString();
                result.Success = false;
                return(result);
            }
            finally
            {
                con.Close();
            }
        }
Esempio n. 19
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);
        }
Esempio n. 20
0
        /// <summary>
        /// This will install a new version of the database or update an older version.  The database must exist in order for this to work.
        /// If it does not exist the InstallResult.Success will be set to false and there will be a message.
        /// </summary>
        /// <returns></returns>
        internal InstallResult PerformDatabaseUpdate()
        {
            InstallResult result = new InstallResult();

            result = RunDatabaseTests();
            if (!result.Success)
            {
                return(result);
            }

            Logger.Info("Current Database Version: {0}", DatabaseVersionInstalled.ToString());
            Logger.Info("Update Script Version: {0}", DatabaseUpdateVersion.ToString());

            if (DatabaseIsNew)
            {
                result = BuildNewDatabase();
                if (!result.Success)
                {
                    return(result);
                }
            }

            //Yes we want to run the function above and below.
            //The code (above) creates the initial database which could be 100 versions old.
            //This code (below) will update the database to the lastest version.

            if (!DatabaseIsCurrent)
            {
                Logger.Info("Database exists it's out of date and will be updated.");
                Logger.Info("The following scripts will be ran on the database");
                var scripts = GetScriptsToRun();
                foreach (var item in scripts)
                {
                    Logger.Info("{0}.", item.ScriptName);
                }

                foreach (var item in scripts)
                {
                    Logger.Info("Running {0} item.", item.ScriptName);
                    var script = RunSingleScript(item.ScriptName);
                    if (script.Status == Models.SchemaChange.Status_Failed)
                    {
                        string message = string.Format("The script {0} failed. With message {1}. The script has stopped. \r\n\r\nFix the errors and run it again.", script.ScriptName, script.ScriptErrors);
                        Logger.Info(message);
                        result.Success = false;
                        result.Message = message;
                        return(result);
                    }
                    else
                    {
                        Logger.Info("{0}:{1}.", script.Comment, script.Status);
                    }
                }
            }
            else
            {
                Logger.Info("The database is current, nothing to do here.");
            }

            Logger.Info("Database update finished!");
            return(result);
        }