예제 #1
0
        /// <summary>
        /// Initializes a new <see cref="DatabaseConnection"/>.
        /// </summary>
        /// <param name="connectionString">The connection string <see cref="IReadOnlySetting{T}"/>.</param>
        /// <param name="logger">An <see cref="ILogger"/>.</param>
        /// <param name="maxConnections">The max number of connections for per-read/write connection.</param>
        /// <exception cref="ArgumentNullException">
        /// - <paramref name="connectionString"/>
        /// - <paramref name="logger"/>
        /// </exception>
        /// <exception cref="ArgumentOutOfRangeException">
        /// - <paramref name="maxConnections"/> is below 1.
        /// </exception>
        public DatabaseConnection(IReadOnlySetting <string> connectionString, ILogger logger, int maxConnections)
        {
            if (logger == null)
            {
                throw new ArgumentNullException(nameof(logger));
            }

            if (maxConnections < 0)
            {
                throw new ArgumentOutOfRangeException(nameof(maxConnections));
            }

            _ConnectionString = connectionString ?? throw new ArgumentNullException(nameof(connectionString));

            if (maxConnections > 0)
            {
                _ConnectionLock = new SemaphoreSlim(maxConnections, maxConnections);
            }
            else
            {
                _ConnectionLock = null;
            }

            var jsonSerializerOptions = _JsonSerializerOptions = new JsonSerializerOptions
            {
                PropertyNameCaseInsensitive = true
            };

            jsonSerializerOptions.Converters.Add(new BooleanJsonConverter());
            jsonSerializerOptions.Converters.Add(new NullableDateTimeConverter());
        }
예제 #2
0
 /// <summary>
 /// Initailizes a new <see cref="RemoteItemQueueFactoryV3"/>.
 /// </summary>
 /// <param name="baseUrl">The <see cref="Uri"/>, pointing at the root URL for the remote queue service.</param>
 /// <param name="httpClient">An <see cref="IHttpClient"/>.</param>
 /// <param name="applicationApiKey">An <see cref="IReadOnlySetting{T}"/> containing the application ApiKey.</param>
 /// <param name="logger">An <see cref="ILogger"/>.</param>
 /// <exception cref="ArgumentNullException">
 /// - <paramref name="baseUrl"/>
 /// - <paramref name="httpClient"/>
 /// - <paramref name="applicationApiKey"/>
 /// - <paramref name="logger"/>
 /// </exception>
 public RemoteItemQueueFactoryV3(Uri baseUrl, IHttpClient httpClient, IReadOnlySetting <Guid> applicationApiKey, ILogger logger)
 {
     _BaseUrl            = baseUrl ?? throw new ArgumentNullException(nameof(baseUrl));
     _HttpClient         = httpClient ?? throw new ArgumentNullException(nameof(httpClient));
     _ApplicationApiKey  = applicationApiKey ?? throw new ArgumentNullException(nameof(applicationApiKey));
     _Logger             = logger ?? throw new ArgumentNullException(nameof(logger));
     _RefreshCountTimers = new List <Timer>();
 }
예제 #3
0
 /// <summary>
 /// Initializes a new <see cref="DatabaseConnection"/>.
 /// </summary>
 /// <param name="connectionString">The connection string <see cref="IReadOnlySetting{T}"/>.</param>
 /// <param name="logger">An <see cref="ILogger"/>.</param>
 /// <exception cref="ArgumentNullException">
 /// - <paramref name="connectionString"/>
 /// - <paramref name="logger"/>
 /// </exception>
 public DatabaseConnection(IReadOnlySetting <string> connectionString, ILogger logger)
     : this(connectionString, logger, maxConnections : 0)
 {
 }