示例#1
0
 private static void ShowHelpText(CommandLineOptions options) {
     Console.Write(HelpText.AutoBuild(options));
 }
示例#2
0
        private static void DoReverseEngineer(
            CommandLineOptions options,
            DashingSettings dashingSettings,
            ReverseEngineerSettings reverseEngineerSettings,
            ConnectionStringSettings connectionString) {
            // overwrite the path with the default if necessary
            if (string.IsNullOrEmpty(options.Location)) {
                options.Location = dashingSettings.DefaultSavePath;
            }

            // if it is still empty, ...
            if (string.IsNullOrEmpty(options.Location) && options.ReverseEngineer) {
                throw new CatchyException("You must specify a location for generated files to be saved");
            }

            // require a generated namespace
            if (string.IsNullOrEmpty(reverseEngineerSettings.GeneratedNamespace)) {
                throw new CatchyException("You must specify a GeneratedNamespace in the Project ini file");
            }

            DatabaseSchema schema;
            var engineer = new Engineer(reverseEngineerSettings.ExtraPluralizationWords);

            var databaseReader = new DatabaseReader(connectionString.ConnectionString, connectionString.ProviderName);
            schema = databaseReader.ReadAll();
            var maps = engineer.ReverseEngineer(
                schema,
                new DialectFactory().Create(connectionString.ToSystem()),
                reverseEngineerSettings.GetTablesToIgnore(),
                consoleAnswerProvider,
                true);
            var reverseEngineer = new ModelGenerator();
            var sources = reverseEngineer.GenerateFiles(maps, schema, reverseEngineerSettings.GeneratedNamespace, consoleAnswerProvider);

            foreach (var source in sources) {
                File.WriteAllText(options.Location + "\\" + source.Key + ".cs", source.Value);
            }
        }
示例#3
0
 private static void TryFindIgnoreConfigSetting(CommandLineOptions options) {
     var directories = new[] { new DirectoryInfo(options.WeaveDir), new DirectoryInfo(Path.Combine(options.WeaveDir, 
         options.WeaveDir.LastIndexOf("bin", StringComparison.InvariantCultureIgnoreCase) >= options.WeaveDir.Length - 4 ? "../" : "../../")), };
     foreach (var directoryInfo in directories) {
         foreach (var fileInfo in directoryInfo.GetFiles().Where(fileInfo => fileInfo.Name.EndsWith(".config"))) {
             try {
                 var configMap = new ExeConfigurationFileMap();
                 configMap.ExeConfigFilename = fileInfo.FullName;
                 var config = ConfigurationManager.OpenMappedExeConfiguration(configMap, ConfigurationUserLevel.None);
                 if (config.AppSettings.Settings.AllKeys.Contains("dashing:ignorepeverify")) {
                     if (config.AppSettings.Settings["dashing:ignorepeverify"].Value.Equals("true", StringComparison.InvariantCultureIgnoreCase)) {
                         options.IgnorePeVerify = true;
                     }
                 }
             }
             catch {
                 // do nothing ... probably not the type of config file we're expecting
             }
         }
     }
 }
示例#4
0
        private static void ParseIni(
            CommandLineOptions options,
            out ConnectionStringSettings connectionStringSettings,
            out DashingSettings dashingSettings,
            out ReverseEngineerSettings reverseEngineerSettings) {
            var config = IniParser.Parse(options.ConfigPath);

            connectionStringSettings = new ConnectionStringSettings();
            connectionStringSettings = IniParser.AssignTo(config["Database"], connectionStringSettings);

            dashingSettings = new DashingSettings();
            dashingSettings = IniParser.AssignTo(config["Dashing"], dashingSettings);

            // fix path to dll to be avsolute path
            if (!Path.IsPathRooted(dashingSettings.PathToDll)) {
                dashingSettings.PathToDll = Path.Combine(Path.GetDirectoryName(options.ConfigPath), dashingSettings.PathToDll);
            }

            reverseEngineerSettings = new ReverseEngineerSettings();
            reverseEngineerSettings = IniParser.AssignTo(config["ReverseEngineer"], reverseEngineerSettings);
        }
示例#5
0
        private static void InnerMain(string[] args) {
            var options = new CommandLineOptions();

            if (!Parser.Default.ParseArguments(args, options)) {
                ShowHelpText(options);
                return;
            }

            isVerbose = options.Verbose;

            // weaving
            if (options.Weave) {
                if (string.IsNullOrWhiteSpace(options.WeaveDir)) {
                    throw new CatchyException("You must specify the directory to weave");
                }

                if (!options.IgnorePeVerify) {
                    TryFindIgnoreConfigSetting(options);
                }

                var task = new ExtendDomainTask {
                    LaunchDebugger = options.LaunchDebugger,
                    WeaveDir = options.WeaveDir,
                    Logger = new ConsoleLogger(options.Verbose),
                    IgnorePEVerify = options.IgnorePeVerify
                };
                if (!task.Execute()) {
                    throw new CatchyException("Weaving failed");
                }

                return;
            }

            // prevalidation
            if (string.IsNullOrWhiteSpace(options.ConfigPath)) {
                throw new CatchyException("You must specify a configuration path or a project name");
            }

            if (!File.Exists(options.ConfigPath)) {
                throw new CatchyException("Could not locate configuration file {0}", options.ConfigPath);
            }

            // dependency init
            consoleAnswerProvider = new ConsoleAnswerProvider("~" + Path.GetFileNameWithoutExtension(options.ConfigPath) + ".answers");

            // parse all of the configuration stuffs
            ConnectionStringSettings connectionStringSettings;
            DashingSettings dashingSettings;
            ReverseEngineerSettings reverseEngineerSettings;
            ParseIni(options, out connectionStringSettings, out dashingSettings, out reverseEngineerSettings);

            // postvalidation
            if (!File.Exists(dashingSettings.PathToDll)) {
                throw new CatchyException("Could not locate {0}", dashingSettings.PathToDll);
            }

            // load the configuration NOW and try to inherit its version of Dashing, Dapper, etc
            var configAssembly = Assembly.LoadFrom(dashingSettings.PathToDll);
            GC.KeepAlive(configAssembly);
            configObject = LoadConfiguration(configAssembly, dashingSettings, connectionStringSettings);

            // now decide what to do
            if (options.Script) {
                DoScript(options.Location, options.Naive, connectionStringSettings, dashingSettings, reverseEngineerSettings);
            }
            else if (options.Seed) {
                DoSeed(connectionStringSettings);
            }
            else if (options.Migration) {
                DoMigrate(options.Naive, connectionStringSettings, dashingSettings, reverseEngineerSettings);
            }
            else if (options.ReverseEngineer) {
                DoReverseEngineer(options, dashingSettings, reverseEngineerSettings, connectionStringSettings);
            }
            else {
                ShowHelpText(options);
            }
        }