Ejemplo n.º 1
0
        //added by Yang Li
        /// <summary>
        /// 搜索符合查询条件的节点
        /// </summary>
        /// <param name="treeViewDataContextDS"></param>
        private void SearchByQueryCondition(ObservableCollection <ZookeeperTreeNodeModel> treeViewDataContextDS)
        {
            string searchKey = string.Empty;

            if (!string.IsNullOrWhiteSpace(SearchKey))
            {
                searchKey = SearchKey.Trim().ToLower();
            }

            // 删除不符合查询条件的所有节点(【/zookeeper】节点以及它的后代节点除外)
            int treeCount = treeViewDataContextDS.Count;

            for (int j = (treeCount - 1); j > -1; --j)
            {
                ZookeeperTreeNodeModel rootNode = treeViewDataContextDS[j];

                if (rootNode.DisplayName.Equals("zookeeper"))
                {
                    continue;
                }

                // 判断没有后代的鼻祖节点是否符合查询条件。如果不符合,则删除该鼻祖节点;如果符合,则不删除该鼻祖节点,而是退出本次循环,进入下棵树的遍历。
                if (rootNode.Childs.Count == 0)
                {
                    if (!IsMatchedAncestorNode(rootNode, searchKey))
                    {
                        TreeViewDataContext[0].Childs.Remove(rootNode);
                    }

                    continue;
                }

                SearchByQueryCondition(rootNode, searchKey);
            }
        }
Ejemplo n.º 2
0
        //added by Yang Li
        private void DoSearch()
        {
            try
            {
                if (_zk == null)
                {
                    this.AddLog(LogType.Info, "Search Operation: Please connect to Server firstly.", false);
                    return;
                }

                this.DoRefresh1();
                if (TreeViewDataContext == null || !TreeViewDataContext.Any())
                {
                    this.AddLog(LogType.Info, "Search Operation: No content can be searched.", false);
                    return;
                }

                if (string.IsNullOrWhiteSpace(SearchKey))
                {
                    this.AddLog(LogType.Error, "Search Operation: Please enter Search Condition before clicking Search button.", false);
                    return;
                }

                SearchKey = SearchKey.Trim().Replace("/", "/");
                if (SearchKey.Equals("/"))
                {
                    this.AddLog(LogType.Info, "Search Operation: Search successfully.", false);
                    return;
                }

                SearchByQueryCondition(TreeViewDataContext[0].Childs);
                this.RaiseToolBarCanExecuteChanged();
                this.AddLog(LogType.Info, "Search Operation: Search successfully.", false);
            }
            catch (Exception ex)
            {
                //this.AddLog(LogType.Fatal, ex.Message);
                this.AddLog(LogType.Fatal, string.Format("Search Operation failed. The error message is 【{0}】.", ex.Message));
            }
        }