Exemple #1
0
        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);
        }
Exemple #2
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);
        }
Exemple #3
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;
        }
Exemple #4
0
        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);
        }
Exemple #5
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),
            });
        }
Exemple #6
0
        public override void Read(ConsoleReadContext context, PasswordTaskParameter param)
        {
            string value;

            while (true)
            {
                value = UtilConsole.ReadPassword(param.Label, param.CharMask);
                if (string.IsNullOrEmpty(value) || param.CancelString.Equals(value, StringComparison.OrdinalIgnoreCase))
                {
                    context.IsCanceled = true;
                    return;
                }
                if (value.Length < param.MinLength)
                {
                    UtilConsole.WriteWarning("Password length too short");
                    continue;
                }
                if (value.Length > param.MaxLength)
                {
                    UtilConsole.WriteWarning("Password length too long");
                    continue;
                }

                break;
            }

            context[param.Name] = value;
        }
Exemple #7
0
        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);
        }
Exemple #8
0
        public override void LoadFromConsole(DateRangeModel columnModel)
        {
            var min = UtilConsole.ReadDate("min date (without time)");
            var max = UtilConsole.ReadDate("max date (without time)");

            columnModel.MinDate = min.Date;
            columnModel.MaxDate = max.Date;
        }
Exemple #9
0
        public override void LoadFromConsole(DoubleRangeModel columnModel)
        {
            var min = UtilConsole.ReadDouble("min");
            var max = UtilConsole.ReadDouble("max");

            columnModel.Min = min;
            columnModel.Max = max;
        }
Exemple #10
0
        private void StartTaskExecutionMode(ExecuteTaskOptions options)
        {
            _consoleTaskExecutor.Execute(options.Task, options.TaskParams.ToArray());

            if (options.Pause)
            {
                UtilConsole.Pause();
            }
        }
Exemple #11
0
        public override void Read(ConsoleReadContext context, IntegerTaskParameter param)
        {
            var value = UtilConsole.ReadInteger(param.Label, param.MinValue, param.MaxValue, param.DefaultValue);

            if (value == null)
            {
                context.IsCanceled = true;
                return;
            }

            context[param.Name] = value.Value;
        }
Exemple #12
0
        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;
        }
Exemple #13
0
        public override void Read(ConsoleReadContext context, FolderTaskParameter param)
        {
            var value = UtilConsole.ReadFolder(param.Label, param.ShouldExist);

            if (string.IsNullOrEmpty(value))
            {
                context.IsCanceled = true;
                return;
            }

            context[param.Name] = value;
        }
Exemple #14
0
        public override void Read(ConsoleReadContext context, SelectStringTaskParameter param)
        {
            var value = UtilConsole.SelectFromList(param.List, param.Label, param.ExitValue, param.DefaultValue);

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

            context[param.Name] = value;
        }
Exemple #15
0
        public override void LoadFromConsole(DateTimeRangeModel columnModel)
        {
            var minDate = UtilConsole.ReadDate("min date (without time)");
            var maxDate = UtilConsole.ReadDate("max date (without time)");
            var minTime = UtilConsole.ReadTime("min time");
            var maxTime = UtilConsole.ReadTime("max time");

            columnModel.MinDate = minDate.Date;
            columnModel.MaxDate = maxDate.Date;
            columnModel.MinTime = UtilDataGeneration.NeutralDate.Add(minTime);
            columnModel.MaxTime = UtilDataGeneration.NeutralDate.Add(maxTime);
        }
Exemple #16
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;
        }
Exemple #17
0
        public void Execute(ConsoleModeContext ctx)
        {
            SetupLanguage();
            _tasks = _consoleTaskLocator.GetTaskHolderList();
            ctx.TaskList.Clear();
            ctx.TaskList.AddRange(_tasks);
            ctx.TaskList.ForEach(th => th.Task.Context = ctx);

            var currentTasks = _tasks;
            var pageInfo     = SetupPageInfo(currentTasks);

            _lastTask = null;
            _lastData = null;

            while (true)
            {
                UtilConsole.Clear();
                ShowWelcomeMessage();
                ShowTasks(currentTasks, pageInfo);
                Console.Write("Select task :>");
                var opt = Console.ReadLine();
                if (string.IsNullOrWhiteSpace(opt))
                {
                    currentTasks = _tasks;
                    pageInfo     = SetupPageInfo(currentTasks);
                    continue;
                }

                CommonTaskHolder selectedTask = null;

                var askForData = true;
                if (opt == "!")
                {
                    if (_lastTask != null)
                    {
                        selectedTask = _lastTask;
                    }
                }
                else if (opt == "!!")
                {
                    if (_lastTask != null)
                    {
                        selectedTask = _lastTask;
                    }
                    askForData = false;
                }
                else if (Regex.IsMatch(opt, "^!\\d+$"))
                {
                    var favoriteMacroKey = opt[1..];
Exemple #18
0
        public override void LoadFromConsole(IntegerRangeModel columnModel)
        {
            var min = UtilConsole.ReadInteger("min");

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

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

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

            columnModel.Min = min.Value;
            columnModel.Max = max.Value;
        }
Exemple #19
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);
        }
Exemple #20
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;
        }
Exemple #21
0
        private Task StartWebMode(WebOptions options)
        {
            var config = new LocalWebServerConfig {
                Port = options.Port
            };
            var tokenSource = new CancellationTokenSource();
            var token       = new CancellationToken();

            /*var task = */ _localWebServer.RunAsync(config, token);
            UtilConsole.WriteSuccess("Local server started. Press <Enter> to stop...");

            if (options.OpenWindow)
            {
                var url = $"http://localhost:{config.Port}";
                UtilSystem.OpenUrl(url);
            }

            Console.ReadLine();
            Console.WriteLine("Stopping local server...");
            _localWebServer.Stop();
            tokenSource.Cancel();
            return(Task.CompletedTask);
        }
Exemple #22
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);
        }
Exemple #23
0
 public void WriteSuccess(string input)
 {
     UtilConsole.WriteSuccess(input);
 }
Exemple #24
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);
            }
        }
 static void Init()
 {
     // Get existing open window if one exist, otherwise create a new one
     window = (UtilConsole)EditorWindow.GetWindow(typeof(UtilConsole));
 }
Exemple #26
0
        public override void LoadFromConsole(TemplateModel columnModel)
        {
            var template = UtilConsole.ReadString("template");

            columnModel.Template = template;
        }
Exemple #27
0
 public void WriteError(string input)
 {
     UtilConsole.WriteError(input);
 }