Esempio n. 1
0
 private void Clear()
 {
     SearchText = "";
     FilteredSentenceResultVM.Clear();
     _allSentenceResultVM.Clear();
     CombinationsResultVM.Clear();
     ClearFoundWords();
     Progress   = 0;
     TotalFound = 0;
 }
Esempio n. 2
0
        private async Task GenerateCombinations()
        {
            if (string.IsNullOrEmpty(SearchText))
            {
                return;
            }

            ChangeEnableButtons(false);

            Progress = 0;
            CombinationsResultVM.Clear();

            var searchText = SearchText.ToCharArray();

            var sentencesList = GetSentencesList();

            var i = 0;

            TotalFound = 1;

            await Task.Run(() =>
            {
                var permutations = WordPermutations.GetPermutations(SearchText);

                foreach (var sentence in sentencesList)
                {
                    if (_searchStopped)
                    {
                        break;
                    }

                    var wordIndex = 0;

                    foreach (var word in sentence.Words)
                    {
                        if (word == null)
                        {
                            Debug.WriteLine($"Word is null. Sentence: {sentence}");
                            break;
                        }

                        if (permutations.Contains(word))
                        {
                            permutations.Remove(word);

                            _uiContext.Send(state =>
                                            CombinationsResultVM.Add(new CombinationsResultVM
                            {
                                Word           = word,
                                Id             = TotalFound,
                                IsWord         = true,
                                FirstSentence  = sentence,
                                FoundWordIndex = wordIndex
                            })
                                            , null);

                            ++TotalFound;
                        }

                        ++wordIndex;
                    }

                    i++;

                    var progress = (int)((i / (float)sentencesList.Count) * 100);

                    _uiContext.Send((state) => Progress = progress, null);
                }

                --TotalFound;

                foreach (var item in permutations)
                {
                    _uiContext.Send(state =>
                                    CombinationsResultVM.Add(new CombinationsResultVM
                    {
                        Word   = item,
                        Id     = 0,
                        IsWord = false
                    })
                                    , null);
                }

                ChangeEnableButtons(true);
                Progress = 0;
            });
        }