WebApplications.Utilities.Database.Configuration.DatabaseElement.GetConnection C# (CSharp) Méthode

GetConnection() private méthode

private GetConnection ( [ connectionName = null, [ ensureIdentical = null, CancellationToken cancellationToken = default(CancellationToken) ) : Task
connectionName [
ensureIdentical [
cancellationToken System.Threading.CancellationToken
Résultat Task
        public Task<LoadBalancedConnection> GetConnection(
            [CanBeNull] string connectionName = null,
            [CanBeNull] bool? ensureIdentical = null,
            CancellationToken cancellationToken = default(CancellationToken))
        {
            LoadBalancedConnectionElement connectionElement = string.IsNullOrWhiteSpace(connectionName)
                ? Connections.FirstOrDefault(c => c.Enabled)
                : Connections[connectionName];
            if (connectionElement == null)
                throw new LoggingException(
                    () => Resources.DatabaseElement_GetSchemas_No_Connection,
                    Id);

            return connectionElement.GetLoadBalancedConnection(ensureIdentical, cancellationToken);
        }

Usage Example

Exemple #1
0
        public Task <LoadBalancedConnection> GetConnection(
            [NotNull] string database,
            [CanBeNull] string connectionName   = null,
            [CanBeNull] bool?ensureIdentical    = null,
            CancellationToken cancellationToken = default(CancellationToken))
        {
            if (database == null)
            {
                throw new ArgumentNullException("database");
            }

            DatabaseElement db = Databases[database];

            if ((db == null) ||
                (!db.Enabled))
            {
                return(TaskResult <LoadBalancedConnection> .FromException(
                           new LoggingException(
                               () => Resources.DatabaseConfiguration_GetSqlProgram_DatabaseIdNotFound,
                               database)));
            }

            return(db.GetConnection(connectionName, ensureIdentical, cancellationToken));
        }