Exemplo n.º 1
0
        /// <summary>
        /// Stores supplemental metadata representing distinct dictionary keys seen on the stream.
        /// </summary>
        /// <typeparam name="TKey">The type of dictionary key in the stream.</typeparam>
        /// <typeparam name="TValue">The type of dictionary value in the stream.</typeparam>
        /// <param name="source">The source stream to write.</param>
        public void SummarizeDistinctKeysInSupplementalMetadata <TKey, TValue>(Emitter <Dictionary <TKey, TValue> > source)
        {
            if (!this.writer.TryGetMetadata(source.Id, out PsiStreamMetadata meta))
            {
                throw new ArgumentException("Stream metadata is not available because the stream has not been written.");
            }

            // update supplemental meta to reflect distinct keys seen
            source.Aggregate(
                new SortedSet <TKey>(),
                (set, dict) =>
            {
                foreach (var key in dict.Keys)
                {
                    if (!set.Contains(key))
                    {
                        set.UnionWith(dict.Keys);
                        meta.SetSupplementalMetadata(new DistinctKeysSupplementalMetadata <TKey>(set), this.serializers);
                        return(set);
                    }
                }

                return(set);
            },
                DeliveryPolicy.Unlimited);
        }