public void VisitSelectedPartitions(ContextPartitionSelector contextPartitionSelector, ContextPartitionVisitor visitor) { int nestingLevel = _factory.FactoryContext.NestingLevel; if (contextPartitionSelector is ContextPartitionSelectorHash) { var hash = (ContextPartitionSelectorHash)contextPartitionSelector; if (hash.Hashes == null || hash.Hashes.IsEmpty()) { return; } foreach (int hashCode in hash.Hashes) { var handle = _partitionKeys.Get(hashCode); if (handle != null) { visitor.Visit(nestingLevel, _pathId, _factory.Binding, hashCode, this, handle); } } return; } if (contextPartitionSelector is ContextPartitionSelectorFiltered) { var filter = (ContextPartitionSelectorFiltered)contextPartitionSelector; var identifierHash = new ContextPartitionIdentifierHash(); foreach (var entry in _partitionKeys) { identifierHash.Hash = entry.Key; identifierHash.ContextPartitionId = entry.Value.ContextPartitionOrPathId; if (filter.Filter(identifierHash)) { visitor.Visit(nestingLevel, _pathId, _factory.Binding, entry.Key, this, entry.Value); } } return; } if (contextPartitionSelector is ContextPartitionSelectorAll) { foreach (var entry in _partitionKeys) { visitor.Visit(nestingLevel, _pathId, _factory.Binding, entry.Key, this, entry.Value); } return; } if (contextPartitionSelector is ContextPartitionSelectorById) { var byId = (ContextPartitionSelectorById)contextPartitionSelector; foreach (var entry in _partitionKeys) { int cpid = entry.Value.ContextPartitionOrPathId; if (byId.ContextPartitionIds.Contains(cpid)) { visitor.Visit(nestingLevel, _pathId, _factory.Binding, entry.Key, this, entry.Value); } } return; } throw ContextControllerSelectorUtil.GetInvalidSelector(new Type[] { typeof(ContextPartitionSelectorHash) }, contextPartitionSelector); }
public override void VisitSelectedPartitions( IntSeqKey path, ContextPartitionSelector selector, ContextPartitionVisitor visitor, ContextPartitionSelector[] selectorPerLevel) { if (selector is ContextPartitionSelectorHash) { var selectorHash = (ContextPartitionSelectorHash) selector; if (selectorHash.Hashes == null || selectorHash.Hashes.IsEmpty()) { return; } foreach (var hash in selectorHash.Hashes) { var subpathOrCPId = GetSubpathOrCPId(path, hash); if (subpathOrCPId != -1) { realization.ContextPartitionRecursiveVisit( path, subpathOrCPId, this, visitor, selectorPerLevel); } } return; } if (selector is ContextPartitionSelectorFiltered) { var filter = (ContextPartitionSelectorFiltered) selector; var identifierHash = new ContextPartitionIdentifierHash(); VisitPartitions( path, ( hash, subpathOrCPId) => { identifierHash.Hash = hash; if (factory.FactoryEnv.IsLeaf) { identifierHash.ContextPartitionId = subpathOrCPId; } if (filter.Filter(identifierHash)) { realization.ContextPartitionRecursiveVisit( path, subpathOrCPId, this, visitor, selectorPerLevel); } }); return; } if (selector is ContextPartitionSelectorAll) { VisitPartitions( path, ( hash, subpathOrCPId) => realization.ContextPartitionRecursiveVisit( path, subpathOrCPId, this, visitor, selectorPerLevel)); return; } if (selector is ContextPartitionSelectorById) { var byId = (ContextPartitionSelectorById) selector; VisitPartitions( path, ( hash, subpathOrCPId) => { if (byId.ContextPartitionIds.Contains(subpathOrCPId)) { realization.ContextPartitionRecursiveVisit( path, subpathOrCPId, this, visitor, selectorPerLevel); } }); return; } throw ContextControllerSelectorUtil.GetInvalidSelector( new[] {typeof(ContextPartitionSelectorHash)}, selector); }