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

            return(View(simulator));
        }
Exemplo n.º 9
0
        public SimulatorView()
        {
            ViewModel = new SimulatorViewModel();

            this.InitializeComponent();
        }
Exemplo n.º 10
0
 public void Show(GameConfiguration configuration)
 {
     DataContext = new SimulatorViewModel(configuration);
     Show();
 }
Exemplo n.º 11
0
 public void Show(GameConfiguration configuration)
 {
     DataContext = new SimulatorViewModel(configuration);
     Show();
 }