Пример #1
0
        //------------------------------------------------------------------------------------------ static --
        public static NavSiteInfo GetSiteNav(bool resetCache)
        {
            AjaxService.ASPdatabaseService.GetSetVal();
            if (resetCache)
            {
                ASPdatabaseNET.Memory.AppCache.Reset();
            }

            var userSessionInfo  = ASPdatabaseNET.Users.UserSessionLogic.GetUser();
            var usersPermissions = userSessionInfo.UserInfo.AllPermissions;

            var rtn = new NavSiteInfo();
            var tmpNavDatabaseArray = new List <NavDatabaseInfo>();
            var dbList = SQLObjectsCRUD.ASPdb_Connection__GetAll(true);

            foreach (var dbItem in dbList)
            {
                if (dbItem.Active)
                {
                    tmpNavDatabaseArray.Add(new NavDatabaseInfo()
                    {
                        ConnectionId = dbItem.ConnectionId, ConnectionName = dbItem.ConnectionName
                    });
                }
            }
            rtn.Databases = tmpNavDatabaseArray.ToArray();

            foreach (var database in rtn.Databases)
            {
                try
                {
                    var aspdb_Tables = SQLObjectsCRUD.ASPdb_Table__GetAll(database.ConnectionId, false);
                    var tmpList1     = new List <NavSectionItemInfo>();
                    foreach (var table in aspdb_Tables)
                    {
                        if (!table.Hide && usersPermissions.CheckPermissions(table.ConnectionId, table.Schema, table.TableId).View)
                        {
                            string url = String.Format("#00-Table-{0}", table.TableId);
                            tmpList1.Add(new NavSectionItemInfo()
                            {
                                Id = table.TableId, Name = table.TableName, Schema = table.Schema, URL = url
                            });
                        }
                    }
                    var aspdb_Views = SQLObjectsCRUD.ASPdb_View__GetAll(database.ConnectionId);
                    var tmpList2    = new List <NavSectionItemInfo>();
                    foreach (var view in aspdb_Views)
                    {
                        if (!view.Hide && usersPermissions.CheckPermissions(view.ConnectionId, view.Schema, -1).View)
                        {
                            string url = String.Format("#00-View-{0}", view.ViewId);
                            tmpList2.Add(new NavSectionItemInfo()
                            {
                                Id = view.ViewId, Name = view.ViewName, Schema = view.Schema, URL = url
                            });
                        }
                    }

                    if (tmpList1.Count > 0)
                    {
                        database.Section_Tables = new NavSectionInfo()
                        {
                            SectionName = String.Format("Tables ({0})", tmpList1.Count),
                            SectionType = NavSectionInfo.SectionTypes.Tables,
                            Items       = tmpList1.ToArray()
                        }
                    }
                    ;
                    if (tmpList2.Count > 0)
                    {
                        database.Section_Views = new NavSectionInfo()
                        {
                            SectionName = String.Format("Views ({0})", tmpList2.Count),
                            SectionType = NavSectionInfo.SectionTypes.Views,
                            Items       = tmpList2.ToArray()
                        }
                    }
                    ;
                }
                catch (Exception exc)
                {
                    ASPdb.Framework.Debug.RecordException(exc);
                    database.ConnectionName += " (Error)";
                    string msg = exc.Message;
                    if (msg.Length > 171)
                    {
                        msg = msg.Substring(0, 170);
                        var arr = msg.Split(new char[] { ' ' });
                        msg = msg.Substring(0, msg.Length - arr.Last().Length) + "...";
                    }
                    database.Section_Tables = new NavSectionInfo()
                    {
                        SectionName = msg
                    };
                }
            }

            var tmpDatabases = new List <NavDatabaseInfo>();

            foreach (var database in rtn.Databases)
            {
                bool isEmpty = true;
                if (database.Section_Tables != null && database.Section_Tables.Items != null && database.Section_Tables.Items.Length > 0)
                {
                    isEmpty = false;
                    database.Section_Tables.Items = (from r in database.Section_Tables.Items
                                                     orderby r.Schema, r.Name
                                                     select r).ToArray();
                }
                if (database.Section_Views != null && database.Section_Views.Items != null && database.Section_Views.Items.Length > 0)
                {
                    isEmpty = false;
                }

                if (!isEmpty)
                {
                    tmpDatabases.Add(database);
                }
            }
            rtn.Databases = tmpDatabases.ToArray();

            rtn.IsInDemoMode = Users.UserSessionLogic.IsInDemoMode;

            return(rtn);
        }
Пример #2
0
        //----------------------------------------------------------------------------------------------------
        public static ManageAssetResponse GetAssetsLists(int connectionId)
        {
            AjaxService.ASPdatabaseService.GetSetVal();
            var rtn = new AssetsLists_PopulatorHelper(connectionId, true);
            var aspdb_Connection = DataAccess.SQLObjectsCRUD.ASPdb_Connection__Get(connectionId);

            if (!aspdb_Connection.Active)
            {
                throw new Exception("This connection is inactive.");
            }

            rtn.ConnectionName = aspdb_Connection.ConnectionName;


            //-----------------------------------------------------------
            var aspdb_Tables = SQLObjectsCRUD.ASPdb_Table__GetAll(connectionId, true);

            foreach (var item in aspdb_Tables)
            {
                var basicAssetInfo = item.ToBasicAssetInfo();
                if (basicAssetInfo.Active)
                {
                    rtn.Tables_Active.Add(basicAssetInfo);
                }
                else
                {
                    rtn.Tables_Hidden.Add(basicAssetInfo);
                }
            }


            //-----------------------------------------------------------
            var aspdb_Views = SQLObjectsCRUD.ASPdb_View__GetAll(connectionId);

            foreach (var item in aspdb_Views)
            {
                var basicAssetInfo = item.ToBasicAssetInfo();
                if (basicAssetInfo.Active)
                {
                    rtn.SqlViews_Active.Add(basicAssetInfo);
                }
                else
                {
                    rtn.SqlViews_Hidden.Add(basicAssetInfo);
                }
            }


            //-----------------------------------------------------------
            var schemaInfos = GenericInterface.Schemas__GetAll(connectionId);

            foreach (var item in schemaInfos)
            {
                var basicAssetInfo = new BasicAssetInfo(true, BasicAssetInfo.E_AssetTypes.Schema);
                basicAssetInfo.ConnectionId = connectionId;
                basicAssetInfo.GenericId    = item.SchemaId;
                basicAssetInfo.Schema       = item.SchemaName;
                rtn.Schemas.Add(basicAssetInfo);
            }


            return(new ManageAssetResponse()
            {
                ResponseType = ManageAssetResponse.ResponseTypesEnum.GetAssetsLists,
                AssetsListsInfo = rtn.ToAssetsLists()
            });
        }