Beispiel #1
0
        /// <summary>
        /// Get Menu info.
        /// </summary>
        /// <returns></returns>
        public static MenuModel GetMenuInfo()
        {
            var serverAdapter = new ServerAdapter(DataBaseTypeEnum.MySql | DataBaseTypeEnum.SqlServer | DataBaseTypeEnum.Sqlite | DataBaseTypeEnum.Oracle);

            if (serverAdapter.ServerList == null || !serverAdapter.ServerList.Any())
            {
                return(null);
            }

            var resultMenu = new ConcurrentBag <MenuModel>();

            serverAdapter.ServerList.AsParallel().ForEach(baseserver =>
            {
                var dbList = baseserver.DbBaseTableAccess.GetDataBaseModels(baseserver.ConnectionString);
                if (dbList != null && dbList.Any())
                {
                    var i           = 2;
                    var baseserver1 = baseserver;
                    dbList.ForEach(f =>
                    {
                        var childMenu = new List <MenuModel>();
                        try
                        {
                            var tables = baseserver1.DbBaseTableAccess.GetTableList(baseserver1.ConnectionString, f.Name);
                            var views  = baseserver1.DbBaseTableAccess.GetViews(baseserver1.ConnectionString, f.Name);
                            if (tables != null && tables.Any())
                            {
                                childMenu.AddRange(tables.Select(r => new MenuModel {
                                    Menuid = i++, Icon = "icon-table", Menuname = r.Name, Url = $"/home/ShowTableInfo?datatableName={f.Name}&tableName={r.Name.Replace("#", "**")}&type=table&dbType={baseserver.CurrentDataBaseTypeEnum.GetHashCode()}"
                                }).ToList());
                            }

                            if (views != null && views.Any())
                            {
                                childMenu.AddRange(views.Select(r => new MenuModel {
                                    Menuid = i++, Icon = "icon-table", Menuname = r.Name, Url = $"/home/ShowTableInfo?datatableName={f.Name}&tableName={r.Name.Replace("#", "**")}&type=view&dbType={baseserver.CurrentDataBaseTypeEnum.GetHashCode()}"
                                }).ToList());
                            }
                            resultMenu.Add(new MenuModel {
                                Menuid = i++, Menuname = f.Name, Icon = "icon-database", Menus = childMenu
                            });
                        }
                        catch (Exception ex)
                        {
                            ErrorInfoServer.Push(ex);
                        }
                    });
                }
            });

            return(new MenuModel {
                Menus = resultMenu.ToList()
            });
        }
Beispiel #2
0
        /// <summary>
        /// 获取视图信息
        /// </summary>
        /// <param name="dataBaseName"></param>
        /// <param name="tableName"></param>
        /// <param name="dbType"></param>
        /// <returns></returns>
        public static View GetViewInfo(string dataBaseName, string tableName, DataBaseTypeEnum dbType)
        {
            var serverAdapter = new ServerAdapter(dbType);

            if (serverAdapter.ServerList == null || !serverAdapter.ServerList.Any())
            {
                return(null);
            }
            var baseServer = serverAdapter.ServerList.First();

            return(baseServer.DbBaseTableAccess.GetViewInfo(baseServer.ConnectionString, dataBaseName, tableName));
        }