예제 #1
0
        public override void LoadFromConsole(RandomPatternModel columnModel)
        {
            while (true)
            {
                var key   = UtilConsole.ReadString("Name for this pattern");
                var value = UtilConsole.ReadString("Allowed characters for this pattern");
                columnModel.Patterns.Add(key, value);

                var readBool = UtilConsole.ReadBool("Continue adding pattern sources?");
                if (readBool == null || readBool == false)
                {
                    break;
                }

                Console.WriteLine();
                Console.WriteLine("Current pattern sources:");
                foreach (var p in columnModel.Patterns)
                {
                    Console.WriteLine("{0}: {1}", p.Key, p.Value);
                }
            }

            var pattern = UtilConsole.ReadString("template");

            columnModel.Template = pattern;
        }
예제 #2
0
        public override IList <TaskParameter> GetTaskParameterDefinition()
        {
            bool reader(ConsoleReadContext ctx)
            {
                IDictionary <string, object> result = new Dictionary <string, object>();
                var file = UtilConsole.ReadString("Target file. Press <enter> to use a default name");

                if (string.IsNullOrEmpty(file))
                {
                    var filename = Guid.NewGuid() + ".data-gen.json";
                    file = Path.Combine(Environment.CurrentDirectory, filename);
                    UtilConsole.ColorWriteLine(ConsoleColor.DarkYellow, "  Target file would be {0}", file);
                }

                if (!GetInputForNewFile(result))
                {
                    return(false);
                }
                result[FILE] = file;
                return(true);
            }

            return(new List <TaskParameter>
            {
                new CustomConsoleTaskParameter(reader),
            });
        }
예제 #3
0
        private ColumnModel CreateColumnDefinition()
        {
            var colName = UtilConsole.ReadString("Column name");

            var dataType = UtilConsole.SelectFromEnum("Data type", DataType.None);

            if (dataType == DataType.None)
            {
                return(null);
            }

            var sourceDic = new Dictionary <DataType, List <ColumnDefinitionType> >
            {
                {
                    DataType.Integer,
                    new List <ColumnDefinitionType>
                    {
                        ColumnDefinitionType.IntegerRange, ColumnDefinitionType.DatabaseQuery
                    }
                },
                {
                    DataType.Double,
                    new List <ColumnDefinitionType>
                    {
                        ColumnDefinitionType.DoubleRange, ColumnDefinitionType.DatabaseQuery
                    }
                },
                {
                    DataType.DateTime,
                    new List <ColumnDefinitionType>
                    {
                        ColumnDefinitionType.DateRange, ColumnDefinitionType.DateTimeRange,
                        ColumnDefinitionType.DatabaseQuery
                    }
                },
                {
                    DataType.String,
                    new List <ColumnDefinitionType>
                    {
                        ColumnDefinitionType.RandomPattern, ColumnDefinitionType.RandomChars,
                        ColumnDefinitionType.Template, ColumnDefinitionType.DatabaseQuery
                    }
                },
                { DataType.Guid, new List <ColumnDefinitionType> {
                      ColumnDefinitionType.Guid
                  } }
            };
            var sourceList         = sourceDic[dataType];
            var sourceListAsString = sourceList.Select(itm => itm.ToString()).ToList();
            var sourceTypeAsString = UtilConsole.SelectFromList(sourceListAsString, "Select generator source");
            var sourceType         = UtilEnum.Get <ColumnDefinitionType>(sourceTypeAsString);

            var def    = _columnModelFactory.GetInstance(sourceType);
            var loader = _consoleLoaderFactory.GetInstance(sourceType);

            def.Name = colName;
            loader.LoadFromConsole(def);

            return(def);
        }
예제 #4
0
        public override void Read(ConsoleReadContext context, StringTaskParameter param)
        {
            var value = UtilConsole.ReadString(param.Label, param.DefaultValue,
                                               param.CancelString, param.RegularExpression,
                                               param.MinLength, param.MaxLength);

            if (string.IsNullOrEmpty(value) && !param.AllowEmpty)
            {
                context.IsCanceled = true;
                return;
            }

            context[param.Name] = value;
        }
예제 #5
0
        private static string ReplaceParameters(string json, ConsoleModeContext context)
        {
            var matches = Regex.Matches(json, @"@\{([a-zA-Z0-9_]+)\}");

            foreach (Match match in matches)
            {
                var varName = match.Groups[1].Value;
                if (!context.ExtendedInfo.ContainsKey(varName))
                {
                    var value = UtilConsole.ReadString(string.Format("Value for '{0}'", varName));
                    context.ExtendedInfo[varName] = value;
                }
            }

            foreach (var itm in context.ExtendedInfo)
            {
                json = Regex.Replace(json, "@{" + itm.Key + "}", itm.Value.ToString());
            }

            return(json);
        }
예제 #6
0
        public override void LoadFromConsole(RandomCharsModel columnModel)
        {
            var allowedChars = UtilConsole.ReadString("allowed chars");

            var min = UtilConsole.ReadInteger("min length");

            if (min == null)
            {
                throw new ApplicationException("Aborted");
            }

            var max = UtilConsole.ReadInteger("max length");

            if (min == null)
            {
                throw new ApplicationException("Aborted");
            }

            columnModel.AllowedChars = allowedChars;
            columnModel.MinLength    = min.Value;
            columnModel.MaxLength    = max.Value;
        }
예제 #7
0
        public string GetSetting(string key, bool askUserIfNotFound = false)
        {
            var value = GetValue(CollectionValues.Settings, key);

            if (value != Definitions.ValueNotFound)
            {
                return(value);
            }
            if (!askUserIfNotFound)
            {
                return(null);
            }

            var innerValue = UtilConsole.ReadString(string.Format("Setting {0} not found. Setup {0}:", key));

            if (innerValue == "")
            {
                return(null);
            }

            AddConfigValue(CollectionValues.Settings, key, innerValue);
            return(value);
        }
예제 #8
0
        private static ItemSourceModel CreateSourceDefinition()
        {
            var sourceName = UtilConsole.ReadString("Source name");

            if (sourceName == null)
            {
                return(null);
            }

            var sourceType = UtilConsole.SelectFromEnum("Source type", ItemSourceType.None);

            if (sourceType == ItemSourceType.None)
            {
                return(null);
            }

            switch (sourceType)
            {
            case ItemSourceType.Inline:
                var i = 0;
                HashSet <string> options = new();
                while (true)
                {
                    var option = UtilConsole.ReadString($"Option # {i}");
                    options.Add(option);

                    var shouldContinue = UtilConsole.ReadBool("Continue adding options?", true);
                    if (shouldContinue == null)
                    {
                        return(null);
                    }
                    if (!shouldContinue.Value)
                    {
                        break;
                    }
                }

                return(new InlineSourceModel {
                    Name = sourceName, Content = options.Cast <object>().ToList()
                });

            case ItemSourceType.File:
                var props      = new Dictionary <string, string>();
                var sourcePath = UtilConsole.ReadFile("Source file");
                if (sourcePath == null)
                {
                    return(null);
                }
                var sourceFormat = UtilConsole.SelectFromEnum("Source format", ItemSourceFormat.None);
                if (sourceFormat == ItemSourceFormat.None)
                {
                    return(null);
                }
                if (sourceFormat == ItemSourceFormat.JsonArrayOfObjects)
                {
                    var propName = UtilConsole.ReadString("Property name");
                    if (propName == null)
                    {
                        return(null);
                    }
                    props["propertyName"] = propName;
                }

                return(new FileSourceModel
                {
                    Name = sourceName, Path = sourcePath, Format = sourceFormat, Props = props
                });

            case ItemSourceType.Query:
                var sourceProvider = UtilConsole.SelectFromEnum("Source format", DatabaseEngine.None);
                if (sourceProvider == DatabaseEngine.None)
                {
                    return(null);
                }
                var sourceConnection = UtilConsole.ReadString("Connection string");
                if (sourceConnection == null)
                {
                    return(null);
                }
                var sourceQuery = UtilConsole.ReadString("Query");
                if (sourceQuery == null)
                {
                    return(null);
                }

                return(new QuerySourceModel
                {
                    Name = sourceName, ProviderType = sourceProvider, ConnectionString = sourceConnection,
                    Query = sourceQuery
                });

            default:
                return(null);
            }
        }
예제 #9
0
        public override void LoadFromConsole(TemplateModel columnModel)
        {
            var template = UtilConsole.ReadString("template");

            columnModel.Template = template;
        }