public bool UpdateLanguage(string language) { if (_configData == null || _configDataJsonNode == null) { _errorOutput.WriteLine("Error: Database not loaded"); return(false); } if (!_configDataJsonNode.Languages.Contains(language)) { _errorOutput.WriteLine("Error: Language not found"); return(false); } if (!_configDataTranslateJsonNodes.TryGetValue(language, out var translationJsonNode)) { _errorOutput.WriteLine("Error: Language json not found"); return(false); } var updatedJsonNode = ConfigDatabase.Build(_configDataJsonNode, translationJsonNode); var updatedTranslationJsonNode = ConfigDatabase.BuildTranslateNode(updatedJsonNode, _networkSourceSettings); using var transation = ConfigSaveTransaction.Create(updatedTranslationJsonNode, _fileSourceSettings.DatabaseTranslateFilePath(language)); if (!transation.Apply()) { _errorOutput.WriteLine("Error: Failed update language file"); return(false); } _configDataTranslateJsonNodes[language] = updatedTranslationJsonNode; transation.Commit(); return(true); }
public bool Init() { if (_configData != null || _configDataJsonNode != null) { _errorOutput.WriteLine("Error: Database already loaded"); return(false); } _configDataJsonNode = ConfigDatabase.CreateNode(_networkSourceSettings); _configData = ConfigDatabase.Build(_configDataJsonNode); return(true); }
public ConfigData?GetLanguageData(string language) { if (_configData == null || _configDataJsonNode == null) { _errorOutput.WriteLine("Error: Database not loaded"); return(null); } if (!_configDataTranslateJsonNodes.TryGetValue(language, out var translationJsonNode)) { _errorOutput.WriteLine("Error: Language not found"); return(null); } return(ConfigDatabase.Build(_configDataJsonNode, translationJsonNode)); }
public bool LoadLocal() { Unload(); try { _configDataJsonNode = ConfigDatabase.LoadFromFile <ConfigDataJsonNode>(_fileSourceSettings.DatabaseFilePath); foreach (var language in _configDataJsonNode.Languages) { var path = _fileSourceSettings.DatabaseTranslateFilePath(language); _configDataTranslateJsonNodes.Add(language, ConfigDatabase.LoadFromFile <ConfigDataTranslateJsonNode>(path)); } _configData = ConfigDatabase.Build(_configDataJsonNode); } catch (Exception e) { Unload(); _errorOutput.WriteLine("Error: Failed load database - " + e.Message); return(false); } return(true); }
public bool LoadNetwork() { Unload(); try { _configDataJsonNode = ConfigDatabase.LoadFromUrlAsync <ConfigDataJsonNode>(_httpClient, _networkSourceSettings.DatabaseUrl).GetAwaiter().GetResult(); foreach (var language in _configDataJsonNode.Languages) { var url = _networkSourceSettings.DatabaseTranslateUrl(language); _configDataTranslateJsonNodes.Add(language, ConfigDatabase.LoadFromUrlAsync <ConfigDataTranslateJsonNode>(_httpClient, url).GetAwaiter().GetResult()); } _configData = ConfigDatabase.Build(_configDataJsonNode); } catch (Exception e) { Unload(); _errorOutput.WriteLine("Error: Failed load database - " + e.Message); return(false); } return(true); }