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); }
public override void Read(ConsoleReadContext context, SelectEnumTaskParameter param) { var value = UtilConsole.SelectFromEnum(param.Label, param.EnumType, param.DefaultValue); if (param.DefaultValue.Equals(value) && param.CancelIfDefault) { context.IsCanceled = true; return; } context[param.Name] = value; }
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); } }