migrate server config from v0 to v1, add more transfer bar settings
This commit is contained in:
@@ -47,6 +47,23 @@ public class ConfigurationMigrator : IHostedService
|
||||
_logger.LogWarning("Failed to migrate, skipping", ex);
|
||||
}
|
||||
}
|
||||
|
||||
if (File.Exists(ConfigurationPath(ServerConfigService.ConfigName)))
|
||||
{
|
||||
try
|
||||
{
|
||||
var serverConfig = JsonConvert.DeserializeObject<ServerConfigV0>(File.ReadAllText(ConfigurationPath(ServerConfigService.ConfigName)))!;
|
||||
|
||||
if (serverConfig.Version == 0)
|
||||
{
|
||||
MigrateServerConfigV0toV1(serverConfig);
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogWarning("Failed to migrate ServerConfig", ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public Task StartAsync(CancellationToken cancellationToken)
|
||||
@@ -75,11 +92,12 @@ public class ConfigurationMigrator : IHostedService
|
||||
|
||||
MareConfig mareConfigV1 = mareConfigV0.ToV1();
|
||||
|
||||
int i = 0;
|
||||
var serverConfig = new ServerConfig()
|
||||
{
|
||||
CurrentServer = mareConfigV0.CurrentServer,
|
||||
ServerStorage = mareConfigV0.ServerStorage.ToDictionary(p => p.Key, p => p.Value.ToV1(), StringComparer.Ordinal)
|
||||
ServerStorage = mareConfigV0.ServerStorage.Select(p => p.Value.ToV1()).ToList()
|
||||
};
|
||||
serverConfig.CurrentServer = Array.IndexOf(serverConfig.ServerStorage.Select(s => s.ServerUri).ToArray(), mareConfigV0.CurrentServer);
|
||||
var transientConfig = new TransientConfig()
|
||||
{
|
||||
PlayerPersistentTransientCache = mareConfigV0.PlayerPersistentTransientCache
|
||||
@@ -108,6 +126,28 @@ public class ConfigurationMigrator : IHostedService
|
||||
SaveConfig(tagConfig, ConfigurationPath(ServerTagConfigService.ConfigName));
|
||||
SaveConfig(notesConfig, ConfigurationPath(NotesConfigService.ConfigName));
|
||||
}
|
||||
|
||||
private void MigrateServerConfigV0toV1(ServerConfigV0 serverConfigV0)
|
||||
{
|
||||
_logger.LogInformation("Migration Server Configuration from version 0 to 1");
|
||||
if (File.Exists(ConfigurationPath(ServerConfigService.ConfigName)))
|
||||
File.Copy(ConfigurationPath(ServerConfigService.ConfigName), ConfigurationPath(ServerConfigService.ConfigName) + ".migrated." + serverConfigV0.Version + ".bak", overwrite: true);
|
||||
|
||||
ServerConfig migrated = new();
|
||||
|
||||
var currentServer = serverConfigV0.CurrentServer;
|
||||
var currentServerIdx = Array.IndexOf(serverConfigV0.ServerStorage.Keys.ToArray(), currentServer);
|
||||
|
||||
migrated.CurrentServer = currentServerIdx;
|
||||
migrated.ServerStorage = new();
|
||||
|
||||
foreach (var server in serverConfigV0.ServerStorage)
|
||||
{
|
||||
migrated.ServerStorage.Add(server.Value);
|
||||
}
|
||||
|
||||
SaveConfig(migrated, ConfigurationPath(ServerConfigService.ConfigName));
|
||||
}
|
||||
}
|
||||
|
||||
#pragma warning restore CS0618 // ignore Obsolete tag, the point of this migrator is to migrate obsolete configs to new ones
|
||||
@@ -3,4 +3,4 @@
|
||||
public interface IMareConfiguration
|
||||
{
|
||||
int Version { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -31,6 +31,9 @@ public class MareConfig : IMareConfiguration
|
||||
public bool ShowUploadingBigText { get; set; } = true;
|
||||
public bool ShowVisibleUsersSeparately { get; set; } = true;
|
||||
public int TimeSpanBetweenScansInSeconds { get; set; } = 30;
|
||||
public int TransferBarsHeight { get; set; } = 12;
|
||||
public bool TransferBarsShowText { get; set; } = true;
|
||||
public int TransferBarsWidth { get; set; } = 250;
|
||||
public int Version { get; set; } = 1;
|
||||
public NotificationLocation WarningNotification { get; set; } = NotificationLocation.Both;
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
using MareSynchronos.MareConfiguration.Models;
|
||||
using MareSynchronos.WebAPI;
|
||||
|
||||
namespace MareSynchronos.MareConfiguration.Configurations.Obsolete;
|
||||
|
||||
[Serializable]
|
||||
[Obsolete]
|
||||
public class ServerConfigV0 : IMareConfiguration
|
||||
{
|
||||
public string CurrentServer { get; set; } = string.Empty;
|
||||
|
||||
public Dictionary<string, ServerStorage> ServerStorage { get; set; } = new(StringComparer.OrdinalIgnoreCase)
|
||||
{
|
||||
{ ApiController.MainServiceUri, new ServerStorage() { ServerName = ApiController.MainServer, ServerUri = ApiController.MainServiceUri } },
|
||||
};
|
||||
|
||||
public int Version { get; set; } = 0;
|
||||
}
|
||||
@@ -6,11 +6,12 @@ namespace MareSynchronos.MareConfiguration.Configurations;
|
||||
[Serializable]
|
||||
public class ServerConfig : IMareConfiguration
|
||||
{
|
||||
public int Version { get; set; } = 0;
|
||||
public int CurrentServer { get; set; } = 0;
|
||||
|
||||
public Dictionary<string, ServerStorage> ServerStorage { get; set; } = new(StringComparer.OrdinalIgnoreCase)
|
||||
public List<ServerStorage> ServerStorage { get; set; } = new()
|
||||
{
|
||||
{ ApiController.MainServiceUri, new ServerStorage() { ServerName = ApiController.MainServer, ServerUri = ApiController.MainServiceUri } },
|
||||
{ new ServerStorage() { ServerName = ApiController.MainServer, ServerUri = ApiController.MainServiceUri } },
|
||||
};
|
||||
public string CurrentServer { get; set; } = string.Empty;
|
||||
}
|
||||
|
||||
public int Version { get; set; } = 1;
|
||||
}
|
||||
Reference in New Issue
Block a user