public async Task <QueuDto> GetByNameOrDefaultAsync(string name)
        {
            if (name == null)
            {
                throw new ArgumentNullException(nameof(name));
            }

            using SqlConnection connection = new SqlConnection(this.connectionString);
            await connection.OpenAsync().ConfigureAwait(false);

            using SqlCommand command = connection.CreateCommand();
            command.CommandText      = @"SELECT TOP(1) [Id], [Name], [TopicPattern], [NotificationAdress], [Created] FROM [dbo].[QueuRecord] WHERE [Name] = @name";
            command.CommandType      = System.Data.CommandType.Text;
            command.Parameters.AddWithValue("@name", name);

            using SqlDataReader reader = await command.ExecuteReaderAsync().ConfigureAwait(false);

            while (await reader.ReadAsync().ConfigureAwait(false))
            {
                QueuDto dto = this.MapDto(reader);

                return(dto);
            }

            return(null);
        }
Exemple #2
0
        public async Task <IActionResult> Post([FromBody] QueuCreateReqDto queuDto, [FromQuery] bool explicid = true)
        {
            this.logger.LogTrace("Call Post for Queu name='{0}', topic pattern='{1}', Notification Adress='{2}'.", queuDto.Name, queuDto.TopicPattern, queuDto.NotificationAdress);
            if (explicid == true)
            {
                Guid id = await this.queuRepository.CreateAsync(queuDto).ConfigureAwait(false);

                await this.notificationSender.SetNotificationAdress(id, queuDto.NotificationAdress).ConfigureAwait(false);

                QueuDto dto = await this.queuRepository.GetByIdAsync(id).ConfigureAwait(false);

                this.logger.LogInformation("Create queu with id={0}", dto.Id);
                return(this.CreatedAtAction(nameof(this.Get), new { id = id }, dto));
            }
            else
            {
                QueuDto dto = await this.queuRepository.GetByNameOrDefaultAsync(queuDto.Name).ConfigureAwait(false);

                if (dto == null)
                {
                    Guid id = await this.queuRepository.CreateAsync(queuDto).ConfigureAwait(false);

                    await this.notificationSender.SetNotificationAdress(id, queuDto.NotificationAdress).ConfigureAwait(false);

                    dto = await this.queuRepository.GetByIdAsync(id).ConfigureAwait(false);

                    this.logger.LogInformation("Create queu with id={0}", dto.Id);
                    return(this.CreatedAtAction(nameof(this.Get), new { id = id }, dto));
                }
                else
                {
                    return(this.Ok(dto));
                }
            }
        }
Exemple #3
0
        public async Task <IActionResult> Get(Guid id)
        {
            this.logger.LogTrace("Call Get with Id={0}", id);

            QueuDto dto = await this.queuRepository.GetByIdAsync(id).ConfigureAwait(false);

            return(this.Ok(dto));
        }
        private QueuDto MapDto(SqlDataReader reader)
        {
            QueuDto dto = new QueuDto();

            dto.Created            = (DateTime)reader["Created"];
            dto.Id                 = (Guid)reader["Id"];
            dto.Name               = (string)reader["Name"];
            dto.NotificationAdress = reader.GetString("NotificationAdress");
            dto.TopicPattern       = reader.GetString("TopicPattern");

            return(dto);
        }
Exemple #5
0
        public async Task <IActionResult> Get([FromRoute] string name)
        {
            this.logger.LogTrace("Call get with name={0}", name);

            name = name.Trim();
            QueuDto dto = await this.queuRepository.GetByNameOrDefaultAsync(name).ConfigureAwait(false);

            if (dto == null)
            {
                return(this.NotFound());
            }
            else
            {
                return(this.Ok(dto));
            }
        }
Exemple #6
0
        public static Queu FromDto(QueuDto dto)
        {
            if (dto == null)
            {
                return(null);
            }

            return(new Queu()
            {
                Created = dto.Created.Value,
                Id = dto.Id.Value,
                Name = dto.Name,
                NotificationAdress = dto.NotificationAdress,
                TopicPattern = dto.TopicPattern
            });
        }
        public async Task <QueuDto> GetByIdAsync(Guid id)
        {
            using SqlConnection connection = new SqlConnection(this.connectionString);
            await connection.OpenAsync().ConfigureAwait(false);

            using SqlCommand command = connection.CreateCommand();
            command.CommandText      = @"SELECT TOP(1) [Id], [Name], [TopicPattern], [NotificationAdress], [Created] FROM [dbo].[QueuRecord] WHERE [Id] = @id";
            command.CommandType      = System.Data.CommandType.Text;
            command.Parameters.AddWithValue("@id", id);

            using SqlDataReader reader = await command.ExecuteReaderAsync().ConfigureAwait(false);

            while (await reader.ReadAsync().ConfigureAwait(false))
            {
                QueuDto dto = this.MapDto(reader);

                return(dto);
            }

            throw new PassiveMQNotFoundException("Queu", id);
        }