Пример #1
0
        /// <summary>
        /// Formats the name of the vm ensuring it is not taken.
        /// </summary>
        /// <returns>The vm name.</returns>
        /// <param name="vmName">The desired vm name based off of the group name.</param>
        public string FormatVmName(String vmName, ref List <Exception> excepts)
        {
            GuacamoleDatabaseSearcher searcher = new GuacamoleDatabaseSearcher();
            int vmId = 1;

            if (vmId != -1)
            {
                return(FormatName(vmName + "_" + vmId));
            }
            return(null);
        }
Пример #2
0
        /// <summary>
        /// Initializes the user by checking if they exist and creates a user
        /// if that user does not exist yet.
        /// </summary>
        /// <returns><c>true</c>, if user was initialized, <c>false</c> otherwise.</returns>
        /// <param name="dawgtag">Dawgtag.</param>
        /// <param name="excepts">Excepts.</param>
        protected bool InitializeUser(string dawgtag, ref List <Exception> excepts)
        {
            GuacamoleDatabaseInserter inserter = new GuacamoleDatabaseInserter();
            GuacamoleDatabaseSearcher searcher = new GuacamoleDatabaseSearcher();

            //Check if the user already exists
            if (!searcher.SearchUserName(dawgtag, ref excepts))
            {
                //Add the user if it was not found
                return(inserter.InsertUser(dawgtag, ref excepts));
            }
            return(true);
        }
Пример #3
0
        /// <summary>
        /// Validates the existing name of a group.
        /// </summary>
        /// <returns><c>true</c>, if new group name was validated, <c>false</c> otherwise.</returns>
        /// <param name="groupName">Group name.</param>
        /// <param name="exceptions">Exceptions.</param>
        public bool ValidateExistingGroupName(string groupName, ref List <Exception> exceptions)
        {
            string execptMessage = $"The given group name {groupName} does not exist.";

            GuacamoleDatabaseSearcher searcher = new GuacamoleDatabaseSearcher();

            if (!searcher.SearchConnectionGroupName(groupName, ref exceptions))
            {
                exceptions.Add(new ValidationException(execptMessage));
                return(false);
            }
            if (!searcher.SearchUserGroupName(groupName, ref exceptions))
            {
                exceptions.Add(new ValidationException(execptMessage));
                return(false);
            }
            return(true);
        }
Пример #4
0
        /*******************************************************************************
         *------------------------Primary Validator Methods----------------------------*
         ******************************************************************************/
        /// <summary>
        /// Validates the name of the group by checking if the given name exists within
        /// the guacamole database.
        /// </summary>
        /// <param name="groupName">Group name.</param>
        public bool ValidateNewGroupName(string groupName, ref List <Exception> exceptions)
        {
            string execptMessage = $"The given group name {groupName} already " +
                                   "exists. Please choose another name or edit the existing group.";

            GuacamoleDatabaseSearcher searcher = new GuacamoleDatabaseSearcher();

            if (searcher.SearchConnectionGroupName(groupName, ref exceptions))
            {
                exceptions.Add(new ValidationException(execptMessage));
                return(false);
            }
            if (searcher.SearchUserGroupName(groupName, ref exceptions))
            {
                exceptions.Add(new ValidationException(execptMessage));
                return(false);
            }
            return(true);
        }
Пример #5
0
        public ActionResult UpdateUsers(GroupsToAddDto groupsToAddDto)
        {
            //Method Level Variable Declarations
            List <Exception>          excepts  = new List <Exception>();
            GuacamoleDatabaseInserter inserter = new GuacamoleDatabaseInserter();
            GuacamoleDatabaseDeleter  deleter  = new GuacamoleDatabaseDeleter();
            GuacamoleDatabaseSearcher searcher = new GuacamoleDatabaseSearcher();

            if (!searcher.SearchConnectedUserGroup(groupsToAddDto.Id.ToString(), ref excepts))
            {
                inserter.InsertUserGroup(groupsToAddDto.Id, ref excepts);
                inserter.InsertConnectionGroupIntoUserGroup(groupsToAddDto.Id, false, ref excepts);
            }

            if (excepts.Count != 0)
            {
                return(Ok(false));
            }

            foreach (string id in groupsToAddDto.AddIds)
            {
                //Insert users that are not in the system
                if (!InitializeUser(id, ref excepts))
                {
                    var message = HandleErrors(excepts);
                    return(Ok(false));
                }
                inserter.InsertUserIntoUserGroup(groupsToAddDto.Id, id, ref excepts);
            }

            foreach (string id in groupsToAddDto.RemoveIds)
            {
                deleter.DeleteUserFromUserGroup(groupsToAddDto.Id, id, ref excepts);
            }
            return(Ok(true));
        }