/// <summary> /// 监控所有路径,包括子路径 /// </summary> /// <param name="paths">节点路径</param> /// <param name="watcher">监控</param> /// <param name="isAbsolutePath">是否绝对路径</param> /// <returns>异步,true表示成功,false表示失败</returns> public async Task <bool[]> WatchAllAsync(string[] paths, NodeWatcher watcher, bool isAbsolutePath = false) { CheckConnection(); List <bool> list = new List <bool>(); foreach (var path in paths) { try { var p = GetAbsolutePath(path, isAbsolutePath); if (await zookeeper.existsAsync(p, this) != null) { nodeWatchers[p] = watcher; list.Add(true); var result = await zookeeper.getChildrenAsync(p); await WatchAllAsync(result.Children.Select(c => Combine(p, c)).ToArray(), watcher, true); } else { nodeWatchers.TryRemove(p, out _); list.Add(false); } } catch { list.Add(false); } } return(list.ToArray()); }
/// <summary> /// 监控所有路径,包括子路径 /// </summary> /// <param name="paths">节点路径</param> /// <param name="delegate">监控</param> /// <param name="isAbsolutePath">是否绝对路径</param> /// <returns>异步,true表示成功,false表示失败</returns> public async Task <bool[]> WatchAllAsync(string[] paths, WatcherEvent @delegate, bool isAbsolutePath = false) { var watcher = new NodeWatcher(); watcher.AllTypeChanged += @delegate; return(await WatchAllAsync(paths, watcher, isAbsolutePath)); }
/// <summary> /// 监控多个路径,但是不包括子路径 /// </summary> /// <param name="paths">节点路径</param> /// <param name="watcher">监控</param> /// <param name="isAbsolutePath">是否绝对路径</param> /// <returns>异步,true表示成功,false表示失败</returns> public async Task <bool[]> WatchManyAsync(string[] paths, NodeWatcher watcher, bool isAbsolutePath = false) { CheckConnection(); List <bool> list = new List <bool>(); foreach (var path in paths) { try { var p = GetAbsolutePath(path, isAbsolutePath); if (await zookeeper.existsAsync(p, this) != null) { nodeWatchers[p] = watcher; list.Add(true); } else { nodeWatchers.TryRemove(p, out _); list.Add(false); } } catch { list.Add(false); } } return(list.ToArray()); }
/// <summary> /// 监控指定路径,包括子路径 /// </summary> /// <param name="path">节点路径</param> /// <param name="watcher">监控</param> /// <param name="isAbsolutePath">是否绝对路径</param> /// <returns>异步,true表示成功,false表示失败</returns> public async Task <bool> WatchAllAsync(string path, NodeWatcher watcher, bool isAbsolutePath = false) { var array = await WatchAllAsync(new string[] { path }, watcher, isAbsolutePath); return(array.FirstOrDefault()); }
/// <summary> /// 监控当前路径,包括子路径 /// </summary> /// <param name="watcher">监控</param> /// <returns>异步,true表示成功,false表示失败</returns> public async Task <bool> WatchAllAsync(NodeWatcher watcher) { return(await WatchAllAsync(CurrentPath, watcher, true)); }