static void TestSessionManager() { // disk //VolatileDisk disk = new VolatileDisk(1); PersistentDisk disk = new PersistentDisk(1, "disk1"); // create and write our OS to disk if needed CreateOSOnDisk(disk); // set up file system and mount disk disk.TurnOn(); FileSystem filesystem = new SimpleFS(); filesystem.Mount(disk, "/"); // security system SecuritySystem security = new SimpleSecurity(filesystem, "passwd"); // add pete and his test data if needed CreatePete(security, filesystem); // session manager ShellFactory shells = new SimpleShellFactory(); SessionManager sessionmanager = new SimpleSessionManager(security, filesystem, shells); // terminal TerminalDriver driver = new DotNetConsoleTerminal(); Terminal term = new Terminal(driver); term.Connect(); // allow terminals to connect and establish new sessions for users try { while (true) { Session session = sessionmanager.NewSession(term); if (session == null) { throw new Exception("Failed to create new session!"); } session.Run(); // after session exits, time to log out! session.Logout(); } } catch (Exception ex) { Console.WriteLine(ex.Message); } term.Disconnect(); disk.TurnOff(); }
static void TestLogicalFileSystem() { //DiskDriver disk = new VolatileDisk(1); DiskDriver disk = new PersistentDisk(1, "disk1"); disk.TurnOn(); FileSystem fs = new SimpleFS(); fs.Format(disk); fs.Mount(disk, "/"); Directory root = fs.GetRootDirectory(); Directory dir1 = root.CreateDirectory("dir1"); Directory dir2 = root.CreateDirectory("dir2"); Random r = new Random(); byte[] bytes1 = CreateTestBytes(r, 1000); File file2 = dir2.CreateFile("file2"); FileStream stream1 = file2.Open(); stream1.Write(0, bytes1); stream1.Close(); File file2_2 = (File)fs.Find("/dir2/file2"); FileStream stream2 = file2_2.Open(); byte[] bytes2 = stream2.Read(0, 1000); stream2.Close(); if (!Compare(bytes1, bytes2)) { throw new Exception("bytes read were not the same as written"); } Console.WriteLine("Printing all directories..."); RecursivelyPrintDirectories(root); Console.WriteLine(); Console.WriteLine("Moving file2 to dir1..."); file2.Move(dir1); Console.WriteLine("Printing all directories..."); RecursivelyPrintDirectories(root); Console.WriteLine(); Console.WriteLine("Renaming dir2 to renamed..."); dir2.Rename("renamed"); Console.WriteLine("Printing all directories..."); RecursivelyPrintDirectories(root); Console.WriteLine(); Console.WriteLine("Deleting renamed..."); dir2.Delete(); Console.WriteLine("Printing all directories..."); RecursivelyPrintDirectories(root); Console.WriteLine(); Console.WriteLine("Deleting dir1..."); dir1.Delete(); Console.WriteLine("Printing all directories..."); RecursivelyPrintDirectories(root); Console.WriteLine(); fs.Unmount("/"); disk.TurnOff(); }