Пример #1
0
        private static void BuildClasses(string connectionString, string path, string namespacePrefix, CacheType cacheType)
        {
            try {
                using (var cn = new SqlConnection(connectionString)) {
                    cn.Open();

                    List <string> schemas = new List <string>();
                    using (var cmd = new SqlCommand(File.ReadAllText(MapPath(@"..\sql\schemas.sql")), cn)) {
                        using (SqlDataReader reader = cmd.ExecuteReader()) {
                            while (reader.Read())
                            {
                                schemas.Add(reader["SCHEMA_NAME"] as string);
                            }
                        }
                    }
                    foreach (var schema in schemas)
                    {
                        List <string> tables = new List <string>();
                        using (var cmd = new SqlCommand(File.ReadAllText(MapPath(@"..\sql\tables.sql")), cn)) {
                            cmd.Parameters.AddWithValue("@TABLE_SCHEMA", schema);
                            using (SqlDataReader reader = cmd.ExecuteReader()) {
                                while (reader.Read())
                                {
                                    string tableName = reader["TABLE_NAME"] as string;

                                    SqlBackedTable t             = new SqlBackedTable(connectionString, namespacePrefix, schema, tableName, cacheType != CacheType.None);
                                    string         directoryPath = string.Format("{0}\\{1}\\", path, schema);
                                    string         classPath     = string.Format("{0}{1}.cs", directoryPath, tableName);

                                    Directory.CreateDirectory(directoryPath);

                                    Console.WriteLine("Wrote: " + classPath);

                                    File.WriteAllText(classPath, t.GetClass());
                                }
                            }
                        }
                    }
                }
            } catch (Exception ex) {
                Console.WriteLine("An exception occurred");
                Console.WriteLine(ex.Message);
                Console.WriteLine("---------");
                Console.WriteLine(ex.StackTrace);
            }
        }
Пример #2
0
        private static void BuildClasses(string connectionString, string path, string namespacePrefix, CacheType cacheType)
        {
            try {
                using (var cn = new SqlConnection(connectionString)) {
                    cn.Open();

                    List<string> schemas = new List<string>();
                    using (var cmd = new SqlCommand(File.ReadAllText(MapPath(@"..\sql\schemas.sql")), cn)) {
                        using (SqlDataReader reader = cmd.ExecuteReader()) {
                            while (reader.Read()) {
                                schemas.Add(reader["SCHEMA_NAME"] as string);
                            }
                        }
                    }
                    foreach (var schema in schemas) {

                        List<string> tables = new List<string>();
                        using (var cmd = new SqlCommand(File.ReadAllText(MapPath(@"..\sql\tables.sql")), cn)) {
                            cmd.Parameters.AddWithValue("@TABLE_SCHEMA", schema);
                            using (SqlDataReader reader = cmd.ExecuteReader()) {
                                while (reader.Read()) {
                                    string tableName = reader["TABLE_NAME"] as string;

                                    SqlBackedTable t = new SqlBackedTable(connectionString, namespacePrefix, schema, tableName, cacheType != CacheType.None);
                                    string directoryPath = string.Format("{0}\\{1}\\", path, schema);
                                    string classPath = string.Format("{0}{1}.cs", directoryPath, tableName);

                                    Directory.CreateDirectory(directoryPath);

                                    Console.WriteLine("Wrote: " + classPath);

                                    File.WriteAllText(classPath, t.GetClass());
                                }
                            }
                        }
                    }

                }
                File.Copy(MapPath(@"..\Code\ITableBacked.cs"), path + @"\ITableBacked.cs", true);
                File.Copy(MapPath(@"..\Code\PerformanceLogger.cs"), path + @"\PerformanceLogger.cs", true);
                File.Copy(MapPath(@"..\Code\ICacheProvider.cs"), path + @"\ICacheProvider.cs", true);
                File.Copy(MapPath(@"..\Code\CacheConnector.cs"), path + @"\CacheConnector.cs", true);
                File.Copy(MapPath(@"..\Code\DatabaseConnector.cs"), path + @"\DatabaseConnector.cs", true);
                File.Copy(MapPath(@"..\Code\BatchContext.cs"), path + @"\BatchContext.cs", true);
                File.Copy(MapPath(@"..\Code\DataResult.cs"), path + @"\DataResult.cs", true);

                if (cacheType == CacheType.Redis) {
                    File.Copy(MapPath(@"..\Code\CacheProviders\RedisCacheProvider.cs"), path + @"\RedisCacheProvider.cs", true);
                }

                if (cacheType == CacheType.AzureCache) {
                    File.Copy(MapPath(@"..\Code\CacheProviders\AzureCacheProvider.cs"), path + @"\AzureCacheProvider.cs", true);
                }
                if (cacheType == CacheType.InProcess) {
                    File.Copy(MapPath(@"..\Code\CacheProviders\MemoryCacheProvider.cs"), path + @"\MemoryCacheProvider.cs", true);
                }

            } catch (Exception ex) {
                Console.WriteLine("An exception occurred");
                Console.WriteLine(ex.Message);
                Console.WriteLine("---------");
                Console.WriteLine(ex.StackTrace);
            }
        }