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))); } }
public ActionResult Edit(string id) { CacheHelper.SetPreviousPage(_cache, Request.Headers["Referer"].ToString()); var simulator = new SimulatorViewModel(_cache); simulator.SelectedSensor = id; return(View(simulator)); }
public async Task <IActionResult> Put(SimulatorViewModel simulatorModel) { var simulator = _mapper.Map <SimulatorViewModel, Simulator>(simulatorModel); _context.Entry(simulator).State = EntityState.Modified; await _context.SaveChangesAsync(); return(NoContent()); }
public async Task <IActionResult> Post(SimulatorViewModel simulatorModel) { var simulator = _mapper.Map <SimulatorViewModel, Simulator>(simulatorModel); _context.Add(simulator); await _context.SaveChangesAsync(); return(Ok(simulator.ID)); }
public async Task <ActionResult> Edit(SimulatorViewModel model, string action) { if (action.Equals("Cancel")) { return(Redirect(CacheHelper.GetPreviousPage(_cache))); } var list = await CacheHelper.GetSimulatedSensorListFromCacheAsync(_cache); var item = list.First(t => t.HardwareId.Equals(model.SelectedSensor)); var index = list.IndexOf(item); list.Remove(item); list.Insert(index, model.SensorInEdit); await CacheHelper.AddSimulatedSensorListInCacheAsync(_cache, list); return(RedirectToAction(nameof(Index))); }
public FuseModel(SimulatorViewModel owner) { Owner = owner; }
// initialize MainWindow with data context of SimualtorViewModel public MainWindow() { InitializeComponent(); _viewModel = DataContext as SimulatorViewModel; _viewModel?.LoadFile("../../Resources/source.S", RichTextBoxEditor.Document); }
public ActionResult Index() { var simulator = new SimulatorViewModel(_cache); return(View(simulator)); }
public SimulatorView() { ViewModel = new SimulatorViewModel(); this.InitializeComponent(); }
public void Show(GameConfiguration configuration) { DataContext = new SimulatorViewModel(configuration); Show(); }