/// <summary> /// Erweitert orderBy um /// </summary> /// <typeparam name="TCol"></typeparam> /// <param name="selector"></param> /// <param name="descending"></param> private void DefOrderBy <TCol>(Func <Asteroid, TCol> selector, bool descending) { if (first) { first = false; if (descending) { orderedQuery = query.OrderByDescending(selector); } else { orderedQuery = query.OrderBy(selector); } } else { if (descending) { orderedQuery = orderedQuery.ThenByDescending(selector); } else { orderedQuery = orderedQuery.ThenBy(selector); } } }
protected virtual void Sort(SortDescriptorCollection descriptors) { SortDescriptor[] currentDescriptors = descriptors.ToArray(); if (this.CurrentOperation != ItemSourceOperation.None) { return; } if (currentDescriptors.Length == 0) { this.view = this.dataSource; this.Filter(this.masterTemplate.FilterDescriptors); return; } this.CurrentOperation = ItemSourceOperation.Sorting; List <object> sortView = this.view as List <object>; if (sortView == null) { sortView = new List <object>(this.view.Count); foreach (object item in this.view) { sortView.Add(item); } } ParallelQuery <object> query = sortView.AsParallel(); SortDescriptor firstDescriptor = currentDescriptors.First(); if (firstDescriptor.Direction == ListSortDirection.Descending) { query = query.OrderByDescending(x => this.GetValue(x, firstDescriptor.PropertyName)); } else { query = query.OrderBy(x => this.GetValue(x, firstDescriptor.PropertyName)); } OrderedParallelQuery <object> orderedQuery = query as OrderedParallelQuery <object>; for (int i = 1; i < currentDescriptors.Length; i++) { SortDescriptor currentDescriptor = currentDescriptors[i]; if (currentDescriptor.Direction == ListSortDirection.Descending) { orderedQuery = orderedQuery.ThenByDescending(x => this.GetValue(x, currentDescriptor.PropertyName)); } else { orderedQuery = orderedQuery.ThenBy(x => this.GetValue(x, currentDescriptor.PropertyName)); } } this.view = orderedQuery.ToList(); this.CurrentOperation = ItemSourceOperation.None; }
internal static ParallelQuery <int> MakeOrderByThenBy(bool orderPreserved) { int[] a = Enumerable.Range(0, 100).Reverse().ToArray(); ParallelQuery <int> ipe = a.AsParallel(); if (orderPreserved) { ipe = ipe.AsOrdered(); } return(ipe.OrderBy(i => i % 5).ThenBy(i => - i)); }
protected static ulong ReduceToInterval(ulong start, ulong end, ParallelQuery <SimulationResult> d) { ulong reducedtime = 0UL; var takenResults = new HashSet <SimulationResult>(); foreach (var m in d.OrderBy(t => t.Start)) { if (m.Start < start) { reducedtime += start - m.Start; takenResults.Add(m); } if (m.End > end) { reducedtime += (m.End - end); takenResults.Add(m); } if (m.Start > start && m.End < end) { break; } } foreach (var m in d.OrderByDescending(t => t.Start)) { if (m.Start < start && !takenResults.Contains(m)) { reducedtime += start - m.Start; } if (m.End > end && !takenResults.Contains(m)) { reducedtime += (m.End - end); } if (m.Start > start && m.End < end) { break; } } return(d.Sum(t => t.Total, new object()) - reducedtime); }
public static void RunParallelEnumerableExceptionsTests() { int[] ints = new int[0]; ParallelQuery <int> pquery = ints.AsParallel(); //AsParallel Assert.Throws <ArgumentNullException>(() => ((IEnumerable <int>)null).AsParallel()); Assert.Throws <ArgumentNullException>(() => ((IEnumerable)null).AsParallel()); Assert.Throws <ArgumentNullException>(() => ((Partitioner <int>)null).AsParallel()); //AsOrdered Assert.Throws <ArgumentNullException>(() => ParallelEnumerable.AsOrdered((ParallelQuery <int>)null)); Assert.Throws <ArgumentNullException>(() => ParallelEnumerable.AsOrdered((ParallelQuery)null)); Assert.Throws <ArgumentNullException>(() => ParallelEnumerable.AsUnordered <int>((ParallelQuery <int>)null)); //With* Assert.Throws <ArgumentException>(() => ParallelEnumerable.WithExecutionMode(pquery, (ParallelExecutionMode)100)); Assert.Throws <ArgumentException>(() => ParallelEnumerable.WithMergeOptions(pquery, (ParallelMergeOptions)100)); //Obsoleted operators #pragma warning disable 618 //disable build warnning for Obsoleted methods Assert.Throws <NotSupportedException>(() => ParallelEnumerable.Zip <int, int, int>(null, (IEnumerable <int>)null, null)); Assert.Throws <NotSupportedException>(() => ParallelEnumerable.Join <int, int, int, int>(null, (IEnumerable <int>)null, null, null, null)); Assert.Throws <NotSupportedException>(() => ParallelEnumerable.Join <int, int, int, int>(null, (IEnumerable <int>)null, null, null, null, null)); Assert.Throws <NotSupportedException>(() => ParallelEnumerable.GroupJoin <int, int, int, int>(null, (IEnumerable <int>)null, null, null, null)); Assert.Throws <NotSupportedException>(() => ParallelEnumerable.GroupJoin <int, int, int, int>(null, (IEnumerable <int>)null, null, null, null, null)); #pragma warning restore 618 //SelectMany Assert.Throws <ArgumentNullException>(() => ParallelEnumerable.SelectMany <int, int, int>(null, (Func <int, int, IEnumerable <int> >)null, null)); Assert.Throws <ArgumentNullException>(() => ParallelEnumerable.SelectMany <int, int, int>(pquery, (Func <int, int, IEnumerable <int> >)null, null)); //OrderBy Assert.Throws <ArgumentNullException>(() => ParallelEnumerable.OrderBy <int, int>(null, null, null)); Assert.Throws <ArgumentNullException>(() => ParallelEnumerable.OrderBy <int, int>(pquery, null, null)); Assert.Throws <ArgumentNullException>(() => ParallelEnumerable.OrderByDescending <int, int>(null, null, null)); Assert.Throws <ArgumentNullException>(() => ParallelEnumerable.OrderByDescending <int, int>(pquery, null, null)); Assert.Throws <ArgumentNullException>(() => ParallelEnumerable.ThenBy <int, int>(null, null, null)); Assert.Throws <ArgumentNullException>(() => ParallelEnumerable.ThenBy <int, int>(pquery.OrderBy(x => x), null, null)); Assert.Throws <ArgumentNullException>(() => ParallelEnumerable.ThenByDescending <int, int>(null, null, null)); Assert.Throws <ArgumentNullException>(() => ParallelEnumerable.ThenByDescending <int, int>(pquery.OrderBy(x => x), null, null)); //GroupBy Assert.Throws <ArgumentNullException>(() => ParallelEnumerable.GroupBy <int, int, int>((ParallelQuery <int>)null, i => i, (i, j) => i)); Assert.Throws <ArgumentNullException>(() => ParallelEnumerable.GroupBy <int, int, int>(pquery, null, (i, j) => i)); Assert.Throws <ArgumentNullException>(() => ParallelEnumerable.GroupBy <int, int, int>(pquery, i => i, (Func <int, IEnumerable <int>, int>)null)); Assert.Throws <ArgumentNullException>(() => ParallelEnumerable.GroupBy <int, int, int, int>((ParallelQuery <int>)null, i => i, i => i, (i, j) => i)); Assert.Throws <ArgumentNullException>(() => ParallelEnumerable.GroupBy <int, int, int, int>(pquery, null, i => i, (i, j) => i)); Assert.Throws <ArgumentNullException>(() => ParallelEnumerable.GroupBy <int, int, int, int>(pquery, i => i, null, (i, j) => i)); Assert.Throws <ArgumentNullException>(() => ParallelEnumerable.GroupBy <int, int, int, int>(pquery, i => i, i => i, (Func <int, IEnumerable <int>, int>)null)); //Aggregate Assert.Throws <ArgumentNullException>(() => ParallelEnumerable.Aggregate <int, int, int>((ParallelQuery <int>)null, 0, (i, j) => i, (i, j) => i, i => i)); Assert.Throws <ArgumentNullException>(() => ParallelEnumerable.Aggregate <int, int, int>(pquery, 0, null, (i, j) => i, i => i)); Assert.Throws <ArgumentNullException>(() => ParallelEnumerable.Aggregate <int, int, int>(pquery, 0, (i, j) => i, null, i => i)); Assert.Throws <ArgumentNullException>(() => ParallelEnumerable.Aggregate <int, int, int>(pquery, 0, (i, j) => i, (i, j) => i, null)); //Count Assert.Throws <ArgumentNullException>(() => ParallelEnumerable.Count((ParallelQuery <int>)null, i => true)); Assert.Throws <ArgumentNullException>(() => ParallelEnumerable.Count(pquery, null)); //Sum Assert.Throws <ArgumentNullException>(() => ParallelEnumerable.Sum((ParallelQuery <int>)null, i => i)); Assert.Throws <ArgumentNullException>(() => ParallelEnumerable.Sum((ParallelQuery <int?>)null, i => i)); Assert.Throws <ArgumentNullException>(() => ParallelEnumerable.Sum((ParallelQuery <long>)null, i => i)); Assert.Throws <ArgumentNullException>(() => ParallelEnumerable.Sum((ParallelQuery <long?>)null, i => i)); Assert.Throws <ArgumentNullException>(() => ParallelEnumerable.Sum((ParallelQuery <float>)null, i => i)); Assert.Throws <ArgumentNullException>(() => ParallelEnumerable.Sum((ParallelQuery <float?>)null, i => i)); Assert.Throws <ArgumentNullException>(() => ParallelEnumerable.Sum((ParallelQuery <double>)null, i => i)); Assert.Throws <ArgumentNullException>(() => ParallelEnumerable.Sum((ParallelQuery <double?>)null, i => i)); Assert.Throws <ArgumentNullException>(() => ParallelEnumerable.Sum((ParallelQuery <double>)null, i => i)); Assert.Throws <ArgumentNullException>(() => ParallelEnumerable.Sum((ParallelQuery <double?>)null, i => i)); //Min Assert.Throws <ArgumentNullException>(() => ParallelEnumerable.Min((ParallelQuery <int>)null, i => i)); Assert.Throws <ArgumentNullException>(() => ParallelEnumerable.Min((ParallelQuery <int?>)null, i => i)); Assert.Throws <ArgumentNullException>(() => ParallelEnumerable.Min((ParallelQuery <long>)null, i => i)); Assert.Throws <ArgumentNullException>(() => ParallelEnumerable.Min((ParallelQuery <long?>)null, i => i)); Assert.Throws <ArgumentNullException>(() => ParallelEnumerable.Min((ParallelQuery <float>)null, i => i)); Assert.Throws <ArgumentNullException>(() => ParallelEnumerable.Min((ParallelQuery <float?>)null, i => i)); Assert.Throws <ArgumentNullException>(() => ParallelEnumerable.Min((ParallelQuery <double>)null, i => i)); Assert.Throws <ArgumentNullException>(() => ParallelEnumerable.Min((ParallelQuery <double?>)null, i => i)); Assert.Throws <ArgumentNullException>(() => ParallelEnumerable.Min((ParallelQuery <double>)null, i => i)); Assert.Throws <ArgumentNullException>(() => ParallelEnumerable.Min((ParallelQuery <double?>)null, i => i)); //Max Assert.Throws <ArgumentNullException>(() => ParallelEnumerable.Max((ParallelQuery <int>)null)); Assert.Throws <ArgumentNullException>(() => ParallelEnumerable.Max((ParallelQuery <int>)null, i => i)); Assert.Throws <ArgumentNullException>(() => ParallelEnumerable.Max((ParallelQuery <int?>)null, i => i)); Assert.Throws <ArgumentNullException>(() => ParallelEnumerable.Max((ParallelQuery <long>)null, i => i)); Assert.Throws <ArgumentNullException>(() => ParallelEnumerable.Max((ParallelQuery <long?>)null, i => i)); Assert.Throws <ArgumentNullException>(() => ParallelEnumerable.Max((ParallelQuery <float>)null, i => i)); Assert.Throws <ArgumentNullException>(() => ParallelEnumerable.Max((ParallelQuery <float?>)null, i => i)); Assert.Throws <ArgumentNullException>(() => ParallelEnumerable.Max((ParallelQuery <double>)null, i => i)); Assert.Throws <ArgumentNullException>(() => ParallelEnumerable.Max((ParallelQuery <double?>)null, i => i)); Assert.Throws <ArgumentNullException>(() => ParallelEnumerable.Max((ParallelQuery <double>)null, i => i)); Assert.Throws <ArgumentNullException>(() => ParallelEnumerable.Max((ParallelQuery <double?>)null, i => i)); //Average Assert.Throws <ArgumentNullException>(() => ParallelEnumerable.Average((ParallelQuery <int>)null, i => i)); Assert.Throws <ArgumentNullException>(() => ParallelEnumerable.Average((ParallelQuery <int?>)null, i => i)); Assert.Throws <ArgumentNullException>(() => ParallelEnumerable.Average((ParallelQuery <long>)null, i => i)); Assert.Throws <ArgumentNullException>(() => ParallelEnumerable.Average((ParallelQuery <long?>)null, i => i)); Assert.Throws <ArgumentNullException>(() => ParallelEnumerable.Average((ParallelQuery <float>)null, i => i)); Assert.Throws <ArgumentNullException>(() => ParallelEnumerable.Average((ParallelQuery <float?>)null, i => i)); Assert.Throws <ArgumentNullException>(() => ParallelEnumerable.Average((ParallelQuery <double>)null, i => i)); Assert.Throws <ArgumentNullException>(() => ParallelEnumerable.Average((ParallelQuery <double?>)null, i => i)); Assert.Throws <ArgumentNullException>(() => ParallelEnumerable.Average((ParallelQuery <double>)null, i => i)); Assert.Throws <ArgumentNullException>(() => ParallelEnumerable.Average((ParallelQuery <double?>)null, i => i)); }
public static OrderedParallelQuery <T> OrderByAlphaNumeric <T>(this ParallelQuery <T> source, Func <T, string> selector, int maxDigits = 7) { return(source.OrderBy(i => AlphaNumericReplacer(selector(i), maxDigits), StringComparer.Ordinal)); }
public Hero GetModifierHero(ParallelQuery <Hero> allies) { return(allies.OrderBy(x => x.Health).FirstOrDefault(x => x.HasModifier(abilityModifier.Name))); }
public IEnumerable <ChatMessageViewModel> ProcessMessages(IEnumerable <Message> messages) { ParallelQuery <ChatMessageViewModel> result = messages.AsParallel().Select(CreateMessageViewModel); return(result.OrderBy(x => x.MessageDateTime)); }
public static OrderedParallelQuery <T> Shuffle <T>(this ParallelQuery <T> list) { return(list.OrderBy(i => _rng.Next())); }