Exemplo n.º 1
0
        /// <summary>
        /// 计算本选择器是不是另一个规则的选择器有交集。
        /// </summary>
        /// <param name="other"></param>
        /// <returns></returns>
        public bool HasJoint(Selector other, out bool?sourceResult, out bool?destinationResult, out bool?typeResult)
        {
            sourceResult      = Source.Covers(other.Source);
            destinationResult = Destination.Covers(other.Destination);
            typeResult        = Type.HasFlag(other.Type);
            if (Type == TypePredicate.All && other.Type == TypePredicate.All)
            {
                typeResult = null;
            }

            if ((Source.IsDomain || Source.IsIP) && (other.Source.IsDomain || other.Source.IsIP) &&
                Source.IsSubDomain(other.Source) == false && other.Source.IsSubDomain(Source) == false)
            {
                return(false);
            }

            if ((Destination.IsDomain || Destination.IsIP) && (other.Destination.IsDomain || other.Destination.IsIP) && destinationResult == false &&
                Destination.IsSubDomain(other.Destination) == false && other.Destination.IsSubDomain(Destination) == false)
            {
                return(false);
            }

            //如果我的目标字段是1st-party,对方来源和目标不是1st-party,则不包含
            if (Destination.Value == "1st-party" && IsNot1stParty(other))
            {
                return(false);
            }
            //如果我的来源和目标不是1st-party,对方的目标字段是1st-party,则不包含
            if (other.Destination.Value == "1st-party" && IsNot1stParty(this))
            {
                return(false);
            }

            if (Type != TypePredicate.All && other.Type != TypePredicate.All && Type != other.Type)
            {
                return(false);
            }

            return(true);
        }