Exemplo n.º 1
0
        public Task Connect(string endpoint,
                            string key,
                            string topic,
                            string subject,
                            string eventType,
                            string dataVersion)
        {
            if (string.IsNullOrEmpty(endpoint) ||
                string.IsNullOrEmpty(key) ||
                string.IsNullOrEmpty(topic) ||
                string.IsNullOrEmpty(subject) ||
                string.IsNullOrEmpty(eventType) ||
                string.IsNullOrEmpty(dataVersion))
            {
                throw new InvalidDataException();
            }

            _endpoint    = endpoint;
            _key         = key;
            _topic       = topic;
            _subject     = subject;
            _eventType   = eventType;
            _dataVersion = dataVersion;

            TopicCredentials topicCredentials = new TopicCredentials(_key);

            _eventGridClient = new EventGridClient(topicCredentials);
            _isConnected     = true;

            _consoleLoggerService.Log(value: _translationsService.GetString("EventGridConnected"),
                                      logType: ConsoleLogTypes.EventGrid);

            return(Task.FromResult(true));
        }
Exemplo n.º 2
0
        public Task Connect(string connectionString)
        {
            _source            = new CancellationTokenSource();
            _cancellationToken = _source.Token;
            _eventHubClient    = EventHubClient.CreateFromConnectionString(connectionString);
            _isConnected       = true;

            _consoleLoggerService.Log(value: _translationsService.GetString("EventHubConnected"),
                                      logType: ConsoleLogTypes.EventHub);
            _isConnected = true;
            SendConnectionUpdatedMessage();
            return(Task.FromResult(true));
        }
Exemplo n.º 3
0
        public Task Connect(string hostName, string topic)
        {
            _source            = new CancellationTokenSource();
            _cancellationToken = _source.Token;
            _topic             = topic;
            _mqttClient        = new MqttClient(hostName);

            var clientId = Guid.NewGuid().ToString();

            _mqttClient.Connect(clientId);

            _consoleLoggerService.Log(value: _translationsService.GetString("MqttPublisherConnected"),
                                      logType: ConsoleLogTypes.MqttPublisher);
            _isConnected = true;
            SendConnectionUpdatedMessage();
            return(Task.FromResult(true));
        }
        public async Task Disconnect()
        {
            _source.Cancel();
            await _deviceClient.CloseAsync();

            _isConnected = false;

            SendDeviceConnectionUpdatedMessage();

            _consoleLoggerService.Log(_translationsService.GetString("DeviceDisconnected"),
                                      ConsoleLogTypes.D2CCommunication);
        }
        public Task Connect(string connectionString,
                            string entity,
                            ServiceBusPublisherTypes serviceBusPublisherType)
        {
            _serviceBusPublisherTypes = serviceBusPublisherType;
            if (serviceBusPublisherType == ServiceBusPublisherTypes.Queue)
            {
                _senderClient = new QueueClient(connectionString, entity);
            }
            else
            {
                _senderClient = new TopicClient(connectionString, entity);
            }
            IsConnected = true;

            _consoleLoggerService.Log(value: _translationsService.GetString("ServiceBusConnected"),
                                      logType: ConsoleLogTypes.ServiceBus);

            return(Task.FromResult(true));
        }