Implement conditional config saving based on potential changes
Added a check for potential modifications to determine whether the configuration should be saved. Introduced a new method `HasPotentialModification` in the `Configuration` class to identify one-time-enabled items and update the saving logic accordingly. Cleaned up and refactored related code for better readability and maintainability.
This commit is contained in:
parent
cdfa50e1ec
commit
117d6f5162
@ -65,7 +65,6 @@ public class Configuration
|
||||
Console.WriteLine(backup.ToString());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public List<BackupCombination> GetBackupCombinations()
|
||||
@ -96,7 +95,7 @@ public class Configuration
|
||||
{
|
||||
foreach (Backup backup in backups)
|
||||
{
|
||||
if (!(backup.Enabled??true) || backup.DbConnectionStringsName != dbConnection.Name )
|
||||
if (!(backup.Enabled ?? true) || backup.DbConnectionStringsName != dbConnection.Name)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
@ -117,10 +116,62 @@ public class Configuration
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
return combinations;
|
||||
}
|
||||
|
||||
public bool HasPotentialModification()
|
||||
{
|
||||
bool returnPotentialModification = false;
|
||||
|
||||
if (DbConnectionStrings != null)
|
||||
{
|
||||
foreach (DbConnection dbConnection in DbConnectionStrings)
|
||||
{
|
||||
if (dbConnection.isOneTimeEnabled())
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (UpdateString != null)
|
||||
{
|
||||
foreach (Update update in UpdateString)
|
||||
{
|
||||
if (update.isOneTimeEnabled())
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (BackupDB != null)
|
||||
{
|
||||
foreach (Backup backup in BackupDB)
|
||||
{
|
||||
if (backup.isOneTimeEnabled())
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
if (backup.StoreDirPaths != null)
|
||||
{
|
||||
foreach (PathWrapper path in backup.StoreDirPaths)
|
||||
{
|
||||
if (path.isOneTimeEnabled())
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return returnPotentialModification;
|
||||
}
|
||||
}
|
||||
@ -16,8 +16,11 @@ if (configuration == null)
|
||||
return -1;
|
||||
}
|
||||
|
||||
bool storeConfigPotentialChanges = configuration.HasPotentialModification();
|
||||
|
||||
//update part
|
||||
if (configuration.UpdateString != null){
|
||||
if (configuration.UpdateString != null)
|
||||
{
|
||||
try
|
||||
{
|
||||
UpdateDb(configuration);
|
||||
@ -47,7 +50,10 @@ foreach (BackupCombination combination in backupCombinations)
|
||||
//Update one time config
|
||||
|
||||
//store configuration
|
||||
SaveConfiguration(configuration);
|
||||
if (storeConfigPotentialChanges)
|
||||
{
|
||||
SaveConfiguration(configuration);
|
||||
}
|
||||
|
||||
//final info
|
||||
Console.WriteLine("Program finished correctly!!");
|
||||
@ -64,8 +70,6 @@ return 0;
|
||||
|
||||
Configuration? GetConfiguration()
|
||||
{
|
||||
|
||||
|
||||
try
|
||||
{
|
||||
Console.WriteLine($"---- program started path: {Environment.CurrentDirectory}");
|
||||
@ -203,7 +207,7 @@ void BackupDatabase(BackupCombination backupCombination)
|
||||
|
||||
//Deactivate if only one time possible run
|
||||
|
||||
if ((backupCombination.Path.IsOneTimeOpaque ?? false) && (backupCombination.Path.Enabled??true))
|
||||
if ((backupCombination.Path.IsOneTimeOpaque ?? false) && (backupCombination.Path.Enabled ?? true))
|
||||
{
|
||||
backupCombination.Path.Enabled = false;
|
||||
}
|
||||
@ -248,6 +252,7 @@ void UpdateDb(Configuration dbConfiguration)
|
||||
{
|
||||
update.Enabled = false;
|
||||
}
|
||||
|
||||
Console.WriteLine($"------ MySql Data upgrade name: {update.Name} finished! -----");
|
||||
}
|
||||
catch (Exception e)
|
||||
|
||||
@ -6,7 +6,7 @@ public class Backup : StandardBehaviour
|
||||
{
|
||||
|
||||
public string DbConnectionStringsName { get; set; }
|
||||
public List<PathWrapper> StoreDirPaths { get; set; }
|
||||
public List<PathWrapper>? StoreDirPaths { get; set; }
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
|
||||
@ -8,4 +8,9 @@ public class StandardBehaviour
|
||||
public Boolean? Enabled { get; set; }
|
||||
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
|
||||
public Boolean? IsOneTimeOpaque { get; set; }
|
||||
|
||||
public bool isOneTimeEnabled()
|
||||
{
|
||||
return ((Enabled ?? true) && (IsOneTimeOpaque ?? false));
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user