Пример #1
0
        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();
        }
Пример #2
0
        static void TestSessionManager()
        {
            SlowDisk disk = new SlowDisk(42);

            disk.TurnOn();

            FileSystem filesystem = new SimpleFS();

            filesystem.Format(disk);
            filesystem.Mount(disk, "/");

            //make dir/files
            Directory root     = filesystem.GetRootDirectory();
            Directory usersDir = root.CreateDirectory("users");
            Directory johnDir  = usersDir.CreateDirectory("john");
            Directory subDir   = johnDir.CreateDirectory("subdir");

            subDir.CreateFile("file1");
            subDir.CreateFile("file2");
            // add an /etc/passwd file that contains users for security system.


            SecuritySystem security = new SimpleSecurity();

            security.AddUser("john");
            security.SetPassword("john", "foo");


            ShellFactory   shells         = new SimpleShellFactory();
            SessionManager sessionManager = new SimpleSessionManager(security, filesystem, shells);
            TerminalDriver driver         = new DotNetConsoleTerminal();
            Terminal       term           = new Terminal(driver);

            term.Connect();

            while (true)
            {
                Session session = sessionManager.NewSession(term);
                if (session == null)
                {
                    throw new Exception("Failed to get sessions!");
                }
                session.Run();

                // after session exits, logout
                session.Logout();
            }

            term.Disconnect();
        }