/// <summary> /// Creates new queue and sends response /// </summary> private async Task UpdateQueue(MqClient client, HorseMessage message) { NetworkOptionsBuilder builder = await System.Text.Json.JsonSerializer.DeserializeAsync <NetworkOptionsBuilder>(message.Content); HorseQueue queue = _server.FindQueue(message.Target); if (queue == null) { if (message.WaitResponse) { await client.SendAsync(message.CreateResponse(HorseResultCode.NotFound)); } return; } foreach (IAdminAuthorization authorization in _server.AdminAuthorizations) { bool grant = await authorization.CanUpdateQueueOptions(client, queue, builder); if (!grant) { if (message.WaitResponse) { await client.SendAsync(message.CreateResponse(HorseResultCode.Unauthorized)); } return; } } builder.ApplyToQueue(queue.Options); if (builder.Status.HasValue) { await queue.SetStatus(builder.Status.Value); } _server.OnQueueUpdated.Trigger(queue); //if creation successful, sends response if (message.WaitResponse) { await client.SendAsync(message.CreateResponse(HorseResultCode.Ok)); } }
/// <summary> /// Creates new queue and sends response /// </summary> private async Task UpdateQueue(MqClient client, TmqMessage message) { if (_server.AdminAuthorization == null) { if (message.ResponseRequired) { await client.SendAsync(MessageBuilder.ResponseStatus(message, KnownContentTypes.Unauthorized)); } return; } NetworkOptionsBuilder builder = new NetworkOptionsBuilder(); builder.Load(message.ToString()); Channel channel = _server.FindChannel(message.Target); if (channel == null) { if (message.ResponseRequired) { await client.SendAsync(MessageBuilder.ResponseStatus(message, KnownContentTypes.NotFound)); } return; } ChannelQueue queue = channel.FindQueue(builder.Id); if (queue == null) { if (message.ResponseRequired) { await client.SendAsync(MessageBuilder.ResponseStatus(message, KnownContentTypes.NotFound)); } return; } bool grant = await _server.AdminAuthorization.CanUpdateQueueOptions(client, channel, queue, builder); if (!grant) { if (message.ResponseRequired) { await client.SendAsync(MessageBuilder.ResponseStatus(message, KnownContentTypes.Unauthorized)); } return; } builder.ApplyToQueue(queue.Options); if (builder.Status.HasValue) { await queue.SetStatus(builder.Status.Value); } //if creation successful, sends response if (message.ResponseRequired) { await client.SendAsync(MessageBuilder.ResponseStatus(message, KnownContentTypes.Ok)); } }
/// <summary> /// Creates new queue and sends response /// </summary> private async Task CreateQueue(MqClient client, HorseMessage message) { NetworkOptionsBuilder builder = null; if (message.Length > 0) { builder = await System.Text.Json.JsonSerializer.DeserializeAsync <NetworkOptionsBuilder>(message.Content); } HorseQueue queue = _server.FindQueue(message.Target); //if queue exists, we can't create. return duplicate response. if (queue != null) { if (message.WaitResponse) { await client.SendAsync(message.CreateResponse(HorseResultCode.Duplicate)); } return; } //check authority if client can create queue foreach (IClientAuthorization authorization in _server.Authorizations) { bool grant = await authorization.CanCreateQueue(client, message.Target, builder); if (!grant) { if (message.WaitResponse) { await client.SendAsync(message.CreateResponse(HorseResultCode.Unauthorized)); } return; } } //creates new queue QueueOptions options = QueueOptions.CloneFrom(_server.Options); if (builder != null) { builder.ApplyToQueue(options); } queue = await _server.CreateQueue(message.Target, options, message, _server.DeliveryHandlerFactory, true, false); //if creation successful, sends response if (message.WaitResponse) { if (queue != null) { await client.SendAsync(message.CreateResponse(HorseResultCode.Ok)); } else { await client.SendAsync(message.CreateResponse(HorseResultCode.Failed)); } } }