Beispiel #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();
        }
Beispiel #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();
        }
Beispiel #3
0
        static void TestTerminal()
        {
            TerminalDriver driver = new DotNetConsoleTerminal();
            Terminal       term   = new Terminal(driver);

            term.Connect();

            term.Write("Enter some text: ");
            term.Echo = true;
            string s1 = term.ReadLine();

            term.Write("You entered: " + s1);

            term.Disconnect();
        }
Beispiel #4
0
        static void TestTerminalDriver()
        {
            TerminalDriver driver = new DotNetConsoleTerminal();

            driver.InstallInterruptHandler(new TestHandler(driver));
            driver.Connect();

            driver.SendChar('f');
            driver.SendChar('o');
            driver.SendChar('o');
            driver.SendNewLine();

            Thread.Sleep(100000);
            driver.Disconnect();
        }