예제 #1
0
 /// <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);
         }
     }
 }
예제 #2
0
 public Hero GetModifierHero(ParallelQuery <Hero> allies)
 {
     return
         (allies.OrderByDescending(x => x.Equals(Hero))
          .ThenBy(x => x.Health / x.MaximumHealth)
          .FirstOrDefault(x => x.HasModifier(abilityModifier.Name)));
 }
예제 #3
0
        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;
        }
예제 #4
0
        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);
        }
        private void RefreshResults()
        {
            if (null != mToken)
            {
                mToken.Cancel();
            }
            mToken = new CancellationTokenSource();

            string sSearch = textBox.Text;

            System.Threading.Tasks.Task.Run(() =>
            {
                lock (mSymbolLocker)
                {
                    if (!mToken.IsCancellationRequested)
                    {
                        if (!mSearchInSolution && mSymbols == null)
                        {
                            mSymbols = CTagsGenerator.GeneratorFromDocument(Common.Instance.DTE2.ActiveDocument);
                        }

                        try
                        {
                            //System.Diagnostics.Stopwatch sw = new System.Diagnostics.Stopwatch();
                            //sw.Start();

                            ParallelQuery <SymbolData> source = null;
                            if (mSearchInSolution)
                            {
                                source = Common.Instance.SolutionWatcher.Files
                                         .AsParallel()
                                         .WithCancellation(mToken.Token)
                                         .Where(file => file != null && file.Symbols != null)
                                         .SelectMany(file => file.Symbols)
                                ;
                            }
                            else
                            {
                                source = mSymbols
                                         .AsParallel()
                                         .WithCancellation(mToken.Token)
                                ;
                            }

                            ParallelQuery <SearchResultData <SymbolData> > results = source
                                                                                     .Where(symbol => (symbol.Type & mSupportedSymbolTypes) != 0)
                                                                                     .Select(symbolData => new SearchResultData <SymbolData>(symbolData, sSearch, symbolData.Symbol, null, symbolData.Class, symbolData.Parameters));

                            int total = results.Count();

                            if (!string.IsNullOrWhiteSpace(sSearch))
                            {
                                int searchStringLen = sSearch.Length;
                                results             = results.Where(resultData => resultData.SearchScore > searchStringLen);
                            }

                            results = results
                                      .OrderByDescending(resultData => resultData.SearchScore)
                            ;

                            int count = results.Count();

                            //EnvDTE.FontsAndColorsItems fontsAndColor = Common.Instance.DTE2.Properties.Item("FontsAndColorsItems") as EnvDTE.FontsAndColorsItems;
                            //fontsAndColor.Item("Line Number").Foreground
                            //fontsAndColor.Item("Keywords").Foreground

                            /*Action<IEnumerable> refreshMethod = (res) =>
                             * {
                             *      results.ForAll(result => result.RefreshSearchFormatted());
                             * };
                             * Dispatcher.BeginInvoke(refreshMethod, results);*/

                            Action <IEnumerable> setMethod = (res) =>
                            {
                                listView.ItemsSource = res;

                                string title = mQuickMethodToolWindow.Title;
                                int pos      = title.IndexOf(" [");
                                if (pos != -1)
                                {
                                    title = title.Substring(0, pos);
                                }
                                mQuickMethodToolWindow.Title = title + " [" + count + "/" + total + "]";
                            };
                            Dispatcher.Invoke(setMethod, results.ToList());


                            //sw.Stop();
                            //System.Diagnostics.Debug.WriteLine("PLINQ time " + sw.Elapsed.TotalMilliseconds);
                        }
                        catch (Exception) { }
                    }
                }
            });
        }