Exemplo n.º 1
0
 public ThingSetupInfo(IThingConfiguration thingConfiguration, IThingTemplate thingTemplate, IThing thing)
     : base(thingConfiguration.Settings)
 {
     Address  = thingConfiguration.Address;
     Template = thingTemplate;
     Id       = thing.Id;
 }
Exemplo n.º 2
0
        private async Task InitThingAsync(IThingConfiguration thingConfiguration)
        {
            var thing = await _thingBuilder.Build(thingConfiguration);

            if (thing == null)
            {
                return;
            }

            _requestDispatcher.Process(new KernelRequest($"InitThing {thing.Id}", () => thing.InitAsync()));
        }
Exemplo n.º 3
0
        public async Task <Thing> Build(IThingConfiguration thingConfiguration)
        {
            var gateway = _gatewayRepository.FirstOrDefault(x => x.Name == thingConfiguration.GatewayName);

            if (gateway == null)
            {
                Log.Warn($"Gateway '{thingConfiguration.GatewayName}' for thing '{thingConfiguration.Name}' not found");

                return(null);
            }

            var thingTemplate = _thingTemplateRepository.GetTemplate(thingConfiguration.Template);

            return(await CreateThing(thingConfiguration, thingTemplate, gateway));
        }
Exemplo n.º 4
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);
        }