Ejemplo n.º 1
0
        static int Main(string[] args)
        {
            try
            {
                using (AuthLogic.Disable())
                    using (CultureInfoUtils.ChangeCulture("en"))
                        using (CultureInfoUtils.ChangeCultureUI("en"))
                        {
                            DynamicLogicStarter.AssertRoslynIsPresent();
                            Starter.Start(UserConnections.Replace(Settings.Default.ConnectionString));

                            Console.WriteLine("..:: Welcome to Southwind Loading Application ::..");
                            Console.WriteLine("Database: {0}", Regex.Match(((SqlConnector)Connector.Current).ConnectionString, @"Initial Catalog\=(?<db>.*)\;").Groups["db"].Value);
                            Console.WriteLine();

                            if (args.Any())
                            {
                                switch (args.First().ToLower().Trim('-', '/'))
                                {
                                case "sql": SqlMigrationRunner.SqlMigrations(true); return(0);

                                case "csharp": SouthwindMigrations.CSharpMigrations(true); return(0);

                                case "load": Load(args.Skip(1).ToArray()); return(0);

                                default:
                                {
                                    SafeConsole.WriteLineColor(ConsoleColor.Red, "Unkwnown command " + args.First());
                                    Console.WriteLine("Examples:");
                                    Console.WriteLine("   sql: SQL Migrations");
                                    Console.WriteLine("   csharp: C# Migrations");
                                    Console.WriteLine("   load 1-4,7: Load processes 1 to 4 and 7");
                                    return(-1);
                                }
                                }
                            } //if(args.Any())

                            while (true)
                            {
                                Action action = new ConsoleSwitch <string, Action>
                                {
                                    { "N", NewDatabase },
                                    { "G", CodeGenerator.GenerateCodeConsole },
                                    { "SQL", SqlMigrationRunner.SqlMigrations },
                                    { "CS", () => SouthwindMigrations.CSharpMigrations(false), "C# Migrations" },
                                    { "S", Synchronize },
                                    { "L", () => Load(null), "Load" },
                                }.Choose();

                                if (action == null)
                                {
                                    return(0);
                                }

                                action();
                            }
                        }
            }
            catch (Exception e)
            {
                SafeConsole.WriteColor(ConsoleColor.DarkRed, e.GetType().Name + ": ");
                SafeConsole.WriteLineColor(ConsoleColor.Red, e.Message);
                SafeConsole.WriteLineColor(ConsoleColor.DarkRed, e.StackTrace.Indent(4));
                return(-1);
            }
        }
Ejemplo n.º 2
0
        static int Main(string[] args)
        {
            try
            {
                using (AuthLogic.Disable())
                    using (CultureInfoUtils.ChangeCulture("en"))
                        using (CultureInfoUtils.ChangeCultureUI("en"))
                        {
                            ConfigRoot = new ConfigurationBuilder()
                                         .SetBasePath(Directory.GetCurrentDirectory())
                                         .AddJsonFile("appsettings.json")
                                         .AddJsonFile($"appsettings.{Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT")}.json", true)
                                         .AddUserSecrets <Program>().Build();

                            var connectionString = ConfigRoot.GetConnectionString("ConnectionString");
                            Starter.Start(connectionString);

                            Console.WriteLine("..:: Welcome to Southwind Loading Application ::..");
                            Console.WriteLine("Database: {0}", Regex.Match(((SqlConnector)Connector.Current).ConnectionString, @"Initial Catalog\=(?<db>.*)\;").Groups["db"].Value);
                            Console.WriteLine();

                            if (args.Any())
                            {
                                switch (args.First().ToLower().Trim('-', '/'))
                                {
                                case "sql": SqlMigrationRunner.SqlMigrations(true); return(0);

                                case "csharp": SouthwindMigrations.CSharpMigrations(true); return(0);

                                case "load": Load(args.Skip(1).ToArray()); return(0);

                                default:
                                {
                                    SafeConsole.WriteLineColor(ConsoleColor.Red, "Unkwnown command " + args.First());
                                    Console.WriteLine("Examples:");
                                    Console.WriteLine("   sql: SQL Migrations");
                                    Console.WriteLine("   csharp: C# Migrations");
                                    Console.WriteLine("   load 1-4,7: Load processes 1 to 4 and 7");
                                    return(-1);
                                }
                                }
                            } //if(args.Any())

                            while (true)
                            {
                                Action action = new ConsoleSwitch <string, Action>
                                {
                                    { "N", NewDatabase },
                                    { "G", CodeGenerator.GenerateCodeConsole },
                                    { "SQL", SqlMigrationRunner.SqlMigrations },
                                    { "CS", () => SouthwindMigrations.CSharpMigrations(false), "C# Migrations" },
                                    { "S", Synchronize },
                                    { "L", () => Load(null), "Load" },
                                }.Choose();

                                if (action == null)
                                {
                                    return(0);
                                }

                                action();
                            }
                        }
            }
            catch (Exception e)
            {
                SafeConsole.WriteColor(ConsoleColor.DarkRed, e.GetType().Name + ": ");
                SafeConsole.WriteLineColor(ConsoleColor.Red, e.Message);
                SafeConsole.WriteLineColor(ConsoleColor.DarkRed, e.StackTrace.Indent(4));
                return(-1);
            }
        }