Example #1
0
        private async Task <Thing> CreateThing(IThingConfiguration thingConfiguration, IThingTemplate thingTemplate, IGateway gateway)
        {
            var thing = new Thing(thingConfiguration.Name, gateway.Id, thingTemplate, _thingChannelBuilder, _messageHub);

            var thingHandler = gateway.CreateThingHandler(new ThingSetupInfo(thingConfiguration, thingTemplate, thing));

            if (thingHandler == null)
            {
                Log.Error($"Gateway '{thingConfiguration.GatewayName}' does not create thing handler for thing '{thingConfiguration.Name}'");

                return(null);
            }

            Log.Info($"Thing handler for thing '{thingConfiguration.Name}' created");

            thing.SetHandler(thingHandler);

            await thingHandler.SetupAsync(_messageHub).ConfigureAwait(false);

            await _thingRepository.AddAsync(thing).ConfigureAwait(false);

            return(thing);
        }