コード例 #1
0
ファイル: SmcTicketThread.cs プロジェクト: dwenndson/TesteSMI
        public SmcTicketThread(SmcDto smcDto, ClientSettings clientSettings,
                               BrokerSettings brokerSettings, IMqttClientConfiguration mqttClientConfiguration,
                               IMqttClientMethods mqttClientMethods, Topic topic,
                               CommandRules commandRules, IEventService eventService, IForwarderSenderService forwarderSenderService)
        {
            Smc                             = smcDto;
            _eventService                   = eventService;
            _forwarderSenderService         = forwarderSenderService;
            Tickets                         = new ConcurrentPriorityQueue <TicketThreadObject>();
            _executingCommandSemaphore      = new SemaphoreSlim(1, 1);
            _waitingCommandMessageSemaphore = new SemaphoreSlim(1, 1);
            _answerSemaphore                = new SemaphoreSlim(1, 1);

            var localClientSettings = new ClientSettings
            {
                ClientId = clientSettings.ClientId, ClientName = clientSettings.ClientName
            };

            localClientSettings.ClientId   = localClientSettings.ClientId.Replace("serial", smcDto.Serial);
            localClientSettings.ClientName = localClientSettings.ClientName.Replace("serial", smcDto.Serial);
            localClientSettings.DebugMode  = clientSettings.DebugMode;
            localClientSettings.AutoReconnectDelayInSeconds = clientSettings.AutoReconnectDelayInSeconds;
            var localTopic = new Topic {
                Address = topic.Address, QoS = topic.QoS
            };

            localTopic.Address = localTopic.Address
                                 .Replace("{smc-or-meter}", CommandDeviceType.Smc.ToString().ToLower())
                                 .Replace("{serial}", smcDto.Serial);
            _mqttClient = new IoGMqttClient(localClientSettings, brokerSettings, mqttClientConfiguration,
                                            mqttClientMethods);
            _mqttClient.Subscribe(localTopic);
            _mqttClient.MessageReceivedHandler += ReceivedUpdate;
            _commandRules = commandRules;
        }
 public IogServicesMqttCommandsReceiverHostedService(IOptions <Forwarder> mqttConfiguration,
                                                     IServiceProvider serviceProvider, IMqttClientMethods mqttClientMethods,
                                                     IMqttClientConfiguration mqttClientConfiguration, IEventService eventService)
 {
     _mqttConfiguration       = mqttConfiguration.Value.Mqtt;
     _serviceProvider         = serviceProvider;
     _mqttClientConfiguration = mqttClientConfiguration;
     _mqttClientMethods       = mqttClientMethods;
     _eventService            = eventService;
 }
コード例 #3
0
        public IogServicesMqttMessagesReceiverTask(IOptionsMonitor <Forwarder> forwarderConfig,
                                                   IMqttClientMethods mqttClientMethods,
                                                   IMqttClientConfiguration mqttClientConfiguration,
                                                   IServiceProvider services)
        {
            var client = forwarderConfig.CurrentValue.Mqtt.HostedServiceClientSettings;
            var broker = forwarderConfig.CurrentValue.Mqtt.BrokerSettings;

            _ioGMqttClient    = new IoGMqttClient(client, broker, mqttClientConfiguration, mqttClientMethods);
            _topicToSubscribe = forwarderConfig.CurrentValue.Mqtt.HostedServiceSubscribeTopic;
            Services          = services;
        }
コード例 #4
0
ファイル: ThreadService.cs プロジェクト: dwenndson/TesteSMI
 public ThreadService(IMqttClientMethods mqttClientMethods, IMqttClientConfiguration mqttClientConfiguration,
                      IOptions <Forwarder> forwarderConfig, IServiceProvider serviceProvider, ISmcService smcService,
                      IOptions <CommandRules> commandRules, IEventService eventService,
                      IForwarderSenderService forwarderSenderService, IMeterService meterService)
 {
     _mqttClientConfiguration = mqttClientConfiguration;
     _mqttClientMethods       = mqttClientMethods;
     _brokerSettings          = forwarderConfig.Value.Mqtt.BrokerSettings;
     _baseClientSettings      = forwarderConfig.Value.Mqtt.CommandsBaseClientSettings;
     _subscribeTopic          = forwarderConfig.Value.Mqtt.BaseCommandsSubscribeTopic;
     _smcService   = smcService;
     _commandRules = commandRules.Value;
     _eventService = eventService;
     _eventService.AThreadIsShuttingDown += AThreadIsShuttingDown;
     _forwarderSenderService              = forwarderSenderService;
     _meterService = meterService;
 }
コード例 #5
0
ファイル: CommandThread.cs プロジェクト: dwenndson/TesteSMI
        public CommandThread(MeterDto meterDto, ClientSettings clientSettings, BrokerSettings brokerSettings,
                             IMqttClientConfiguration mqttClientConfiguration, IMqttClientMethods mqttClientMethods, Topic topic,
                             IServiceProvider serviceProvider, CommandRules commandRules)
        {
            MeterDto           = meterDto;
            _mutex             = new Semaphore(0, 10000);
            _answeredSemaphore = new Semaphore(1, 1);
            _commandQueue      = new ConcurrentQueue <Command>();
            _serviceProvider   = serviceProvider;
            _commandRules      = commandRules;


            clientSettings.ClientId   = clientSettings.ClientId.Replace("serial", meterDto.Serial);
            clientSettings.ClientName = clientSettings.ClientName.Replace("serial", meterDto.Serial);
            topic.Address             = topic.Address.Replace("{smc-or-meter}", "meter").Replace("{serial}", meterDto.Serial);
            _mqttClient = new IoGMqttClient(clientSettings, brokerSettings, mqttClientConfiguration, mqttClientMethods);
            _mqttClient.Subscribe(topic);
            _mqttClient.MessageReceivedHandler += ReceivedCommandAnswer;
        }