Пример #1
0
        static int Main(string[] args)
        {
            if (args == null || args.Length == 0)
            {
                return(ExitCode.InvalidArguments);
            }

            try
            {
                if (args[0] == CommandType.AddMigration)
                {
                    var commandParams = AddMigrationParams.FromArgumentsArray(args);
                    return(new AddMigrationExecutor().Run(commandParams));
                }
                else if (args[0] == CommandType.ScriptMigration)
                {
                    var commandParams = ScriptMigrationParams.FromArgumentsArray(args);
                    return(new ScriptMigrationExecutor().Run(commandParams));
                }
                else if (args[0] == CommandType.FindDbContextSubtypes)
                {
                    var commandParams = FindDbContextSubtypeParams.FromArgumentsArray(args);
                    var types         = TypeFinder.GetDbContextTypeFullNamesFromAssebly(commandParams.AssemblyFileName);
                    return(writeResult(types));
                }
                else if (args[0] == CommandType.FindMigrationSubtypes)
                {
                    var commandParams = FindMigrationSubtypeParams.FromArgumentsArray(args);
                    var types         = TypeFinder.GetMigrationByDbContextFromAssebly(commandParams.AssemblyFileName);
                    return(writeResult(types));
                }
            }
            catch (InvalidOperationException)
            {
                return(ExitCode.CanNotFindDbContext);
            }
            catch (FileNotFoundException e)
            {
                LogException(e);
                return(ExitCode.CanNotFindFile);
            }
            catch (ArgumentException e)
            {
                LogException(e);
                return(ExitCode.InvalidArguments);
            }
            catch (Exception e)
            {
                LogException(e);
                return(ExitCode.Exception);
            }

            return(ExitCode.InvalidCommand);
        }