public ReadyHandler() { PendingGuilds = new SynchronizedDictionary <ShardId, ISynchronizedDictionary <Snowflake, bool> >(); InitialReadys = new SynchronizedDictionary <ShardId, Tcs>(); _delays = new SynchronizedDictionary <ShardId, DelayToken>(); }
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); }
public Bucket(int degreeOfParallelism) { _degreeOfParallelism = degreeOfParallelism; _tokens = Channel.CreateUnbounded <Token>(); _tasks = new SynchronizedDictionary <DiscordCommandContext, Task>(degreeOfParallelism); _ = RunAsync(); }
public static CachedSharedUser GetOrAddSharedUser(this IGatewayDispatcher dispatcher, ISynchronizedDictionary <Snowflake, CachedSharedUser> userCache, UserJsonModel model) { return(userCache.GetOrAdd(model.Id, static (_, tuple) => { var(client, model) = tuple; return new CachedSharedUser(client, model); }, (dispatcher.Client, model))); }
public ContractResolver(DefaultJsonSerializer serializer) { _serializer = serializer; _stringEnumConverter = new StringEnumConverter(); _streamConverter = new StreamConverter(serializer); _jsonTokenConverter = new JsonTokenConverter(); _snowflakeConverter = new SnowflakeConverter(); _optionalConverters = new SynchronizedDictionary <Type, OptionalConverter>(); }
public DefaultGatewayChunker( IOptions <DefaultGatewayChunkerConfiguration> options, ILogger <DefaultGatewayChunker> logger) { Logger = logger; _operations = new SynchronizedDictionary <string, ChunkOperation>(); _binder = new Binder <IGatewayClient>(this); }
/// <summary> /// Instantiates a new <see cref="DefaultCommandQueue"/>. /// </summary> /// <param name="options"> The options instance. </param> public DefaultCommandQueue( IOptions <DefaultCommandQueueConfiguration> options) { var configuration = options.Value; DegreeOfParallelism = configuration.DegreeOfParallelism; _guildBuckets = new SynchronizedDictionary <Snowflake, Bucket>(); _binder = new Binder <DiscordBotBase>(this); }
public static IMember GetOrAddMemberTransient(this IGatewayDispatcher dispatcher, ISynchronizedDictionary <Snowflake, CachedSharedUser> userCache, ISynchronizedDictionary <Snowflake, CachedMember> memberCache, Snowflake guildId, MemberJsonModel memberModel) { if (!memberModel.User.HasValue) { return(null); } var member = dispatcher.GetOrAddMember(userCache, memberCache, guildId, memberModel); return(member ?? new TransientMember(dispatcher.Client, guildId, memberModel) as IMember); }
/// <inheritdoc/> public bool TryGetCache <TEntity>(out ISynchronizedDictionary <Snowflake, TEntity> cache) { lock (this) { if (_caches.TryGetValue(typeof(TEntity), out var boxedCache)) { cache = (ISynchronizedDictionary <Snowflake, TEntity>)boxedCache; return(true); } cache = default; return(false); } }
public InteractivityExtension( IOptions <InteractivityExtensionConfiguration> options, ILogger <InteractivityExtension> logger) : base(logger) { var configuration = options.Value; DefaultMessageTimeout = configuration.DefaultMessageTimeout; DefaultReactionTimeout = configuration.DefaultReactionTimeout; DefaultMenuTimeout = configuration.DefaultMenuTimeout; _messageWaiters = new SynchronizedDictionary <Snowflake, LinkedList <Waiter <MessageReceivedEventArgs> > >(); _reactionWaiters = new SynchronizedDictionary <Snowflake, LinkedList <Waiter <ReactionAddedEventArgs> > >(); _menus = new SynchronizedDictionary <Snowflake, MenuBase>(); }
static void UncacheThread(ISynchronizedDictionary <Snowflake, CachedGuildChannel> channelCache, Dictionary <Snowflake, IReadOnlyList <CachedThreadChannel> > uncachedThreads, KeyValuePair <Snowflake, List <ChannelJsonModel> > kvp, CachedThreadChannel cachedThreadChannel) { channelCache.Remove(cachedThreadChannel.Id); List <CachedThreadChannel> list; if (uncachedThreads.TryGetValue(kvp.Key, out var boxedList)) { list = boxedList as List <CachedThreadChannel>; } else { uncachedThreads.Add(kvp.Key, list = new List <CachedThreadChannel>()); } list.Add(cachedThreadChannel); }
public bool TryGetCache <TEntity>(Snowflake parentId, out ISynchronizedDictionary <Snowflake, TEntity> cache, bool lookupOnly = false) where TEntity : CachedSnowflakeEntity { lock (this) { if (!_nestedCaches.TryGetValue(typeof(TEntity), out var nestedCache)) { cache = default; return(false); } if (nestedCache.TryGetValue(parentId, out var boxedCache)) { cache = (ISynchronizedDictionary <Snowflake, TEntity>)boxedCache; return(true); } if (!lookupOnly && _supportedNestedTypes.Contains(typeof(TEntity))) { if (typeof(TEntity) == typeof(CachedUserMessage)) { var messageCache = new MessageDictionary(MessagesPerChannel).Synchronized(); cache = (ISynchronizedDictionary <Snowflake, TEntity>)messageCache; } else if (typeof(TEntity) == typeof(CachedMember)) { var memberCache = new MemberDictionary(this).Synchronized(); cache = (ISynchronizedDictionary <Snowflake, TEntity>)memberCache; } else { cache = new SynchronizedDictionary <Snowflake, TEntity>(); } nestedCache.Add(parentId, cache); return(true); } cache = default; return(false); } }
/// <inheritdoc/> public bool TryRemoveCache <TEntity>(Snowflake parentId, out ISynchronizedDictionary <Snowflake, TEntity> cache) { lock (this) { if (!_nestedCaches.TryGetValue(typeof(TEntity), out var nestedCache)) { cache = default; return(false); } if (nestedCache.TryRemove(parentId, out var boxedCache)) { cache = (ISynchronizedDictionary <Snowflake, TEntity>)boxedCache; return(true); } cache = default; return(false); } }
/// <summary> /// This constructor will copy the entries from another instance. /// Tracking information will also be copied depending on the values /// of the 'copyAccessedTracking' and 'copyGottenTracking' arguments. /// </summary> /// <param name="other">The instance that will be copied to create this new instance.</param> /// <param name="copyAccessedTracking">A boolean indicating whether or not to copy 'Accessed' tracking information.</param> /// <param name="copyGottenTracking">A boolean indicating whether or not to copy 'Gotten' tracking information.</param> public SynchronizedDictionary(ISynchronizedDictionary <TKey, TValue> other, bool copyAccessedTracking, bool copyGottenTracking) : this() { if (other == null) { throw new ArgumentNullException("other", "The argument must not be null."); } lock (_syncRoot) // just in case there are static operations { _innerDict = new Dictionary <TKey, TValue>(other); if (copyAccessedTracking) { _trackAccessed = other.TrackAccessed; _accessed = other.Accessed == null ? null : new List <TKey>(other.Accessed); } if (copyGottenTracking) { _trackGotten = other.TrackGotten; _gotten = other.Gotten == null ? null : new List <TKey>(other.Gotten); } } }
/// <summary> /// This constructor will copy the entries from another instance. /// Tracking information (Accessed and Gotten) will also be copied /// depending on the value of the 'copyTracking' argument. /// </summary> /// <param name="other">>The instance that will be copied to create this new instance.</param> /// <param name="copyTracking">A boolean indicating whether or not to copy all tracking information.</param> public SynchronizedDictionary(ISynchronizedDictionary <TKey, TValue> other, bool copyTracking) : this(copyTracking, copyTracking) { }
static DefaultGatewayRateLimiter() { _sharedBuckets = new SynchronizedDictionary <Snowflake, ISynchronizedDictionary <GatewayPayloadOperation, Bucket> >(1); }
/// <summary> /// Attempts to get the users cache from this cache provider. /// </summary> /// <param name="cacheProvider"> The cache provider to retrieve the cache from. </param> /// <param name="cache"> The given cache. </param> /// <returns> /// <see langword="true"/> if the cache exists. /// </returns> public static bool TryGetUsers(this IGatewayCacheProvider cacheProvider, out ISynchronizedDictionary <Snowflake, CachedSharedUser> cache) => cacheProvider.TryGetCache(out cache);
/// <summary> /// This constructor will copy the entries from another instance. /// All tracking information (Accessed and Gotten) will also be copied. /// </summary> /// <param name="other">The instance that will be copied to create this new instance.</param> public SynchronizedDictionary(ISynchronizedDictionary <TKey, TValue> other) : this(other, true, true) { }
/// <inheritdoc cref="TryGetUsers"/> /// <summary> /// Attempts to get the stages cache from this cache provider. /// </summary> public static bool TryGetStages(this IGatewayCacheProvider cacheProvider, Snowflake guildId, out ISynchronizedDictionary <Snowflake, CachedStage> cache, bool lookupOnly = false) => cacheProvider.TryGetCache(guildId, out cache, lookupOnly);
/// <inheritdoc cref="TryGetUsers"/> /// <summary> /// Attempts to get the guilds cache from this cache provider. /// </summary> public static bool TryGetGuilds(this IGatewayCacheProvider cacheProvider, out ISynchronizedDictionary <Snowflake, CachedGuild> cache) => cacheProvider.TryGetCache(out cache);
/// <summary> /// Instantiates a new <see cref="MenuBase"/>. /// </summary> protected MenuBase() { _tcs = new Tcs(); _buttons = GetButtons(this); }
/// <inheritdoc cref="TryGetUsers"/> /// <summary> /// Attempts to get the messages cache from this cache provider. /// </summary> public static bool TryGetMessages(this IGatewayCacheProvider cacheProvider, Snowflake channelId, out ISynchronizedDictionary <Snowflake, CachedUserMessage> cache, bool lookupOnly = false) => cacheProvider.TryGetCache(channelId, out cache, lookupOnly);
static MenuBase() { _typeCache = new SynchronizedDictionary <Type, KeyValuePair <IEmoji, MethodInfo>[]>(); }