private bool GetInputForNewFile(IDictionary <string, object> result) { Console.WriteLine("First, we are going to add column definitions..."); var definitionList = new List <ColumnModel>(); var sourceList = new List <ItemSourceModel>(); result["columns"] = definitionList; result["sources"] = sourceList; if (!ReadColumnDefinitions(definitionList)) { return(false); } var readSources = UtilConsole.ReadBool("Add external sources to the definition file?"); if (readSources == null || readSources == false) { return(true); } if (!ReadSourceDefinition(sourceList)) { return(false); } return(true); }
private static bool ReadSourceDefinition(List <ItemSourceModel> sourceList) { var i = 0; while (true) { Console.WriteLine($"External item source # {i + 1}"); var def = CreateSourceDefinition(); if (def == null) { continue; } sourceList.Add(def); i++; var shouldContinue = UtilConsole.ReadBool("Continue adding sources?", true); if (shouldContinue == null) { return(false); } if (!shouldContinue.Value) { break; } } return(true); }
private bool ReadColumnDefinitions(List <ColumnModel> columnList) { var i = 0; while (true) { Console.WriteLine($"Column # {i + 1}"); var def = CreateColumnDefinition(); if (def == null) { continue; } columnList.Add(def); i++; var shouldContinue = UtilConsole.ReadBool("Continue adding columns?", true); if (shouldContinue == null) { return(false); } if (!shouldContinue.Value) { break; } } return(true); }
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; }
public override void Read(ConsoleReadContext context, BoolTaskParameter param) { var value = UtilConsole.ReadBool(param.Label, param.DefaultValue); if (value == null) { context.IsCanceled = true; return; } context[param.Name] = value.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); } }