Ejemplo n.º 1
0
        public async Task <SmartSqlMapConfig> LoadAsync(string path, ISmartSqlMapper smartSqlMapper)
        {
            _logger.Debug($"SmartSql.ZooKeeperConfigLoader Load: {path} Starting");
            var config = await LoadConfigAsync(path, smartSqlMapper);

            _logger.Debug($"SmartSql.ZooKeeperConfigLoader Load: {path} End");
            smartSqlMapper.LoadConfig(config);
            return(config);
        }
Ejemplo n.º 2
0
        public SmartSqlMapConfig Load(String path, ISmartSqlMapper smartSqlMapper)
        {
            _logger.Debug($"SmartSql.LocalFileConfigLoader Load: {path} Starting");
            var config = LoadConfig(path, smartSqlMapper);

            _logger.Debug($"SmartSql.LocalFileConfigLoader Load: {path} End");
            smartSqlMapper.LoadConfig(config);
            if (config.Settings.IsWatchConfigFile)
            {
                _logger.Debug($"SmartSql.LocalFileConfigLoader Load Add WatchConfig: {path} .");
                WatchConfig(smartSqlMapper);
            }
            return(config);
        }
Ejemplo n.º 3
0
        public async Task <SmartSqlMapConfig> LoadAsync(string path, ISmartSqlMapper smartSqlMapper)
        {
            _logger.LogDebug($"SmartSql.ZooKeeperConfigLoader Load: {path} Starting");
            var configResult = await ZooClient.getDataAsync(path, new SmartSqlMapConfigWatcher(_loggerFactory, smartSqlMapper, this));

            var configStream = new ConfigStream
            {
                Path   = path,
                Stream = new MemoryStream(configResult.Data)
            };
            var config = LoadConfig(configStream, smartSqlMapper);

            foreach (var sqlmapSource in config.SmartSqlMapSources)
            {
                switch (sqlmapSource.Type)
                {
                case SmartSqlMapSource.ResourceType.File:
                {
                    var sqlmap = await LoadSmartSqlMapAsync(sqlmapSource.Path, config);

                    config.SmartSqlMaps.Add(sqlmap);
                    break;
                }

                case SmartSqlMapSource.ResourceType.Directory:
                {
                    var sqlmapChildren = await ZooClient.getChildrenAsync(sqlmapSource.Path);

                    foreach (var sqlmapChild in sqlmapChildren.Children)
                    {
                        var sqlmapPath = $"{sqlmapSource.Path}/{sqlmapChild}";
                        var sqlmap     = await LoadSmartSqlMapAsync(sqlmapPath, config);

                        config.SmartSqlMaps.Add(sqlmap);
                    }
                    break;
                }

                default:
                {
                    throw new ArgumentException("unknow SmartSqlMap.Type!");
                }
                }
            }
            _logger.LogDebug($"SmartSql.ZooKeeperConfigLoader Load: {path} End");

            smartSqlMapper.LoadConfig(config);
            return(config);
        }
Ejemplo n.º 4
0
        public override SmartSqlMapConfig Load(String path, ISmartSqlMapper smartSqlMapper)
        {
            _logger.LogDebug($"LocalFileConfigLoader Load: {path} Starting");
            var configStream = LoadConfigStream(path);
            var config       = LoadConfig(configStream, smartSqlMapper);

            foreach (var sqlmapSource in config.SmartSqlMapSources)
            {
                switch (sqlmapSource.Type)
                {
                case SmartSqlMapSource.ResourceType.File:
                {
                    LoadSmartSqlMap(config, sqlmapSource.Path);
                    break;
                }

                case SmartSqlMapSource.ResourceType.Directory:
                {
                    var childSqlmapSources = Directory.EnumerateFiles(sqlmapSource.Path, "*.xml");
                    foreach (var childSqlmapSource in childSqlmapSources)
                    {
                        LoadSmartSqlMap(config, childSqlmapSource);
                    }
                    break;
                }

                default:
                {
                    _logger.LogDebug($"LocalFileConfigLoader unknow SmartSqlMapSource.ResourceType:{sqlmapSource.Type}.");
                    break;
                }
                }
            }
            _logger.LogDebug($"LocalFileConfigLoader Load: {path} End");

            smartSqlMapper.LoadConfig(config);

            if (config.Settings.IsWatchConfigFile)
            {
                _logger.LogDebug($"LocalFileConfigLoader Load Add WatchConfig: {path} Starting.");
                WatchConfig(smartSqlMapper);
                _logger.LogDebug($"LocalFileConfigLoader Load Add WatchConfig: {path} End.");
            }
            return(config);
        }
Ejemplo n.º 5
0
        public async Task <SmartSqlMapConfig> LoadAsync(string path, ISmartSqlMapper smartSqlMapper)
        {
            _logger.Debug($"SmartSql.ZooKeeperConfigLoader Load: {path} Starting");
            var configResult = await ZooClient.getDataAsync(path, new SmartSqlMapConfigWatcher(smartSqlMapper, this));

            var configStream = new ConfigStream
            {
                Path   = path,
                Stream = new MemoryStream(configResult.Data)
            };
            var config = LoadConfig(configStream, smartSqlMapper);

            foreach (var sqlmapSource in config.SmartSqlMapSources)
            {
                var sqlmap = await LoadSmartSqlMapAsync(sqlmapSource.Path, config);

                config.SmartSqlMaps.Add(sqlmap);
            }
            _logger.Debug($"SmartSql.ZooKeeperConfigLoader Load: {path} End");

            smartSqlMapper.LoadConfig(config);
            return(config);
        }
Ejemplo n.º 6
0
        public override SmartSqlMapConfig Load(String path, ISmartSqlMapper smartSqlMapper)
        {
            _logger.Debug($"SmartSql.LocalFileConfigLoader Load: {path} Starting");
            var configStream = LoadConfigStream(path);
            var config       = LoadConfig(configStream, smartSqlMapper);

            foreach (var sqlmapSource in config.SmartSqlMapSources)
            {
                _logger.Debug($"SmartSql.LoadSmartSqlMap Load: {sqlmapSource.Path}");
                var sqlmapStream = LoadConfigStream(sqlmapSource.Path);
                var sqlmap       = LoadSmartSqlMap(sqlmapStream, config);
                config.SmartSqlMaps.Add(sqlmap);
            }
            _logger.Debug($"SmartSql.LocalFileConfigLoader Load: {path} End");

            smartSqlMapper.LoadConfig(config);

            if (config.Settings.IsWatchConfigFile)
            {
                _logger.Debug($"SmartSql.LocalFileConfigLoader Load Add WatchConfig: {path} .");
                WatchConfig(smartSqlMapper);
            }
            return(config);
        }
Ejemplo n.º 7
0
 public void LoadConfig(SmartSqlMapConfig smartSqlMapConfig)
 {
     MapperInstance.LoadConfig(smartSqlMapConfig);
 }
Ejemplo n.º 8
0
 public void LoadConfig(SmartSqlMapConfig smartSqlMapConfig)
 {
     SqlMapper.LoadConfig(smartSqlMapConfig);
 }
Ejemplo n.º 9
0
        public override SmartSqlMapConfig Load(string path, ISmartSqlMapper smartSqlMapper)
        {
            _logger.LogDebug($"NativeConfigLoader Load: { _smartSqlOptions.SqlMapperPath} Starting");

            var config = new SmartSqlMapConfig()
            {
                Path               = _smartSqlOptions.SqlMapperPath,
                SmartSqlMapper     = smartSqlMapper,
                SmartSqlMaps       = new List <SmartSqlMap>(),
                SmartSqlMapSources = new List <SmartSqlMapSource>()
                {
                    new SmartSqlMapSource()
                    {
                        Path = _smartSqlOptions.SqlMapperPath,
                        Type = SmartSqlMapSource.ResourceType.Directory
                    }
                },
                Database = new Database()
                {
                    DbProvider = new DbProvider()
                    {
                        ParameterPrefix = _smartSqlOptions.ParameterPrefix,
                        Name            = _smartSqlOptions.DbProviderFactory.GetType().Name,
                        Type            = _smartSqlOptions.DbProviderFactory.GetType().AssemblyQualifiedName
                    },
                    WriteDataSource = new WriteDataSource()
                    {
                        ConnectionString = _smartSqlOptions.ConnectionString,
                        Name             = _smartSqlOptions.LoggingName
                    },
                    ReadDataSources = new List <ReadDataSource>()
                    {
                        new ReadDataSource()
                        {
                            ConnectionString = _smartSqlOptions.ConnectionString,
                            Name             = _smartSqlOptions.LoggingName,
                            Weight           = 1,
                        }
                    },
                },
                Settings = new Settings()
                {
                    ParameterPrefix   = _smartSqlOptions.ParameterPrefix,
                    IsWatchConfigFile = true
                },
            };

            if (_smartSqlOptions.UseManifestResource)
            {
                foreach (var sourceName in Assembly.GetExecutingAssembly().GetManifestResourceNames())
                {
                    LoadManifestSmartSqlMap(config, sourceName);
                }
            }
            else
            {
                foreach (var sqlmapSource in config.SmartSqlMapSources)
                {
                    switch (sqlmapSource.Type)
                    {
                    case SmartSqlMapSource.ResourceType.File:
                    {
                        LoadSmartSqlMap(config, sqlmapSource.Path);
                        break;
                    }

                    case SmartSqlMapSource.ResourceType.Directory:
                    {
                        var childSqlmapSources = Directory.EnumerateFiles(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, sqlmapSource.Path), "*.xml");
                        foreach (var childSqlmapSource in childSqlmapSources)
                        {
                            LoadSmartSqlMap(config, childSqlmapSource);
                        }
                        break;
                    }

                    default:
                    {
                        _logger.LogDebug($"LocalFileConfigLoader unknow SmartSqlMapSource.ResourceType:{sqlmapSource.Type}.");
                        break;
                    }
                    }
                }
            }
            _logger.LogDebug($"LocalFileConfigLoader Load: { _smartSqlOptions.SqlMapperPath} End");
            smartSqlMapper.LoadConfig(config);

            if (config.Settings.IsWatchConfigFile)
            {
                _logger.LogDebug($"LocalFileConfigLoader Load Add WatchConfig: { _smartSqlOptions.SqlMapperPath} Starting.");
                WatchConfig(smartSqlMapper);
                _logger.LogDebug($"LocalFileConfigLoader Load Add WatchConfig: { _smartSqlOptions.SqlMapperPath} End.");
            }
            return(config);
        }