コード例 #1
0
        public void VisitSelectedPartitions(ContextPartitionSelector contextPartitionSelector, ContextPartitionVisitor visitor)
        {
            var nestingLevel = _factory.FactoryContext.NestingLevel;

            if (contextPartitionSelector is ContextPartitionSelectorFiltered filtered)
            {
                var identifier = new ContextPartitionIdentifierPartitioned();
                foreach (var entry in _partitionKeys)
                {
                    identifier.ContextPartitionId = entry.Value.ContextPartitionOrPathId;
                    var identifierOA = GetKeyObjectsAccountForMultikey(entry.Key);
                    identifier.Keys = identifierOA;

                    if (filtered.Filter(identifier))
                    {
                        visitor.Visit(nestingLevel, _pathId, _factory.Binding, identifierOA, this, entry.Value);
                    }
                }
                return;
            }
            else if (contextPartitionSelector is ContextPartitionSelectorSegmented partitioned)
            {
                if (partitioned.PartitionKeys?.IsEmpty() != false)
                {
                    return;
                }
                foreach (var keyObjects in partitioned.PartitionKeys)
                {
                    var key            = GetKeyObjectForLookup(keyObjects);
                    var instanceHandle = _partitionKeys.Get(key);
                    if (instanceHandle != null)
                    {
                        visitor.Visit(nestingLevel, _pathId, _factory.Binding, keyObjects, this, instanceHandle);
                    }
                }
                return;
            }
            else if (contextPartitionSelector is ContextPartitionSelectorById filteredById)
            {
                foreach (var entry in _partitionKeys)
                {
                    if (filteredById.ContextPartitionIds.Contains(entry.Value.ContextPartitionOrPathId))
                    {
                        visitor.Visit(nestingLevel, _pathId, _factory.Binding, GetKeyObjectsAccountForMultikey(entry.Key), this, entry.Value);
                    }
                }
                return;
            }
            else if (contextPartitionSelector is ContextPartitionSelectorAll)
            {
                foreach (var entry in _partitionKeys)
                {
                    visitor.Visit(nestingLevel, _pathId, _factory.Binding, GetKeyObjectsAccountForMultikey(entry.Key), this, entry.Value);
                }
                return;
            }
            throw ContextControllerSelectorUtil.GetInvalidSelector(new Type[] { typeof(ContextPartitionSelectorSegmented) }, contextPartitionSelector);
        }
コード例 #2
0
        public override void VisitSelectedPartitions(
            IntSeqKey path,
            ContextPartitionSelector selector,
            ContextPartitionVisitor visitor,
            ContextPartitionSelector[] selectorPerLevel)
        {
            if (selector is ContextPartitionSelectorSegmented) {
                var partitioned = (ContextPartitionSelectorSegmented) selector;
                if (partitioned.PartitionKeys == null || partitioned.PartitionKeys.IsEmpty()) {
                    return;
                }

                foreach (var key in partitioned.PartitionKeys) {
                    var keyForLookup = key.Length == 1 ? key[0] : new HashableMultiKey(key);
                    var subpathOrCPId = GetSubpathOrCPId(path, keyForLookup);
                    if (subpathOrCPId != -1) {
                        realization.ContextPartitionRecursiveVisit(
                            path,
                            subpathOrCPId,
                            this,
                            visitor,
                            selectorPerLevel);
                    }
                }

                return;
            }

            if (selector is ContextPartitionSelectorFiltered) {
                var filtered = (ContextPartitionSelectorFiltered) selector;
                var identifier = new ContextPartitionIdentifierPartitioned();
                VisitPartitions(
                    path,
                    (
                        key,
                        subpathOrCPId) => {
                        if (factory.FactoryEnv.IsLeaf) {
                            identifier.ContextPartitionId = subpathOrCPId;
                        }

                        var keys = key is HashableMultiKey ? ((HashableMultiKey) key).Keys : new[] {key};
                        identifier.Keys = keys;
                        if (filtered.Filter(identifier)) {
                            realization.ContextPartitionRecursiveVisit(
                                path,
                                subpathOrCPId,
                                this,
                                visitor,
                                selectorPerLevel);
                        }
                    });
                return;
            }

            if (selector is ContextPartitionSelectorAll) {
                VisitPartitions(
                    path,
                    (
                        key,
                        subpathOrCPId) => realization.ContextPartitionRecursiveVisit(
                        path,
                        subpathOrCPId,
                        this,
                        visitor,
                        selectorPerLevel));
                return;
            }

            if (selector is ContextPartitionSelectorById) {
                var ids = (ContextPartitionSelectorById) selector;
                VisitPartitions(
                    path,
                    (
                        key,
                        subpathOrCPId) => {
                        if (ids.ContextPartitionIds.Contains(subpathOrCPId)) {
                            realization.ContextPartitionRecursiveVisit(
                                path,
                                subpathOrCPId,
                                this,
                                visitor,
                                selectorPerLevel);
                        }
                    });
            }

            throw ContextControllerSelectorUtil.GetInvalidSelector(
                new[] {typeof(ContextPartitionSelectorSegmented)},
                selector);
        }