public GetConnectionStringsOperation(string databaseName, string connectionStringName = null, ConnectionStringType type = ConnectionStringType.None)
 {
     _databaseName         = databaseName;
     _connectionStringName = connectionStringName;
     _type = type;
 }
Example #2
0
        public static void ConnectToDB(ConnectionStringType connectionStringType)
        {
            var connectionString = GetConnectionString(connectionStringType == ConnectionStringType.Eorg ? "ConnectionString" : "SourceConnectionString");

            Connection = CreateConnection(connectionString);
        }
        public static string CreateConnectionString(IDatabaseConnectionServiceModel connectionCredentails, ConnectionStringType connectionStringType)
        {
            var connectionStringBuilder = ConnectionManipulatorFactory.GetConnectionStringBuilder(connectionStringType);

            return(connectionStringBuilder.CreateConnectionString(connectionCredentails));
        }
 /// <summary>
 /// Converts the <see cref="sourceValue" /> parameter to the <see cref="destinationType" /> parameter using <see cref="formatProvider"
 /// /> and <see cref="ignoreCase" />
 /// </summary>
 /// <param name="sourceValue">the <see cref="System.Object"/> to convert from</param>
 /// <param name="destinationType">the <see cref="System.Type" /> to convert to</param>
 /// <param name="formatProvider">not used by this TypeConverter.</param>
 /// <param name="ignoreCase">when set to <c>true</c>, will ignore the case when converting.</param>
 /// <returns>
 /// an instance of <see cref="ConnectionStringType" />, or <c>null</c> if there is no suitable conversion.
 /// </returns>
 public override object ConvertFrom(object sourceValue, global::System.Type destinationType, global::System.IFormatProvider formatProvider, bool ignoreCase) => ConnectionStringType.CreateFrom(sourceValue);
        void ParseConnectionString(string connectionString)
        {
            logger.LogInformation("Parsing: " + connectionString);

            string GetConnectionStringValue(IDictionary <string, string> dict, string propertyName)
            {
                if (!dict.TryGetValue(propertyName, out string value))
                {
                    logger.LogTrace($"The connection string is missing the property: {propertyName}");
                }
                else
                {
                    logger.LogTrace($"Connection Property Found: {propertyName}={value}");
                }
                return(value);
            }

            ConnectionStringType ValidateParams()
            {
                ConnectionStringType result = ConnectionStringType.Invalid;

                if (!string.IsNullOrWhiteSpace(this.HostName))                                                         //direct
                {
                    if (!string.IsNullOrWhiteSpace(this.DeviceId) && !string.IsNullOrWhiteSpace(this.SharedAccessKey)) // direct sas
                    {
                        result = ConnectionStringType.DirectSas;
                    }
                    else if (!string.IsNullOrWhiteSpace(this.X509) && !string.IsNullOrWhiteSpace(this.DeviceId)) // direct with cert
                    {
                        result = ConnectionStringType.DirectCert;
                    }
                    else
                    {
                        this.logger.LogWarning("Connection string require Sas or X509 credential");
                    }
                }
                else if (!string.IsNullOrWhiteSpace(this.ScopeId))        // use DPS
                {
                    if (!string.IsNullOrWhiteSpace(this.SharedAccessKey)) // use group enrollment key
                    {
                        result = ConnectionStringType.DPSSas;
                    }
                    else if (!string.IsNullOrWhiteSpace(this.MasterAccessKey))
                    {
                        result = ConnectionStringType.DPSSasMaster;
                    }
                    else if (!string.IsNullOrWhiteSpace(this.X509))
                    {
                        result = ConnectionStringType.DPSCert;
                    }
                    else
                    {
                        this.logger.LogWarning("Connection string require Sas or X509 credential");
                    }
                }
                return(result);
            }

            IDictionary <string, string> map = connectionString.ToDictionary(';', '=');

            if (map == null)
            {
                logger.LogError("Cannot parse connection string");
                return;
            }
            this.HostName        = GetConnectionStringValue(map, nameof(this.HostName));
            this.ScopeId         = GetConnectionStringValue(map, nameof(this.ScopeId));
            this.DeviceId        = GetConnectionStringValue(map, nameof(this.DeviceId));
            this.SharedAccessKey = GetConnectionStringValue(map, nameof(this.SharedAccessKey));
            this.X509            = GetConnectionStringValue(map, nameof(this.X509));
            this.MasterAccessKey = GetConnectionStringValue(map, nameof(this.MasterAccessKey));

            if (string.IsNullOrEmpty(this.ModelId))
            {
                this.ModelId = GetConnectionStringValue(map, nameof(ModelId));
                logger.LogTrace($"Using ModelId from connection string: {this.ModelId}");
            }
            else
            {
                logger.LogTrace($"ModelId set {this.ModelId}, ignoring from connection string.");
            }

            this.connectionStringType = ValidateParams();

            logger.LogInformation($"Connection Type: {this.connectionStringType}");
        }
Example #6
0
 /// <summary>
 /// Sensitive information should be encrypted when passed to DAL.
 /// </summary>
 /// <param name="connectionStringType"></param>
 /// <param name="id"></param>
 /// <param name="pwd"></param>
 /// <param name="TimeoutSecs"></param>
 public DAL(ConnectionStringType connectionStringType, string id, string pwd, int TimeoutSecs = 300)
 {
     this.TimeoutSecs = TimeoutSecs;
     Connection       = new DALConnection(connectionStringType, id, pwd);
 }
Example #7
0
 public MissingConnectionStringForDatabaseType(ConnectionStringType type) : base($"ConnectionString for database type '{type}' is missing")
 {
 }
Example #8
0
 public GetConnectionStringsOperation(string connectionStringName, ConnectionStringType type)
 {
     _connectionStringName = connectionStringName;
     _type = type;
 }
Example #9
0
 /// <summary>
 /// 默认的构造函数使用Config库
 /// </summary>
 public DataAccessBase(ConnectionStringType connectionStringType = ConnectionStringType.WebSite)
 {
     CurrentContext = DBContextFactory(connectionStringType);
     CurrentContext.Database.Log            = (sql) => Log.Write(LogLevel.Info, sql);
     CurrentContext.Database.CommandTimeout = TimeOut; //时间单位是毫秒
 }
 public static string ToSerialString(this ConnectionStringType value) => value switch
 {
 /// <summary>
 /// Initializes a new instance of the ConnStringValueTypePair class.
 /// </summary>
 /// <param name="value">Value of pair.</param>
 /// <param name="type">Type of database. Possible values include:
 /// 'MySql', 'SQLServer', 'SQLAzure', 'Custom', 'NotificationHub',
 /// 'ServiceBus', 'EventHub', 'ApiHub', 'DocDb', 'RedisCache',
 /// 'PostgreSQL'</param>
 public ConnStringValueTypePair(string value, ConnectionStringType type)
 {
     Value = value;
     Type  = type;
     CustomInit();
 }
Example #12
0
        public string GenerateConnectionString(ConnectionStringType connectionStringType = ConnectionStringType.Default)
        {
            string server = string.Format(@"Data Source={0}{1}\{2}", serverAddress,
                sqlServerPortString.Trim().Length > 0 ? string.Format(",{0}", sqlServerPortString.Trim()) : string.Empty,
                serverInstanceName.Trim().Length > 0 ? serverInstanceName.Trim() : string.Empty);

            string database = string.Empty;

            if (connectionStringType != ConnectionStringType.EmptyCatalog)
                database = string.Format(@"Initial Catalog={0}", connectionStringType == ConnectionStringType.UseMaster ? "master" : databaseName);

            string authentication = string.Empty;

            if (databaseAuthentication == Authentication.Windows) authentication = "Integrated Security=True";
            else authentication = string.Format(@"User Id={0}; Password={1}", userName, password);

            return string.Format("{0};{1};{2};", server, database, authentication);
        }
Example #13
0
 /// <summary>
 /// 根据参数类型实例化
 /// </summary>
 /// <param name="content">内容,链接字符串本身或链接结点的名称</param>
 /// <param name="type">ConnectionStringType枚举</param>
 public SqlHelper(string content, ConnectionStringType type)
     : base(content, type)
 {
 }
Example #14
0
 public Database(String connectionString, ConnectionStringType connectionStringType, String provider = SqlServerProvider)
 {
     Open(connectionString, connectionStringType, provider);
 }
Example #15
0
        protected CrmConnection CreateConnectionFromConnectionStringInConfigFile(string key, ConnectionStringType connType)
        {
            var connStringSetting = ConfigurationManager.ConnectionStrings[key];

            if (connStringSetting == null)
            {
                throw new ArgumentException("Connection string for a required Crm service was not found in the connectionStrings section of your config file. The missing connection string name is:" + key);
            }
            return(CreateConnectionFromConnectionString(connStringSetting.ConnectionString, connType));
        }
Example #16
0
 /// <summary>
 /// Deletes the connection string configuration.
 /// </summary>
 /// <param name="externalIdentifier">The external identifier.</param>
 /// <param name="connectionStringType">Type of the connection string.</param>
 /// <param name="cancellationToken">The cancellation token.</param>
 public async Task DeleteConnectionStringConfiguration(String externalIdentifier,
                                                       ConnectionStringType connectionStringType,
                                                       CancellationToken cancellationToken)
 {
     throw new NotImplementedException("This is only required to complete the interface");
 }
Example #17
0
        protected CrmConnection CreateConnectionFromConnectionString(string connectionString, ConnectionStringType connType)
        {
            if (string.IsNullOrEmpty(connectionString))
            {
                throw new ArgumentException("Connection string cannot be null or empty.");
            }

            var conn = CrmConnection.Parse(connectionString);

            switch (connType)
            {
            case ConnectionStringType.OrgService:
                this.OrganisationServiceConnectionString = connectionString;
                break;

            case ConnectionStringType.DeploymentService:
                this.DeploymentServiceConnectionString = connectionString;
                break;

            case ConnectionStringType.DiscoveryService:
                this.DiscoveryServiceConnectionString = connectionString;
                break;
            }

            return(conn);
        }
Example #18
0
 public GetConnectionStringCommand(string connectionStringName = null, ConnectionStringType type = ConnectionStringType.None)
 {
     _connectionStringName = connectionStringName;
     _type = type;
 }
Example #19
0
        /// <summary>
        /// Deletes the given connection string.
        /// </summary>
        /// <param name="externalIdentifier">The external identifier.</param>
        /// <param name="connectionStringType">Type of the connection string.</param>
        /// <param name="cancellationToken">The cancellation token.</param>
        /// <exception cref="NotFoundException">No configuration found for Connection String Identifier [{connectionStringIdentifier}] and DataModelType [{dataModelType}]</exception>
        public async Task DeleteConnectionStringConfiguration(String externalIdentifier, ConnectionStringType connectionStringType, CancellationToken cancellationToken)
        {
            this.GuardAgainstNoExternalIdentifier(externalIdentifier);

            // Find the record in the config repository
            using (ConnectionStringConfigurationContext context = this.ContextResolver())
            {
                ConnectionStringConfiguration configuration =
                    await context.ConnectionStringConfiguration.SingleOrDefaultAsync(c => c.ExternalIdentifier == externalIdentifier &&
                                                                                     c.ConnectionStringTypeId == (Int32)connectionStringType, cancellationToken);

                if (configuration == null)
                {
                    throw new
                          NotFoundException($"No connection string configuration found for External Identifier [{externalIdentifier}]");
                }

                context.Remove(configuration);

                await context.SaveChangesAsync(cancellationToken);
            }
        }