Exemple #1
0
        public void Process(Update update, object userState, out IState state)
        {
            var chat       = update.GetChat().ToChat();
            var apiChat    = new ApiChat(_api, chat, _limiter);
            var userInChat = new UserInChat(chat, update.GetUser());
            var locker     = _userInChatLockers.GetOrCreateLocker(userInChat);

            lock (locker)
            {
                state = _stateProvider.GetStateForUserInChat(userInChat);
#if !DEBUG
                try
                {
#endif
                var callContext = new CallContext(apiChat, update, userState, userInChat);

                try
                {
                    if (Process(callContext, state,
                                update))
                    {
                        state.ClearForward();
                    }
                }
                catch (CommandNotFoundException)
                {
                    if (callContext.IsMessage)
                    {
                        callContext.Echo(LocalizedStrings.FlowEngine_UnrecognizedCommand, update.GetMessageId());
                    }
                    else
                    {
                        throw;  //if it was not message update - it's developer fail that was not supported (don't post buttons if you dont support them) //todo: low substitute exception
                    }
                }
                catch (BrakeFlowCallException exception)
                {
                    if (callContext.IsMessage || callContext.IsQuery)
                    {
                        callContext.ReplyEcho(exception.Message);
                    }
                }
#if !DEBUG
            }
            catch (Exception exception)
            {
                throw new ChatException(apiChat, exception.Message, exception);
            }
#endif
            }
        }