This commit is contained in:
2020-01-27 22:42:22 +00:00
parent 48b35e23a2
commit bb1a51af4a
2 changed files with 13 additions and 14 deletions

View File

@@ -546,7 +546,7 @@ namespace AyaNova.Biz
if (await LocaleExistsAsync(SourceLocaleName)) if (await LocaleExistsAsync(SourceLocaleName))
{ {
//If there are any validation errors, log in joblog and move on //If there are any validation errors, log in joblog and move on
JobsBiz.LogJobAsync(jobId, $"LocaleBiz::ImportV7Async -> - Locale \"{SourceLocaleName}\" already exists in database, can not import over an existing locale", ct); await JobsBiz.LogJobAsync(jobId, $"LocaleBiz::ImportV7Async -> - Locale \"{SourceLocaleName}\" already exists in database, can not import over an existing locale", ct);
return false; return false;
} }

View File

@@ -1,4 +1,4 @@
using System; using System.Threading.Tasks;
using System.IO; using System.IO;
using Newtonsoft.Json.Linq; using Newtonsoft.Json.Linq;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
@@ -41,7 +41,7 @@ namespace AyaNova.Biz
/// Prime the locales /// Prime the locales
/// This may be called before there are any users on a fresh db boot /// This may be called before there are any users on a fresh db boot
/// </summary> /// </summary>
public static void PrimeLocales() public static async Task PrimeLocales()
{// {//
@@ -53,19 +53,18 @@ namespace AyaNova.Biz
} }
ImportLocale(ResourceFolderPath, "en"); await ImportLocale(ResourceFolderPath, "en");
ImportLocale(ResourceFolderPath, "es"); await ImportLocale(ResourceFolderPath, "es");
ImportLocale(ResourceFolderPath, "fr"); await ImportLocale(ResourceFolderPath, "fr");
ImportLocale(ResourceFolderPath, "de"); await ImportLocale(ResourceFolderPath, "de");
//Ensure locales are present, not missing any keys and that there is a server default locale that exists //Ensure locales are present, not missing any keys and that there is a server default locale that exists
LocaleBiz lb = LocaleBiz.GetBizInternal(ServiceProviderProvider.DBContext, 1, AuthorizationRoles.OpsAdminFull); LocaleBiz lb = LocaleBiz.GetBizInternal(ServiceProviderProvider.DBContext, 1, AuthorizationRoles.OpsAdminFull);
lb.ValidateLocalesAsync(); await lb.ValidateLocalesAsync();
} }
private static void ImportLocale(string resourceFolderPath, string localeCode) private static async Task ImportLocale(string resourceFolderPath, string localeCode)
{ {
AyContext ct = ServiceProviderProvider.DBContext; AyContext ct = ServiceProviderProvider.DBContext;
var LocalePath = Path.Combine(resourceFolderPath, $"{localeCode}.json"); var LocalePath = Path.Combine(resourceFolderPath, $"{localeCode}.json");
@@ -74,7 +73,7 @@ namespace AyaNova.Biz
throw new System.Exception($"E1013: stock locale file \"{localeCode}\" not found where expected: \"{LocalePath}\", installation damaged?"); throw new System.Exception($"E1013: stock locale file \"{localeCode}\" not found where expected: \"{LocalePath}\", installation damaged?");
} }
JObject o = JObject.Parse(File.ReadAllText(LocalePath)); JObject o = JObject.Parse(await File.ReadAllTextAsync(LocalePath));
Locale l = new Locale(); Locale l = new Locale();
l.Name = localeCode; l.Name = localeCode;
@@ -89,8 +88,8 @@ namespace AyaNova.Biz
l.LocaleItems.Add(new LocaleItem() { Key = key, Display = display });//, Locale = l l.LocaleItems.Add(new LocaleItem() { Key = key, Display = display });//, Locale = l
} }
ct.Locale.Add(l); await ct.Locale.AddAsync(l);
ct.SaveChanges(); await ct.SaveChangesAsync();
} }