public async Task Update(ICommand command)
        {
            var state  = _state.State;
            var config = _state.Config;
            var runner = new CommandRunner(_offsetTime.Offset, command, state, config);

            foreach (var item in runner)
            {
                _logger.DebugFormat(this, "Start executing command: {0}", item.Command);
                if (!item.IsValid())
                {
                    _logger.ErrorFormat(this, "Command is invalid: {0}", item.Command);
                    return;
                }
                item.Execute();
                _logger.DebugFormat(this, "End executing command: {0}", item.Command);
                var container = _handlers.GetOrDefault(item.Command.GetType());
                if (container != null)
                {
                    var handlers = container.GetHandlers();
                    foreach (var handler in handlers)
                    {
                        await container.Invoke(handler, item.Command);

                        OnStateUpdated(state);
                    }
                }
                OnStateUpdated(state);
            }
            var response = await _api.Post(new IntentRequest(_state.User.Login, state.Version, command));

            if (!response.Success)
            {
                _logger.Error(this, "State declined from server.");
                return;
            }
            var result = response.Result;

            state.Version = result.NewVersion;
            _logger.Debug(this, "State approved from server.");
        }
Example #2
0
 public void ScheduleNotice(NoticeModel notice)
 {
     _logger.DebugFormat(this, "ScheduleNotice: '{0}'", notice);
     _notices.Push(notice);
 }