コード例 #1
0
        static void CreatePete(SecuritySystem security, FileSystem filesystem)
        {
            // add user steven if not already there
            int peteUserID = -1;

            try
            {
                peteUserID = security.UserID("steven");
            }
            catch (Exception)
            {
                peteUserID = security.AddUser("steven");
                security.SetPassword("steven", "foobar42");
            }

            // create some test files for user pete if needed
            if (filesystem.Find(security.UserHomeDirectory(peteUserID)) != null)
            {
                try
                {
                    Directory peteDir = (Directory)filesystem.Find(security.UserHomeDirectory(peteUserID));

                    Directory  subDir  = peteDir.CreateDirectory("subdir");
                    File       file1   = subDir.CreateFile("file1");
                    File       file2   = subDir.CreateFile("file2");
                    FileStream stream1 = file1.Open();
                    stream1.Write(0, ASCIIEncoding.ASCII.GetBytes("hello from file 1!"));
                    stream1.Close();
                    FileStream stream2 = file2.Open();
                    stream2.Write(0, ASCIIEncoding.ASCII.GetBytes("back at you from file 2!"));
                    stream2.Close();
                }
                catch (Exception)
                {
                    // Nothing here
                }
            }
        }