Exemple #1
0
        public bool RemoveLanguage(string language, bool deleteFile)
        {
            using var trasactionGroup = new TransactionGroup(2);
            if (deleteFile)
            {
                string translationJsonPath = _fileSourceSettings.DatabaseTranslateFilePath(language);
                if (File.Exists(translationJsonPath))
                {
                    trasactionGroup.Add(DeleteFileTransaction.Create(translationJsonPath));
                }
            }
            var updatedJsonNode = _configDataJsonNode;

            if (updatedJsonNode != null && updatedJsonNode.Languages.Contains(language))
            {
                var builder = new ConfigDataJsonNode.Builder(updatedJsonNode);
                builder.Languages.Remove(language);
                updatedJsonNode = builder.Build();
                trasactionGroup.Add(ConfigSaveTransaction.Create(updatedJsonNode, _fileSourceSettings.DatabaseFilePath));
            }
            if (!trasactionGroup.Apply())
            {
                _errorOutput.WriteLine("Error: Failed remove language");
                return(false);
            }
            _configDataTranslateJsonNodes.Remove(language);
            _configDataJsonNode = updatedJsonNode;
            trasactionGroup.Commit();
            return(true);
        }
Exemple #2
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);
        }
Exemple #3
0
        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);
        }
Exemple #4
0
        public bool CreateLanguage(string language)
        {
            if (_configData == null || _configDataJsonNode == null ||
                _configDataJsonNode.Languages.Contains(language))
            {
                _errorOutput.WriteLine("Error: Database not loaded");
                return(false);
            }
            if (_configDataJsonNode.Languages.Contains(language))
            {
                _errorOutput.WriteLine("Error: Language name already exist");
                return(false);
            }
            string translationJsonPath = _fileSourceSettings.DatabaseTranslateFilePath(language);

            if (File.Exists(translationJsonPath))
            {
                _errorOutput.WriteLine("Error: Language folder already exist");
                return(false);
            }
            var newTranslationJsonNode = ConfigDatabase.BuildTranslateNode(_configData, _networkSourceSettings);

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

            Directory.CreateDirectory(Path.GetDirectoryName(translationJsonPath));
            using var trasactionGroup = new TransactionGroup(2);
            trasactionGroup.Add(ConfigSaveTransaction.Create(newTranslationJsonNode, translationJsonPath));
            trasactionGroup.Add(ConfigSaveTransaction.Create(updatedJsonNode, _fileSourceSettings.DatabaseFilePath));
            if (!trasactionGroup.Apply())
            {
                _errorOutput.WriteLine("Error: Failed write language files");
                return(false);
            }
            _configDataTranslateJsonNodes[language] = newTranslationJsonNode;
            _configDataJsonNode = updatedJsonNode;
            trasactionGroup.Commit();
            return(true);
        }