예제 #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
            }
        }
예제 #2
0
        public static ApiChat GetChat(int chatID)
        {
            string cacheKey = GetCacheKey(chatID);

            CacheManager <string, ApiChat> cache = GetCache();

            ApiChat chat = cache[cacheKey];

            if (chat == null)
            {
                chat = Chat.FetchByID(chatID).ToApi(true);
                cache.Insert(cacheKey, chat, 60, System.Web.Caching.CacheItemPriority.NotRemovable);
            }

            return(chat);
        }
예제 #3
0
        private void CheckVersion(string versionNumber, string versionFile)
        {
            var versionText = versionFile;
            var strings     = versionText.Split(new[] { "||" }, StringSplitOptions.None);

            _history = strings[1];

            VersionNumber = strings[0];
            if (versionNumber != VersionNumber)
            {
                _gameProvider.UsingDb(
                    context =>
                {
                    TelemetryStatic.TelemetryClient = new TelemetryClient();
                    var parentId        = TelemetryStatic.TelemetryClient.Context.Operation.Id;
                    var subscribedChats = context.ChatInTelegrams.Where(chat => chat.Subscribed).ToArray();

                    Parallel.ForEach(subscribedChats, chat =>
                    {
                        TelemetryStatic.TelemetryClient = new TelemetryClient();
                        var operationContext            = TelemetryStatic.TelemetryClient.Context.Operation;

                        operationContext.ParentId = parentId;
                        operationContext.Name     = "Update notification";
                        TelemetryStatic.TelemetryClient.Context.Properties[TelemetryStatic.ChatKey] = chat.Id.ToString();

                        LocalizedStrings.Language = chat.LanguageIndex;
                        var chatId  = chat.Id;
                        var apiChat = new ApiChat(_api, new BotFlow.Persistance.Chat(chatId, ""), _limiter);
                        try
                        {
                            apiChat.Echo(LocalizedStrings.GameUpdatedMessage, 0, null);
                        }
                        catch (ApiChatException exception)
                        {
                            var apiRequestException = exception.InnerException as ApiRequestException;
                            if (apiRequestException != null && apiRequestException.ErrorCode != 400)
                            {
                                throw;                                                                             //это кейс что Chat was deactivated
                            }
                        }
                        //todo: should return it context.Delete(chat);
                    });
                    //context.SaveChanges();
                });
            }
        }
예제 #4
0
        public static List <ApiShout> GetChatShoutDelta(int chatID, int lastReceivedShoutID, int?userID)
        {
            //TODO: GJ: refactor some of this into the ShoutCache so that it can be used everywhere
            ApiChat         apiChat     = GetChat(chatID);
            List <ApiShout> deltaShouts = new List <ApiShout>();

            if (apiChat.Shouts[0].ShoutID > lastReceivedShoutID)
            {
                foreach (ApiShout apiShout in apiChat.Shouts)
                {
                    if (apiShout.ShoutID > lastReceivedShoutID)
                    {
                        deltaShouts.Add(apiShout);
                    }
                }
            }

            if (userID.HasValue)
            {
            }
            //TODO: GJ: update the last active time stamp for this user in this chat

            return(deltaShouts);
        }
예제 #5
0
 public GameStateBannerProvider(ApiChat apiChat)
 {
     _apiChat = apiChat;
 }