Example #1
0
        public override void Read(ConsoleReadContext context, FileTaskParameter param)
        {
            var value = UtilConsole.ReadFile(param.Label, param.ShouldExist);

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

            context[param.Name] = value;
        }
Example #2
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);
            }
        }