コード例 #1
0
        public static void Run(string projectFolder, SystemDevelopmentConfiguration configuration, Logger log)
        {
            var outputFilePath = Path.Combine(projectFolder, "GeneratedCode", "TypedDataLayer.cs");

            log.Info("Writing generated code to " + outputFilePath);
            var outputDir = Path.GetDirectoryName(outputFilePath);

            log.Debug("Creating directory: " + outputDir);
            Directory.CreateDirectory(outputDir);

            var baseNamespace = configuration.LibraryNamespaceAndAssemblyName + ".DataAccess";

            using (var writer = new StreamWriter(outputFilePath)) {
                writeUsingStatements(writer);

                var databaseInfo = DatabaseOps.CreateDatabase(
                    DatabaseFactory.CreateDatabaseInfo(configuration.databaseConfiguration.DatabaseType, configuration.databaseConfiguration.ConnectionString));

                ExecuteDatabaseUpdatesScript.Run(projectFolder, databaseInfo, log);
                generateDataAccessCodeForDatabase(
                    log,
                    databaseInfo,
                    projectFolder,
                    writer,
                    baseNamespace,
                    configuration);
            }
        }
コード例 #2
0
        private static void generateDataAccessCodeForDatabase(
            Logger log, IDatabase database, string libraryBasePath, TextWriter writer, string baseNamespace, SystemDevelopmentConfiguration configuration)
        {
            var tableNames = DatabaseOps.GetDatabaseTables(database);

            if (configuration.database == null)
            {
                log.Info($"Configuration is missing the <{nameof( configuration.database )}> element.");
                return;
            }

            ensureTablesExist(tableNames, configuration.database.SmallTables, "small");
            ensureTablesExist(tableNames, configuration.database.TablesUsingRowVersionedDataCaching, "row-versioned data caching");
            ensureTablesExist(tableNames, configuration.database.revisionHistoryTables, "revision history");

            ensureTablesExist(tableNames, configuration.database.WhitelistedTables, "whitelisted");
            tableNames =
                tableNames.Where(
                    table => configuration.database.WhitelistedTables == null || configuration.database.WhitelistedTables.Any(i => i.EqualsIgnoreCase(table)));

            database.ExecuteDbMethod(
                cn => {
                writer.WriteLine();
                ConfigurationRetrievalStatics.Generate(writer, baseNamespace, configuration.database);

                // database logic access - standard
                writer.WriteLine();
                TableConstantStatics.Generate(cn, writer, baseNamespace, database, tableNames);

                // database logic access - custom
                writer.WriteLine();
                RowConstantStatics.Generate(cn, writer, baseNamespace, database, configuration.database);

                // retrieval and modification commands - standard
                writer.WriteLine();
                CommandConditionStatics.Generate(cn, writer, baseNamespace, database, tableNames);

                writer.WriteLine();
                var tableRetrievalNamespaceDeclaration = TableRetrievalStatics.GetNamespaceDeclaration(baseNamespace, database);
                TableRetrievalStatics.Generate(cn, writer, tableRetrievalNamespaceDeclaration, database, tableNames, configuration.database);

                writer.WriteLine();
                var modNamespaceDeclaration = StandardModificationStatics.GetNamespaceDeclaration(baseNamespace, database);
                StandardModificationStatics.Generate(cn, writer, modNamespaceDeclaration, database, tableNames, configuration.database);

                foreach (var tableName in tableNames)
                {
                    TableRetrievalStatics.WritePartialClass(cn, libraryBasePath, tableRetrievalNamespaceDeclaration, database, tableName);
                    StandardModificationStatics.WritePartialClass(
                        cn,
                        libraryBasePath,
                        modNamespaceDeclaration,
                        database,
                        tableName,
                        DataAccessStatics.IsRevisionHistoryTable(tableName, configuration.database));
                }

                // retrieval and modification commands - custom
                writer.WriteLine();
                QueryRetrievalStatics.Generate(cn, writer, baseNamespace, database, configuration.database);
                writer.WriteLine();
                CustomModificationStatics.Generate(cn, writer, baseNamespace, database, configuration.database);

                // other commands
                if (cn.DatabaseInfo is OracleInfo)
                {
                    writer.WriteLine();
                    SequenceStatics.Generate(cn, writer, baseNamespace, database, configuration.database.CommandTimeoutSecondsTyped);
                    writer.WriteLine();
                    ProcedureStatics.Generate(cn, writer, baseNamespace, database);
                }
            });
        }