コード例 #1
0
        public void FileSystemPopulate()
        {
            ConfigurationTest.Initialize();
            Random r = new Random(1234);

            using (var io = ConfigurationTest.CreateMemoryIO()) {
                FileSystem fs = FileSystem.Create(io);
                fs.Flush();

                SortedList <int, DirInfo>  dirs  = new SortedList <int, DirInfo>();
                SortedList <int, FileInfo> files = new SortedList <int, FileInfo>();

                Directory d = fs.RootDirectory;
                dirs.Add(fs.RootDirectory.ID, new DirInfo(d));

                for (int i = 0; i < 1000; i++)
                {
                    var parent = dirs.Values[r.Next(dirs.Count)];
                    d = fs.CreateDirectory(parent.Directory, $"dir{nextID}");
                    nextID++;

                    DirInfo info = new DirInfo(d);
                    dirs.Add(d.ID, info);
                    dirs[d.ParentID].Subdirs.Add(d.ID);

                    FileSystemAccessRule accessRule = new FileSystemAccessRule(
                        WindowsIdentity.GetCurrent().User, FileSystemRights.FullControl, InheritanceFlags.None,
                        PropagationFlags.None, AccessControlType.Allow);
                    fs.AddAccessRule(d, accessRule);
                    info.AccessRules.Add(accessRule);

                    FileSystemAuditRule auditRule = new FileSystemAuditRule(
                        WindowsIdentity.GetCurrent().User, FileSystemRights.FullControl, InheritanceFlags.None,
                        PropagationFlags.None, AuditFlags.Success);
                    fs.AddAuditRule(d, auditRule);
                    info.AuditRules.Add(auditRule);
                }

                for (int i = 0; i < 1000; i++)
                {
                    var  parent = dirs.Values[r.Next(dirs.Count)];
                    File f      = fs.CreateFile(parent.Directory, $"file{nextID}");
                    nextID++;

                    FileInfo info = new FileInfo(f);
                    files.Add(f.ID, info);
                    dirs[f.ParentID].Files.Add(f.ID);

                    FileSystemAccessRule accessRule = new FileSystemAccessRule(
                        WindowsIdentity.GetCurrent().User, FileSystemRights.FullControl, InheritanceFlags.None,
                        PropagationFlags.None, AccessControlType.Allow);
                    fs.AddAccessRule(f, accessRule);
                    info.AccessRules.Add(accessRule);

                    FileSystemAuditRule auditRule = new FileSystemAuditRule(
                        WindowsIdentity.GetCurrent().User, FileSystemRights.FullControl, InheritanceFlags.None,
                        PropagationFlags.None, AuditFlags.Success);
                    fs.AddAuditRule(f, auditRule);
                    info.AuditRules.Add(auditRule);
                }

                checkDirectories(fs, fs.RootDirectory, dirs, files);
                fs.Dispose();

                CryptoSettings cryptoSettings = Configuration.CryptoSettings;
                Options        options        = Configuration.Options;
                Configuration.Reset();
                Configuration.CryptoSettings = cryptoSettings;
                Configuration.Options        = options;

                fs = FileSystem.Mount(io);
                checkDirectories(fs, fs.RootDirectory, dirs, files);
            }
        }