Ejemplo n.º 1
0
        public async Task <SmartSqlMap> LoadSmartSqlMapAsync(String path, SmartSqlMapConfig config)
        {
            _logger.LogDebug($"SmartSql.LoadSmartSqlMapAsync Load: {path}");
            var sqlmapResult = await ZooClient.getDataAsync(path, new SmartSqlMapWatcher(_loggerFactory, config, this));

            var sqlmapStream = new ConfigStream
            {
                Path   = path,
                Stream = new MemoryStream(sqlmapResult.Data)
            };

            return(LoadSmartSqlMap(sqlmapStream));
        }
Ejemplo n.º 2
0
        public async Task <SmartSqlMapConfig> LoadAsync()
        {
            _logger.LogDebug($"SmartSql.ZooKeeperConfigLoader Load: {options.SqlMapConfigPath} Starting");
            var configResult = await ZooClient.getDataAsync(options.SqlMapConfigPath, new SmartSqlMapConfigWatcher(_loggerFactory, this));

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

            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: {options.SqlMapConfigPath} End");
            return(config);
        }
 /// <summary>
 /// 从ZooKeeper获取字节数组数据
 /// </summary>
 /// <param name="path"></param>
 /// <returns></returns>
 public byte[] GetBytesData(string path)
 {
     byte[] bytes = ZooClient.getDataAsync(path).Result.Data;
     return(bytes);
 }