/// <summary> /// 部署服务客户端 /// </summary> /// <param name="config">部署服务客户端配置</param> /// <param name="onClient">部署服务客户端就绪</param> public Client(ClientConfig config = null, Action <OnClientParameter> onClient = null) { this.Config = config ?? ConfigLoader.GetUnion(typeof(ClientConfig)).ClientConfig; this.onClient = onClient; if ((deploys = config.Deploys).Length == 0) { throw new ArgumentNullException(); } IgnoreFileNames = config.IgnoreFileNames.getHash(value => value) ?? HashSetCreator.CreateOnly <string>(); Dictionary <HashString, AutoCSer.Net.TcpInternalServer.ServerAttribute> attributes; if (config.ServerAttributes.length() == 0) { attributes = null; } else { attributes = DictionaryCreator.CreateHashString <AutoCSer.Net.TcpInternalServer.ServerAttribute>(); foreach (KeyValue <string, AutoCSer.Net.TcpInternalServer.ServerAttribute> attribute in config.ServerAttributes.notNull()) { attributes.Add(attribute.Key ?? string.Empty, attribute.Value); } } TcpClient tcpClient; int deployIndex = 0; foreach (ClientDeploy deploy in deploys) { if (deploy.Tasks.length() == 0) { throw new ArgumentNullException("deploys[" + deployIndex.toString() + "].Tasks"); } HashString serverName = deploy.ServerName ?? string.Empty; if (!clients.TryGetValue(serverName, out tcpClient)) { if (serverName.String.Length == 0) { clients.Add(serverName, tcpClient = new TcpClient(this, string.Empty, null)); } else { AutoCSer.Net.TcpInternalServer.ServerAttribute attribute; if (attributes.TryGetValue(serverName, out attribute)) { clients.Add(serverName, tcpClient = new TcpClient(this, serverName.String, attribute)); } else { throw new ArgumentNullException("缺少服务命名 " + serverName); } } } deploys[deployIndex++].TcpClient = tcpClient; } }
/// <summary> /// 根据筛选路径值匹配HTML节点集合 /// </summary> /// <param name="node">筛选节点</param> /// <param name="nodes"></param> /// <returns>匹配的 HTML 节点集合</returns> private IEnumerable <Node> get(Node node, HashSet <Node>[] nodes) { if (node != null) { switch (type) { case FilterType.Node: if (isDistinctNode) { HashSet <Node> hashSet = nodes[depth]; if (hashSet == null || !hashSet.Contains(node)) { if (hashSet == null) { nodes[depth] = hashSet = HashSetCreator.CreateOnly <Node>(); } hashSet.Add(node); if (nextFilter == null) { foreach (Node nextNode in getNode(node, hashSet)) { yield return(nextNode); } } else { foreach (Node nextNode in getNode(node, hashSet)) { foreach (Node returnNode in nextFilter.get(nextNode, nodes)) { yield return(returnNode); } } } } } else { if (nextFilter == null) { foreach (Node nextNode in getNode(node)) { yield return(nextNode); } } else { foreach (Node nextNode in getNode(node)) { foreach (Node returnNode in nextFilter.get(nextNode, nodes)) { yield return(returnNode); } } } } break; case FilterType.Class: if (isClass(node)) { if (nextFilter == null) { yield return(node); } else { foreach (Node returnNode in nextFilter.get(node, nodes)) { yield return(returnNode); } } } break; case FilterType.Child: if (nextFilter == null) { foreach (Node nextNode in getChild(node)) { yield return(nextNode); } } else { foreach (Node nextNode in getChild(node)) { foreach (Node returnNode in nextFilter.get(nextNode, nodes)) { yield return(returnNode); } } } break; case FilterType.Value: if (isValue(node)) { if (nextFilter == null) { yield return(node); } else { foreach (Node returnNode in nextFilter.get(node, nodes)) { yield return(returnNode); } } } break; } } }