コード例 #1
0
        public ActionResult CreateGroup(GroupForCreationDto groupForCreationDto)
        {
            //Method Level Variable Declarations
            List <Exception> excepts = new List <Exception>();

            //Check if the group inupt parameters are valid
            using (Validator checker = new Validator())
            {
                checker.ValidateGroupName(groupForCreationDto.Name, ref excepts);
                checker.ValidateVmTotal(groupForCreationDto.Max, ref excepts);
            }

            if (excepts.Count != 0)
            {
                var message = HandleErrors(excepts);
                return(Ok(null));
            }

            //Format connection group type
            using (Formatter styler = new Formatter())
            {
                groupForCreationDto.Type = styler.FormatName(groupForCreationDto.Type);
            }

            //Get affinity bool
            string affinityBool = "0";

            if (groupForCreationDto.Affinity)
            {
                affinityBool = "1";
            }

            //Create connection group
            GuacamoleDatabaseInserter inserter = new GuacamoleDatabaseInserter();

            if (!inserter.InsertConnectionGroup(groupForCreationDto.Name, groupForCreationDto.Type, groupForCreationDto.Max, affinityBool, ref excepts))
            {
                var message = HandleErrors(excepts);
                return(Ok(null));
            }

            //Get the newly created group id
            GuacamoleDatabaseGetter getter = new GuacamoleDatabaseGetter();

            groupForCreationDto.Id = getter.GetConnectionGroupId(groupForCreationDto.Name, ref excepts);
            return(Ok(groupForCreationDto));
        }
コード例 #2
0
        /// <summary>
        /// Creates the new connection group.
        /// </summary>
        /// <returns><c>true</c>, if the connection group was created, <c>false</c> otherwise.</returns>
        /// <param name="groupForCreationDto">Group for creation dto.</param>
        /// <param name="excepts">Excepts.</param>
        private bool CreateConnectionGroup(GroupForCreationDto groupForCreationDto, ref List <Exception> excepts)
        {
            GuacamoleDatabaseInserter inserter = new GuacamoleDatabaseInserter();

            return(inserter.InsertConnectionGroup(groupForCreationDto.Name, groupForCreationDto.MaxVms, ref excepts));
        }