コード例 #1
0
        public Gateway(IGatewayConfiguration gatewayConfiguration, IMessageHub messageHub)
        {
            _messageHub = messageHub;
            Name        = gatewayConfiguration.Name;
            Id          = new GatewayId(gatewayConfiguration.DriverName, gatewayConfiguration.Name);

            _state = new SynchronizedValue <ThingState>();
        }
コード例 #2
0
        private async Task InitGatewayAsync(IGatewayConfiguration gatewayConfiguration, Action <IGateway> afterGatewayCreation)
        {
            var gateway = await _gatewayBuilder.Build(gatewayConfiguration);

            if (gateway == null)
            {
                return;
            }

            afterGatewayCreation(gateway);

            _requestDispatcher.Process(new KernelRequest($"InitGateway {gateway.Id}", () => gateway.InitAsync()));
        }
コード例 #3
0
        private IGatewayHandler CreateGatewayHandler(IGatewayConfiguration gatewayConfiguration, IGateway gateway)
        {
            var driver = _driverSubSystem.GetDriver(gatewayConfiguration.DriverName);

            if (driver == null)
            {
                Log.Warn($"Driver '{gatewayConfiguration.DriverName}' for gateway '{gatewayConfiguration.Name}' not found");

                return(null);
            }

            var gatewayHandler = driver.CreateGatewayHandler(new GatewaySetupInfo(gatewayConfiguration, gateway.Id));

            return(gatewayHandler);
        }
コード例 #4
0
        public async Task <Gateway> Build(IGatewayConfiguration gatewayConfiguration)
        {
            var gateway = new Gateway(gatewayConfiguration, _messageHub);

            var gatewayHandler = CreateGatewayHandler(gatewayConfiguration, gateway);

            if (gatewayHandler == null)
            {
                Log.Error($"Driver '{gatewayConfiguration.DriverName}' does not create gateway handler for gateway '{gatewayConfiguration.Name}'");

                return(null);
            }

            Log.Info($"Gateway handler for gateway '{gatewayConfiguration.Name}' created");

            gateway.SetHandler(gatewayHandler);

            await gatewayHandler.SetupAsync(_messageHub);

            await _gatewayRepository.AddAsync(gateway).ConfigureAwait(false);

            return(gateway);
        }
コード例 #5
0
 public GatewaySetupInfo(IGatewayConfiguration gatewayConfiguration, GatewayId id) : base(gatewayConfiguration.Settings)
 {
     Id          = id;
     GatewayType = gatewayConfiguration.GatewayType;
     Address     = gatewayConfiguration.Address;
 }
コード例 #6
0
 public GatewayConfigurationPackage(IGatewayConfiguration gatewayConfiguration,
                                    IEnumerable <IThingConfiguration> thingConfigurations)
 {
     GatewayConfiguration = gatewayConfiguration;
     ThingConfigurations  = thingConfigurations;
 }