예제 #1
0
 public override object Generate(FileSourceModel model)
 {
     if (_content == null || _content.Count == 0)
     {
         LoadSource(model);
     }
     return(UtilRandom.GetValueFromList(_content, Rnd));
 }
예제 #2
0
 public override object Generate(InlineSourceModel model)
 {
     if (model.Content == null || model.Content.Count == 0)
     {
         return("--ND--");
     }
     return(UtilRandom.GetValueFromList(model.Content, Rnd));
 }
예제 #3
0
        public override object Generate(ColumnModel model)
        {
            if (model is not TemplateModel specModel)
            {
                throw new ApplicationException("Mismatch in model " + model.ColumnDefinitionType +
                                               " inside generator " + GetType().Name);
            }
            if (string.IsNullOrEmpty(specModel.Template))
            {
                specModel.Template = $"{{{GenerationInfo.Sources[0].Name}}}";
            }

            var result = specModel.Template;

            if (_itemGenerators == null)
            {
                _itemGenerators = new Dictionary <string, GeneratorItemBase>();
            }

            while (true)
            {
                var regex = new Regex(@"\{([\w\-|]+)\}");
                var match = regex.Match(result);
                if (!match.Success)
                {
                    break;
                }

                var patternName = match.Groups[1].Value;
                if (patternName.Contains("|"))
                {
                    var sourceArray = patternName.Split('|');
                    patternName = UtilRandom.GetValueFromList(sourceArray, _rnd);
                    _logger.LogInformation($"patternName: {patternName}");
                }

                var sourceModel = GetSource(patternName);
                if (sourceModel == null)
                {
                    return("--ND--");
                }
                var itemGenerator = GetItemGenerator(_itemGenerators, sourceModel);
                var value         = itemGenerator.Generate(sourceModel);
                result = regex.Replace(result, value.ToString(), 1);
            }

            return(result);
        }