示例#1
0
        /// <summary>
        /// Reads user data from file for user with a given ID
        /// </summary>
        /// <param name="id">User ID</param>
        /// <returns>User object with user data</returns>
        public static User GetUserById(string id)
        {
            XmlDocument xmlDoc = ReadUserFile();

            XmlNode user = xmlDoc.SelectSingleNode(".//users/user[@ID='" + id + "']");

            if (user == null)
                throw new Exception("User not found!");

            Assembly asm = typeof(CurrentUser).Assembly;

            User newUser = new User(id, user.Attributes["Login"].Value, user.Attributes["PasswordHash"].Value)
            {
                Name = user.Attributes["Name"].Value
            };

            return newUser;
        }
示例#2
0
        /// <summary>
        /// Reads user data from file for user with a given login
        /// </summary>
        /// <param name="login">User login</param>
        /// <returns>User object with user data</returns>
        public static User GetUserByLogin(string login)
        {
            XmlDocument xmlDoc = ReadUserFile();

            XmlNode user = xmlDoc.SelectSingleNode(".//users/user[@login='******']");

            if (user == null)
                throw new Exception("User not found!");

            Assembly asm = typeof(CurrentUser).Assembly;

            User newUser = new User(user.Attributes["ID"].Value, user.Attributes["Login"].Value, user.Attributes["PasswordHash"].Value)
            {
                Name = user.Attributes["Name"].Value,
                Role = (UserRole)Enum.Parse(typeof(UserRole), user.Attributes["Role"].Value)
            };

            return newUser;
        }
示例#3
0
        /// <summary>
        /// Reads user data from file for all users
        /// </summary>
        /// <returns>List of User objects with user data</returns>
        public static Dictionary<string, User> GetUserList()
        {
            Dictionary<string, User> lstUsers = new Dictionary<string, User>();

            XmlDocument xmlDoc = ReadUserFile();
            XmlNodeList users = xmlDoc.GetElementsByTagName("users").Item(0).ChildNodes;

            Assembly asm = typeof(CurrentUser).Assembly;

            // Loop on all nodes existing in "temp"
            foreach (XmlNode node in users)
            {
                // Determines the type of the current node name by searching in the assembly object "asm"
                Type t = asm.GetType("MCBR.UIBlock.MCBRWeb.User." + node.Name);

                // The vehicle nodes inside the current "type" node
                XmlNodeList itemsOfType = node.ChildNodes;

                // Loop on all vehicle nodes inside the current type
                foreach (XmlNode user in itemsOfType)
                {
                    string id = user.Attributes["ID"].Value;

                    User newUser = new User(id)
                    {
                        Login = user.Attributes["Login"].Value,
                        Name = user.Attributes["Name"].Value,
                        Role = (UserRole)Enum.Parse(typeof(UserRole), user.Attributes["Role"].Value)
                    };

                    // Add to dictionary
                    lstUsers.Add(id, newUser);
                }
            }

            return lstUsers;
        }