Ejemplo n.º 1
0
        public IDataProvider GetDataProvider(IEnumerable <NamedValue> attributes)
        {
            var versionText = attributes.FirstOrDefault(_ => _.Name == "version");

            var version = versionText.Value switch
            {
                var x when x.StartsWith("7.3.") || x == "7.3" || x == "7_3" => DB2iSeriesVersion.V7_3,
                var x when x.StartsWith("7.2.") || x == "7.2" || x == "7_2" => DB2iSeriesVersion.V7_2,
                _ => DB2iSeriesVersion.V7_1
            };

            var providerType = attributes.FirstOrDefault(_ => _.Name == "assemblyName")?.Value switch
            {
#if NETFRAMEWORK
                DB2iSeriesAccessClientProviderAdapter.AssemblyName => DB2iSeriesProviderType.AccessClient,
#endif
                DB2.DB2ProviderAdapter.AssemblyName => DB2iSeriesProviderType.DB2,
                OleDbProviderAdapter.AssemblyName => DB2iSeriesProviderType.OleDb,
                OdbcProviderAdapter.AssemblyName => DB2iSeriesProviderType.Odbc,
                null => DB2iSeriesProviderOptions.Defaults.ProviderType,
                var x => throw ExceptionHelper.InvalidAssemblyName(x)
            };

            var mapGuidAsString = attributes.Any(x => x.Name == Constants.ProviderFlags.MapGuidAsString);

            return(DB2iSeriesTools.GetDataProvider(version, providerType, new DB2iSeriesMappingOptions(mapGuidAsString)));
        }
    }
}
        public DB2iSeriesDataProvider AutoDetectDataProvider(string connectionString)
        {
            try
            {
                var providerType = GetProviderType(connectionString);
                var minLevel     = GetServerMinLevel(connectionString, providerType);

                return(DB2iSeriesTools.GetDataProvider(minLevel, providerType, new DB2iSeriesMappingOptions(mapGuidAsString)));
            }
            catch (Exception e)
            {
                throw ExceptionHelper.ConnectionStringParsingFailure(e);
            }
        }
        private ServerVersion GetServerVersion(string connectionString, DB2iSeriesProviderType providerType)
        {
            using (var conn = (DbConnection)DB2iSeriesTools.GetDataProvider(DB2iSeriesVersion.V7_1, providerType, DB2iSeriesMappingOptions.Default).CreateConnection(connectionString))
            {
                conn.Open();

                var serverVersionParts = conn.ServerVersion.Substring(0, 5).Split('.');
                var major = int.Parse(serverVersionParts.First());
                var minor = int.Parse(serverVersionParts.Last());

                var patchLevel = GetMaxPatchLevel(conn, major, minor);

                return(new ServerVersion(major, minor, patchLevel));
            }
        }