Beispiel #1
0
        static void Run(RunOptions options)
        {
            var logger = new ConsoleLogger(options.LogLevel);

            var operations = new List <Autofac.Core.IModule> {
                new JintTransformModule(),
                new RazorTransformModule(),
                new FluidTransformModule(),
                new HumanizeModule()
            };

            // todo: add lambda parser, etc

            using (var outer = new ConfigurationContainer(operations.ToArray()).CreateScope(options.ArrangementWithMode(), logger, options.GetParameters())) {
                var process = outer.Resolve <Process>();

                if (process.Errors().Any())
                {
                    Environment.Exit(1);
                }

                var providers = new List <Autofac.Core.IModule> {
                    new ConsoleProviderModule()
                };

                var output = process.GetOutputConnection();

                if (output == null || output.Provider == "internal" || output.Provider == "console")
                {
                    logger.SuppressConsole();
                    if (options.Format == "csv")
                    {
                        output.Provider    = "file"; // delimited file
                        output.Delimiter   = ",";
                        output.Stream      = true;
                        output.Synchronous = true; // got odd results when using Async methods
                        output.File        = "dummy.csv";
                        providers.Add(new CsvHelperProviderModule(Console.OpenStandardOutput()));
                    }
                    else
                    {
                        output.Provider = "json";
                        output.Stream   = true;
                        output.Format   = "json";
                        output.File     = "dummy.json";
                        providers.Add(new JsonProviderModule(Console.OpenStandardOutput()));
                    }
                }
                else
                {
                    providers.Add(new CsvHelperProviderModule());
                    providers.Add(new JsonProviderModule());
                }

                // PROVIDERS
                providers.Add(new AdoProviderModule());
                providers.Add(new BogusModule());
                providers.Add(new SqliteModule());
                providers.Add(new SqlServerModule());
                providers.Add(new PostgreSqlModule());
                providers.Add(new MySqlModule());
                providers.Add(new ElasticsearchModule());
                providers.Add(new RazorProviderModule());
                // solr

                var modules = providers.Union(operations).ToArray();

                using (var inner = new Container(modules).CreateScope(process, logger)) {
                    inner.Resolve <IProcessController>().Execute();
                }
            }
        }
Beispiel #2
0
        static void Run(RunOptions options)
        {
            var logger = new ConsoleLogger(options.LogLevel);

            var operations = new List <Autofac.Core.IModule> {
                new JintTransformModule(),
                new RazorTransformModule(),
                new FluidTransformModule(),
                new HumanizeModule(),
                new LambdaParserModule()
            };

            // todo: geoCode, etc

            using (var outer = new ConfigurationContainer(operations.ToArray()).CreateScope(options.ArrangementWithMode(), logger, options.GetParameters())) {
                var process = outer.Resolve <Process>();

                if (options.Mode != "default" && options.Mode != process.Mode)
                {
                    process.Mode = options.Mode;
                    process.Load();
                }

                if (process.Errors().Any())
                {
                    var context = new PipelineContext(logger, process);
                    context.Error("The configuration has errors.");
                    foreach (var error in process.Errors())
                    {
                        context.Error(error);
                    }
                    Environment.Exit(1);
                }

                var providers = new List <Autofac.Core.IModule> {
                    new ConsoleProviderModule()
                };

                var output = process.GetOutputConnection();

                if (output == null || output.Provider == "internal" || output.Provider == "console")
                {
                    logger.SuppressConsole();
                    if (options.Format == "csv")
                    {
                        output.Provider    = "file"; // delimited file
                        output.Delimiter   = ",";
                        output.Stream      = true;
                        output.Synchronous = true; // got odd results when using Async methods
                        output.File        = "dummy.csv";
                        providers.Add(new CsvHelperProviderModule(Console.OpenStandardOutput()));
                    }
                    else
                    {
                        output.Provider = "json";
                        output.Stream   = true;
                        output.Format   = "json";
                        output.File     = "dummy.json";
                        providers.Add(new JsonProviderModule(Console.OpenStandardOutput()));
                    }
                }
                else
                {
                    providers.Add(new CsvHelperProviderModule());
                    providers.Add(new JsonProviderModule());
                }

                // PROVIDERS
                providers.Add(new AdoProviderModule());
                providers.Add(new BogusModule());
                providers.Add(new SqliteModule());
                providers.Add(new SqlServerModule());
                providers.Add(new PostgreSqlModule());
                providers.Add(new MySqlModule());
                providers.Add(new ElasticsearchModule());
                providers.Add(new RazorProviderModule());
                providers.Add(new AwsCloudWatchProviderModule());
                providers.Add(new AmazonConnectProviderModule());
                providers.Add(new MailModule());
                // solr

                var modules = providers.Union(operations).ToArray();

                if (options.Mode.ToLower() == "schema")
                {
                    using (var inner = new Container(modules).CreateScope(process, logger)) {
                        process = new SchemaService(inner).GetProcess(process);
                        process.Connections.Clear();
                        Console.WriteLine(process.Serialize());
                        Environment.Exit(0);
                    }
                }
                else if (process.Entities.Count == 1 && !process.Entities[0].Fields.Any(f => f.Input))
                {
                    using (var inner = new Container(modules).CreateScope(process, logger)) {
                        if (new SchemaService(inner).Help(process))
                        {
                            process.Load();
                        }
                        else
                        {
                            Console.Error.WriteLine($"Unable to detect fields in {process.Entities[0].Name}.");
                            Environment.Exit(1);
                        }
                    }
                }

                using (var inner = new Container(modules).CreateScope(process, logger)) {
                    inner.Resolve <IProcessController>().Execute();
                }
            }
        }