<commit_before>/*
    Copyright 2021 <NAME>

    Permission to use, copy, modify, and distribute this software for any
    purpose with or without fee is hereby granted, provided that the above
    copyright notice and this permission notice appear in all copies.

    THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
    WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
    MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
    ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
    WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
    ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
    OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/

using System;
using System.Collections.Generic;
using System.Linq;
using System.Management.Automation;

namespace PSql
{
    /// <summary>
    ///   Information necessary to connect to an Azure SQL Database or
    ///   compatible database.
    /// </summary>
    public class AzureSqlContext : SqlContext
    {
        /// <summary>
        ///   Initializes a new <see cref="AzureSqlContext"/> instance with
        ///   default property values.
        /// </summary>
        public AzureSqlContext()
        {
            // Encryption is required for connections to Azure SQL Database
            EncryptionMode = EncryptionMode.Full;
        }

        /// <summary>
        ///   Initializes a new <see cref="AzureSqlContext"/> instance by
        ///   property values from the specified instance, and optionally with
        ///   the specified database name.
        /// </summary>
        /// <param name="other">
        ///   The instance from which to copy property values.
        /// </param>
        /// <param name="databaseName">
        ///   The name of the database to set on the copy.  If <c>null</c>, the
        ///   copy will retain the database name of <paramref name="other"/>.
        ///   The default is <c>null</c>.
        /// </param>
        /// <exception cref="ArgumentNullException">
        ///   <paramref name="other"/> is <c>null</c>.
        /// </exception>
        public AzureSqlContext(AzureSqlContext other, string? databaseName = null)
            : base(other, databaseName)
        {
            ResourceGroupName  = other.ResourceGroupName;
            ServerFullName     = other.ServerFullName;
            AuthenticationMode = other.AuthenticationMode;
        }

        public sealed override bool IsAzure => true;

        public string? ResourceGroupName { get; set; }

        public string? ServerFullName { get; internal set; }

        public AzureAuthenticationMode AuthenticationMode { get; set; }

        /// <summary>
        ///   Creates a new object that is a copy of the current instance,
        ///   optionally with the specified database name.
        /// </summary>
        /// <param name="databaseName">
        ///   The name of the database to set on the copy.  If <c>null</c>, the
        ///   copy will retain the database name of the current instance.  The
        ///   default is <c>null</c>.
        /// </param>

        /// <inheritdoc cref="SqlContext.Clone(string?)" />
        public new AzureSqlContext Clone(string? databaseName = null)
            => (AzureSqlContext) CloneCore(databaseName);

        /// <inheritdoc/>
        protected override SqlContext CloneCore(string? databaseName = null)
            => new AzureSqlContext(this, databaseName);

        protected override void ConfigureServerName(dynamic /*SqlConnectionStringBuilder*/ builder)
        {
            builder.DataSource = ServerFullName ?? ResolveServerFullName();
        }

        protected override void ConfigureDefaultDatabaseName(dynamic /*SqlConnectionStringBuilder*/ builder)
        {
            if (!string.IsNullOrEmpty(DatabaseName))
                builder.InitialCatalog = DatabaseName;
            else
                builder.InitialCatalog = MasterDatabaseName;
        }

        protected override void ConfigureAuthentication(dynamic /*SqlConnectionStringBuilder*/ builder)
        {
            var mode = AuthenticationMode;<commit_msg>Doc comments.<commit_after>/*
    Copyright 2021 <NAME>

    Permission to use, copy, modify, and distribute this software for any
    purpose with or without fee is hereby granted, provided that the above
    copyright notice and this permission notice appear in all copies.

    THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
    WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
    MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
    ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
    WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
    ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
    OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/

using System;
using System.Collections.Generic;
using System.Linq;
using System.Management.Automation;

namespace PSql
{
    /// <summary>
    ///   Information necessary to connect to an Azure SQL Database or
    ///   compatible database.
    /// </summary>
    public class AzureSqlContext : SqlContext
    {
        /// <summary>
        ///   Initializes a new <see cref="AzureSqlContext"/> instance with
        ///   default property values.
        /// </summary>
        public AzureSqlContext()
        {
            // Encryption is required for connections to Azure SQL Database
            EncryptionMode = EncryptionMode.Full;
        }

        /// <summary>
        ///   Initializes a new <see cref="AzureSqlContext"/> instance by
        ///   property values from the specified instance, and optionally with
        ///   the specified database name.
        /// </summary>
        /// <param name="other">
        ///   The instance from which to copy property values.
        /// </param>
        /// <param name="databaseName">
        ///   The name of the database to set on the copy.  If <c>null</c>, the
        ///   copy will retain the database name of <paramref name="other"/>.
        ///   The default is <c>null</c>.
        /// </param>
        /// <exception cref="ArgumentNullException">
        ///   <paramref name="other"/> is <c>null</c>.
        /// </exception>
        public AzureSqlContext(AzureSqlContext other, string? databaseName = null)
            : base(other, databaseName)
        {
            ResourceGroupName  = other.ResourceGroupName;
            ServerFullName     = other.ServerFullName;
            AuthenticationMode = other.AuthenticationMode;
        }

        /// <inheritdoc/>
        public sealed override bool IsAzure => true;

        /// <summary>
        ///   Gets or sets the name of the resource group containing the
        ///   database server.  The default is <c>null</c>.
        /// </summary>
        public string? ResourceGroupName { get; set; }

        /// <summary>
        ///   Gets the DNS name of the database server.  The value is
        ///   <c>null</c> until the context is used to create a connection
        ///   string.
        /// </summary>
        public string? ServerFullName { get; internal set; }

        /// <summary>
        ///   Gets or sets the method used to authenticate with the database
        ///   server.  The default is
        ///   <see cref="AzureAuthenticationMode.Default"/>.
        /// </summary>
        public AzureAuthenticationMode AuthenticationMode { get; set; }

        /// <inheritdoc cref="SqlContext.Clone(string?)" />
        public new AzureSqlContext Clone(string? databaseName = null)
            => (AzureSqlContext) CloneCore(databaseName);

        /// <inheritdoc/>
        protected override SqlContext CloneCore(string? databaseName = null)
            => new AzureSqlContext(this, databaseName);

        protected override void ConfigureServerName(dynamic /*SqlConnectionStringBuilder*/ builder)
        {
            builder.DataSource = ServerFullName ?? ResolveServerFullName();
        }

        protected override void ConfigureDefaultDatabaseName(dynamic /*SqlConnectionStringBuilder*/ builder)
        {
            if (!string.IsNullOrEmpty(DatabaseName))
                builder.InitialCatalog = DatabaseName;
            else
                builder.InitialCatalog = MasterDatabaseName;
        }

        protected override void ConfigureAuthentication(dynamic /*SqlConnectionStringBuilder*/ builder)
        {
            var mode = AuthenticationMode;
{'fraction_non_alphanumeric': 0.09234155949484417, 'fraction_numerical': 0.000926891437840343, 'mean_word_length': 2.157278712509144, 'pattern_counts': {'":': 0, '<': 73, '<?xml version=': 0, '>': 79, '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': '3718105', 'n_tokens_mistral': 2095, 'n_tokens_neox': 2024, 'n_words': 761}