示例#1
0
        private void ExecuteActions(ActionTrigger location)
        {
            var actions = _actionRepository.GetToExecute(location);
            var fifthplayCredentials = _credentialsRepository.GetFifthplay();
            var iftttKey             = _credentialsRepository.GetIfttt();
            var timestamp            = DateTimeOffset.UtcNow;

            Parallel.ForEach(actions, action =>
            {
                try
                {
                    switch (action.ActionTypeName)
                    {
                    case "switch":
                        _fifthplayRepository.SwitchSmartPlug(fifthplayCredentials.Username, fifthplayCredentials.Password,
                                                             action.DeviceIdentifier, (action.ActionArgumentValue == "on" ? true : false));
                        break;

                    case "IFTTT Maker Event":
                        _iftttRepository.TriggerEvent(iftttKey, "homebased", location.ToString(), null, null);
                        break;

                    default:
                        throw new InvalidOperationException($"Action type {action.ActionTypeName} unsupported");
                    }

                    _logger.Log(action, timestamp);
                }
                catch (Exception ex)
                {
                    _logger.Log(ex, action, timestamp);
                }
            });
        }
        public override Task LoadViewModel()
        {
            var credentials = _credentialsRepository.GetFifthplay();

            if (credentials != null)
            {
                Email = credentials.Username;
            }

            return(base.LoadViewModel());
        }