private static async Task AddDevice(CreateDeviceCommand command) { using (var query = _services.GetService <IDeviceQueries>()) { if (await query.Exists(command.EquipNum)) { return; } var _mediator = _services.GetService <IMediator>(); await _mediator.Send(command); } }
public async Task ExecuteAsync_ReturnsDeviceClient() { // Arrange Mock <IDeviceClientFactory> deviceClientFactoryMock = new Mock <IDeviceClientFactory>(); var expectedDeviceClient = new Mock <IDeviceClient>().Object; deviceClientFactoryMock.Setup(m => m.CreateDeviceClient()).Returns(expectedDeviceClient); var command = new CreateDeviceCommand(deviceClientFactoryMock.Object); // Act var deviceClient = await command.ExecuteAsync(); // Assert deviceClient.Should().Be(expectedDeviceClient); }
public async Task <IActionResult> Add(CreateDeviceCommand command) { if (command.Protocol == ProtocolType.Http) { var id = await _mediator.Send(new CreateHttpDeviceCommand() { IpAddress = command.IpAddress, PortNumber = command.PortNumber }); command.ConnectedDeviceId = id; } else { await _mqttMessageService.RegisterPublishMessages(command.ConnectedDeviceId, command.ModelName); await _mqttMessageService.RegisterSubscribeMessages(command.ConnectedDeviceId, command.ModelName); } await _mediator.Send(command); return(Ok()); }
private static async Task Main() { Console.WriteLine("Initializing..."); var connectionString = "HostName=ps-iothub-fm.azure-devices.net;DeviceId=device1;SharedAccessKey=ZJNtwonsWec64h0N0sXaW4jaml5CJ5JVCZMIO8S9erQ="; var deviceClientFactory = new DeviceClientFactory(connectionString); var createDeviceCommand = new CreateDeviceCommand(deviceClientFactory); var deviceClient = await createDeviceCommand.ExecuteAsync(); await deviceClient.OpenAsync(); Console.WriteLine("Device is connected."); var updatePropertiesCommandParameters = new Dictionary <string, object> { { "connectionType", "wi-fi" }, { "connectionStrength", "strong" } }; var updatePropertiesCommand = new UpdateReportedPropertiesCommand(deviceClient); await updatePropertiesCommand.ExecuteAsync(updatePropertiesCommandParameters); while (true) { var obj = new { LuckyNumber = new Random().Next(100, 200), Ts = DateTime.UtcNow }; var sendEventCommand = new SendEventCommand(deviceClient); var sendEventCommandParameters = new Dictionary <string, object> { { "obj", obj } }; await sendEventCommand.ExecuteAsync(sendEventCommandParameters); Console.WriteLine("Message sent."); await Task.Delay(TimeSpan.FromSeconds(2)); } // ReSharper disable once FunctionNeverReturns }
public async Task <ActionResult <int> > Create(CreateDeviceCommand command) { return(await Mediator.Send(command)); }