Ejemplo n.º 1
0
        private static int Main(string[] args)
        {
            var services = new ServiceCollection();

            ConfigureServices(services);
            var serviceProvider = services.BuildServiceProvider();

            ConfigureLogging(serviceProvider);

            var logger = serviceProvider.GetService <ILogger <Program> >();

            var runner = new ShellRunner(serviceProvider);

            try
            {
                runner.LoadFile(args[0]);
                for (int i = 1; i < args.Length; i++)
                {
                    if (args[i].StartsWith("--"))
                    {
                        string name = args[i].Substring(2);
                        i++;
                        if (i >= args.Length)
                        {
                            break;
                        }
                        runner.Context.SetVariable(name, args[i]);
                    }
                    else if (args[i] == "/sqlconn")
                    {
                        i++;
                        if (i >= args.Length)
                        {
                            break;
                        }

                        string sqlconn = args[i];
                        runner.Context.SetDefaultConnection("sqlserver://" + sqlconn);
                    }
                }
            }
            catch (Exception err)
            {
                logger.LogError(err, "DBSH-00146 Error loading input DbShell script");
                return(1);
            }

            try
            {
                runner.Run();
            }
            catch (Exception err)
            {
                logger.LogError(err, "DBSH-00147 Error running process");
                return(2);
            }

            return(0);
        }