private void Filter()
        {
            var watcher = new Stopwatch();

            watcher.Start();

            var inputFilter = txt_input.Text.Any() ? txt_input.Text : string.Empty;

            if (stk_sentences != null)
            {
                stk_sentences.Children.Clear();
            }

            if (!inputFilter.IsEmpty())
            {
                if (inputFilter.IsDigitsOnly() && SenControl_Deprecated.Get().Any(x => x.Id == Convert.ToInt16(inputFilter)))
                {
                    var sen = SenControl_Deprecated.Get().First(x => x.Id == Convert.ToInt16(inputFilter));
                    SentenceWpfController_Deprecated.AddIntoItems(stk_sentences, sen, false);
                    return;
                }
            }

            int count = 0;

            foreach (var sen in SenControl_Deprecated.Get())
            {
                if (sen.Text != string.Empty && !sen.Text.ContainsInsensitive(inputFilter))
                {
                    continue;
                }

                if (!txt_quests.IsEmpty() && txt_quests.Text.IsDigitsOnly())
                {
                    var quant = Convert.ToInt16(txt_quests.Text);
                    if (sen.Questions.Count != quant)
                    {
                        continue;
                    }
                }

                if (cb_QuestType.SelectedIndex != 0)
                {
                    if (!sen.Questions.Any(x => x.Quest.Type == cb_QuestType.SelectedModalType))
                    {
                        continue;
                    }
                }

                SentenceWpfController_Deprecated.AddIntoItems(stk_sentences, sen, false);
                count = count + 1;

                if (count == 60)
                {
                    break;
                }
            }

            Footer.Log(count + " sentences loaded in " + watcher.Elapsed.TotalSeconds + " seconds.");
        }
        private void Insert_Click(object sender, RoutedEventArgs e)
        {
            var sen = txt_input.Text;
            var vm  = new SenVM_Deprecated(sen);

            if (SenControl_Deprecated.Insert(vm, true))
            {
                //LoadSentencesOnGrid(true);
                txt_input.Text = string.Empty;
                var added = SenControl_Deprecated.Get().Last();
                SentenceWpfController_Deprecated.AddIntoItems(stk_sentences, added, true);

                Footer.Log("The sentence has been inserted.");
            }
        }
        private void InsertLinkLoad(List <string> sentencesFound)
        {
            int auto_inserted = 0;

            foreach (var found in sentencesFound)
            {
                var vm = new SenVM_Deprecated(found);
                if (SenControl_Deprecated.Insert(vm, false))
                {
                    var added_sen = SenControl_Deprecated.Get().Last();
                    SentenceWpfController_Deprecated.AddIntoItems(stk_sentences, added_sen, true);
                    auto_inserted = auto_inserted + 1;
                }
            }

            Footer.Log("Auto insert has finished. " + auto_inserted + " sentences were inserted.");
        }
        private void LoadSentencesOnGrid(bool isGridUpdate)
        {
            var watcher = new Stopwatch();

            watcher.Start();

            var sens = SenControl_Deprecated.Get();

            SenControl_Deprecated.PopulateQuestions();

            sens = sens.Take(60);

            foreach (var sen in sens)
            {
                SentenceWpfController_Deprecated.AddIntoItems(stk_sentences, sen, false);
            }

            Footer.Log(sens.Count() + " sentences loaded in " + Math.Round(watcher.Elapsed.TotalSeconds, 2) + " seconds.");
        }
        public async static Task <List <(int, int)> > LinkQuestType(StackPanel stk_sentences, Model type, Stopwatch watcher)
        {
            var tasks = LinkQuestToSentences(type, watcher);
            await Task.WhenAll(tasks);

            var links_found = tasks.Result;

            foreach (var qs in links_found)
            {
                QuestSenControl_Deprecated.Insert(new QuestSenVM_Deprecated(qs.Item1, qs.Item2, type));

                var item_line = new StackPanel();
                if (stk_sentences.Children.OfType <StackPanel>().Any(x => x.Name == "line_" + qs.Item2))
                {
                    item_line = stk_sentences.Children.OfType <StackPanel>().First(x => x.Name == "line_" + qs.Item2);
                    var sen = SenControl_Deprecated.Get().First(x => x.Id == qs.Item2);
                    AddIntoThis(sen, item_line);
                }
            }

            return(links_found);
        }
        public async static Task <List <(int, int)> > LinkQuestToSentences(Model type, Stopwatch watcher)
        {
            var links_found = new List <(int, int)>();
            var quests      = QuestControl.Get(type);//.Where(x => x.Sentences.Count <= 5);
            int actual      = 1;
            var task        = quests.Select(quest => Task.Factory.StartNew(() =>
            {
                foreach (var sen in SenControl_Deprecated.Get())
                {
                    if (type == Model.Voc)
                    {
                        //if (AutoGetSentences_Deprecated.DoesSenContainsVoc((VocVM)quest, sen.Text))
                        //{
                        //    if (!QuestSenControl_Deprecated.Get(type).Any(qs => qs.IdQuest == quest.Id && qs.IdSen == sen.Id))
                        //        links_found.Add((quest.Id, sen.Id));
                        //}
                    }
                }

                var log = "Analysing " + type.ToDesc() + " " + actual + " of " + quests.Count() + ". ";
                log    += links_found.Count + " sentences are suitable to " + type.ToDesc() + "s. " +
                          "Time elapsed: " + Math.Round(watcher.Elapsed.TotalSeconds, 1) + " seconds. ";

                if (actual > 5)
                {
                    var quant_missing  = quests.Count() - actual;
                    var time_to_finish = (watcher.Elapsed.TotalSeconds * quant_missing) / actual;
                    log += "It must finish in " + Math.Round(time_to_finish, 1) + " seconds.";
                }

                Footer.Log(log);
                actual = actual + 1;
            }));
            await Task.WhenAll(task);

            return(links_found);
        }