public static SortingResult SortAndDeduplicate(this IEnumerable <UnicastTransportOperation> source, QueueAddressTranslator addressTranslator) { Dictionary <DeduplicationKey, UnicastTransportOperation> isolatedDispatch = null; Dictionary <DeduplicationKey, UnicastTransportOperation> defaultDispatch = null; foreach (var operation in source) { var destination = addressTranslator.Parse(operation.Destination).Address; var messageId = operation.Message.MessageId; var deduplicationKey = new DeduplicationKey(messageId, destination); if (operation.RequiredDispatchConsistency == DispatchConsistency.Default) { defaultDispatch = defaultDispatch ?? new Dictionary <DeduplicationKey, UnicastTransportOperation>(DeduplicationKey.MessageIdDestinationComparer); defaultDispatch[deduplicationKey] = operation; } else if (operation.RequiredDispatchConsistency == DispatchConsistency.Isolated) { isolatedDispatch = isolatedDispatch ?? new Dictionary <DeduplicationKey, UnicastTransportOperation>(DeduplicationKey.MessageIdDestinationComparer); isolatedDispatch[deduplicationKey] = operation; } } return(new SortingResult(defaultDispatch?.Values, isolatedDispatch?.Values)); }
bool Equals(DeduplicationKey other) { return(string.Equals(messageId, other.messageId) && string.Equals(destination, other.destination)); }