Beispiel #1
0
        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)));
            }
        }
Beispiel #2
0
        public ActionResult Edit(string id)
        {
            CacheHelper.SetPreviousPage(_cache, Request.Headers["Referer"].ToString());
            var simulator = new SimulatorViewModel(_cache);

            simulator.SelectedSensor = id;

            return(View(simulator));
        }
Beispiel #3
0
        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());
        }
Beispiel #4
0
        public async Task <IActionResult> Post(SimulatorViewModel simulatorModel)
        {
            var simulator = _mapper.Map <SimulatorViewModel, Simulator>(simulatorModel);

            _context.Add(simulator);
            await _context.SaveChangesAsync();

            return(Ok(simulator.ID));
        }
Beispiel #5
0
        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)));
        }
Beispiel #6
0
 public FuseModel(SimulatorViewModel owner)
 {
     Owner = owner;
 }
Beispiel #7
0
 // initialize MainWindow with data context of SimualtorViewModel
 public MainWindow()
 {
     InitializeComponent();
     _viewModel = DataContext as SimulatorViewModel;
     _viewModel?.LoadFile("../../Resources/source.S", RichTextBoxEditor.Document);
 }
Beispiel #8
0
        public ActionResult Index()
        {
            var simulator = new SimulatorViewModel(_cache);

            return(View(simulator));
        }
        public SimulatorView()
        {
            ViewModel = new SimulatorViewModel();

            this.InitializeComponent();
        }
Beispiel #10
0
 public void Show(GameConfiguration configuration)
 {
     DataContext = new SimulatorViewModel(configuration);
     Show();
 }
 public void Show(GameConfiguration configuration)
 {
     DataContext = new SimulatorViewModel(configuration);
     Show();
 }