Пример #1
0
        /// <summary>
        /// 查找主机应该位于的分组节点,如果没有找到,则返回空值
        /// </summary>
        /// <param name="host">要添加的节点</param>
        /// <returns>返回主机应该位于的分组节点,如果没有找到,则返回空值</returns>
        public TreeNode FindCollectionNodeForHost(Host host)
        {
            ListConfig cfg        = Env.ClientConfig.HostListViewConfig;
            TreeNode   parentNode = null;

            //查找第一级别分组
            if (cfg.FirstGroupType == ListConfig.GroupType.None)
            {
                return(null);
            }
            foreach (TreeNode node in this.Nodes)
            {
                HostCollectionBase b = node as HostCollectionBase;
                if (b != null && b.IsHostInThisGroup(host))
                {
                    parentNode = node;
                    break;
                }
            }
            //如果没有找到,则创建
            if (parentNode == null)
            {
                switch (cfg.FirstGroupType)
                {
                case ListConfig.GroupType.UserDefine:
                    parentNode = new HostUserDefineCollectionNode()
                    {
                        GroupLevel = 0, GroupName = HostUserDefineCollectionNode.GetHostGroupName(host)
                    };
                    break;

                case ListConfig.GroupType.IPHeader:
                    parentNode = new HostIPCollectionNode()
                    {
                        GroupLevel = 0, IPHeader = host.HostSub.IPHeader
                    };
                    break;

                case ListConfig.GroupType.UserGroup:
                    parentNode = new HostGroupCollectionNode()
                    {
                        GroupLevel = 0, GroupName = host.GroupName
                    };
                    break;
                }
                this.Nodes.Add(parentNode);
            }

            //查找第二级节点
            if (cfg.SecondGroupType == ListConfig.GroupType.None)
            {
                return(parentNode);
            }
            TreeNode subNode = null;

            foreach (TreeNode node in parentNode.Nodes)
            {
                HostCollectionBase b = node as HostCollectionBase;
                if (b != null && b.IsHostInThisGroup(host))
                {
                    subNode = node;
                    break;
                }
            }
            //如果没有找到,则创建
            if (subNode == null)
            {
                switch (cfg.SecondGroupType)
                {
                case ListConfig.GroupType.UserDefine:
                    subNode = new HostUserDefineCollectionNode()
                    {
                        GroupLevel = 1, GroupName = HostUserDefineCollectionNode.GetHostGroupName(host)
                    };
                    break;

                case ListConfig.GroupType.IPHeader:
                    subNode = new HostIPCollectionNode()
                    {
                        GroupLevel = 1, IPHeader = host.HostSub.IPHeader
                    };
                    break;

                case ListConfig.GroupType.UserGroup:
                    subNode = new HostGroupCollectionNode()
                    {
                        GroupLevel = 1, GroupName = host.GroupName
                    };
                    break;
                }
                parentNode.Nodes.Add(subNode);
            }

            return(subNode);
        }
Пример #2
0
		/// <summary>
		/// 查找主机应该位于的分组节点,如果没有找到,则返回空值
		/// </summary>
		/// <param name="host">要添加的节点</param>
		/// <returns>返回主机应该位于的分组节点,如果没有找到,则返回空值</returns>
		public TreeNode FindCollectionNodeForHost(Host host)
		{
			ListConfig cfg = Env.ClientConfig.HostListViewConfig;
			TreeNode parentNode = null;

			//查找第一级别分组
			if (cfg.FirstGroupType == ListConfig.GroupType.None) return null;
			foreach (TreeNode node in this.Nodes)
			{
				HostCollectionBase b = node as HostCollectionBase;
				if (b != null && b.IsHostInThisGroup(host))
				{
					parentNode = node;
					break;
				}
			}
			//如果没有找到,则创建
			if (parentNode == null)
			{
				switch (cfg.FirstGroupType)
				{
					case ListConfig.GroupType.UserDefine:
						parentNode = new HostUserDefineCollectionNode() { GroupLevel = 0, GroupName = HostUserDefineCollectionNode.GetHostGroupName(host) };
						break;
					case ListConfig.GroupType.IPHeader:
						parentNode = new HostIPCollectionNode() { GroupLevel = 0, IPHeader = host.HostSub.IPHeader };
						break;
					case ListConfig.GroupType.UserGroup:
						parentNode = new HostGroupCollectionNode() { GroupLevel = 0, GroupName = host.GroupName };
						break;
				}
				this.Nodes.Add(parentNode);
			}

			//查找第二级节点
			if (cfg.SecondGroupType == ListConfig.GroupType.None) return parentNode;
			TreeNode subNode = null;
			foreach (TreeNode node in parentNode.Nodes)
			{
				HostCollectionBase b = node as HostCollectionBase;
				if (b != null && b.IsHostInThisGroup(host))
				{
					subNode = node;
					break;
				}
			}
			//如果没有找到,则创建
			if (subNode == null)
			{
				switch (cfg.SecondGroupType)
				{
					case ListConfig.GroupType.UserDefine:
						subNode = new HostUserDefineCollectionNode() { GroupLevel = 1, GroupName = HostUserDefineCollectionNode.GetHostGroupName(host) };
						break;
					case ListConfig.GroupType.IPHeader:
						subNode = new HostIPCollectionNode() { GroupLevel = 1, IPHeader = host.HostSub.IPHeader };
						break;
					case ListConfig.GroupType.UserGroup:
						subNode = new HostGroupCollectionNode() { GroupLevel = 1, GroupName = host.GroupName };
						break;
				}
				parentNode.Nodes.Add(subNode);
			}

			return subNode;
		}