public static void ToDictionary_ElementSelector_CustomComparator(Labeled <ParallelQuery <int> > labeled, int count)
        {
            ParallelQuery <int> query = labeled.Item;
            IntegerRangeSet     seen  = new IntegerRangeSet(0, count);

            Assert.All(query.ToDictionary(x => x, y => y * 2, new ModularCongruenceComparer(count)),
                       p => { seen.Add(p.Key); Assert.Equal(p.Key * 2, p.Value); });
            seen.AssertComplete();
        }
        public static void ToDictionary(Labeled <ParallelQuery <int> > labeled, int count)
        {
            ParallelQuery <int> query = labeled.Item;
            IntegerRangeSet     seen  = new IntegerRangeSet(0, count);

            Assert.All(query.ToDictionary(x => x * 2),
                       p => { seen.Add(p.Key / 2); Assert.Equal(p.Key, p.Value * 2); });
            seen.AssertComplete();
        }
        public static void ToDictionary_UniqueKeys_CustomComparator(Labeled <ParallelQuery <int> > labeled, int count)
        {
            ParallelQuery <int> query = labeled.Item;

            if (count > 2)
            {
                AggregateException e = Assert.Throws <AggregateException>(() => query.ToDictionary(x => x, new ModularCongruenceComparer(2)));
                Assert.IsType <ArgumentException>(e.InnerException);
            }
            else if (count == 1 || count == 2)
            {
                IntegerRangeSet seen = new IntegerRangeSet(0, count);
                foreach (KeyValuePair <int, int> entry in query.ToDictionary(x => x, new ModularCongruenceComparer(2)))
                {
                    seen.Add(entry.Key);
                    Assert.Equal(entry.Key, entry.Value);
                }
                seen.AssertComplete();
            }
            else
            {
                Assert.Empty(query.ToDictionary(x => x, new ModularCongruenceComparer(2)));
            }
        }
        private static Dictionary <CultureInfo, string> ReadLocalizableRuleDetails(XElement ruleResourceElement, XName ruleDetailElementName)
        {
            ArgumentValidator.ThrowIfNull("ruleResourceElement", ruleResourceElement);
            ArgumentValidator.ThrowIfNull("ruleDetailElementName", ruleDetailElementName);
            ParallelQuery <KeyValuePair <CultureInfo, string> > source = from localizedDetailsElement in ruleResourceElement.Elements(ruleDetailElementName).AsParallel <XElement>()
                                                                         let elementValue = localizedDetailsElement.Value.Trim()
                                                                                            let langCode = localizedDetailsElement.Attribute("langcode").Value
                                                                                                           select new KeyValuePair <CultureInfo, string>(new CultureInfo(langCode, false), elementValue);
            Dictionary <CultureInfo, string> result;

            try
            {
                Dictionary <CultureInfo, string> dictionary = source.ToDictionary((KeyValuePair <CultureInfo, string> localizedDetails) => localizedDetails.Key, (KeyValuePair <CultureInfo, string> localizedDetails) => localizedDetails.Value);
                result = dictionary;
            }
            catch (AggregateException ex)
            {
                throw new XmlException(Strings.ClassificationRuleCollectionUnexpectedContents, ex.Flatten());
            }
            return(result);
        }
        internal static Dictionary <CultureInfo, ClassificationRuleCollectionLocalizableDetails> ReadAllRulePackageMetadata(XElement rulePackDetailsElement)
        {
            ArgumentValidator.ThrowIfNull("rulePackDetailsElement", rulePackDetailsElement);
            ParallelQuery <ClassificationRuleCollectionLocalizableDetails> source = from localizedDetailsElement in rulePackDetailsElement.Elements(XmlProcessingUtils.GetMceNsQualifiedNodeName("LocalizedDetails")).AsParallel <XElement>()
                                                                                    let name = localizedDetailsElement.Element(XmlProcessingUtils.GetMceNsQualifiedNodeName("Name")).Value
                                                                                               let publisherName = localizedDetailsElement.Element(XmlProcessingUtils.GetMceNsQualifiedNodeName("PublisherName")).Value
                                                                                                                   let description = localizedDetailsElement.Element(XmlProcessingUtils.GetMceNsQualifiedNodeName("Description")).Value
                                                                                                                                     let langCode = localizedDetailsElement.Attribute("langcode").Value
                                                                                                                                                    select new ClassificationRuleCollectionLocalizableDetails
            {
                Name          = name,
                PublisherName = publisherName,
                Description   = description,
                Culture       = new CultureInfo(langCode, false)
            };
            Dictionary <CultureInfo, ClassificationRuleCollectionLocalizableDetails> result;

            try
            {
                Dictionary <CultureInfo, ClassificationRuleCollectionLocalizableDetails> dictionary = source.ToDictionary((ClassificationRuleCollectionLocalizableDetails localizedDetails) => localizedDetails.Culture, (ClassificationRuleCollectionLocalizableDetails localizedDetails) => localizedDetails);
                result = dictionary;
            }
            catch (AggregateException ex)
            {
                throw new XmlException(Strings.ClassificationRuleCollectionUnexpectedContents, ex.Flatten());
            }
            return(result);
        }