Example #1
0
        }//main

        private static int Run(string[] args)
        {
            //Read command line parameters
            UnpackArguments(args);
            if (_showHelp)
            {
                ShowHelp();
                Console.WriteLine();
                if (string.IsNullOrEmpty(_configFile))
                {
                    return(0);
                }
            }
            //get config file name
            if (string.IsNullOrEmpty(_configFile))
            {
                WriteError("Invalid arguments - missing config file parameter (/cfg:<file>).");
                ShowHelp();
                return(-1); //return error
            }
            if (!File.Exists(_configFile))
            {
                WriteError("Config file not found: " + _configFile);
                return(-1); //return error
            }
            //load config
            var xmlConfig = LoadConfig(_configFile);
            var fback     = new ConsoleProcessFeedback();

            //execute command
            switch (_command)
            {
            case "dbfirst":
                Console.WriteLine("COMMAND: dbfirst");
                Console.WriteLine("Generating entity definitions from the database...");
                var dbFirst       = new DbFirstProcessor(fback);
                var dbFirstConfig = new DbFirstConfig(xmlConfig);
                var success       = dbFirst.GenerateEntityModelSources(dbFirstConfig);
                return(success ? 0 : -1);

            case "dbupdate":
                Console.WriteLine("COMMAND: dbupdate");
                Console.WriteLine("Generating DB update scripts...");
                var dbUpdate = new DbUpdateProcessor(fback);
                var ok       = dbUpdate.GenerateScripts(xmlConfig);
                return(ok ? 0 : -1);

            default:
                WriteError(Util.SafeFormat(" Command type arg ({0}) is invalid or missing. Expected 'dbfirst' or 'dbupdate'. ", _command));
                ShowHelp();
                return(-1);
            }
        }
        public void TestDbToEntitiesSourceGenerator()
        {
            Startup.BooksApp.LogTestStart();

            var xmlConfigTemplate =
                @"<Settings>
  <Provider>@Provider@</Provider>
  <ConnectionString>@ConnString@</ConnectionString>
  <OutputPath>_Generated_BookEntities_@[email protected]</OutputPath><!-- Will go into bin folder. -->
  <Namespace>Vita.Samples.BooksGenerated</Namespace>
  <AppClassName>BookStoreApp</AppClassName>
  <Schemas>books</Schemas>
  <Options>Binary16AsGuid, BinaryKeysAsGuid, AutoOnGuidPrimaryKeys, AddOneToManyLists,GenerateConsoleAppCode,UtcDates</Options>
  <AutoValues>CreatedOn:CreatedOn</AutoValues>
  <ForceDataTypes>@ForceDataTypes@</ForceDataTypes> <!-- for SQLite -->
  <TableNames></TableNames> <!-- Explicit table list - use it in Oracle, we add it directly in config object below -->
</Settings>
";
            var sqliteForceTypes = "CreatedOn:System.DateTime,CreatedIn:System.Guid,UpdatedIn:System.Guid";
            var forceTypes       = Startup.ServerType == DbServerType.SQLite? sqliteForceTypes : string.Empty;
            var driver           = Startup.Driver;
            var xml = xmlConfigTemplate
                      .Replace("@Provider@", Startup.ServerType.ToString())
                      .Replace("@ConnString@", Startup.CurrentConfig.ConnectionString)
                      .Replace("@ForceDataTypes@", forceTypes);
            var xmlConfig = new XmlDocument();

            xmlConfig.LoadXml(xml);
            var dbFirstConfig = new DbFirstConfig(xmlConfig);

            var traceFbk = new TraceProcessFeedback();
            var dbfirst  = new DbFirstProcessor(traceFbk);

            try {
                var success = dbfirst.GenerateEntityModelSources(dbFirstConfig);
                Assert.IsTrue(success, "Source generation failed.");
            } catch (Exception ex) {
                var err = ex.ToLogString();
                Debug.WriteLine(err);
                throw;
            }
        }