Esempio n. 1
0
        public async Task <IActionResult> Patch([FromRoute] string fqdn, [FromBody] SwitchViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var match = await _dbContext.Switches.FindAsync(fqdn);

            if (match == null)
            {
                return(NotFound());
            }

            if (model.DeployState.HasValue)
            {
                match.DeployState = model.DeployState.Value;
            }

            if (model.Configured.HasValue)
            {
                match.Configured = model.Configured.Value;
            }

            await _dbContext.SaveChangesAsync();

            await _hubContext.Clients.All.SendAsync("Update", ToViewModel(match));

            return(Ok());
        }
Esempio n. 2
0
        public SwitchViewModel UpdateSwitch(string userId, SwitchViewModel model)
        {
            if (model.Id == null)
            {
                throw new LynexException("Switch id is null");
            }

            var @switch = _switchRepository.Get(model.Id);

            if (@switch == null)
            {
                throw new LynexException(string.Format("Switch {0} does not exist", model.Id));
            }

            @switch.Name            = model.Name;
            @switch.Type            = model.Type;
            @switch.IconId          = model.IconId;
            @switch.ChipId          = model.ChipId;
            @switch.UpdatedDateTime = DateTime.UtcNow;
            _switchRepository.Update(@switch);
            _switchRepository.Save();

            model = new SwitchViewModel(@switch);

            return(model);
        }
        public MachineConfigViewModel(IEventAggregator eventAggregator, ISkeletonGameProvider skeletonGameProvider,
                                      ISkeletonOSC skeletonOSC, ILoggerFacade loggerFacade) : base(eventAggregator, loggerFacade)
        {
            Title = "Machine";

            _skeletonGameProvider = skeletonGameProvider;
            _skeletonOSC          = skeletonOSC;

            _eventAggregator.GetEvent <LoadYamlFilesChanged>().Subscribe(async x => await OnLoadYamlFilesChanged());

            SaveMachineConfigCommand = new DelegateCommand(() =>
            {
                try
                {
                    SaveMachineConfig();
                }
                catch (Exception ex)
                {
                    var msg = $"Error saving machine configuration. {ex.Message}";
                    Log(msg, Category.Exception);
                    _eventAggregator.GetEvent <ErrorMessageEvent>().Publish(msg);
                }
            });

            SendOscMessageCommand = new DelegateCommand <object>((x) =>
            {
                try
                {
                    var obj = x as SwitchViewModel;

                    SwitchViewModel pushedSwitch = null;
                    if (obj.Number.Contains("D"))
                    {
                        pushedSwitch = this.DedicatedSwitches.First((c) => c == obj);
                    }
                    else
                    {
                        pushedSwitch = this.Switches.First((c) => c == obj);
                    }

                    pushedSwitch.State = !pushedSwitch.State;

                    var value = 0.0f;
                    if (pushedSwitch.State)
                    {
                        value = 1.0f;
                    }

                    _skeletonOSC.Send($@"/sw/{pushedSwitch.Name}", value);
                }
                catch { }
            });

            InitializeCollections();
        }
        public ViewModel()
        {
            ButtonOneCommand = new Command(ButtonOneCommandMethod);
            ButtonTwoCommand = new Command(ButtonTwoCommandMethod);
            ImageViewModel  image       = new ImageViewModel(UrlString: "https://cdn.pixabay.com/photo/2016/11/29/03/28/animal-1867062_960_720.jpg");
            ButtonViewModel button      = new ButtonViewModel(Title: "This is a button", Command: ButtonOneCommand);
            ButtonViewModel button2     = new ButtonViewModel(Title: "This is another button", Command: ButtonTwoCommand);
            SwitchViewModel switchModel = new SwitchViewModel();

            CellCollection.Add(image);
            CellCollection.Add(button);
            CellCollection.Add(label);
            CellCollection.Add(button2);
            CellCollection.Add(switchModel);
            OnPropertyChanged("CellCollection");
        }
Esempio n. 5
0
        public ActionResult Switch(SwitchViewModel switchPayment)
        {
            var result  = new DataJsonResult();
            var payment = _currencyService.GetSingleById <Payment>(switchPayment.Id);

            if (payment != null)
            {
                payment.Enabled = switchPayment.Enabled;
                _currencyService.Update(payment);
            }
            else
            {
                result.ErrorMessage = "支付方式不存在!";
            }

            return(Json(result));
        }
Esempio n. 6
0
        public IHttpActionResult UpdateSwitch(SwitchViewModel model)
        {
            var result = _switchService.UpdateSwitch(User.Identity.GetUserId(), model);

            var client = LynexWebSocketHandler.GetWebSocketSession(model.SiteId);

            if (client != null)
            {
                var list             = _switchService.GetSwitchesAndSchedule(User.Identity.GetUserId(), model.SiteId);
                var webSocketMessage = new WebSocketMessage(WebSocketMessageType.PiSiteStatus);
                webSocketMessage.BroadcastType = WebSocketBroadcastType.Pi;
                webSocketMessage.Message       = list;
                client.SendToPi(JsonConvert.SerializeObject(webSocketMessage));
            }

            var obj = new
            {
                Success = true,
                Message = "",
                Results = result,
            };

            return(Ok(obj));
        }
Esempio n. 7
0
        public ActionResult Index()
        {
            var model = new SwitchViewModel();

            return(View(model));
        }