Ejemplo n.º 1
0
        public void UpdateMetrics(ISolverData solverData = null)
        {
            if (solverData == null)
            {
                solverData = GetSelectedSolverData();
            }

            var metrics = new SearchMetrics
            {
                Heads  = solverData.AllHeads.Count(x => x.IsSelected),
                Chests = solverData.AllChests.Count(x => x.IsSelected),
                Gloves = solverData.AllGloves.Count(x => x.IsSelected),
                Waists = solverData.AllWaists.Count(x => x.IsSelected),
                Legs   = solverData.AllLegs.Count(x => x.IsSelected),
                Charms = solverData.AllCharms.Count(x => x.IsSelected),
            };

            if (solverData.AllJewels.Length > 0)
            {
                metrics.MinSlotSize = solverData.AllJewels.Min(x => x.Jewel.SlotSize);
                metrics.MaxSlotSize = solverData.AllJewels.Max(x => x.Jewel.SlotSize);
            }
            else
            {
                metrics.MinSlotSize = 0;
                metrics.MaxSlotSize = 0;
            }

            metrics.UpdateCombinationCount();

            SearchMetrics = metrics;
        }
Ejemplo n.º 2
0
        private async Task SearchArmorSetsInternal(CancellationToken cancellationToken)
        {
            ISolverData solverData = root.GetSelectedSolverData();

            if (solverData == null)
            {
                return;
            }

            var sw = Stopwatch.StartNew();

            IList <ArmorSetSearchResult> result = await root.GetSelectedSolver().SearchArmorSets(solverData, cancellationToken);

            sw.Stop();

            SearchMetrics metrics = root.SearchMetrics;

            metrics.TimeElapsed     = (int)sw.ElapsedMilliseconds;
            metrics.MatchingResults = result?.Count ?? 0;

            await Dispatcher.Yield(DispatcherPriority.SystemIdle);

            root.SearchMetrics = null;
            root.SearchMetrics = metrics;

            IsDataLoading = true;
            IsDataLoaded  = false;

            await Dispatcher.Yield(DispatcherPriority.SystemIdle);

            try
            {
                if (solverData == null)
                {
                    rawFoundArmorSets = null;
                    return;
                }

                if (result != null)
                {
                    rawFoundArmorSets = result.Where(x => x.IsMatch).Select(x => new ArmorSetViewModel(
                                                                                root,
                                                                                solverData,
                                                                                x.ArmorPieces,
                                                                                x.Charm,
                                                                                x.Jewels.Select(j => new ArmorSetJewelViewModel(j.Jewel, j.Count)),
                                                                                x.SpareSlots
                                                                                ));

                    ApplySorting(true);
                }
            }
            finally
            {
                IsDataLoading = false;
                IsDataLoaded  = true;
            }
        }
Ejemplo n.º 3
0
        public void CreateSolverData()
        {
            if (IsDataLoaded == false || SelectedAbilities == null)
            {
                return;
            }

            ISolverData solverData = Extensions.SolverData.SelectedValue;

            var desiredAbilities = SelectedAbilities
                                   .Where(x => x.IsChecked)
                                   .Select(x => x.Ability)
                                   .ToList();

            solverData.Setup(
                InParameters.Slots.Select(x => x.Value).ToList(),
                GlobalData.Instance.Heads.Where(x => ArmorPieceMatchInParameters(x)),
                GlobalData.Instance.Chests.Where(x => ArmorPieceMatchInParameters(x)),
                GlobalData.Instance.Gloves.Where(x => ArmorPieceMatchInParameters(x)),
                GlobalData.Instance.Waists.Where(x => ArmorPieceMatchInParameters(x)),
                GlobalData.Instance.Legs.Where(x => ArmorPieceMatchInParameters(x)),
                GlobalData.Instance.Charms.Where(x => EquipmentMatchInParameters(x)),
                GlobalData.Instance.Jewels.Where(x => DecorationMatchInParameters(x)).Select(CreateSolverDataJewelModel),
                desiredAbilities
                );

            /*************************************************************/
            var metrics = new SearchMetrics
            {
                Heads  = solverData.AllHeads.Count(x => x.IsSelected),
                Chests = solverData.AllChests.Count(x => x.IsSelected),
                Gloves = solverData.AllGloves.Count(x => x.IsSelected),
                Waists = solverData.AllWaists.Count(x => x.IsSelected),
                Legs   = solverData.AllLegs.Count(x => x.IsSelected),
                Charms = solverData.AllCharms.Count(x => x.IsSelected),
            };

            if (solverData.AllJewels.Length > 0)
            {
                metrics.MinSlotSize = solverData.AllJewels.Min(x => x.Jewel.SlotSize);
                metrics.MaxSlotSize = solverData.AllJewels.Max(x => x.Jewel.SlotSize);
            }
            else
            {
                metrics.MinSlotSize = 0;
                metrics.MaxSlotSize = 0;
            }

            metrics.UpdateCombinationCount();

            SearchMetrics = metrics;
            /*************************************************************/

            UpdateAdvancedSearch();

            rawFoundArmorSets = null;
        }
Ejemplo n.º 4
0
        public void Search(IMatcher matcher)
        {
            cancelSource = new CancellationTokenSource();
            var cancelToken = new CancellationTokenSource().Token;

            var ig = IgnoredExtensions.ToDictionary(k => k, v => v);

            Task.Run(() =>
            {
                var watch = new Stopwatch();
                watch.Start();

                var files = FileScanner.GetFiles(ParentFolder, FilePattern, ig, SearchSubfolders);

                SearchStatusUpdate?.Invoke(new SearchStatus {
                    FilesComplete = 0, FilesRemaining = files.Count
                });

                var count = 1;

                Parallel.ForEach(files,
                                 (file, state) =>
                {
                    if (cancelSource.IsCancellationRequested)
                    {
                        state.Break();
                    }

                    matcher.Search(file, SearchTerm, ResultFound);

                    //throttle to speed things up
                    if (count++ % 30 == 0)
                    {
                        SearchStatusUpdate?.Invoke(
                            new SearchStatus {
                            FilesComplete = count, FilesRemaining = files.Count
                        });
                    }
                });

                SearchStatusUpdate?.Invoke(new SearchStatus {
                    FilesComplete = count, FilesRemaining = files.Count
                });

                watch.Stop();

                var metrics = new SearchMetrics
                {
                    ElapsedTime   = watch.Elapsed,
                    FilesSearched = files.Count
                };

                SearchComplete?.Invoke(metrics);
            }, cancelToken);
        }
Ejemplo n.º 5
0
        private async Task SearchArmorSetsInternal(CancellationToken cancellationToken)
        {
            ISolverData solverData = Extensions.SolverData.SelectedValue;

            if (solverData == null)
            {
                return;
            }

            var sw = Stopwatch.StartNew();

            IList <ArmorSetSearchResult> result = await Extensions.Solver.SelectedValue.SearchArmorSets(solverData, cancellationToken);

            sw.Stop();

            SearchMetrics metrics = SearchMetrics;

            metrics.TimeElapsed     = (int)sw.ElapsedMilliseconds;
            metrics.MatchingResults = result?.Count ?? 0;

            SearchMetrics = null;
            SearchMetrics = metrics;

            if (solverData == null)
            {
                rawFoundArmorSets = null;
                return;
            }

            if (result != null)
            {
                rawFoundArmorSets = result.Where(x => x.IsMatch).Select(x => new ArmorSetViewModel(
                                                                            this,
                                                                            solverData,
                                                                            x.ArmorPieces,
                                                                            x.Charm,
                                                                            x.Jewels.Select(j => new ArmorSetJewelViewModel(j.Jewel, j.Count)).ToList(),
                                                                            x.SpareSlots
                                                                            ));

                ApplySorting(true);
            }
        }