/// <summary> /// Retreives the content from the source provided. /// </summary> /// <param name="source">Github or LocalDisk must be used</param> /// <returns>A list of file resources for use with the database</returns> public static List <GithubResource> GetDataFiles(SourceSelectionOption source) { var updateMessage = $"Retreiving files from {Enum.GetName(typeof(SourceSelectionOption), source)}"; log.Info(updateMessage); // Local database download Path var localDataPath = Path.GetFullPath(Path.Combine(ConfigManager.Config.ContentServer.LocalContentPath)); // Check the data path and create if needed. if (CheckLocalDataPath(localDataPath)) { List <GithubResource> fileList = new List <GithubResource>(); // Attempt to get remote data from github. if (source == SourceSelectionOption.Github) { // Delete the database content to remove old content if (Directory.Exists(localDataPath)) { wipeContentFolder(localDataPath); } fileList = RemoteSync(); } // Load prevoous download/local data else if (source == SourceSelectionOption.LocalDisk) { fileList = LocalSync(); } return(fileList); } return(null); }
public HttpResponseMessage RedeployDatabase(RedeployRequest request) { // Only allow one request at a time: if (Database.Redeploy.RedeploymentActive) { return(Request.CreateResponse(HttpStatusCode.MethodNotAllowed, "A Redeployment already in progress!")); } //TODO: Fix this hack, make the redeploy request object work properly: bool forceDeploy = false; //Request.RequestUri.Query.ToLowerInvariant().Contains("request.force=true") ? true : false; SourceSelectionOption dataSource = Request.RequestUri.Query.ToLowerInvariant().Contains("request.dataSource=") ? SourceSelectionOption.LocalDisk : SourceSelectionOption.Github; DatabaseSelectionOption databaseName = DatabaseSelectionOption.None; foreach (KeyValuePair <string, string> query in Request.GetQueryNameValuePairs()) { if (query.Key.ToLowerInvariant() == "request.sourceselection") { Enum.TryParse <SourceSelectionOption>(query.Value, out dataSource); } if (query.Key.ToLowerInvariant() == "request.databaseselection") { // try to parse selection enum Enum.TryParse <DatabaseSelectionOption>(query.Value, out databaseName); } if (query.Key.ToLowerInvariant() == "request.force") { // try to parse selection enum if (Convert.ToBoolean(query.Value)) { forceDeploy = true; } } } // Check to determine if a userModified flag has been set in the database var modifiedFlagPresent = WorldDb.UserModifiedFlagPresent(); if (!modifiedFlagPresent || forceDeploy) { string errorResult = Database.Redeploy.RedeployDatabaseFromSource(databaseName, dataSource); if (errorResult == null) { return(Request.CreateResponse(HttpStatusCode.OK, "Database(s) have been redeployed and should now be completely reset. Please remember to recreate your user accounts if you reset the authentication database!")); } else { return(Request.CreateResponse(HttpStatusCode.InternalServerError, $"There was an error durring your request. {errorResult}")); } } return(Request.CreateResponse(HttpStatusCode.MethodNotAllowed, "You have unexported changes in your database. Please specify 'force = true' in your request.")); }
public static void RedeployWorld(Session session, params string[] parameters) { bool forceRedploy = false; var sourceSelection = new SourceSelectionOption(); var userModifiedFlagPresent = DatabaseManager.World.UserModifiedFlagPresent(); // Match parameters if (parameters?.Length > 0) { foreach (string sourceSelectionItem in System.Enum.GetNames(typeof(SourceSelectionOption))) { if (parameters[0].ToLower() == sourceSelectionItem.ToLower()) { if (Enum.TryParse(sourceSelectionItem, out sourceSelection)) { break; } } } string force = parameters[1]; if (force.Length > 0) { if (force.ToLowerInvariant().Contains("force")) { Console.WriteLine("Force redeploy reached!"); forceRedploy = true; } } } if (forceRedploy || !userModifiedFlagPresent) { string errorResult = Database.Redeploy.RedeployDatabaseFromSource(DatabaseSelectionOption.World, sourceSelection); if (errorResult == null) { Console.WriteLine("The World Database has been deployed!"); } else { Console.WriteLine($"There was an error durring your request. {errorResult}"); } return; } Console.WriteLine("User created content has been detected in the database. Please export the current database or include the 'force' parameter with this command."); }
public static void RedeployAllDatabases(Session session, params string[] parameters) { if (parameters?.Length < 2 && parameters?.Length > 3) { Console.WriteLine("Usage: redeploy <datbase selection> <source selection> force"); return; } var databaseSelection = new DatabaseSelectionOption(); var sourceSelection = new SourceSelectionOption(); bool forceRedploy = false; if (parameters?.Length > 0) { // Loop through the enum to attempt at matching the first parameter with an option foreach (string dbSelection in System.Enum.GetNames(typeof(DatabaseSelectionOption))) { if (parameters[0].ToLower() == dbSelection.ToLower()) { if (Enum.TryParse(dbSelection, out databaseSelection)) { break; } } } // Loop through the enum to attempt at matching the second parameter with an option foreach (string sourceSelectionItem in System.Enum.GetNames(typeof(SourceSelectionOption))) { if (parameters[1].ToLower() == sourceSelectionItem.ToLower()) { if (Enum.TryParse(sourceSelectionItem, out sourceSelection)) { break; } } } if (parameters?.Length > 2) { if (parameters[2].ToLowerInvariant().Contains("force")) { Console.WriteLine("Force redeploy reached!"); forceRedploy = true; } } } var userModifiedFlagPresent = DatabaseManager.World.UserModifiedFlagPresent() && (databaseSelection == DatabaseSelectionOption.World || databaseSelection == DatabaseSelectionOption.All) ? true : false; if (forceRedploy || !userModifiedFlagPresent) { string errorResult = Database.Redeploy.RedeployDatabaseFromSource(databaseSelection, sourceSelection); // Database.RemoteContentSync.RedeployWorldDatabase(); if (errorResult == null) { Console.WriteLine("All databases have been redeployed!"); } else { Console.WriteLine($"There was an error durring your request. {errorResult}"); } return; } Console.WriteLine("User modified objects were found in the database.\nYou must also pass the 'force' parameter with this command, to start the database reset process."); }
/// <summary> /// Attempts to download and redeploy data from Github, to the specified database(s). WARNING: CAN CAUSE LOSS OF DATA IF USED IMPROPERLY! /// </summary> /// <remarks> /// Load Data from 2 or 3 locations, in sequential order: /// First Search Path: ${Downloads}\\Database\\Base\\ /// Second Search Path if updating world database: ACE-World\\${WorldGithubFilename} /// Third Search Path: ${Downloads}\\Database\\Updates\\ /// </remarks> public static string RedeployDatabaseFromSource(DatabaseSelectionOption databaseSelection, SourceSelectionOption dataSource) { if (RedeploymentActive) { return("There is already an active redeployment in progress..."); } if (databaseSelection == DatabaseSelectionOption.None) { return("You must select a database other than 0 (None).."); } if (dataSource == SourceSelectionOption.None) { return("You must select a source option other than 0 (None).."); } // Determine if the config settings appear valid: if (ConfigManager.Config.ContentServer == null) { return("ContentServer configration missing from config! Please edit the config!"); } if (ConfigManager.Config.ContentServer.LocalContentPath?.Length <= 0) { return($"Data path missing from the ContentServer config! Please edit the config! {ConfigManager.Config.ContentServer.LocalContentPath}"); } log.Info($"A full database Redeployment has been initiated for {Enum.GetName(typeof(DatabaseSelectionOption), databaseSelection)}!"); RedeploymentActive = true; // Setup the database requirements. Initialize(); List <GithubResource> databaseFiles = null; databaseFiles = GetDataFiles(dataSource); if (databaseFiles == null) { if (dataSource == SourceSelectionOption.Github) { RedeploymentActive = false; var couldNotDownload = RemaingApiCalls == 0 ? $"API limit reached, please wait until {ApiResetTime.ToString()} and then try again." : "Unknown issue downloading."; log.Info(couldNotDownload); return(couldNotDownload); } } if (databaseFiles?.Count > 0) { List <GithubResourceList> resources = new List <GithubResourceList>(); ParseDownloads(databaseFiles); if (databaseSelection == DatabaseSelectionOption.All) { resources.Add(AuthenticationDownloads); resources.Add(ShardDownloads); resources.Add(WorldDownloads); } else { switch (databaseSelection) { case DatabaseSelectionOption.Authentication: { resources.Add(AuthenticationDownloads); break; } case DatabaseSelectionOption.Shard: { resources.Add(ShardDownloads); break; } case DatabaseSelectionOption.World: { resources.Add(WorldDownloads); break; } } } foreach (var resource in resources) { if (resource.Downloads.Count == 0) { continue; } var baseFile = string.Empty; List <string> updates = new List <string>(); var worldFile = string.Empty; // Seporate base files from updates foreach (var download in resource.Downloads) { if (download.Type == GithubResourceType.SqlBaseFile) { baseFile = download.FilePath; } if (download.Type == GithubResourceType.SqlUpdateFile) { updates.Add(download.FilePath); } if (download.Type == GithubResourceType.WorldReleaseSqlFile) { worldFile = download.FilePath; } } try { // Delete and receate the database ResetDatabase(resource.ConfigDatabaseName); // First sequence, load the world base if (File.Exists(baseFile)) { ReadAndLoadScript(baseFile, resource.ConfigDatabaseName, resource.DefaultDatabaseName); } else { var errorMessage = $"There was an error locating the base file {baseFile} for {resource.DefaultDatabaseName}!"; log.Error(errorMessage); } // Second, if this is the world database, we will load ACE-World if (resource.DefaultDatabaseName == DefaultWorldDatabaseName) { if (File.Exists(worldFile)) { ReadAndLoadScript(worldFile, resource.ConfigDatabaseName, resource.DefaultDatabaseName); } else { var errorMessage = $"There was an error locating the base file {worldFile} for {resource.DefaultDatabaseName}!"; log.Error(errorMessage); return(errorMessage); } } // Last, run all updates if (updates.Count() > 0) { foreach (var file in updates) { ReadAndLoadScript(file, resource.ConfigDatabaseName, resource.DefaultDatabaseName); } } } catch (Exception error) { var errorMessage = error.Message; if (error.InnerException != null) { errorMessage += " Inner: " + error.InnerException.Message; } log.Error(errorMessage); RedeploymentActive = false; return(errorMessage); } } RedeploymentActive = false; // Success return(null); } RedeploymentActive = false; // Could not find configuration or error in function. var configErrorMessage = "No data files were found on local disk or an unknown error has occurred."; log.Error(configErrorMessage); return(configErrorMessage); }
/// <summary> /// Database Redeployment Request with optional Parameter allowing force overwrite operations. /// </summary> /// <param name="forceDeploy">force a database overwrite/wipe</param> /// <param name="databaseSelection">database selection option</param> /// <param name="sourceSelection">source selection option</param> public RedeployRequest(bool forceDeploy, DatabaseSelectionOption databaseSelection, SourceSelectionOption sourceSelection) { DatabaseSelection = databaseSelection; SourceSelection = sourceSelection; ForceDeploy = forceDeploy; }