コード例 #1
0
        public bool AddLanguage(string language)
        {
            if (_configData == null || _configDataJsonNode == null)
            {
                _errorOutput.WriteLine("Error: Database not loaded");
                return(false);
            }
            if (_configDataJsonNode.Languages.Contains(language))
            {
                _errorOutput.WriteLine("Error: Language alreaady exist");
                return(false);
            }
            string translationJsonPath    = _fileSourceSettings.DatabaseTranslateFilePath(language);
            var    newTranslationJsonNode = ConfigDatabase.LoadFromFile <ConfigDataTranslateJsonNode>(translationJsonPath);

            ConfigDataJsonNode.Builder builder = new ConfigDataJsonNode.Builder(_configDataJsonNode);
            builder.Languages.Add(language);
            var updatedJsonNode = builder.Build();

            using var transation = ConfigSaveTransaction.Create(updatedJsonNode, _fileSourceSettings.DatabaseFilePath);
            if (!transation.Apply())
            {
                _errorOutput.WriteLine("Error: Failed add language to list");
                return(false);
            }
            _configDataTranslateJsonNodes[language] = newTranslationJsonNode;
            _configDataJsonNode = updatedJsonNode;
            transation.Commit();
            return(true);
        }
コード例 #2
0
 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);
 }