<commit_before>﻿using IdentityServer4.MongoDB.Configuration;
using Microsoft.Extensions.Options;
using MongoDB.Driver;
using System;

namespace IdentityServer4.MongoDB.DbContexts
{
    public class MongoDBContextBase : IDisposable
    {
        private readonly IMongoClient _client;

        public MongoDBContextBase(IOptions<MongoDBConfiguration> settings)
        {
            if (settings.Value == null)
                throw new ArgumentNullException(nameof(settings), "MongoDBConfiguration cannot be null.");

            if (settings.Value.ConnectionString == null)
                throw new ArgumentNullException(nameof(settings), "MongoDBConfiguration.ConnectionString cannot be null.");

            MongoUrl mongoUrl = MongoUrl.Create(settings.Value.ConnectionString);

            if (settings.Value.Database == null && mongoUrl.DatabaseName == null)
                throw new ArgumentNullException(nameof(settings), "MongoDBConfiguration.Database cannot be null.");

            var clientSettings = MongoClientSettings.FromUrl(mongoUrl);

            if (clientSettings.SslSettings != null)
            {
                clientSettings.SslSettings = settings.Value.SslSettings;
                clientSettings.UseSsl = true;
            }
            else
            {
                clientSettings.UseSsl = false;
            }

            _client = new MongoClient(settings.Value.ConnectionString);
            Database = _client.GetDatabase(settings.Value.Database ?? mongoUrl.DatabaseName);
        }

        protected IMongoDatabase Database { get; }

        public void Dispose()
        {
            // TODO
        }
    }
}<commit_msg>create MongoClient based on complete MongoClientSettings (#25)<commit_after>﻿using IdentityServer4.MongoDB.Configuration;
using Microsoft.Extensions.Options;
using MongoDB.Driver;
using System;

namespace IdentityServer4.MongoDB.DbContexts
{
    public class MongoDBContextBase : IDisposable
    {
        private readonly IMongoClient _client;

        public MongoDBContextBase(IOptions<MongoDBConfiguration> settings)
        {
            if (settings.Value == null)
                throw new ArgumentNullException(nameof(settings), "MongoDBConfiguration cannot be null.");

            if (settings.Value.ConnectionString == null)
                throw new ArgumentNullException(nameof(settings), "MongoDBConfiguration.ConnectionString cannot be null.");

            if (settings.Value.Database == null && mongoUrl.DatabaseName == null)
                throw new ArgumentNullException(nameof(settings), "MongoDBConfiguration.Database cannot be null.");

            var mongoUrl = MongoUrl.Create(settings.Value.ConnectionString);
            var clientSettings = MongoClientSettings.FromUrl(mongoUrl);

            if (clientSettings.SslSettings != null)
            {
                clientSettings.SslSettings = settings.Value.SslSettings;
                clientSettings.UseSsl = true;
            }
            else
            {
                clientSettings.UseSsl = false;
            }

            _client = new MongoClient(clientSettings);
            Database = _client.GetDatabase(settings.Value.Database ?? mongoUrl.DatabaseName);
        }

        protected IMongoDatabase Database { get; }

        public void Dispose()
        {
            // TODO
        }
    }
}
{'fraction_non_alphanumeric': 0.08075089392133493, 'fraction_numerical': 0.0017878426698450535, 'mean_word_length': 2.357, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4938177', 'n_tokens_mistral': 845, 'n_tokens_neox': 795, 'n_words': 178}