Пример #1
0
        /// <summary>
        /// Returns database connection parameters for given server type
        /// </summary>
        public async Task <ConnectParams> GetDatabaseConnectionAsync(TestServerType serverType, string databaseName)
        {
            ConnectionProfile  connectionProfile = null;
            TestServerIdentity serverIdentiry    = ConnectionTestUtils.TestServers.FirstOrDefault(x => x.ServerType == serverType);

            if (serverIdentiry == null)
            {
                connectionProfile = ConnectionTestUtils.Setting.Connections.FirstOrDefault(x => x.ServerType == serverType);
            }
            else
            {
                connectionProfile = ConnectionTestUtils.Setting.GetConnentProfile(serverIdentiry.ProfileName, serverIdentiry.ServerName);
            }

            if (connectionProfile != null)
            {
                string password = connectionProfile.Password;
                if (string.IsNullOrEmpty(password))
                {
                    Credential credential = await ReadCredential(connectionProfile.formatCredentialId());

                    password = credential.Password;
                }
                ConnectParams conenctParam = ConnectionTestUtils.CreateConnectParams(connectionProfile.ServerName, connectionProfile.Database,
                                                                                     connectionProfile.User, password);
                if (!string.IsNullOrEmpty(databaseName))
                {
                    conenctParam.Connection.DatabaseName = databaseName;
                }
                if (serverType == TestServerType.Azure)
                {
                    conenctParam.Connection.ConnectTimeout         = 30;
                    conenctParam.Connection.Encrypt                = true;
                    conenctParam.Connection.TrustServerCertificate = false;
                }
                return(conenctParam);
            }
            return(null);
        }