Esempio n. 1
0
        //---------------------------------------------------------------------------------------
        // Returns a QueryOperator<T> for any IEnumerable<T> data source. This will just do a
        // cast and return a reference to the same data source if the source is another query
        // operator, but will lazily allocate a scan operation and return that otherwise.
        //
        // Arguments:
        //    source  - any enumerable data source to be wrapped
        //
        // Return Value:
        //    A query operator.
        //

        internal static QueryOperator <TOutput> AsQueryOperator(IEnumerable <TOutput> source)
        {
            Contract.Assert(source != null);

            // Just try casting the data source to a query operator, in the case that
            // our child is just another query operator.
            QueryOperator <TOutput> sourceAsOperator = source as QueryOperator <TOutput>;

            if (sourceAsOperator == null)
            {
                OrderedParallelQuery <TOutput> orderedQuery = source as OrderedParallelQuery <TOutput>;
                if (orderedQuery != null)
                {
                    // We have to handle OrderedParallelQuery<T> specially. In all other cases,
                    // ParallelQuery *is* the QueryOperator<T>. But, OrderedParallelQuery<T>
                    // is not QueryOperator<T>, it only has a reference to one. Ideally, we
                    // would want SortQueryOperator<T> to inherit from OrderedParallelQuery<T>,
                    // but that conflicts with other constraints on our class hierarchy.
                    sourceAsOperator = (QueryOperator <TOutput>)orderedQuery.SortOperator;
                }
                else
                {
                    // If the cast failed, then the data source is a real piece of data. We
                    // just construct a new scan operator on top of it.
                    sourceAsOperator = new ScanQueryOperator <TOutput>(source);
                }
            }

            Contract.Assert(sourceAsOperator != null);

            return(sourceAsOperator);
        }
Esempio n. 2
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);
         }
     }
 }
        public string ExportMatrix(Grid matrixGrid)
        {
            string matrixString = IsLatexSelected ? @"\begin{" + LatexDelimiters[SelectedLatexDelimiter] + "}" : "■(";

            OrderedParallelQuery <View> orderedCells = matrixGrid.Children.AsParallel().OrderBy(c =>
                                                                                                Grid.GetRow(c) * matrixGrid.ColumnDefinitions.Count + Grid.GetColumn(c));

            foreach (BorderEntry view in orderedCells)
            {
                matrixString += view.Text;

                if (Grid.GetColumn(view) == matrixGrid.ColumnDefinitions.Count - 1)
                {
                    if (Grid.GetRow(view) != matrixGrid.RowDefinitions.Count - 1)
                    {
                        matrixString += IsLatexSelected ? @"\\" : "@";
                    }
                }
                else
                {
                    matrixString += IsLatexSelected ? " & " : "&";
                }
            }

            matrixString += IsLatexSelected ? @"\end{" + LatexDelimiters[SelectedLatexDelimiter] + "}" : ")";
            return(matrixString);
        }
Esempio n. 4
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;
        }
        public static void ShowParallelLinq(List <string> data)
        {
            OrderedParallelQuery <string> parallelGroups = data.AsParallel().OrderBy(item => item);

            // Show the total count of items still
            // matches the original count
            //System.Diagnostics.Trace.Assert(
            //  data.Count == parallelGroups.Sum(
            //      item => item.Count()));
        }
        internal static QueryOperator <TOutput> AsQueryOperator(IEnumerable <TOutput> source)
        {
            QueryOperator <TOutput> @operator = source as QueryOperator <TOutput>;

            if (@operator != null)
            {
                return(@operator);
            }
            OrderedParallelQuery <TOutput> query = source as OrderedParallelQuery <TOutput>;

            if (query != null)
            {
                return(query.SortOperator);
            }
            return(new ScanQueryOperator <TOutput>(source));
        }
Esempio n. 7
0
        Encrypt(IEnumerable <string> data)
        {
            OrderedParallelQuery <string> parallelGroups =
                data.AsParallel().OrderBy(item => item);

            // Show the total count of items still
            // matches the original count
            System.Diagnostics.Trace.Assert(
                data.Count() == parallelGroups.Sum(
                    item => item.Count()));
            // ...


            return(data.AsParallel().Select(
                       item => Encrypt(item)).ToList());
        }
Esempio n. 8
0
        Encrypt(IEnumerable <string> data)
        {
            OrderedParallelQuery <string> parallelGroups =
                data.AsParallel().OrderBy(item => item);

            // Show the total count of items still
            // matches the original count
            if (data.Count() != parallelGroups.Sum(
                    item => item.Count()))
            {
                throw new Exception("data.Count() != parallelGroups.Sum(item => item.Count()");
            }
            // ...

            return(data.AsParallel().Select(
                       item => Encrypt(item)).ToList());
        }
 internal FilteredSortedSet(OrderedParallelQuery <Asteroid> orderedQuery)
 {
     this.orderedQuery = orderedQuery;
 }
        public static void AddPredictions_Odds(OrderedParallelQuery <PredictionContainer> tempPredictions, ref ObservableCollection <ListOfPredictions> Predictions, bool UseFinal = false)
        {
            Predictions.Clear();

            ListOfPredictions
                CertainRenewed = new ListOfPredictions {
                Category = "Certain Renewal"
            },
                LikelyRenewed = new ListOfPredictions {
                Category = "Likely Renewal"
            },
                LeaningRenewed = new ListOfPredictions {
                Category = "Leaning Towards Renewal"
            },
                LeaningCanceled = new ListOfPredictions {
                Category = "Leaning Towards Cancellation"
            },
                LikelyCanceled = new ListOfPredictions {
                Category = "Likely Cancellation"
            },
                CertainCanceled = new ListOfPredictions {
                Category = "Certain Cancellation"
            };

            foreach (PredictionContainer p in tempPredictions)
            {
                var odds = UseFinal? p.finalodds : p.odds;

                if (odds > 0.8)
                {
                    CertainRenewed.Add(p);
                }
                else if (odds > 0.6)
                {
                    LikelyRenewed.Add(p);
                }
                else if (odds > 0.5)
                {
                    LeaningRenewed.Add(p);
                }
                else if (odds == 0.5)
                {
                    if (p.show.ShowIndex > p.show._calculatedThreshold)
                    {
                        LeaningRenewed.Add(p);
                    }
                    else
                    {
                        LeaningCanceled.Add(p);
                    }
                }
                else if (odds > 0.4)
                {
                    LeaningCanceled.Add(p);
                }
                else if (odds > 0.2)
                {
                    LikelyCanceled.Add(p);
                }
                else
                {
                    CertainCanceled.Add(p);
                }
            }

            if (CertainRenewed.Count > 0)
            {
                Predictions.Add(CertainRenewed);
            }
            if (LikelyRenewed.Count > 0)
            {
                Predictions.Add(LikelyRenewed);
            }
            if (LeaningRenewed.Count > 0)
            {
                Predictions.Add(LeaningRenewed);
            }
            if (LeaningCanceled.Count > 0)
            {
                Predictions.Add(LeaningCanceled);
            }
            if (LikelyCanceled.Count > 0)
            {
                Predictions.Add(LikelyCanceled);
            }
            if (CertainCanceled.Count > 0)
            {
                Predictions.Add(CertainCanceled);
            }
        }
Esempio n. 11
0
        public List <Result> Query(Query query)
        {
            if (_updateSource != null && !_updateSource.IsCancellationRequested)
            {
                _updateSource.Cancel();
                Logger.WoxDebug($"cancel init {_updateSource.Token.GetHashCode()} {Thread.CurrentThread.ManagedThreadId} {query.RawQuery}");
                _updateSource.Dispose();
            }
            var source = new CancellationTokenSource();

            _updateSource = source;
            var token = source.Token;

            ConcurrentBag <Result> resultRaw = new ConcurrentBag <Result>();

            if (token.IsCancellationRequested)
            {
                return(new List <Result>());
            }
            Parallel.ForEach(_win32s, (program, state) =>
            {
                if (token.IsCancellationRequested)
                {
                    state.Break();
                }
                if (program.Enabled)
                {
                    var r = program.Result(query.Search, _context.API);
                    if (r != null && r.Score > 0)
                    {
                        resultRaw.Add(r);
                    }
                }
            });
            if (token.IsCancellationRequested)
            {
                return(new List <Result>());
            }
            Parallel.ForEach(_uwps, (program, state) =>
            {
                if (token.IsCancellationRequested)
                {
                    state.Break();
                }
                if (program.Enabled)
                {
                    var r = program.Result(query.Search, _context.API);
                    if (token.IsCancellationRequested)
                    {
                        state.Break();
                    }
                    if (r != null && r.Score > 0)
                    {
                        resultRaw.Add(r);
                    }
                }
            });

            if (token.IsCancellationRequested)
            {
                return(new List <Result>());
            }
            OrderedParallelQuery <Result> sorted = resultRaw.AsParallel().OrderByDescending(r => r.Score);
            List <Result> results = new List <Result>();

            foreach (Result r in sorted)
            {
                if (token.IsCancellationRequested)
                {
                    return(new List <Result>());
                }
                var ignored = _settings.IgnoredSequence.Any(entry =>
                {
                    if (entry.IsRegex)
                    {
                        return(Regex.Match(r.Title, entry.EntryString).Success);
                    }
                    else
                    {
                        return(r.Title.ToLower().Contains(entry.EntryString));
                    }
                });
                if (!ignored)
                {
                    results.Add(r);
                }
                if (results.Count == 30)
                {
                    break;
                }
            }
            return(results);
        }
Esempio n. 12
0
        private void CreateGames(OrderedParallelQuery <ILogEvent> rawEvents)
        {
            games.Clear();

            DateTime start = default;
            DateTime end   = DateTime.MaxValue;

            var gameEvents         = new List <ILogEvent>();
            var preGameStartEvents = new List <ILogEvent>();

            bool isGame    = false;
            int  gameCount = 0;

            Enums.TeamID teamID = Enums.TeamID.None;

            Enums.StageData.StageName currentStage = Enums.StageData.StageName.Espeon;

            int currentPointBlue   = 0;
            int currentPointYellow = 0;

            foreach (var @event in rawEvents)
            {
                // プレイヤーに起きたイベントとして追加
                if (@event is PlayerEvent playerEvent)
                {
                    playerEvent.Player.Events.Add(playerEvent);
                    playerEvent.DoEffect();
                }
                else if (@event is TeamWinEvent teamWinEvent)
                {
                    teamID = teamWinEvent.WinnerTeam;
                }
                else if (@event is GetPointEvent pointEvent)
                {
                    if (pointEvent.Team == Enums.TeamID.Blue)
                    {
                        pointEvent.OldPoint = currentPointBlue;
                        currentPointBlue    = pointEvent.CurrentPoint;
                    }
                    else if (pointEvent.Team == Enums.TeamID.Yellow)
                    {
                        pointEvent.OldPoint = currentPointYellow;
                        currentPointYellow  = pointEvent.CurrentPoint;
                    }
                }
                else if (@event is ChangeStageEvent changeStage)
                {
                    changeStage.OldStage = currentStage;
                    currentStage         = changeStage.CurrentStage;
                }
                else if (@event.Type == Enums.EventType.GameStart)
                {
                    start  = @event.Time;
                    isGame = true;

                    currentPointBlue   = 0;
                    currentPointYellow = 0;
                }
                else if (@event.Type == Enums.EventType.GameEnd)
                {
                    end = @event.Time;
                }

                if (end < @event.Time)
                {
                    // ゲームエンドの時間を過ぎたのでイベントを追加してリセット(次のゲームへ)
                    var game = new Game(currentStage, start, end, teamID, currentPointBlue, currentPointYellow);
                    game.AddRangePreGameStartEvents(preGameStartEvents);
                    game.AddRangeInGameEvent(gameEvents);

                    preGameStartEvents.Clear();
                    gameEvents.Clear();

                    games.Add(string.Format(CultureInfo.InvariantCulture, "#{0:D2} {1}", gameCount, game.Stage), game);
                    gameCount++;

                    end   = DateTime.MaxValue;
                    start = default;

                    teamID = Enums.TeamID.None;

                    isGame = false;
                }

                if (isGame)
                {
                    gameEvents.Add(@event);
                }
                else
                {
                    preGameStartEvents.Add(@event);
                }
            }

            GameSelectBox.ItemsSource = games;
            if (games.Count > 0)
            {
                GameSelectBox.SelectedIndex = 0;
            }
        }
 public static OrderedParallelQuery <TSource> ThenByDescending <TSource, TKey>(this OrderedParallelQuery <TSource> source, Func <TSource, TKey> keySelector, IComparer <TKey> comparer);
 public static OrderedParallelQuery <TSource> ThenBy <TSource, TKey>(this OrderedParallelQuery <TSource> source, Func <TSource, TKey> keySelector);