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)); }
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)); }
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 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)); }
public async Task Disconnect() { _source.Cancel(); await _deviceClient.CloseAsync(); _isConnected = false; SendDeviceConnectionUpdatedMessage(); _consoleLoggerService.Log(_translationsService.GetString("DeviceDisconnected"), ConsoleLogTypes.D2CCommunication); }
public async Task SaveDeviceSettingFromDiskAsync(BaseSetting deviceSetting) { var savePicker = new Windows.Storage.Pickers.FileSavePicker(); savePicker.SuggestedStartLocation = Windows.Storage.Pickers.PickerLocationId.DocumentsLibrary; // Dropdown of file types the user can save the file as savePicker.FileTypeChoices.Add(_translationsService.GetString("JsonConfig"), new List <string>() { FileTypeFilterJsonExtension }); // Default file name if the user does not type one in or select a file to replace savePicker.SuggestedFileName = _translationsService.GetString("DeviceConfigFileName"); Windows.Storage.StorageFile file = await savePicker.PickSaveFileAsync(); if (file != null) { // Prevent updates to the remote version of the file until // we finish making changes and call CompleteUpdatesAsync. Windows.Storage.CachedFileManager.DeferUpdates(file); var deviceSettingJsonString = JsonConvert.SerializeObject(deviceSetting); // write to file await Windows.Storage.FileIO.WriteTextAsync(file, deviceSettingJsonString); // Let Windows know that we're finished changing the file so // the other app can update the remote version of the file. // Completing updates may require Windows to ask for user input. await Windows.Storage.CachedFileManager.CompleteUpdatesAsync(file); } }