public async Task <bool> Start() { bool returnValue = false; try { // *** // *** Initialize the relay providers. // *** await this.TemperatureChangedRelayProviderSender?.Initialize(); await this.TemperatureChangedRelayProviderReceiver?.Initialize(); await this.DeviceCommandRelayProviderSender?.Initialize(); await this.DeviceCommandRelayProviderReceiver?.Initialize(); // *** // *** Relay the TemperatureChangedEventArgs via SignalR. // *** _temperatureChangedEventMap = new EventRelayMap <TemperatureChangedEventArgs>(this.ApplicationInstanceIdentity, this.TemperatureChangedRelayProviderSender, this.TemperatureChangedRelayProviderReceiver, this.EventAggregator.GetEvent <Events.TemperatureChangedEvent>(), (e) => { e.SensorReading.Source = ApplicationSensorReadingSource.Cloud; return(e); }, (e) => { return(e.SensorReading.Source == ApplicationSensorReadingSource.Device); }, (e) => { return(e); }, (e) => { return(e.SensorReading.Source == ApplicationSensorReadingSource.Device); }); // *** // *** Relay the DeviceCommandEventArgs via an IoT Hub // *** _deviceCommandEventMap = new EventRelayMap <DeviceCommandEventArgs>(this.ApplicationInstanceIdentity, this.DeviceCommandRelayProviderSender, this.DeviceCommandRelayProviderReceiver, this.EventAggregator.GetEvent <Events.DeviceCommandEvent>(), (e) => { return(e); }, (e) => { return(true); }, (e) => { return(e); }, (e) => { return(true); }); returnValue = true; } catch (Exception ex) { this.EventAggregator.GetEvent <Events.DebugEvent>().Publish(new DebugEventArgs(ex)); } return(returnValue); }
public async Task<bool> Start() { bool returnValue = false; try { // *** // *** Configure and connect to the SignalR hub // *** _hubConnection = new HubConnection(this.MobileServicesConfiguration.Url); _hubConnection.Headers["x-zumo-application"] = this.MobileServicesConfiguration.ApplicationKey; this._proxy = this._hubConnection.CreateHubProxy("RelayHub"); await this._hubConnection.Start(); // *** // *** Link the TemperatureChangedEventArgs to SignalR // *** _temperatureChangedEventMap = new EventRelayMap<TemperatureChangedEventArgs>(this.ApplicationInstanceIdentity, _hubConnection, _proxy, this.EventAggregator.GetEvent<Events.TemperatureChangedEvent>(), (e) => { e.SensorReading.Source = ApplicationSensorReadingSource.Cloud; return e; }, (e) => { return e.SensorReading.Source == ApplicationSensorReadingSource.Device; }, (e) => { return e; }, (e) => { return e.SensorReading.Source == ApplicationSensorReadingSource.Device; }); // *** // *** Link the DeviceCommandEventArgs to SignalR // *** _deviceCommandEventMap = new EventRelayMap<DeviceCommandEventArgs>(this.ApplicationInstanceIdentity, _hubConnection, _proxy, this.EventAggregator.GetEvent<Events.DeviceCommandEvent>(), (e) => { return e; }, (e) => { return true; }, (e) => { return e; }, (e) => { return true; }); returnValue = true; } catch (Exception ex) { this.EventAggregator.GetEvent<Events.DebugEvent>().Publish(new DebugEventArgs(ex)); } return returnValue; }
public Task <bool> Stop() { bool returnValue = false; if (_temperatureChangedEventMap != null) { _temperatureChangedEventMap.Dispose(); _temperatureChangedEventMap = null; } if (_deviceCommandEventMap != null) { _deviceCommandEventMap.Dispose(); _deviceCommandEventMap = null; } return(Task <bool> .FromResult(returnValue)); }