Refactored setting processing
This commit is contained in:
		
							parent
							
								
									dfc0647fb0
								
							
						
					
					
						commit
						53f98d4e3c
					
				@ -7,29 +7,120 @@ namespace Processor;
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
public static class AppSettings
 | 
					public static class AppSettings
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    #region DeepL Settings
 | 
					    #region Common DB Code
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    #region DeepL Mode
 | 
					    private static readonly Dictionary<string, object> CACHES = new();
 | 
				
			||||||
 | 
					    private static readonly Dictionary<string, bool> CACHE_LOADED = new();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    private static SettingDeepLMode CACHE_DEEPL_MODE = SettingDeepLMode.DISABLED;
 | 
					    private static async Task<T> GetSetting<T>(string settingName, T defaultValue)
 | 
				
			||||||
    private static bool CACHE_DEEPL_MODE_IS_LOADED = false;
 | 
					 | 
				
			||||||
    
 | 
					 | 
				
			||||||
    public static async Task SetDeepLMode(SettingDeepLMode mode)
 | 
					 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        // Convert the enum to its int value:
 | 
					        // When possible, use the cache:
 | 
				
			||||||
        var intValue = (int)mode;
 | 
					        if (CACHE_LOADED.ContainsKey(settingName) && CACHE_LOADED[settingName])
 | 
				
			||||||
 | 
					            return (T)CACHES[settingName];
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        var settingValue = defaultValue;
 | 
				
			||||||
 | 
					        try
 | 
				
			||||||
 | 
					        {
 | 
				
			||||||
 | 
					            // Get the database:
 | 
				
			||||||
 | 
					            await using var db = ProcessorMeta.ServiceProvider.GetRequiredService<DataContext>();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            // Check, if the setting is already set:
 | 
				
			||||||
 | 
					            if (await db.Settings.FirstOrDefaultAsync(n => n.Code == settingName) is { } existingSetting)
 | 
				
			||||||
 | 
					            {
 | 
				
			||||||
 | 
					                settingValue = settingValue switch
 | 
				
			||||||
 | 
					                {
 | 
				
			||||||
 | 
					                    bool => (T)(object)existingSetting.BoolValue,
 | 
				
			||||||
 | 
					                    string => (T)(object)existingSetting.TextValue,
 | 
				
			||||||
 | 
					                    int => (T)(object)existingSetting.IntegerValue,
 | 
				
			||||||
 | 
					                    Guid => (T)(object)existingSetting.GuidValue,
 | 
				
			||||||
 | 
					                    
 | 
				
			||||||
 | 
					                    SettingDeepLMode or
 | 
				
			||||||
 | 
					                    SettingDeepLAction or
 | 
				
			||||||
 | 
					                    SettingGeneratorMode => (T)(object)existingSetting.IntegerValue,
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					                    _ => defaultValue,
 | 
				
			||||||
 | 
					                };
 | 
				
			||||||
 | 
					                return settingValue;
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            // Does not exist, so create it:
 | 
				
			||||||
 | 
					            var setting = new Setting
 | 
				
			||||||
 | 
					            {
 | 
				
			||||||
 | 
					                Code = settingName,
 | 
				
			||||||
 | 
					            };
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            switch (settingValue)
 | 
				
			||||||
 | 
					            {
 | 
				
			||||||
 | 
					                case bool:
 | 
				
			||||||
 | 
					                    setting.BoolValue = (bool)(object)settingValue;
 | 
				
			||||||
 | 
					                    break;
 | 
				
			||||||
 | 
					                
 | 
				
			||||||
 | 
					                case string:
 | 
				
			||||||
 | 
					                    setting.TextValue = (string)(object)settingValue;
 | 
				
			||||||
 | 
					                    break;
 | 
				
			||||||
 | 
					                
 | 
				
			||||||
 | 
					                case int:
 | 
				
			||||||
 | 
					                    setting.IntegerValue = (int)(object)settingValue;
 | 
				
			||||||
 | 
					                    break;
 | 
				
			||||||
 | 
					                
 | 
				
			||||||
 | 
					                case Guid:
 | 
				
			||||||
 | 
					                    setting.GuidValue = (Guid)(object)settingValue;
 | 
				
			||||||
 | 
					                    break;
 | 
				
			||||||
 | 
					                
 | 
				
			||||||
 | 
					                case SettingDeepLMode:
 | 
				
			||||||
 | 
					                case SettingDeepLAction:
 | 
				
			||||||
 | 
					                case SettingGeneratorMode:
 | 
				
			||||||
 | 
					                    setting.IntegerValue = (int)(object)settingValue;
 | 
				
			||||||
 | 
					                    break;
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            await db.Settings.AddAsync(setting);
 | 
				
			||||||
 | 
					            await db.SaveChangesAsync();
 | 
				
			||||||
 | 
					            return settingValue;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					        finally
 | 
				
			||||||
 | 
					        {
 | 
				
			||||||
 | 
					            CACHE_LOADED[settingName] = true;
 | 
				
			||||||
 | 
					            CACHES[settingName] = settingValue!;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					    
 | 
				
			||||||
 | 
					    public static async Task SetSetting<T>(string settingName, T settingValue)
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
        // Update the cache:
 | 
					        // Update the cache:
 | 
				
			||||||
        CACHE_DEEPL_MODE = mode;
 | 
					        CACHES[settingName] = settingValue!;
 | 
				
			||||||
        CACHE_DEEPL_MODE_IS_LOADED = true;
 | 
					        CACHE_LOADED[settingName] = true;
 | 
				
			||||||
        
 | 
					        
 | 
				
			||||||
        // Get the database:
 | 
					        // Get the database:
 | 
				
			||||||
        await using var db = ProcessorMeta.ServiceProvider.GetRequiredService<DataContext>();
 | 
					        await using var db = ProcessorMeta.ServiceProvider.GetRequiredService<DataContext>();
 | 
				
			||||||
        
 | 
					        
 | 
				
			||||||
        // Check, if the setting is already set:
 | 
					        // Check, if the setting is already set:
 | 
				
			||||||
        if (await db.Settings.FirstOrDefaultAsync(n => n.Code == SettingNames.DEEPL_MODE) is {} existingSetting)
 | 
					        if (await db.Settings.FirstOrDefaultAsync(n => n.Code == settingName) is { } existingSetting)
 | 
				
			||||||
        {
 | 
					        {
 | 
				
			||||||
            existingSetting.IntegerValue = intValue;
 | 
					            switch (settingValue)
 | 
				
			||||||
 | 
					            {
 | 
				
			||||||
 | 
					                case bool:
 | 
				
			||||||
 | 
					                    existingSetting.BoolValue = (bool)(object)settingValue;
 | 
				
			||||||
 | 
					                    break;
 | 
				
			||||||
 | 
					                
 | 
				
			||||||
 | 
					                case string:
 | 
				
			||||||
 | 
					                    existingSetting.TextValue = (string)(object)settingValue;
 | 
				
			||||||
 | 
					                    break;
 | 
				
			||||||
 | 
					                
 | 
				
			||||||
 | 
					                case int:
 | 
				
			||||||
 | 
					                    existingSetting.IntegerValue = (int)(object)settingValue;
 | 
				
			||||||
 | 
					                    break;
 | 
				
			||||||
 | 
					                
 | 
				
			||||||
 | 
					                case Guid:
 | 
				
			||||||
 | 
					                    existingSetting.GuidValue = (Guid)(object)settingValue;
 | 
				
			||||||
 | 
					                    break;
 | 
				
			||||||
 | 
					                
 | 
				
			||||||
 | 
					                case SettingDeepLMode:
 | 
				
			||||||
 | 
					                case SettingDeepLAction:
 | 
				
			||||||
 | 
					                case SettingGeneratorMode:
 | 
				
			||||||
 | 
					                    existingSetting.IntegerValue = (int)(object)settingValue;
 | 
				
			||||||
 | 
					                    break;
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
            await db.SaveChangesAsync();
 | 
					            await db.SaveChangesAsync();
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
        
 | 
					        
 | 
				
			||||||
@ -38,281 +129,78 @@ public static class AppSettings
 | 
				
			|||||||
        {
 | 
					        {
 | 
				
			||||||
            var setting = new Setting
 | 
					            var setting = new Setting
 | 
				
			||||||
            {
 | 
					            {
 | 
				
			||||||
                Code = SettingNames.DEEPL_MODE,
 | 
					                Code = SettingNames.GENERATOR_DOTNET_ENABLED,
 | 
				
			||||||
                IntegerValue = intValue,
 | 
					 | 
				
			||||||
            };
 | 
					            };
 | 
				
			||||||
            
 | 
					            
 | 
				
			||||||
 | 
					            switch (settingValue)
 | 
				
			||||||
 | 
					            {
 | 
				
			||||||
 | 
					                case bool:
 | 
				
			||||||
 | 
					                    setting.BoolValue = (bool)(object)settingValue;
 | 
				
			||||||
 | 
					                    break;
 | 
				
			||||||
 | 
					                
 | 
				
			||||||
 | 
					                case string:
 | 
				
			||||||
 | 
					                    setting.TextValue = (string)(object)settingValue;
 | 
				
			||||||
 | 
					                    break;
 | 
				
			||||||
 | 
					                
 | 
				
			||||||
 | 
					                case int:
 | 
				
			||||||
 | 
					                    setting.IntegerValue = (int)(object)settingValue;
 | 
				
			||||||
 | 
					                    break;
 | 
				
			||||||
 | 
					                
 | 
				
			||||||
 | 
					                case Guid:
 | 
				
			||||||
 | 
					                    setting.GuidValue = (Guid)(object)settingValue;
 | 
				
			||||||
 | 
					                    break;
 | 
				
			||||||
 | 
					                
 | 
				
			||||||
 | 
					                case SettingDeepLMode:
 | 
				
			||||||
 | 
					                case SettingDeepLAction:
 | 
				
			||||||
 | 
					                case SettingGeneratorMode:
 | 
				
			||||||
 | 
					                    setting.IntegerValue = (int)(object)settingValue;
 | 
				
			||||||
 | 
					                    break;
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					            
 | 
				
			||||||
            await db.Settings.AddAsync(setting);
 | 
					            await db.Settings.AddAsync(setting);
 | 
				
			||||||
            await db.SaveChangesAsync();
 | 
					            await db.SaveChangesAsync();
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    public static async Task<SettingDeepLMode> GetDeepLMode()
 | 
					    #endregion   
 | 
				
			||||||
    {
 | 
					 | 
				
			||||||
        if (CACHE_DEEPL_MODE_IS_LOADED)
 | 
					 | 
				
			||||||
            return CACHE_DEEPL_MODE;
 | 
					 | 
				
			||||||
    
 | 
					    
 | 
				
			||||||
        var mode = SettingDeepLMode.DISABLED;
 | 
					    #region DeepL Settings
 | 
				
			||||||
        try
 | 
					 | 
				
			||||||
        {
 | 
					 | 
				
			||||||
            // Get the database:
 | 
					 | 
				
			||||||
            await using var db = ProcessorMeta.ServiceProvider.GetRequiredService<DataContext>();
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
            // Check, if the setting is already set:
 | 
					    #region DeepL Mode
 | 
				
			||||||
            if (await db.Settings.FirstOrDefaultAsync(n => n.Code == SettingNames.DEEPL_MODE) is { } existingSetting)
 | 
					 | 
				
			||||||
            {
 | 
					 | 
				
			||||||
                mode = (SettingDeepLMode) existingSetting.IntegerValue;
 | 
					 | 
				
			||||||
                return mode;
 | 
					 | 
				
			||||||
            }
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
            // Does not exist, so create it:
 | 
					    public static async Task SetDeepLMode(SettingDeepLMode mode) => await AppSettings.SetSetting(SettingNames.DEEPL_MODE, mode);
 | 
				
			||||||
            var setting = new Setting
 | 
					 | 
				
			||||||
            {
 | 
					 | 
				
			||||||
                Code = SettingNames.DEEPL_MODE,
 | 
					 | 
				
			||||||
                IntegerValue = (int) mode,
 | 
					 | 
				
			||||||
            };
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
            await db.Settings.AddAsync(setting);
 | 
					    public static async Task<SettingDeepLMode> GetDeepLMode() => await AppSettings.GetSetting(SettingNames.DEEPL_MODE, SettingDeepLMode.DISABLED);
 | 
				
			||||||
            await db.SaveChangesAsync();
 | 
					 | 
				
			||||||
            return mode;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
        finally
 | 
					 | 
				
			||||||
        {
 | 
					 | 
				
			||||||
            CACHE_DEEPL_MODE = mode;
 | 
					 | 
				
			||||||
            CACHE_DEEPL_MODE_IS_LOADED = true;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
    #endregion
 | 
					    #endregion
 | 
				
			||||||
    
 | 
					    
 | 
				
			||||||
    #region DeepL API Key
 | 
					    #region DeepL API Key
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    private static string CACHE_DEEPL_API_KEY = string.Empty;
 | 
					    public static async Task SetDeepLAPIKey(string apiKey) => await AppSettings.SetSetting(SettingNames.DEEPL_API_KEY, apiKey);
 | 
				
			||||||
    private static bool CACHE_DEEPL_API_KEY_IS_LOADED = false;
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
    public static async Task SetDeepLAPIKey(string apiKey)
 | 
					    public static async Task<string> GetDeepLAPIKey() => await AppSettings.GetSetting(SettingNames.DEEPL_API_KEY, string.Empty);
 | 
				
			||||||
    {
 | 
					 | 
				
			||||||
        // Update the cache:
 | 
					 | 
				
			||||||
        CACHE_DEEPL_API_KEY = apiKey;
 | 
					 | 
				
			||||||
        CACHE_DEEPL_API_KEY_IS_LOADED = true;
 | 
					 | 
				
			||||||
        
 | 
					 | 
				
			||||||
        // Get the database:
 | 
					 | 
				
			||||||
        await using var db = ProcessorMeta.ServiceProvider.GetRequiredService<DataContext>();
 | 
					 | 
				
			||||||
        
 | 
					 | 
				
			||||||
        // Check, if the setting is already set:
 | 
					 | 
				
			||||||
        if (await db.Settings.FirstOrDefaultAsync(n => n.Code == SettingNames.DEEPL_API_KEY) is {} existingSetting)
 | 
					 | 
				
			||||||
        {
 | 
					 | 
				
			||||||
            existingSetting.TextValue = apiKey;
 | 
					 | 
				
			||||||
            await db.SaveChangesAsync();
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
        
 | 
					 | 
				
			||||||
        // Does not exist, so create it:
 | 
					 | 
				
			||||||
        else
 | 
					 | 
				
			||||||
        {
 | 
					 | 
				
			||||||
            var setting = new Setting
 | 
					 | 
				
			||||||
            {
 | 
					 | 
				
			||||||
                Code = SettingNames.DEEPL_API_KEY,
 | 
					 | 
				
			||||||
                TextValue = apiKey,
 | 
					 | 
				
			||||||
            };
 | 
					 | 
				
			||||||
            
 | 
					 | 
				
			||||||
            await db.Settings.AddAsync(setting);
 | 
					 | 
				
			||||||
            await db.SaveChangesAsync();
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
    
 | 
					 | 
				
			||||||
    public static async Task<string> GetDeepLAPIKey()
 | 
					 | 
				
			||||||
    {
 | 
					 | 
				
			||||||
        // Check the cache:
 | 
					 | 
				
			||||||
        if (CACHE_DEEPL_API_KEY_IS_LOADED)
 | 
					 | 
				
			||||||
            return CACHE_DEEPL_API_KEY;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        var key = string.Empty;
 | 
					 | 
				
			||||||
        try
 | 
					 | 
				
			||||||
        {
 | 
					 | 
				
			||||||
            // Get the database:
 | 
					 | 
				
			||||||
            await using var db = ProcessorMeta.ServiceProvider.GetRequiredService<DataContext>();
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
            // Check, if the setting is already set:
 | 
					 | 
				
			||||||
            if (await db.Settings.FirstOrDefaultAsync(n => n.Code == SettingNames.DEEPL_API_KEY) is { } existingSetting)
 | 
					 | 
				
			||||||
            {
 | 
					 | 
				
			||||||
                key = existingSetting.TextValue;
 | 
					 | 
				
			||||||
                return key;
 | 
					 | 
				
			||||||
            }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
            // Does not exist, so create it:
 | 
					 | 
				
			||||||
            var setting = new Setting
 | 
					 | 
				
			||||||
            {
 | 
					 | 
				
			||||||
                Code = SettingNames.DEEPL_API_KEY,
 | 
					 | 
				
			||||||
                TextValue = key,
 | 
					 | 
				
			||||||
            };
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
            await db.Settings.AddAsync(setting);
 | 
					 | 
				
			||||||
            await db.SaveChangesAsync();
 | 
					 | 
				
			||||||
            return key;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
        finally
 | 
					 | 
				
			||||||
        {
 | 
					 | 
				
			||||||
            CACHE_DEEPL_API_KEY = key;
 | 
					 | 
				
			||||||
            CACHE_DEEPL_API_KEY_IS_LOADED = true;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
    #endregion
 | 
					    #endregion
 | 
				
			||||||
    
 | 
					    
 | 
				
			||||||
    #region DeepL Action
 | 
					    #region DeepL Action
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    private static SettingDeepLAction CACHE_DEEPL_ACTION = SettingDeepLAction.MANUAL;
 | 
					    public static async Task SetDeepLAction(SettingDeepLAction action) => await AppSettings.SetSetting(SettingNames.DEEPL_ACTION, action);
 | 
				
			||||||
    private static bool CACHE_DEEPL_ACTION_IS_LOADED = false;
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
    public static async Task SetDeepLAction(SettingDeepLAction action)
 | 
					    public static async Task<SettingDeepLAction> GetDeepLAction() => await AppSettings.GetSetting(SettingNames.DEEPL_ACTION, SettingDeepLAction.MANUAL);
 | 
				
			||||||
    {
 | 
					 | 
				
			||||||
        // Convert the enum to its int value:
 | 
					 | 
				
			||||||
        var intValue = (int)action;
 | 
					 | 
				
			||||||
        
 | 
					 | 
				
			||||||
        // Update the cache:
 | 
					 | 
				
			||||||
        CACHE_DEEPL_ACTION = action;
 | 
					 | 
				
			||||||
        CACHE_DEEPL_ACTION_IS_LOADED = true;
 | 
					 | 
				
			||||||
        
 | 
					 | 
				
			||||||
        // Get the database:
 | 
					 | 
				
			||||||
        await using var db = ProcessorMeta.ServiceProvider.GetRequiredService<DataContext>();
 | 
					 | 
				
			||||||
        
 | 
					 | 
				
			||||||
        // Check, if the setting is already set:
 | 
					 | 
				
			||||||
        if (await db.Settings.FirstOrDefaultAsync(n => n.Code == SettingNames.DEEPL_ACTION) is {} existingSetting)
 | 
					 | 
				
			||||||
        {
 | 
					 | 
				
			||||||
            existingSetting.IntegerValue = intValue;
 | 
					 | 
				
			||||||
            await db.SaveChangesAsync();
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
        
 | 
					 | 
				
			||||||
        // Does not exist, so create it:
 | 
					 | 
				
			||||||
        else
 | 
					 | 
				
			||||||
        {
 | 
					 | 
				
			||||||
            var setting = new Setting
 | 
					 | 
				
			||||||
            {
 | 
					 | 
				
			||||||
                Code = SettingNames.DEEPL_ACTION,
 | 
					 | 
				
			||||||
                IntegerValue = intValue,
 | 
					 | 
				
			||||||
            };
 | 
					 | 
				
			||||||
            
 | 
					 | 
				
			||||||
            await db.Settings.AddAsync(setting);
 | 
					 | 
				
			||||||
            await db.SaveChangesAsync();
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
    
 | 
					 | 
				
			||||||
    public static async Task<SettingDeepLAction> GetDeepLAction()
 | 
					 | 
				
			||||||
    {
 | 
					 | 
				
			||||||
        // Check the cache:
 | 
					 | 
				
			||||||
        if (CACHE_DEEPL_ACTION_IS_LOADED)
 | 
					 | 
				
			||||||
            return CACHE_DEEPL_ACTION;
 | 
					 | 
				
			||||||
        
 | 
					 | 
				
			||||||
        var action = SettingDeepLAction.MANUAL;
 | 
					 | 
				
			||||||
        try
 | 
					 | 
				
			||||||
        {
 | 
					 | 
				
			||||||
            // Get the database:
 | 
					 | 
				
			||||||
            await using var db = ProcessorMeta.ServiceProvider.GetRequiredService<DataContext>();
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
            // Check, if the setting is already set:
 | 
					 | 
				
			||||||
            if (await db.Settings.FirstOrDefaultAsync(n => n.Code == SettingNames.DEEPL_ACTION) is { } existingSetting)
 | 
					 | 
				
			||||||
            {
 | 
					 | 
				
			||||||
                action = (SettingDeepLAction) existingSetting.IntegerValue;
 | 
					 | 
				
			||||||
                return action;
 | 
					 | 
				
			||||||
            }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
            // Does not exist, so create it:
 | 
					 | 
				
			||||||
            var setting = new Setting
 | 
					 | 
				
			||||||
            {
 | 
					 | 
				
			||||||
                Code = SettingNames.DEEPL_ACTION,
 | 
					 | 
				
			||||||
                IntegerValue = (int) action,
 | 
					 | 
				
			||||||
            };
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
            await db.Settings.AddAsync(setting);
 | 
					 | 
				
			||||||
            await db.SaveChangesAsync();
 | 
					 | 
				
			||||||
            return action;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
        finally
 | 
					 | 
				
			||||||
        {
 | 
					 | 
				
			||||||
            CACHE_DEEPL_ACTION = action;
 | 
					 | 
				
			||||||
            CACHE_DEEPL_ACTION_IS_LOADED = true;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
    #endregion
 | 
					    #endregion
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    #region DeepL Source Culture
 | 
					    #region DeepL Source Culture
 | 
				
			||||||
    
 | 
					    
 | 
				
			||||||
    private static int CACHE_DEEPL_SOURCE_CULTURE = -1;
 | 
					    public static async Task SetDeepLSourceCultureIndex(int cultureIndex) => await AppSettings.SetSetting(SettingNames.DEEPL_SOURCE_CULTURE, cultureIndex);
 | 
				
			||||||
    private static bool CACHE_DEEPL_SOURCE_CULTURE_IS_LOADED = false;
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
    public static async Task SetDeepLSourceCultureIndex(int cultureIndex)
 | 
					    public static async Task<int> GetDeepLSourceCultureIndex() => await AppSettings.GetSetting(SettingNames.DEEPL_SOURCE_CULTURE, -1);
 | 
				
			||||||
    {
 | 
					 | 
				
			||||||
        // Update the cache:
 | 
					 | 
				
			||||||
        CACHE_DEEPL_SOURCE_CULTURE = cultureIndex;
 | 
					 | 
				
			||||||
        CACHE_DEEPL_SOURCE_CULTURE_IS_LOADED = true;
 | 
					 | 
				
			||||||
        
 | 
					 | 
				
			||||||
        // Get the database:
 | 
					 | 
				
			||||||
        await using var db = ProcessorMeta.ServiceProvider.GetRequiredService<DataContext>();
 | 
					 | 
				
			||||||
        
 | 
					 | 
				
			||||||
        // Check, if the setting is already set:
 | 
					 | 
				
			||||||
        if (await db.Settings.FirstOrDefaultAsync(n => n.Code == SettingNames.DEEPL_SOURCE_CULTURE) is {} existingSetting)
 | 
					 | 
				
			||||||
        {
 | 
					 | 
				
			||||||
            existingSetting.IntegerValue = cultureIndex;
 | 
					 | 
				
			||||||
            await db.SaveChangesAsync();
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
        
 | 
					 | 
				
			||||||
        // Does not exist, so create it:
 | 
					 | 
				
			||||||
        else
 | 
					 | 
				
			||||||
        {
 | 
					 | 
				
			||||||
            var setting = new Setting
 | 
					 | 
				
			||||||
            {
 | 
					 | 
				
			||||||
                Code = SettingNames.DEEPL_SOURCE_CULTURE,
 | 
					 | 
				
			||||||
                IntegerValue = cultureIndex,
 | 
					 | 
				
			||||||
            };
 | 
					 | 
				
			||||||
            
 | 
					 | 
				
			||||||
            await db.Settings.AddAsync(setting);
 | 
					 | 
				
			||||||
            await db.SaveChangesAsync();
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
    
 | 
					 | 
				
			||||||
    public static async Task<int> GetDeepLSourceCultureIndex()
 | 
					 | 
				
			||||||
    {
 | 
					 | 
				
			||||||
        // Check the cache:
 | 
					 | 
				
			||||||
        if (CACHE_DEEPL_SOURCE_CULTURE_IS_LOADED)
 | 
					 | 
				
			||||||
            return CACHE_DEEPL_SOURCE_CULTURE;
 | 
					 | 
				
			||||||
        
 | 
					 | 
				
			||||||
        var cultureIndex = -1;
 | 
					 | 
				
			||||||
        try
 | 
					 | 
				
			||||||
        {
 | 
					 | 
				
			||||||
            // Get the database:
 | 
					 | 
				
			||||||
            await using var db = ProcessorMeta.ServiceProvider.GetRequiredService<DataContext>();
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
            // Check, if the setting is already set:
 | 
					 | 
				
			||||||
            if (await db.Settings.FirstOrDefaultAsync(n => n.Code == SettingNames.DEEPL_SOURCE_CULTURE) is { } existingSetting)
 | 
					 | 
				
			||||||
            {
 | 
					 | 
				
			||||||
                cultureIndex = existingSetting.IntegerValue;
 | 
					 | 
				
			||||||
                return cultureIndex;
 | 
					 | 
				
			||||||
            }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
            // Does not exist, so create it:
 | 
					 | 
				
			||||||
            var setting = new Setting
 | 
					 | 
				
			||||||
            {
 | 
					 | 
				
			||||||
                Code = SettingNames.DEEPL_SOURCE_CULTURE,
 | 
					 | 
				
			||||||
                IntegerValue = cultureIndex,
 | 
					 | 
				
			||||||
            };
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
            await db.Settings.AddAsync(setting);
 | 
					 | 
				
			||||||
            await db.SaveChangesAsync();
 | 
					 | 
				
			||||||
            return cultureIndex;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
        finally
 | 
					 | 
				
			||||||
        {
 | 
					 | 
				
			||||||
            CACHE_DEEPL_SOURCE_CULTURE = cultureIndex;
 | 
					 | 
				
			||||||
            CACHE_DEEPL_SOURCE_CULTURE_IS_LOADED = true;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
    #endregion
 | 
					    #endregion
 | 
				
			||||||
    
 | 
					    
 | 
				
			||||||
    #endregion
 | 
					    #endregion
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    #region Translation Settings
 | 
					    #region Culture Settings
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    #region List of culture indices
 | 
					    #region List of culture indices
 | 
				
			||||||
    
 | 
					    
 | 
				
			||||||
@ -465,519 +353,57 @@ public static class AppSettings
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    #region Generator Mode
 | 
					    #region Generator Mode
 | 
				
			||||||
    
 | 
					    
 | 
				
			||||||
    private static SettingGeneratorMode CACHE_GENERATOR_MODE = SettingGeneratorMode.MANUAL;
 | 
					    public static async Task<SettingGeneratorMode> GetGeneratorMode() => await AppSettings.GetSetting(SettingNames.GENERATOR_MODE, SettingGeneratorMode.MANUAL);
 | 
				
			||||||
    private static bool CACHE_GENERATOR_MODE_IS_LOADED = false;
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
    public static async Task<SettingGeneratorMode> GetGeneratorMode()
 | 
					    public static async Task SetGeneratorMode(SettingGeneratorMode mode) => await AppSettings.SetSetting(SettingNames.GENERATOR_MODE, mode);
 | 
				
			||||||
    {
 | 
					 | 
				
			||||||
        // When possible, use the cache:
 | 
					 | 
				
			||||||
        if (CACHE_GENERATOR_MODE_IS_LOADED)
 | 
					 | 
				
			||||||
            return CACHE_GENERATOR_MODE;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        var generatorMode = SettingGeneratorMode.MANUAL;
 | 
					 | 
				
			||||||
        try
 | 
					 | 
				
			||||||
        {
 | 
					 | 
				
			||||||
            // Get the database:
 | 
					 | 
				
			||||||
            await using var db = ProcessorMeta.ServiceProvider.GetRequiredService<DataContext>();
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
            // Check, if the setting is already set:
 | 
					 | 
				
			||||||
            if (await db.Settings.FirstOrDefaultAsync(n => n.Code == SettingNames.GENERATOR_MODE) is { } existingSetting)
 | 
					 | 
				
			||||||
            {
 | 
					 | 
				
			||||||
                generatorMode = (SettingGeneratorMode) existingSetting.IntegerValue;
 | 
					 | 
				
			||||||
                return generatorMode;
 | 
					 | 
				
			||||||
            }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
            // Does not exist, so create it:
 | 
					 | 
				
			||||||
            var setting = new Setting
 | 
					 | 
				
			||||||
            {
 | 
					 | 
				
			||||||
                Code = SettingNames.GENERATOR_MODE,
 | 
					 | 
				
			||||||
                IntegerValue = (int) generatorMode,
 | 
					 | 
				
			||||||
            };
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
            await db.Settings.AddAsync(setting);
 | 
					 | 
				
			||||||
            await db.SaveChangesAsync();
 | 
					 | 
				
			||||||
            return generatorMode;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
        finally
 | 
					 | 
				
			||||||
        {
 | 
					 | 
				
			||||||
            CACHE_GENERATOR_MODE_IS_LOADED = true;
 | 
					 | 
				
			||||||
            CACHE_GENERATOR_MODE = generatorMode;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
    
 | 
					 | 
				
			||||||
    public static async Task SetGeneratorMode(SettingGeneratorMode mode)
 | 
					 | 
				
			||||||
    {
 | 
					 | 
				
			||||||
        // Update the cache:
 | 
					 | 
				
			||||||
        CACHE_GENERATOR_MODE = mode;
 | 
					 | 
				
			||||||
        CACHE_GENERATOR_MODE_IS_LOADED = true;
 | 
					 | 
				
			||||||
        
 | 
					 | 
				
			||||||
        // Get the database:
 | 
					 | 
				
			||||||
        await using var db = ProcessorMeta.ServiceProvider.GetRequiredService<DataContext>();
 | 
					 | 
				
			||||||
        
 | 
					 | 
				
			||||||
        // Check, if the setting is already set:
 | 
					 | 
				
			||||||
        if (await db.Settings.FirstOrDefaultAsync(n => n.Code == SettingNames.GENERATOR_MODE) is { } existingSetting)
 | 
					 | 
				
			||||||
        {
 | 
					 | 
				
			||||||
            existingSetting.IntegerValue = (int) mode;
 | 
					 | 
				
			||||||
            await db.SaveChangesAsync();
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
        
 | 
					 | 
				
			||||||
        // Does not exist, so create it:
 | 
					 | 
				
			||||||
        else
 | 
					 | 
				
			||||||
        {
 | 
					 | 
				
			||||||
            var setting = new Setting
 | 
					 | 
				
			||||||
            {
 | 
					 | 
				
			||||||
                Code = SettingNames.GENERATOR_MODE,
 | 
					 | 
				
			||||||
                IntegerValue = (int) mode,
 | 
					 | 
				
			||||||
            };
 | 
					 | 
				
			||||||
            
 | 
					 | 
				
			||||||
            await db.Settings.AddAsync(setting);
 | 
					 | 
				
			||||||
            await db.SaveChangesAsync();
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
    #endregion
 | 
					    #endregion
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    #region .NET Generator Enabled/Disabled
 | 
					    #region .NET Generator Enabled/Disabled
 | 
				
			||||||
    
 | 
					    
 | 
				
			||||||
    private static bool CACHE_GENERATOR_DOTNET_ENABLED = true;
 | 
					    public static async Task<bool> GetGeneratorDotnetEnabled() => await AppSettings.GetSetting(SettingNames.GENERATOR_DOTNET_ENABLED, false);
 | 
				
			||||||
    private static bool CACHE_GENERATOR_DOTNET_ENABLED_IS_LOADED = false;
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
    public static async Task<bool> GetGeneratorDotnetEnabled()
 | 
					    public static async Task SetGeneratorDotnetEnabled(bool enabled) => await AppSettings.SetSetting(SettingNames.GENERATOR_DOTNET_ENABLED, enabled);
 | 
				
			||||||
    {
 | 
					 | 
				
			||||||
        // When possible, use the cache:
 | 
					 | 
				
			||||||
        if (CACHE_GENERATOR_DOTNET_ENABLED_IS_LOADED)
 | 
					 | 
				
			||||||
            return CACHE_GENERATOR_DOTNET_ENABLED;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        var generatorDotnetEnabled = false;
 | 
					 | 
				
			||||||
        try
 | 
					 | 
				
			||||||
        {
 | 
					 | 
				
			||||||
            // Get the database:
 | 
					 | 
				
			||||||
            await using var db = ProcessorMeta.ServiceProvider.GetRequiredService<DataContext>();
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
            // Check, if the setting is already set:
 | 
					 | 
				
			||||||
            if (await db.Settings.FirstOrDefaultAsync(n => n.Code == SettingNames.GENERATOR_DOTNET_ENABLED) is { } existingSetting)
 | 
					 | 
				
			||||||
            {
 | 
					 | 
				
			||||||
                generatorDotnetEnabled = existingSetting.BoolValue;
 | 
					 | 
				
			||||||
                return generatorDotnetEnabled;
 | 
					 | 
				
			||||||
            }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
            // Does not exist, so create it:
 | 
					 | 
				
			||||||
            var setting = new Setting
 | 
					 | 
				
			||||||
            {
 | 
					 | 
				
			||||||
                Code = SettingNames.GENERATOR_DOTNET_ENABLED,
 | 
					 | 
				
			||||||
                BoolValue = generatorDotnetEnabled,
 | 
					 | 
				
			||||||
            };
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
            await db.Settings.AddAsync(setting);
 | 
					 | 
				
			||||||
            await db.SaveChangesAsync();
 | 
					 | 
				
			||||||
            return generatorDotnetEnabled;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
        finally
 | 
					 | 
				
			||||||
        {
 | 
					 | 
				
			||||||
            CACHE_GENERATOR_DOTNET_ENABLED_IS_LOADED = true;
 | 
					 | 
				
			||||||
            CACHE_GENERATOR_DOTNET_ENABLED = generatorDotnetEnabled;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
    
 | 
					 | 
				
			||||||
    public static async Task SetGeneratorDotnetEnabled(bool enabled)
 | 
					 | 
				
			||||||
    {
 | 
					 | 
				
			||||||
        // Update the cache:
 | 
					 | 
				
			||||||
        CACHE_GENERATOR_DOTNET_ENABLED = enabled;
 | 
					 | 
				
			||||||
        CACHE_GENERATOR_DOTNET_ENABLED_IS_LOADED = true;
 | 
					 | 
				
			||||||
        
 | 
					 | 
				
			||||||
        // Get the database:
 | 
					 | 
				
			||||||
        await using var db = ProcessorMeta.ServiceProvider.GetRequiredService<DataContext>();
 | 
					 | 
				
			||||||
        
 | 
					 | 
				
			||||||
        // Check, if the setting is already set:
 | 
					 | 
				
			||||||
        if (await db.Settings.FirstOrDefaultAsync(n => n.Code == SettingNames.GENERATOR_DOTNET_ENABLED) is { } existingSetting)
 | 
					 | 
				
			||||||
        {
 | 
					 | 
				
			||||||
            existingSetting.BoolValue = enabled;
 | 
					 | 
				
			||||||
            await db.SaveChangesAsync();
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
        
 | 
					 | 
				
			||||||
        // Does not exist, so create it:
 | 
					 | 
				
			||||||
        else
 | 
					 | 
				
			||||||
        {
 | 
					 | 
				
			||||||
            var setting = new Setting
 | 
					 | 
				
			||||||
            {
 | 
					 | 
				
			||||||
                Code = SettingNames.GENERATOR_DOTNET_ENABLED,
 | 
					 | 
				
			||||||
                BoolValue = enabled,
 | 
					 | 
				
			||||||
            };
 | 
					 | 
				
			||||||
            
 | 
					 | 
				
			||||||
            await db.Settings.AddAsync(setting);
 | 
					 | 
				
			||||||
            await db.SaveChangesAsync();
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
    #endregion
 | 
					    #endregion
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    #region .NET Generator Destination Path
 | 
					    #region .NET Generator Destination Path
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    private static string CACHE_GENERATOR_DOTNET_DESTINATION_PATH = string.Empty;
 | 
					    public static async Task<string> GetGeneratorDotnetDestinationPath() => await AppSettings.GetSetting(SettingNames.GENERATOR_DOTNET_DESTINATION_PATH, string.Empty);
 | 
				
			||||||
    private static bool CACHE_GENERATOR_DOTNET_DESTINATION_PATH_IS_LOADED = false;
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
    public static async Task<string> GetGeneratorDotnetDestinationPath()
 | 
					    public static async Task SetGeneratorDotnetDestinationPath(string path) => await AppSettings.SetSetting(SettingNames.GENERATOR_DOTNET_DESTINATION_PATH, path);
 | 
				
			||||||
    {
 | 
					 | 
				
			||||||
        // When possible, use the cache:
 | 
					 | 
				
			||||||
        if (CACHE_GENERATOR_DOTNET_DESTINATION_PATH_IS_LOADED)
 | 
					 | 
				
			||||||
            return CACHE_GENERATOR_DOTNET_DESTINATION_PATH;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        var generatorDotnetDestinationPath = string.Empty;
 | 
					 | 
				
			||||||
        try
 | 
					 | 
				
			||||||
        {
 | 
					 | 
				
			||||||
            // Get the database:
 | 
					 | 
				
			||||||
            await using var db = ProcessorMeta.ServiceProvider.GetRequiredService<DataContext>();
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
            // Check, if the setting is already set:
 | 
					 | 
				
			||||||
            if (await db.Settings.FirstOrDefaultAsync(n => n.Code == SettingNames.GENERATOR_DOTNET_DESTINATION_PATH) is { } existingSetting)
 | 
					 | 
				
			||||||
            {
 | 
					 | 
				
			||||||
                generatorDotnetDestinationPath = existingSetting.TextValue;
 | 
					 | 
				
			||||||
                return generatorDotnetDestinationPath;
 | 
					 | 
				
			||||||
            }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
            // Does not exist, so create it:
 | 
					 | 
				
			||||||
            var setting = new Setting
 | 
					 | 
				
			||||||
            {
 | 
					 | 
				
			||||||
                Code = SettingNames.GENERATOR_DOTNET_DESTINATION_PATH,
 | 
					 | 
				
			||||||
                TextValue = generatorDotnetDestinationPath,
 | 
					 | 
				
			||||||
            };
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
            await db.Settings.AddAsync(setting);
 | 
					 | 
				
			||||||
            await db.SaveChangesAsync();
 | 
					 | 
				
			||||||
            return generatorDotnetDestinationPath;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
        finally
 | 
					 | 
				
			||||||
        {
 | 
					 | 
				
			||||||
            CACHE_GENERATOR_DOTNET_DESTINATION_PATH_IS_LOADED = true;
 | 
					 | 
				
			||||||
            CACHE_GENERATOR_DOTNET_DESTINATION_PATH = generatorDotnetDestinationPath;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
    
 | 
					 | 
				
			||||||
    public static async Task SetGeneratorDotnetDestinationPath(string path)
 | 
					 | 
				
			||||||
    {
 | 
					 | 
				
			||||||
        // Update the cache:
 | 
					 | 
				
			||||||
        CACHE_GENERATOR_DOTNET_DESTINATION_PATH = path;
 | 
					 | 
				
			||||||
        CACHE_GENERATOR_DOTNET_DESTINATION_PATH_IS_LOADED = true;
 | 
					 | 
				
			||||||
        
 | 
					 | 
				
			||||||
        // Get the database:
 | 
					 | 
				
			||||||
        await using var db = ProcessorMeta.ServiceProvider.GetRequiredService<DataContext>();
 | 
					 | 
				
			||||||
        
 | 
					 | 
				
			||||||
        // Check, if the setting is already set:
 | 
					 | 
				
			||||||
        if (await db.Settings.FirstOrDefaultAsync(n => n.Code == SettingNames.GENERATOR_DOTNET_DESTINATION_PATH) is { } existingSetting)
 | 
					 | 
				
			||||||
        {
 | 
					 | 
				
			||||||
            existingSetting.TextValue = path;
 | 
					 | 
				
			||||||
            await db.SaveChangesAsync();
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
        
 | 
					 | 
				
			||||||
        // Does not exist, so create it:
 | 
					 | 
				
			||||||
        else
 | 
					 | 
				
			||||||
        {
 | 
					 | 
				
			||||||
            var setting = new Setting
 | 
					 | 
				
			||||||
            {
 | 
					 | 
				
			||||||
                Code = SettingNames.GENERATOR_DOTNET_DESTINATION_PATH,
 | 
					 | 
				
			||||||
                TextValue = path,
 | 
					 | 
				
			||||||
            };
 | 
					 | 
				
			||||||
            
 | 
					 | 
				
			||||||
            await db.Settings.AddAsync(setting);
 | 
					 | 
				
			||||||
            await db.SaveChangesAsync();
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
    #endregion
 | 
					    #endregion
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    #region .NET Generator Namespace
 | 
					    #region .NET Generator Namespace
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    private static string CACHE_GENERATOR_DOTNET_NAMESPACE = string.Empty;
 | 
					    public static async Task<string> GetGeneratorDotnetNamespace() => await AppSettings.GetSetting(SettingNames.GENERATOR_DOTNET_NAMESPACE, "I18N");
 | 
				
			||||||
    private static bool CACHE_GENERATOR_DOTNET_NAMESPACE_IS_LOADED = false;
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
    public static async Task<string> GetGeneratorDotnetNamespace()
 | 
					    public static async Task SetGeneratorDotnetNamespace(string updatedNamespace) => await AppSettings.SetSetting(SettingNames.GENERATOR_DOTNET_NAMESPACE, updatedNamespace);
 | 
				
			||||||
    {
 | 
					 | 
				
			||||||
        // When possible, use the cache:
 | 
					 | 
				
			||||||
        if (CACHE_GENERATOR_DOTNET_NAMESPACE_IS_LOADED)
 | 
					 | 
				
			||||||
            return CACHE_GENERATOR_DOTNET_NAMESPACE;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        var generatorDotnetNamespace = "I18N";
 | 
					 | 
				
			||||||
        try
 | 
					 | 
				
			||||||
        {
 | 
					 | 
				
			||||||
            // Get the database:
 | 
					 | 
				
			||||||
            await using var db = ProcessorMeta.ServiceProvider.GetRequiredService<DataContext>();
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
            // Check, if the setting is already set:
 | 
					 | 
				
			||||||
            if (await db.Settings.FirstOrDefaultAsync(n => n.Code == SettingNames.GENERATOR_DOTNET_NAMESPACE) is { } existingSetting)
 | 
					 | 
				
			||||||
            {
 | 
					 | 
				
			||||||
                generatorDotnetNamespace = existingSetting.TextValue;
 | 
					 | 
				
			||||||
                return generatorDotnetNamespace;
 | 
					 | 
				
			||||||
            }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
            // Does not exist, so create it:
 | 
					 | 
				
			||||||
            var setting = new Setting
 | 
					 | 
				
			||||||
            {
 | 
					 | 
				
			||||||
                Code = SettingNames.GENERATOR_DOTNET_NAMESPACE,
 | 
					 | 
				
			||||||
                TextValue = generatorDotnetNamespace,
 | 
					 | 
				
			||||||
            };
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
            await db.Settings.AddAsync(setting);
 | 
					 | 
				
			||||||
            await db.SaveChangesAsync();
 | 
					 | 
				
			||||||
            return generatorDotnetNamespace;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
        finally
 | 
					 | 
				
			||||||
        {
 | 
					 | 
				
			||||||
            CACHE_GENERATOR_DOTNET_NAMESPACE_IS_LOADED = true;
 | 
					 | 
				
			||||||
            CACHE_GENERATOR_DOTNET_NAMESPACE = generatorDotnetNamespace;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
    
 | 
					 | 
				
			||||||
    public static async Task SetGeneratorDotnetNamespace(string updatedNamespace)
 | 
					 | 
				
			||||||
    {
 | 
					 | 
				
			||||||
        // Update the cache:
 | 
					 | 
				
			||||||
        CACHE_GENERATOR_DOTNET_NAMESPACE = updatedNamespace;
 | 
					 | 
				
			||||||
        CACHE_GENERATOR_DOTNET_NAMESPACE_IS_LOADED = true;
 | 
					 | 
				
			||||||
        
 | 
					 | 
				
			||||||
        // Get the database:
 | 
					 | 
				
			||||||
        await using var db = ProcessorMeta.ServiceProvider.GetRequiredService<DataContext>();
 | 
					 | 
				
			||||||
        
 | 
					 | 
				
			||||||
        // Check, if the setting is already set:
 | 
					 | 
				
			||||||
        if (await db.Settings.FirstOrDefaultAsync(n => n.Code == SettingNames.GENERATOR_DOTNET_NAMESPACE) is { } existingSetting)
 | 
					 | 
				
			||||||
        {
 | 
					 | 
				
			||||||
            existingSetting.TextValue = updatedNamespace;
 | 
					 | 
				
			||||||
            await db.SaveChangesAsync();
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
        
 | 
					 | 
				
			||||||
        // Does not exist, so create it:
 | 
					 | 
				
			||||||
        else
 | 
					 | 
				
			||||||
        {
 | 
					 | 
				
			||||||
            var setting = new Setting
 | 
					 | 
				
			||||||
            {
 | 
					 | 
				
			||||||
                Code = SettingNames.GENERATOR_DOTNET_NAMESPACE,
 | 
					 | 
				
			||||||
                TextValue = updatedNamespace,
 | 
					 | 
				
			||||||
            };
 | 
					 | 
				
			||||||
            
 | 
					 | 
				
			||||||
            await db.Settings.AddAsync(setting);
 | 
					 | 
				
			||||||
            await db.SaveChangesAsync();
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
    #endregion
 | 
					    #endregion
 | 
				
			||||||
    
 | 
					    
 | 
				
			||||||
    #region .NET Generator Default Culture
 | 
					    #region .NET Generator Default Culture
 | 
				
			||||||
    
 | 
					    
 | 
				
			||||||
    private static int CACHE_GENERATOR_DOTNET_DEFAULT_CULTURE = -1;
 | 
					    public static async Task<int> GetGeneratorDotnetDefaultCultureIndex() => await AppSettings.GetSetting(SettingNames.GENERATOR_DOTNET_DEFAULT_CULTURE, 0);
 | 
				
			||||||
    private static bool CACHE_GENERATOR_DOTNET_DEFAULT_CULTURE_IS_LOADED = false;
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
    public static async Task<int> GetGeneratorDotnetDefaultCultureIndex()
 | 
					    public static async Task SetGeneratorDotnetDefaultCultureIndex(int updatedCulture) => await AppSettings.SetSetting(SettingNames.GENERATOR_DOTNET_DEFAULT_CULTURE, updatedCulture);
 | 
				
			||||||
    {
 | 
					 | 
				
			||||||
        // When possible, use the cache:
 | 
					 | 
				
			||||||
        if (CACHE_GENERATOR_DOTNET_DEFAULT_CULTURE_IS_LOADED)
 | 
					 | 
				
			||||||
            return CACHE_GENERATOR_DOTNET_DEFAULT_CULTURE;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        var generatorDotnetDefaultCulture = 0;
 | 
					 | 
				
			||||||
        try
 | 
					 | 
				
			||||||
        {
 | 
					 | 
				
			||||||
            // Get the database:
 | 
					 | 
				
			||||||
            await using var db = ProcessorMeta.ServiceProvider.GetRequiredService<DataContext>();
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
            // Check, if the setting is already set:
 | 
					 | 
				
			||||||
            if (await db.Settings.FirstOrDefaultAsync(n => n.Code == SettingNames.GENERATOR_DOTNET_DEFAULT_CULTURE) is { } existingSetting)
 | 
					 | 
				
			||||||
            {
 | 
					 | 
				
			||||||
                generatorDotnetDefaultCulture = existingSetting.IntegerValue;
 | 
					 | 
				
			||||||
                return generatorDotnetDefaultCulture;
 | 
					 | 
				
			||||||
            }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
            // Does not exist, so create it:
 | 
					 | 
				
			||||||
            var setting = new Setting
 | 
					 | 
				
			||||||
            {
 | 
					 | 
				
			||||||
                Code = SettingNames.GENERATOR_DOTNET_DEFAULT_CULTURE,
 | 
					 | 
				
			||||||
                IntegerValue = generatorDotnetDefaultCulture,
 | 
					 | 
				
			||||||
            };
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
            await db.Settings.AddAsync(setting);
 | 
					 | 
				
			||||||
            await db.SaveChangesAsync();
 | 
					 | 
				
			||||||
            return generatorDotnetDefaultCulture;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
        finally
 | 
					 | 
				
			||||||
        {
 | 
					 | 
				
			||||||
            CACHE_GENERATOR_DOTNET_DEFAULT_CULTURE_IS_LOADED = true;
 | 
					 | 
				
			||||||
            CACHE_GENERATOR_DOTNET_DEFAULT_CULTURE = generatorDotnetDefaultCulture;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
    
 | 
					 | 
				
			||||||
    public static async Task SetGeneratorDotnetDefaultCultureIndex(int updatedCulture)
 | 
					 | 
				
			||||||
    {
 | 
					 | 
				
			||||||
        // Update the cache:
 | 
					 | 
				
			||||||
        CACHE_GENERATOR_DOTNET_DEFAULT_CULTURE = updatedCulture;
 | 
					 | 
				
			||||||
        CACHE_GENERATOR_DOTNET_DEFAULT_CULTURE_IS_LOADED = true;
 | 
					 | 
				
			||||||
        
 | 
					 | 
				
			||||||
        // Get the database:
 | 
					 | 
				
			||||||
        await using var db = ProcessorMeta.ServiceProvider.GetRequiredService<DataContext>();
 | 
					 | 
				
			||||||
        
 | 
					 | 
				
			||||||
        // Check, if the setting is already set:
 | 
					 | 
				
			||||||
        if (await db.Settings.FirstOrDefaultAsync(n => n.Code == SettingNames.GENERATOR_DOTNET_DEFAULT_CULTURE) is { } existingSetting)
 | 
					 | 
				
			||||||
        {
 | 
					 | 
				
			||||||
            existingSetting.IntegerValue = updatedCulture;
 | 
					 | 
				
			||||||
            await db.SaveChangesAsync();
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
        
 | 
					 | 
				
			||||||
        // Does not exist, so create it:
 | 
					 | 
				
			||||||
        else
 | 
					 | 
				
			||||||
        {
 | 
					 | 
				
			||||||
            var setting = new Setting
 | 
					 | 
				
			||||||
            {
 | 
					 | 
				
			||||||
                Code = SettingNames.GENERATOR_DOTNET_DEFAULT_CULTURE,
 | 
					 | 
				
			||||||
                IntegerValue = updatedCulture,
 | 
					 | 
				
			||||||
            };
 | 
					 | 
				
			||||||
            
 | 
					 | 
				
			||||||
            await db.Settings.AddAsync(setting);
 | 
					 | 
				
			||||||
            await db.SaveChangesAsync();
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
    #endregion
 | 
					    #endregion
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    #region Godot Generator Enabled/Disabled
 | 
					    #region Godot Generator Enabled/Disabled
 | 
				
			||||||
    
 | 
					    
 | 
				
			||||||
    private static bool CACHE_GENERATOR_GODOT_ENABLED = true;
 | 
					    public static async Task<bool> GetGeneratorGodotEnabled() => await AppSettings.GetSetting(SettingNames.GENERATOR_GODOT_ENABLED, false);
 | 
				
			||||||
    private static bool CACHE_GENERATOR_GODOT_ENABLED_IS_LOADED = false;
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
    public static async Task<bool> GetGeneratorGodotEnabled()
 | 
					    public static async Task SetGeneratorGodotEnabled(bool enabled) => await AppSettings.SetSetting(SettingNames.GENERATOR_GODOT_ENABLED, enabled);
 | 
				
			||||||
    {
 | 
					 | 
				
			||||||
        // When possible, use the cache:
 | 
					 | 
				
			||||||
        if (CACHE_GENERATOR_GODOT_ENABLED_IS_LOADED)
 | 
					 | 
				
			||||||
            return CACHE_GENERATOR_GODOT_ENABLED;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        var generatorGodotEnabled = false;
 | 
					 | 
				
			||||||
        try
 | 
					 | 
				
			||||||
        {
 | 
					 | 
				
			||||||
            // Get the database:
 | 
					 | 
				
			||||||
            await using var db = ProcessorMeta.ServiceProvider.GetRequiredService<DataContext>();
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
            // Check, if the setting is already set:
 | 
					 | 
				
			||||||
            if (await db.Settings.FirstOrDefaultAsync(n => n.Code == SettingNames.GENERATOR_GODOT_ENABLED) is { } existingSetting)
 | 
					 | 
				
			||||||
            {
 | 
					 | 
				
			||||||
                generatorGodotEnabled = existingSetting.BoolValue;
 | 
					 | 
				
			||||||
                return generatorGodotEnabled;
 | 
					 | 
				
			||||||
            }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
            // Does not exist, so create it:
 | 
					 | 
				
			||||||
            var setting = new Setting
 | 
					 | 
				
			||||||
            {
 | 
					 | 
				
			||||||
                Code = SettingNames.GENERATOR_GODOT_ENABLED,
 | 
					 | 
				
			||||||
                BoolValue = generatorGodotEnabled,
 | 
					 | 
				
			||||||
            };
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
            await db.Settings.AddAsync(setting);
 | 
					 | 
				
			||||||
            await db.SaveChangesAsync();
 | 
					 | 
				
			||||||
            return generatorGodotEnabled;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
        finally
 | 
					 | 
				
			||||||
        {
 | 
					 | 
				
			||||||
            CACHE_GENERATOR_GODOT_ENABLED_IS_LOADED = true;
 | 
					 | 
				
			||||||
            CACHE_GENERATOR_GODOT_ENABLED = generatorGodotEnabled;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
    
 | 
					 | 
				
			||||||
    public static async Task SetGeneratorGodotEnabled(bool enabled)
 | 
					 | 
				
			||||||
    {
 | 
					 | 
				
			||||||
        // Update the cache:
 | 
					 | 
				
			||||||
        CACHE_GENERATOR_GODOT_ENABLED = enabled;
 | 
					 | 
				
			||||||
        CACHE_GENERATOR_GODOT_ENABLED_IS_LOADED = true;
 | 
					 | 
				
			||||||
        
 | 
					 | 
				
			||||||
        // Get the database:
 | 
					 | 
				
			||||||
        await using var db = ProcessorMeta.ServiceProvider.GetRequiredService<DataContext>();
 | 
					 | 
				
			||||||
        
 | 
					 | 
				
			||||||
        // Check, if the setting is already set:
 | 
					 | 
				
			||||||
        if (await db.Settings.FirstOrDefaultAsync(n => n.Code == SettingNames.GENERATOR_GODOT_ENABLED) is { } existingSetting)
 | 
					 | 
				
			||||||
        {
 | 
					 | 
				
			||||||
            existingSetting.BoolValue = enabled;
 | 
					 | 
				
			||||||
            await db.SaveChangesAsync();
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
        
 | 
					 | 
				
			||||||
        // Does not exist, so create it:
 | 
					 | 
				
			||||||
        else
 | 
					 | 
				
			||||||
        {
 | 
					 | 
				
			||||||
            var setting = new Setting
 | 
					 | 
				
			||||||
            {
 | 
					 | 
				
			||||||
                Code = SettingNames.GENERATOR_GODOT_ENABLED,
 | 
					 | 
				
			||||||
                BoolValue = enabled,
 | 
					 | 
				
			||||||
            };
 | 
					 | 
				
			||||||
            
 | 
					 | 
				
			||||||
            await db.Settings.AddAsync(setting);
 | 
					 | 
				
			||||||
            await db.SaveChangesAsync();
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
    #endregion
 | 
					    #endregion
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    #region Godot Generator Destination Path
 | 
					    #region Godot Generator Destination Path
 | 
				
			||||||
    
 | 
					    
 | 
				
			||||||
    private static string CACHE_GENERATOR_GODOT_DESTINATION_PATH = string.Empty;
 | 
					    public static async Task<string> GetGeneratorGodotDestinationPath() => await AppSettings.GetSetting(SettingNames.GENERATOR_GODOT_DESTINATION_PATH, string.Empty);
 | 
				
			||||||
    private static bool CACHE_GENERATOR_GODOT_DESTINATION_PATH_IS_LOADED = false;
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
    public static async Task<string> GetGeneratorGodotDestinationPath()
 | 
					    public static async Task SetGeneratorGodotDestinationPath(string path) => await AppSettings.SetSetting(SettingNames.GENERATOR_GODOT_DESTINATION_PATH, path);
 | 
				
			||||||
    {
 | 
					 | 
				
			||||||
        // When possible, use the cache:
 | 
					 | 
				
			||||||
        if (CACHE_GENERATOR_GODOT_DESTINATION_PATH_IS_LOADED)
 | 
					 | 
				
			||||||
            return CACHE_GENERATOR_GODOT_DESTINATION_PATH;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        var generatorGodotDestinationPath = string.Empty;
 | 
					 | 
				
			||||||
        try
 | 
					 | 
				
			||||||
        {
 | 
					 | 
				
			||||||
            // Get the database:
 | 
					 | 
				
			||||||
            await using var db = ProcessorMeta.ServiceProvider.GetRequiredService<DataContext>();
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
            // Check, if the setting is already set:
 | 
					 | 
				
			||||||
            if (await db.Settings.FirstOrDefaultAsync(n => n.Code == SettingNames.GENERATOR_GODOT_DESTINATION_PATH) is { } existingSetting)
 | 
					 | 
				
			||||||
            {
 | 
					 | 
				
			||||||
                generatorGodotDestinationPath = existingSetting.TextValue;
 | 
					 | 
				
			||||||
                return generatorGodotDestinationPath;
 | 
					 | 
				
			||||||
            }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
            // Does not exist, so create it:
 | 
					 | 
				
			||||||
            var setting = new Setting
 | 
					 | 
				
			||||||
            {
 | 
					 | 
				
			||||||
                Code = SettingNames.GENERATOR_GODOT_DESTINATION_PATH,
 | 
					 | 
				
			||||||
                TextValue = generatorGodotDestinationPath,
 | 
					 | 
				
			||||||
            };
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
            await db.Settings.AddAsync(setting);
 | 
					 | 
				
			||||||
            await db.SaveChangesAsync();
 | 
					 | 
				
			||||||
            return generatorGodotDestinationPath;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
        finally
 | 
					 | 
				
			||||||
        {
 | 
					 | 
				
			||||||
            CACHE_GENERATOR_GODOT_DESTINATION_PATH_IS_LOADED = true;
 | 
					 | 
				
			||||||
            CACHE_GENERATOR_GODOT_DESTINATION_PATH = generatorGodotDestinationPath;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
    
 | 
					 | 
				
			||||||
    public static async Task SetGeneratorGodotDestinationPath(string path)
 | 
					 | 
				
			||||||
    {
 | 
					 | 
				
			||||||
        // Update the cache:
 | 
					 | 
				
			||||||
        CACHE_GENERATOR_GODOT_DESTINATION_PATH = path;
 | 
					 | 
				
			||||||
        CACHE_GENERATOR_GODOT_DESTINATION_PATH_IS_LOADED = true;
 | 
					 | 
				
			||||||
        
 | 
					 | 
				
			||||||
        // Get the database:
 | 
					 | 
				
			||||||
        await using var db = ProcessorMeta.ServiceProvider.GetRequiredService<DataContext>();
 | 
					 | 
				
			||||||
        
 | 
					 | 
				
			||||||
        // Check, if the setting is already set:
 | 
					 | 
				
			||||||
        if (await db.Settings.FirstOrDefaultAsync(n => n.Code == SettingNames.GENERATOR_GODOT_DESTINATION_PATH) is { } existingSetting)
 | 
					 | 
				
			||||||
        {
 | 
					 | 
				
			||||||
            existingSetting.TextValue = path;
 | 
					 | 
				
			||||||
            await db.SaveChangesAsync();
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
        
 | 
					 | 
				
			||||||
        // Does not exist, so create it:
 | 
					 | 
				
			||||||
        else
 | 
					 | 
				
			||||||
        {
 | 
					 | 
				
			||||||
            var setting = new Setting
 | 
					 | 
				
			||||||
            {
 | 
					 | 
				
			||||||
                Code = SettingNames.GENERATOR_GODOT_DESTINATION_PATH,
 | 
					 | 
				
			||||||
                TextValue = path,
 | 
					 | 
				
			||||||
            };
 | 
					 | 
				
			||||||
            
 | 
					 | 
				
			||||||
            await db.Settings.AddAsync(setting);
 | 
					 | 
				
			||||||
            await db.SaveChangesAsync();
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
    #endregion
 | 
					    #endregion
 | 
				
			||||||
    
 | 
					    
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
		Reference in New Issue
	
	Block a user