コード例 #1
0
        public static CachedMember GetOrAddMember(this IGatewayDispatcher dispatcher,
                                                  ISynchronizedDictionary <Snowflake, CachedSharedUser> userCache, ISynchronizedDictionary <Snowflake, CachedMember> memberCache,
                                                  Snowflake guildId, MemberJsonModel memberModel)
        {
            if (!memberModel.User.HasValue)
            {
                return(null);
            }

            var sharedUser = dispatcher.GetOrAddSharedUser(userCache, memberModel.User.Value);

            if (sharedUser == null)
            {
                return(null);
            }

            if (memberCache.TryGetValue(memberModel.User.Value.Id, out var member))
            {
                member.Update(memberModel);
                return(member);
            }

            member = new CachedMember(sharedUser, guildId, memberModel);
            memberCache.Add(memberModel.User.Value.Id, member);
            return(member);
        }
コード例 #2
0
ファイル: DictionaryTree.cs プロジェクト: lulzzz/BraneCloud
 /// <summary>
 /// The default indexer will try to return a Primary value from this instance.
 /// If the key isn't found, then it will look for it in parents, starting from
 /// the most recently added, and then looking backwards through other parents added earlier.
 /// Note that the "setter" for this indexer has no effect on Parents.
 /// It will only set the value in the top-level Primary dictionary.
 /// Parent and Default values, in other words, continue to "shadow" the keyed property just as before.
 /// If the property associated with a given key is shallowly removed, the shadow value comes back into view.
 /// If it is deeply removed, then the property ceases to exist at any level.
 /// </summary>
 /// <param name="key">The key used to identify a particular property.</param>
 /// <returns>
 /// The value found for the specified key.
 /// </returns>
 public TValue this[TKey key]
 {
     get { return(this[key, false]); }
     set
     {
         lock (_syncRoot)
         {
             if (_localEntries.ContainsKey(key))
             {
                 _localEntries[key] = value;
             }
             else
             {
                 _localEntries.Add(key, value);
             }
         }
     }
 }
コード例 #3
0
            private async Task RunAsync()
            {
                var reader = _tokens.Reader;

                await foreach (var token in reader.ReadAllAsync().ConfigureAwait(false))
                {
                    var tasks = _tasks.Values;
                    if (tasks.Length == _degreeOfParallelism)
                    {
                        await Task.WhenAny(tasks).ConfigureAwait(false);
                    }

                    var task = ExecuteTokenAsync(token);
                    _tasks.Add(token.Context, task);
                }
            }