コード例 #1
0
        public Option <IReadOnlyList <String> > TryGetAndCacheDatabaseEmoteList(String channelName, EmoteCategory category, IApplicationContext context = default)
        {
            if (context is null)
            {
                context = ContextFactory.GetContext();
            }

            var categoryList = CachedEmotes.GetOrAdd(channelName, _ => new ConcurrentDictionary <EmoteCategory, List <String> >());

            IQueryable <String> emotes = context
                                         .Emotes
                                         .Where(x => x.TwitchDisplayName == channelName && x.Category == category)
                                         .Select(x => x.Name);

            categoryList.Remove(category, out _);

            if (emotes.Any())
            {
                var databaseEmoteList = emotes.ToList().AsReadOnly();
                var categoryEmotes    = categoryList.GetOrAdd(category, _ => new List <String>());

                foreach (var emote in databaseEmoteList)
                {
                    categoryEmotes.Add(emote);
                }

                return(() => databaseEmoteList);
            }

            return(Option.Nothing <IReadOnlyList <String> >());
        }
コード例 #2
0
        public Option <IReadOnlyList <String> > TryGetCachedEmoteList(String channelName, EmoteCategory category)
        {
            if (CachedEmotes.TryGetValue(channelName, out var categoryList))
            {
                if (categoryList.TryGetValue(category, out List <String> emoteList))
                {
                    return(() => emoteList.AsReadOnly());
                }
            }

            return(Option.Nothing <IReadOnlyList <String> >());
        }