public async Task Start()
        {
            var contract = new RpiOperationContract()
            {
                Data = new TemperatureModel()
                {
                    Temperature = Temperature
                },
                Operation = RpiOperationContracts.StartAirConditioner
            };
            RpiControllersConnector hub = GetHub();

            try
            {
                await hub.SendContract(contract);
            }
            catch (OperationDataValidationException e)
            {
                Context.ModelState.Errors.AddRange(e.Results.Select(s => new ViewModelValidationError()
                {
                    ErrorMessage = s.Message
                }));
                Context.FailOnInvalidModelState();
            }
        }
        public async Task Stop()
        {
            var contract = new RpiOperationContract()
            {
                Operation = RpiOperationContracts.StopAirConditioner
            };

            RpiControllersConnector hub = GetHub();
            await hub.SendContract(contract);
        }
Example #3
0
        public async Task SwitchOff()
        {
            var contract = new RpiOperationContract()
            {
                Operation = RpiOperationContracts.SwitchOffLedLights
            };

            RpiControllersConnector hub = GetHub();
            await hub.SendContract(contract);
        }
Example #4
0
        private void ReceiveMessage(RpiOperationContract contract)
        {
            logger.LogInformation($"Received contract : {contract}");
            var operation  = Program.OperationResolver.Resolve(contract);
            var validation = operation.Validate(contract).ToList();

            if (validation.Any())
            {
                foreach (var result in validation)
                {
                    logger.LogError(result.Message ?? "Generic error occurred");
                }
            }
            else
            {
                logger.LogInformation($"Executing operation :{contract.Operation}");
                operation.Execute(contract);
            }
        }