public async Task <ActionResult> SimulatorAction(SimulatorViewModel model, string Action) { if (Action.Equals("Cancel")) { return(Redirect(CacheHelper.GetPreviousPage(_cache))); } if (model.SelectedDevice == Guid.Empty) { await FeedbackHelper.Channel.SendMessageAsync("No connection string added to connect to Azure IoT Hub", MessageType.Info); return(RedirectToAction(nameof(Index))); } else { var device = await DigitalTwinsHelper.GetDeviceAsync(model.SelectedDevice, _cache, Loggers.SilentLogger, false); try { if (Action.Equals("Launch") && !CacheHelper.IsInSendingDataState(_cache)) { var list = await CacheHelper.GetSimulatedSensorListFromCacheAsync(_cache); if (list != null && list.Count > 0) { CacheHelper.SetInSendingDataState(_cache, true); try { await SendDataAsync(device.ConnectionString); } catch (Exception) { await FeedbackHelper.Channel.SendMessageAsync("Error during sending", MessageType.Info); } CacheHelper.SetInSendingDataState(_cache, false); } else { await FeedbackHelper.Channel.SendMessageAsync("No sensor defined to send data", MessageType.Info); } } else if (Action.Equals("Stop")) { await FeedbackHelper.Channel.SendMessageAsync("Stopping sending data...", MessageType.Info); CacheHelper.SetInSendingDataState(_cache, false); } } catch (Exception ex) { FeedbackHelper.Channel.SendMessageAsync($"Error - {ex.Message}", MessageType.Info).Wait(); } return(RedirectToAction(nameof(Index))); } }
private async Task LoadAsync(Guid?id = null) { SpaceList = await DigitalTwinsHelper.GetSpacesAsync(_cache, Loggers.SilentLogger); DeviceTypeList = await DigitalTwinsHelper.GetTypesAsync(Models.Types.DeviceType, _cache, Loggers.SilentLogger, onlyEnabled : true); DeviceSubTypeList = await DigitalTwinsHelper.GetTypesAsync(Models.Types.DeviceSubtype, _cache, Loggers.SilentLogger, onlyEnabled : true); if (id != null) { this.SelectedDeviceItem = await DigitalTwinsHelper.GetDeviceAsync((Guid)id, _cache, Loggers.SilentLogger, false); } }