Example #1
0
        private void BuildAutoConverter(XmlNode autoConverterNode)
        {
            if (!autoConverterNode.Attributes.TryGetValueAsString("Name", out String converterName, SmartSqlConfig.Properties))
            {
                throw new SmartSqlException("AutoConverter.Name can not be null.");
            }

            if (!autoConverterNode.Attributes.TryGetValueAsBoolean("Default", out bool isDefault, SmartSqlConfig.Properties))
            {
                isDefault = false;
            }

            var tokenizerXPath = $"{CONFIG_PREFIX}:Tokenizer";
            var tokenizerNode  = autoConverterNode.SelectSingleNode(tokenizerXPath, XmlNsManager);

            if (tokenizerNode == null)
            {
                throw new SmartSqlException("AutoConverter.Tokenizer can not be null");
            }

            var tokenizer = BuildTokenizer(tokenizerNode);

            var wordsConverterXPath = $"{CONFIG_PREFIX}:Converter";
            var wordsConverterNode  = autoConverterNode.SelectSingleNode(wordsConverterXPath, XmlNsManager);

            if (wordsConverterNode == null)
            {
                throw new SmartSqlException("AutoConverter.Converter can not be null");
            }

            var wordsConverter = BuildWordsConverter(wordsConverterNode);

            var autoConverter = new AutoConverter.AutoConverter(converterName, tokenizer, wordsConverter);

            SmartSqlConfig.AutoConverters.Add(autoConverter.Name, autoConverter);
            if (isDefault)
            {
                SmartSqlConfig.DefaultAutoConverter = autoConverter;
            }
        }
Example #2
0
        // todo: not impl
        protected override void BuildAutoConverters()
        {
            if (_configOptions.AutoConverterBuilders == null || !_configOptions.AutoConverterBuilders.Any())
            {
                return;
            }

            foreach (var autoConverterBuilder in _configOptions.AutoConverterBuilders)
            {
                if (String.IsNullOrEmpty(autoConverterBuilder.Name))
                {
                    throw new SmartSqlException("AutoConverterBuilder.Name can not be null");
                }

                if (String.IsNullOrEmpty(autoConverterBuilder.TokenizerName))
                {
                    throw new SmartSqlException("AutoConverterBuilder.TokenizerName can not be null");
                }

                if (String.IsNullOrEmpty(autoConverterBuilder.WordsConverterName))
                {
                    throw new SmartSqlException("AutoConverterBuilder.WordsConverterName can not be null");
                }

                var tokenizer      = _tokenizerBuilder.Build(autoConverterBuilder.TokenizerName, autoConverterBuilder.TokenizerProperties);
                var wordsConverter = _wordsConverterBuilder.Build(autoConverterBuilder.WordsConverterName, autoConverterBuilder.WordsConverterProperties);

                var autoConverter = new AutoConverter.AutoConverter(autoConverterBuilder.Name, tokenizer, wordsConverter);

                SmartSqlConfig.AutoConverters.Add(autoConverter.Name, autoConverter);
                if (autoConverterBuilder.IsDefault)
                {
                    SmartSqlConfig.DefaultAutoConverter = autoConverter;
                }
            }
        }