Example #1
0
        private List <string> Process(List <string> words, CancellationToken cancellationToken)
        {
            int stat = 0;

            ChangeProgressBarPercentage(0);
            var suggestionCrawler = new SuggestionCrawler();

            suggestionCrawler.GetCookie();
            if (cancellationToken.IsCancellationRequested)
            {
                Finish();
                cancellationToken.ThrowIfCancellationRequested();
            }
            words.ForEach((word) =>
            {
                Task.Factory.StartNew(() =>
                {
                    var wp = ProcessString(word, cancellationToken, suggestionCrawler);
                    lock (wordPackungenLock)
                    {
                        if (wp != null)
                        {
                            wordPackungen.Add(wp);
                        }
                    }
                    lock (percentLock)
                    {
                        stat++;
                        ChangeProgressBarPercentage(100 * stat / words.Count);
                    }
                }, cancellationToken: cancellationToken, creationOptions: TaskCreationOptions.AttachedToParent | TaskCreationOptions.LongRunning, scheduler: TaskScheduler.Default);
            });
            return(words);
        }
Example #2
0
        private WordPackung ProcessString(string text, CancellationToken cancellationToken, SuggestionCrawler suggestionCrawler)
        {
            if (cancellationToken.IsCancellationRequested)
            {
                Finish();
                cancellationToken.ThrowIfCancellationRequested();
            }
            var slist = suggestionCrawler.GetSuggestions(text);

            if (slist == null)
            {
                return(null);
            }
            var wlist = new List <Word>();

            foreach (var item2 in slist)
            {
                if (cancellationToken.IsCancellationRequested)
                {
                    Finish();
                    cancellationToken.ThrowIfCancellationRequested();
                }
                var     url     = "https://wort.ir" + item2.full_slug;
                HtmlWeb htmlWeb = new HtmlWeb();
                var     html    = htmlWeb.Load(url);
                try
                {
                    wlist.Add(html.DocumentNode.GetEncapsulatedData <Word>());
                }
                catch (Exception) { }
            }
            if (wlist.Count > 0)
            {
                return new WordPackung()
                       {
                           Text = text, Words = wlist
                       }
            }
            ;
            else
            {
                return(null);
            }
        }