예제 #1
0
        private void AddThemeMention(ThemeMention themeMention)
        {
            if (themeMention.IsDisabled)
            {
                ThemeMention tm;
                ThemeMentions.TryRemove(themeMention.Id, out tm);
                ConcurrentDictionary<long, long> mtl;
                if (MentionThemeLookup.TryGetValue(themeMention.MentionId, out mtl))
                {
                    long id;
                    mtl.TryRemove(themeMention.Id, out id);
                }
                Mention m;
                if (Mentions.TryGetValue(themeMention.MentionId, out m))
                {
                    while (m.Themes != null && m.Themes.Contains(themeMention.ThemeId))
                        m.Themes.Remove(themeMention.ThemeId);
                }
            }
            else
            {
                if (!ReferenceEquals(ThemeMentions.AddOrUpdate(themeMention.Id, themeMention, (x, y) => y), themeMention))
                {
                    return;
                }

                MentionThemeLookup.AddOrUpdate
                    (
                        themeMention.MentionId,
                        new ConcurrentDictionary<long, long>
                            (
                                new KeyValuePair<long, long>[] 
                                { 
                                    new KeyValuePair<long, long>(themeMention.Id, themeMention.ThemeId) 
                                }
                            ),
                        (x, y) => 
                        { 
                            y.AddOrUpdate
                                (
                                    themeMention.Id, 
                                    themeMention.ThemeId, 
                                    (j, k) => 
                                    {    
                                        return k; 
                                    }
                                ); 
                            return y; 
                        }
                    );

                Mention mention;

                if (!Mentions.TryGetValue(themeMention.MentionId, out mention))
                {
                    return;
                }

                if (mention.Themes == null || !mention.Themes.Contains(themeMention.ThemeId))
                {
                    if (mention.Themes == null) mention.Themes = new List<long>();
                    mention.Themes.Add(themeMention.ThemeId);
                }
            }
        }
예제 #2
0
        private void AddThemeMention(ThemeMention themeMention)
        {
            if (themeMention.IsDisabled)
            {
                ThemeMention tm;
                ThemeMentions.TryRemove(themeMention.Id, out tm);
                ConcurrentDictionary <long, long> mtl;
                if (MentionThemeLookup.TryGetValue(themeMention.MentionId, out mtl))
                {
                    long id;
                    mtl.TryRemove(themeMention.Id, out id);
                }
                Mention m;
                if (Mentions.TryGetValue(themeMention.MentionId, out m))
                {
                    while (m.Themes != null && m.Themes.Contains(themeMention.ThemeId))
                    {
                        m.Themes.Remove(themeMention.ThemeId);
                    }
                }
            }
            else
            {
                if (!ReferenceEquals(ThemeMentions.AddOrUpdate(themeMention.Id, themeMention, (x, y) => y), themeMention))
                {
                    return;
                }

                MentionThemeLookup.AddOrUpdate
                (
                    themeMention.MentionId,
                    new ConcurrentDictionary <long, long>
                    (
                        new KeyValuePair <long, long>[]
                {
                    new KeyValuePair <long, long>(themeMention.Id, themeMention.ThemeId)
                }
                    ),
                    (x, y) =>
                {
                    y.AddOrUpdate
                    (
                        themeMention.Id,
                        themeMention.ThemeId,
                        (j, k) =>
                    {
                        return(k);
                    }
                    );
                    return(y);
                }
                );

                Mention mention;

                if (!Mentions.TryGetValue(themeMention.MentionId, out mention))
                {
                    return;
                }

                if (mention.Themes == null || !mention.Themes.Contains(themeMention.ThemeId))
                {
                    if (mention.Themes == null)
                    {
                        mention.Themes = new List <long>();
                    }
                    mention.Themes.Add(themeMention.ThemeId);
                }
            }
        }