예제 #1
0
        /// <summary>
        /// Creates a new room, based on provided parameters.
        /// Throws exception if values are invalid.
        /// </summary>
        /// <param name="owner">IUser object - Owner of the newly created room.</param>
        /// <param name="roomName">Requested room name.</param>
        /// <param name="services">List of streamingplatforms provided initially</param>
        /// <returns>Newly created room</returns>
        public IRoom CreateRoom(IUser owner, string roomName, List <IStreamingPlatform> services)
        {
            // Null checks
            if (owner == null)
            {
                throw new ArgumentNullException("owner", "Owner must not be null.");
            }
            if (services == null)
            {
                throw new ArgumentNullException("services", "Services must not be null.");
            }

            // Value checks
            if (string.IsNullOrEmpty(roomName) || string.IsNullOrWhiteSpace(roomName))
            {
                throw new ArgumentException("roomName", "RoomName must contain a value.");
            }
            if (owner.Id == 0)
            {
                throw new ArgumentException("Owner does not contain a valid Id.", "owner");
            }
            if (services.Count < 1)
            {
                throw new ArgumentException("Services must contain at least 1 streaming platform.", "services");
            }
            if (roomName.Length < 4)
            {
                throw new ArgumentException("roomName", "RoomName must be atleast 4 characters long.");
            }


            // Fields and values
            IRoom  roomToBeCreated;
            string roomKey;

            // Create room key.
            IKeyGenerator keyGenerator = KeyGeneratorFactory.GetKeyGenerator();
            bool          keyIsUnique  = false;

            // Check that key is unique
            // Retry if the key is not unique
            do
            {
                // Generate key
                roomKey = keyGenerator.GenerateKey();

                // Check if the generated key exists.
                keyIsUnique = this._roomDAO.ValidateRoomKey(roomKey);
            } while (keyIsUnique);

            // Create room object.
            roomToBeCreated = new Room(roomName, owner, roomKey, services);

            // Generate room object on DAO
            roomToBeCreated = this._roomDAO.Create(roomToBeCreated);

            // Return created room
            return(roomToBeCreated);
        }
예제 #2
0
        /// <summary>
        /// Builds name for key generator.
        /// </summary>
        /// <param name="key">Key to build key generator name for.</param>
        /// <param name="hierarchyDef">Hierarchy definition.</param>
        /// <returns>Key generator name</returns>
        public string BuildKeyGeneratorName(KeyInfo key, HierarchyDef hierarchyDef)
        {
            var mappingDatabase        = hierarchyDef.Root.MappingDatabase;
            var databaseSuffixRequired =
                key.GeneratorKind == KeyGeneratorKind.Default &&
                KeyGeneratorFactory.IsSequenceBacked(key.SingleColumnType) &&
                !string.IsNullOrEmpty(mappingDatabase);
            var baseName = key.GeneratorBaseName;

            return(databaseSuffixRequired
        ? FormatKeyGeneratorName(mappingDatabase, baseName)
        : baseName);
        }