예제 #1
0
파일: SimManager.cs 프로젝트: tbaggs/SimMan
        private async Task SimulateButtonPush()
        {
            Guid iD = Guid.NewGuid();

            _logger.LogInformation("Generating grid zone {0} for button push", iD);

            Zone zone = new Zone
            {
                Id            = iD,
                Name          = "Zone_Button_Sim",
                IoTDeviceInfo = await _deviceManager.AddDeviceAsync(iD.ToString()).ConfigureAwait(false),
                GridLocation  = await _gridManager.AssignBlock(iD, true).ConfigureAwait(false)
            };

            Location location = await _gridManager.GetGridLocation(zone.GridLocation).ConfigureAwait(false);

            _logger.LogInformation("Creating telemetry data point for device {0}", zone.Name);

            var telemetryDataPoint = new ZoneDataPoint
            {
                DeviceId   = zone.IoTDeviceInfo.DeviceId,
                Name       = "Sim1",
                Type       = zone.Type,
                Grid_x     = location.Rowx,
                Grid_y     = location.Columny,
                Operation  = "button_pushed",
                InZone     = true,
                ZoneId     = zone.Id,
                ZoneGrid_x = location.Rowx,
                ZoneGrid_y = location.Columny,
                ZoneName   = zone.Name
            };

            _logger.LogInformation("Sending button push message to hub");

            await SendIoTHubMessage(zone, telemetryDataPoint).ConfigureAwait(false);


            _logger.LogInformation("Removing device {0} from IoT Hub", zone.Id);

            await _deviceManager.RemoveDeviceAsync(zone.Id.ToString()).ConfigureAwait(false);
        }