Exemplo n.º 1
0
        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);
        }
Exemplo n.º 2
0
        public async Task <Device> AddDeviceAsync(string name, string deviceId, DeviceRepository repo, DeviceConfiguration deviceConfig, DeviceType deviceType,
                                                  EntityHeader org, EntityHeader user, DateTime createTimestamp)
        {
            if (deviceType == null)
            {
                throw new ArgumentNullException(nameof(deviceType));
            }
            if (deviceConfig == null)
            {
                throw new ArgumentNullException(nameof(deviceConfig));
            }
            if (repo == null)
            {
                throw new ArgumentNullException(nameof(repo));
            }


            var device = new Device();

            device.Name             = name;
            device.DeviceId         = deviceId;
            device.DeviceRepository = new EntityHeader()
            {
                Id = repo.Id, Text = repo.Name
            };
            device.DeviceType = new EntityHeader <DeviceType> {
                Id = deviceType.Id, Text = deviceType.Name
            };
            device.DeviceConfiguration = new EntityHeader()
            {
                Id = deviceConfig.Id, Text = deviceConfig.Name
            };
            device.SerialNumber = "SN0001";
            var rnd    = new Random();
            var buffer = new byte[64];

            rnd.NextBytes(buffer);
            device.PrimaryAccessKey = btoa(buffer);
            rnd.NextBytes(buffer);
            device.SecondaryAccessKey = btoa(buffer);

            AddId(device);
            AddAuditProperties(device, createTimestamp, org, user);
            AddOwnedProperties(device, org);

            await _deviceManager.AddDeviceAsync(repo, device, org, user);

            return(device);
        }
        public async Task <InvokeResult> AddDeviceAsync([FromBody] Device device)
        {
            var repo = await GetDeviceRepositoryWithSecretsAsync();

            return(await _deviceManager.AddDeviceAsync(repo, device, OrgEntityHeader, UserEntityHeader));
        }
        public async Task <InvokeResult> AddDeviceAsync(string devicerepoid, [FromBody] Device device)
        {
            var repo = await _repoManager.GetDeviceRepositoryAsync(devicerepoid, OrgEntityHeader, UserEntityHeader);

            return(await _deviceManager.AddDeviceAsync(repo, device, OrgEntityHeader, UserEntityHeader));
        }