コード例 #1
0
        private FolderStatistics GetFolderStatistics(Folder folder)
        {
            FolderStatistics stat = null;

            try
            {
                folder.EnsureProperties(
                    f => f.Name,
                    f => f.Files.Include(fl => fl.Length, fl => fl.Versions.Include(v => v.Length)),
                    f => f.Folders.Include(fl => fl.Name));
                stat = new FolderStatistics
                {
                    ItemCount     = folder.Files.Count,
                    TotalFileSize = folder.Files.Sum(fl => fl.Length + ((fl.Versions != null) ? fl.Versions.Sum(v => v.Length) : 0))
                };
                foreach (var subfolder in folder.Folders)
                {
                    stat += GetFolderStatistics(subfolder);
                }
            }
            catch (Exception e)
            {
                WriteWarning($"Cannot inspect folder: {e.Message}");
            }

            return(stat);
        }
コード例 #2
0
        private FolderStatistics GetFolderStatistics(Folder folder, List list)
        {
            folder.EnsureProperties(
                f => f.ServerRelativeUrl,
                f => f.ListItemAllFields,
                f => f.ItemCount,
                f => f.Files.Include(fl => fl.Length),
                f => f.Files.Include(fl => fl.Versions),
                f => f.Folders.Include(fl => fl.Name));

            var stat = new FolderStatistics
            {
                ItemCount        = folder.ItemCount,
                TotalFileSize    = folder.Files.Sum(fl => fl.Length + fl.Versions.Sum(v => v.Length)),
                FolderCount      = folder.Folders.Count,
                ItemVersionCount = folder.Files.Sum(fl => fl.Versions.Count),
            };

            if (!folder.ListItemAllFields.ServerObjectIsNull())
            {
                folder.ListItemAllFields.EnsureProperty(i => i.HasUniqueRoleAssignments);
                if (folder.ListItemAllFields.HasUniqueRoleAssignments)
                {
                    stat.BrokenPermissionCount++;
                    WriteVerbose($"Folder ${folder.ServerRelativeUrl} has unique permissions");
                }
            }

            if (ItemLevel && (stat.ItemCount > 0))
            {
                var items = GetItemsInFolder(folder, list);
                stat.BrokenPermissionCount += items.Count(i => i.HasUniqueRoleAssignments);
            }

            foreach (var subfolder in folder.Folders)
            {
                stat += GetFolderStatistics(subfolder, list);
            }
            return(stat);
        }