Пример #1
0
        public override Task <InputReply> ReportInputs(InputValue value, ServerCallContext context)
        {
            logger.LogDebug($"Received {value.Value:X8} from {value.Sender}");

            using (DomoCoreInMemDbContext dbcontext = contextFactory.CreateContext())
            {
                foreach (var input in dbcontext.Inputs.Include(x => x.Device)
                         .Where(x => x.Device.Name == value.Sender))
                {
                    if (input.Changed == false)
                    {
                        input.PreviousState = input.CurrentState;
                        if ((value.Value != 0) && ((value.Value & (uint)input.HWValue) == value.Value))
                        {
                            logger.LogDebug($"{input.Id} Pressed");
                            input.CurrentState = Models.InputState.Pressed;
                        }
                        else
                        {
                            input.CurrentState = Models.InputState.Released;
                            if (input.PreviousState == Models.InputState.Pressed)
                            {
                                logger.LogDebug($"{input.Id} Released");
                            }
                        }
                        if (input.PreviousState != input.CurrentState)
                        {
                            input.Changed = true;
                        }
                    }
                }
                dbcontext.SaveChanges();
            }

            return(Task.FromResult(new InputReply {
                Done = true
            }));
        }