コード例 #1
0
        public void Publish(string topic, IRemoteEventData remoteEventData)
        {
            var connection = _connectionPool.Acquire();

            try
            {
                var channel = connection.CreateModel();
                channel.ExchangeDeclare(_exchangeTopic, "topic", true);
                var body       = Encoding.UTF8.GetBytes(_remoteEventSerializer.Serialize(remoteEventData));
                var properties = channel.CreateBasicProperties();
                properties.Persistent = true;
                channel.BasicPublish(_exchangeTopic, topic, properties, body);
            }
            finally
            {
                _connectionPool.Return(connection);
            }
        }
コード例 #2
0
        public void Publish(IRemoteEventData remoteEventData)
        {
            var routingKey = remoteEventData.GetType().FullName;

            var connection = _connectionPool.Acquire();

            try
            {
                var channel = connection.CreateModel();
                channel.ExchangeDeclare(_rabbitMqEventBusOptions.ExchangeName, "direct", true);
                var body       = Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(remoteEventData));
                var properties = channel.CreateBasicProperties();
                properties.Persistent = true;
                channel.BasicPublish(_rabbitMqEventBusOptions.ExchangeName, routingKey, properties, body);
            }
            finally
            {
                _connectionPool.Return(connection);
            }
        }
コード例 #3
0
        /// <summary>
        /// Handles when the guild member receives an invite to a guild.
        /// </summary>
        /// <param name="guild">The guild they were invited to.</param>
        /// <param name="currentTime">The current time.</param>
        public void ReceiveInvite(IGuild guild, TickCount currentTime)
        {
            UpdateInvites(currentTime);

            // If an invite for this guild already exists, update the invite time on that invite instead
            for (var i = 0; i < _invites.Count; i++)
            {
                if (_invites[i].Guild == guild)
                {
                    _invites[i].InviteTime = currentTime;
                    return;
                }
            }

            // Add the invite
            var item = _guildInvitePool.Acquire();

            item.Initialize(guild, currentTime);
            _invites.Add(item);
        }
コード例 #4
0
        /// <summary>
        /// Tests the database connection to make sure it works.
        /// </summary>
        /// <param name="connectionString">The connection string used.</param>
        /// <param name="pool">The pool of connections.</param>
        /// <returns>The name of the database.</returns>
        /// <exception cref="DatabaseConnectionException">The database connection failed to be created.</exception>
        string TestConnectionPoolAndGetDatabase(string connectionString, IObjectPool <PooledDbConnection> pool)
        {
            string database;

            try
            {
                using (var poolableConn = pool.Acquire())
                {
                    database = poolableConn.Connection.Database;

                    using (var cmd = poolableConn.Connection.CreateCommand())
                    {
                        cmd.CommandText = GetTestQueryCommand();
                        cmd.ExecuteNonQuery();
                    }
                }
            }
            catch (DbException ex)
            {
                throw CreateConnectionException(connectionString, ex);
            }

            return(database);
        }