Exemplo n.º 1
0
        public Task Publish(CommandModel command)
        {
            var message = new MqttApplicationMessageBuilder()
                          .WithTopic("BOILER_COMMAND/JSON")
                          .WithPayload(JsonConvert.SerializeObject(command))
                          .Build();

            return(mqttClientService.PublishAsync(message, CancellationToken.None));
        }
Exemplo n.º 2
0
    public Task PublishAsync(string exchange, string typeName, byte[] body,
                             CancellationToken cancellationToken = default)
    {
        var msg = new MqttApplicationMessage
        {
            Topic       = exchange,
            ContentType = typeName,
            Payload     = body
        };

        return(_mqttClientService.PublishAsync(msg));
    }
        public async Task <string> ScheduleAsync(EmailMessage message, CancellationToken cancellationToken)
        {
            var context = _httpContextAccessor.HttpContext;

            if (context is null)
            {
                throw new InvalidOperationException($"Email scheduler is being invoked outside of request context.");
            }
            if (!context.User.Identity.IsAuthenticated)
            {
                throw new UnauthorizedException();
            }
            var owner = context.User.FindFirstValue(OAuth2ClaimTypes.Ownership);

            if (string.IsNullOrEmpty(owner))
            {
                throw new ForbiddenException($"Current user does not specify ownership.");
            }
            var messageId = await _mqttClientService.PublishAsync(new EmailMessageTask(message, owner), cancellationToken);

            return(messageId.HasValue ? messageId.Value.ToString() : string.Empty);
        }
Exemplo n.º 4
0
        // обновление документа
        public async Task UpdateFromUIAsync(Client client, Device device)
        {
            if (device.TypeOfDevice == "Light")
            {
                if (ConnectSingleton.IsConnected == false)
                {
                    await _mqttClientService.ConnectAsync(client.Id);

                    await _mqttClientService.SubscribeAsync(device.Topic);

                    ConnectSingleton.getInstance(true);
                }
                var messagePayload = new MqttApplicationMessageBuilder()
                                     .WithTopic(device.Topic)
                                     .WithPayload(device.Payload)
                                     .WithExactlyOnceQoS()
                                     .WithRetainFlag()
                                     .Build();
                await _mqttClientService.PublishAsync(messagePayload);
            }
            await Devices.ReplaceOneAsync(new BsonDocument("_id", new ObjectId(device.Id)), device);
        }
Exemplo n.º 5
0
 public async Task PublishAsync(string topic, string payload)
 {
     await _mqttClientService.PublishAsync(topic, payload);
 }
Exemplo n.º 6
0
 public async Task PublishToMqttBroker(string topic, string payload)
 {
     await mqttClientService.PublishAsync(topic, payload);
 }
 public Task SendMessageToTopic([FromBody] string payload)
 {
     return(_mqttClient.PublishAsync(payload));
 }
Exemplo n.º 8
0
        public void CatchThief()
        {
            AddMessageToConsole(Me, "Sending catch thief signal.");

            m_MqttClient.PublishAsync("suitceyes/kyd/CatchThief");
        }