From 80b3ad7bd20329e6a5bbf6eeb76af62c87434a7c Mon Sep 17 00:00:00 2001 From: LukePulverenti Luke Pulverenti luke pulverenti Date: Thu, 19 Jul 2012 22:22:44 -0400 Subject: Moved the http server to it's own assembly. added comments and made other minor re-organizations. --- MediaBrowser.Controller/UserController.cs | 35 +++++++++++++++++++++++++------ 1 file changed, 29 insertions(+), 6 deletions(-) (limited to 'MediaBrowser.Controller/UserController.cs') diff --git a/MediaBrowser.Controller/UserController.cs b/MediaBrowser.Controller/UserController.cs index 04ff6d215d..7fac4392e4 100644 --- a/MediaBrowser.Controller/UserController.cs +++ b/MediaBrowser.Controller/UserController.cs @@ -6,8 +6,14 @@ using MediaBrowser.Model.Users; namespace MediaBrowser.Controller { + /// + /// Manages users within the system + /// public class UserController { + /// + /// Gets or sets the path to folder that contains data for all the users + /// public string UsersPath { get; set; } public UserController(string usersPath) @@ -15,6 +21,9 @@ namespace MediaBrowser.Controller UsersPath = usersPath; } + /// + /// Gets all users within the system + /// public IEnumerable GetAllUsers() { if (!Directory.Exists(UsersPath)) @@ -37,6 +46,9 @@ namespace MediaBrowser.Controller return list; } + /// + /// Gets a User from it's directory + /// private User GetFromDirectory(string path) { string file = Path.Combine(path, "user.js"); @@ -44,17 +56,28 @@ namespace MediaBrowser.Controller return JsonSerializer.DeserializeFromFile(file); } - public void CreateUser(User user) + /// + /// Creates a User with a given name + /// + public User CreateUser(string name) { - user.Id = Guid.NewGuid(); + var now = DateTime.Now; - user.DateCreated = user.DateModified = DateTime.Now; + User user = new User() + { + Name = name, + Id = Guid.NewGuid(), + DateCreated = now, + DateModified = now + }; + + user.Path = Path.Combine(UsersPath, user.Id.ToString()); - string userFolder = Path.Combine(UsersPath, user.Id.ToString()); + Directory.CreateDirectory(user.Path); - Directory.CreateDirectory(userFolder); + JsonSerializer.SerializeToFile(user, Path.Combine(user.Path, "user.js")); - JsonSerializer.SerializeToFile(user, Path.Combine(userFolder, "user.js")); + return user; } } } -- cgit v1.2.3