Esempio n. 1
0
        public JsonResult DataRequested()
        {
            string userName    = WebConfigurationManager.AppSettings["NetworkCredentialsUsername"];
            string password    = WebConfigurationManager.AppSettings["NetworkCredentialsPassword"];
            string domain      = WebConfigurationManager.AppSettings["NetworkDomain"];
            string networkPath = WebConfigurationManager.AppSettings["NetworkPath"];

            // Get both the grid Model and the data Model
            // The data model in our case is an autogenerated linq2sql database based on Northwind.
            var gridModel = new FileJqGridModel();
            var grid      = gridModel.FileDataGrid;
            //SetUpGrid(grid);

            string startingPath             = networkPath;
            JQGridTreeExpandData expandData = grid.GetTreeExpandData();

            if (expandData.ParentID != null)
            {
                // GetDirectoryFrom hash returns the full path of the folder per its key (in the ID field of the row)
                startingPath = GetDirectoryFromHash(expandData.ParentID);
            }

            // Take a snapshot of the file system.
            System.IO.DirectoryInfo dir;


            IEnumerable <DirectoryInfo> dirList;
            IEnumerable <FileInfo>      fileList;

            using (UNCAccessWithCredentials unc = new UNCAccessWithCredentials())
            {
                if (unc.NetUseWithCredentials(startingPath, userName, domain, password))
                {
                    dir     = new System.IO.DirectoryInfo(startingPath);
                    dirList = dir.GetDirectories("*.*",
                                                 System.IO.SearchOption.TopDirectoryOnly);

                    fileList = dir.GetFiles("*.*",
                                            System.IO.SearchOption.TopDirectoryOnly);
                }
                else
                {
                    throw new Exception("what happened?");
                }
            }
            // ********************************************************************************************
            // when selecting rows, you need to specify some or all of the following reserved fields
            // tree_level - the level of the row in the tree hierarchy. 0 is for root row.
            // tree_leaf - if the row is leaf (no child rows). This will make it non-expandable and will have an alternative icon
            // tree_expanded - if the row is expanded by default or not
            // tree_parent - the primary key (ID) of the parent row (only applicable for child rows)
            // tree_loaded - true/false - if the tree nodes are already loaded. Can be used to show several levels expanded by default.
            // ********************************************************************************************
            var dirs = from directory in dirList
                       orderby directory.Name
                       select new DirectoryEntry
            {
                // Use Hashtable to make sure there is unique key per folder fullname
                ID            = AddDirectoryToHash(directory.FullName),
                IsDir         = true,
                Name          = "" + directory.Name + "",
                Size          = "[dir]",
                DateCreated   = directory.CreationTime.ToString("d"),
                LastModified  = directory.LastWriteTime.ToString("d"),
                tree_parent   = expandData.ParentID,
                tree_expanded = false,
                tree_leaf     = false,
                tree_level    = expandData.ParentLevel + 1
            };
            var files = from file in fileList
                        orderby file.Name
                        select new DirectoryEntry
            {
                // ID is the primary key and must be set to an unique key
                // GUIDs can be used without the "-" - not allowed for IDs in HTML
                ID           = Guid.NewGuid().ToString().Replace("-", ""),
                IsDir        = false,
                Name         = file.Name,
                Size         = file.Length.ToString(),
                DateCreated  = file.CreationTime.ToString("d"),
                LastModified = file.LastWriteTime.ToString("d"),
                tree_parent  = expandData.ParentID,
                tree_leaf    = true,
                tree_level   = expandData.ParentLevel + 1
            };

            var allFilesAndFolders = files.Concat(dirs)
                                     .AsQueryable()
                                     .OrderByDescending(f => f.Name)
                                     .OrderBy(f => f.IsDir == false);

            return(grid.DataBind(allFilesAndFolders));
        }
Esempio n. 2
0
        public JsonResult AuthorizationRuleOfAuth_RequestData(Guid parentRowID)
        {
            var authGridModel = new AuthorizationGridModel();

            SetUpAuthGridModel(authGridModel);
            JQGridTreeExpandData expandData = authGridModel.AuthorizationGrid.GetTreeExpandData();

            Guid empty = Guid.Empty;
            var  auths = (from s in Uow.aspnet_Sitemaps.GetAll().Where(w => w.IsAuthorize == true && w.Code != "000")
                          join a in Uow.aspnet_AuthorizationRules.GetAll().Where(w => w.RoleId == parentRowID) on s.Code equals a.SiteMapKey into sa
                          from auth in sa.DefaultIfEmpty()
                          orderby s.Sort
                          select new
            {
                IsInRole = (auth == null ? false : true),
                Code = s.Code,
                s.Title,
                s.IsClient,
                s.ParentCode,
                tree_loaded = true,
                tree_level = 0,
                tree_parent = s.ParentCode,
                tree_leaf = false,
                tree_expanded = false
            }).ToList();

            var auths1 = auths.Select((map, idx) => new
            {
                map.IsInRole,
                map.Code,
                map.Title,
                map.IsClient,
                map.ParentCode,
                Sort = idx + 1,
                map.tree_loaded,
                map.tree_level,
                map.tree_parent,
                map.tree_leaf,
                map.tree_expanded
            });

            var auths2 = (from d in auths1
                          where d.ParentCode == "000"
                          select new
            {
                d.IsInRole,
                d.Code,
                d.Title,
                d.IsClient,
                Sort = d.Sort.ToString().PadLeft(5, '0'),
                d.tree_loaded,
                tree_level = 0,
                tree_parent = "",
                tree_leaf = false,
                d.tree_expanded
            }).ToList();

            var auths3 = (from d in auths1
                          join d2 in auths2 on d.ParentCode equals d2.Code
                          select new
            {
                d.IsInRole,
                d.Code,
                d.Title,
                d.IsClient,
                Sort = d2.Sort + d.Sort.ToString().PadLeft(5, '0'),
                d.tree_loaded,
                tree_level = 1,
                tree_parent = d2.Code,
                tree_leaf = false,
                d.tree_expanded
            }).ToList();

            var auths4 = (from d in auths1
                          join d2 in auths3 on d.ParentCode equals d2.Code
                          select new
            {
                d.IsInRole,
                d.Code,
                d.Title,
                d.IsClient,
                Sort = d2.Sort + d.Sort.ToString().PadLeft(5, '0'),
                d.tree_loaded,
                tree_level = 2,
                tree_parent = d2.Code,
                tree_leaf = true,
                d.tree_expanded
            }).ToList();

            var auths5 = (from d in auths3
                          join d2 in auths4 on d.Code equals d2.tree_parent into dd1
                          from dd1s in dd1.DefaultIfEmpty()
                          select new
            {
                d.IsInRole,
                d.Code,
                d.Title,
                d.IsClient,
                Sort = d.Sort,
                d.tree_loaded,
                tree_level = 1,
                tree_parent = d.tree_parent,
                tree_leaf = dd1s == null?true:false,
                d.tree_expanded
            }).ToList();
            var authss = auths2.Union(auths5).Union(auths4).ToList();

            if (expandData.ParentID != null)
            {
                string parentId = expandData.ParentID;
                authss = authss.Where(w => w.tree_parent == parentId).ToList();
            }
            authss = authss.OrderBy(o => o.Sort).ToList();
            return(authGridModel.AuthorizationGrid.DataBind(authss.AsQueryable()));
        }