Beispiel #1
0
        internal static string GetDatabaseName(System.Data.Common.DbConnectionStringBuilder connectionStringBuilder)
        {
            object objDbName;
            string dbName = null;

            if (connectionStringBuilder.TryGetValue("USER ID", out objDbName))
            {
                dbName = objDbName.ToString();
            }
            else if (connectionStringBuilder.TryGetValue("UID", out objDbName))
            {
                dbName = objDbName.ToString();
            }
            return(dbName);
        }
        /// <summary>
        /// Get attribute value fom connection string builder.
        /// </summary>
        /// <param name="connectionStringBuilder">Builder where to read attribute.</param>
        /// <param name="attributeKey">Attribute to read.</param>
        /// <param name="fallbackValue">Fallback value where attribute does not exists.</param>
        /// <returns>Value of requested attribute.</returns>
        private string GetConnectionStringValue(System.Data.Common.DbConnectionStringBuilder connectionStringBuilder, string attributeKey, string fallbackValue = null)
        {
            object result;

            if (connectionStringBuilder.TryGetValue(attributeKey, out result) == false)
            {
                return(fallbackValue);
            }

            return(result.ToString());
        }
Beispiel #3
0
        public static List <string> GetDBNames()
        {
            List <string> strList  = new List <string>();
            var           connList = System.Configuration.ConfigurationManager.ConnectionStrings;

            foreach (ConnectionStringSettings con in connList)
            {
                System.Data.Common.DbConnectionStringBuilder ss = new System.Data.Common.DbConnectionStringBuilder(false);
                ss.ConnectionString = con.ToString();
                object aa = "";
                if (ss.TryGetValue("Initial Catalog", out aa))
                {
                    strList.Add(aa.ToString());
                }
            }
            return(strList);
        }
Beispiel #4
0
        public static string GetConnSettingNameByDBName(string dbName)
        {
            List <string> strList  = new List <string>();
            var           connList = System.Configuration.ConfigurationManager.ConnectionStrings;

            foreach (ConnectionStringSettings con in connList)
            {
                System.Data.Common.DbConnectionStringBuilder ss = new System.Data.Common.DbConnectionStringBuilder(false);
                ss.ConnectionString = con.ToString();
                object aa = "";
                if (ss.TryGetValue("Initial Catalog", out aa))
                {
                    if (dbName == aa.ToString())
                    {
                        return(con.Name);
                    }
                }
            }
            return("");
        }
Beispiel #5
0
        static void Main(string[] args)
        {
            var conn_str = ConfigurationManager.AppSettings["DBConn"];

            if (string.IsNullOrWhiteSpace(conn_str))
            {
                System.Console.WriteLine("未设置数据库连接字符串!");
                System.Console.Read();
                Environment.Exit(0);
            }

            ReCreateDB(conn_str, Encoding.GetEncoding("gb2312"));

            System.Data.Common.DbConnectionStringBuilder s = new System.Data.Common.DbConnectionStringBuilder(false);
            s.ConnectionString = conn_str;
            string dbcode   = "cap_db";
            object database = "";

            if (s.TryGetValue("Initial Catalog", out database))
            {
                dbcode = database.ToString();
            }
            Print("解析数据库元数据...");
            using (SQLServerManagement manage = new SQLServerManagement(conn_str))
            {
                var config = new SQLMetaData();
                SQLMetaDataHelper.InitConfig(config);
                var data = manage.Databases[dbcode].Tables;
                // 解析数据库元数据
                var parser = new MetaDataParser(config);
                parser.Parse(data);
                Print("解析完毕,生成中间配置文件...");

                // 生成中间配置文件
                var config_json_str = JsonConvert.SerializeObject(config);
                SQLMetaDataHelper.OutputConfig(config_json_str);

                // 生成最终文件
                Print("按 'y/Y' 继续生成最终操作类文件...");
                var key = string.Empty;
                do
                {
                    key = System.Console.ReadLine();
                    if (key == "Y" || key == "y")
                    {
                        // 生成DAL最终文件
                        Print("生成DAL...");
                        SQLMetaDataHelper.OutputDAL(config);

                        // 生成Model最终文件
                        Print("生成Model...");
                        SQLMetaDataHelper.OutputModel(config);

                        // 生成Enum最终文件
                        Print("生成Enum...");
                        SQLMetaDataHelper.OutputEnum(config);

                        // 检测partial字段有效性
                        Print("检测partial字段有效性...");
                        SQLMetaDataHelper.DoPartialCheck(config);

                        Print("生成完毕!");
                        break;
                    }
                    System.Console.WriteLine("按‘quit’退出");
                } while (key != "quit");
            }

            Print("结束!");
            System.Console.Read();
            Environment.Exit(0);
        }