private void RunBtnClick(object sender, Avalonia.Interactivity.RoutedEventArgs e)
 {
     //var code = _textEditor.Text;
     //var ast = RegexpParser.parseRegexpFromString(code);
     //Interpreter.run(ast);
     try
     {
         _runBtn.IsEnabled           = false;
         isSuccessfulRun             = true;
         _executionStatus.Background = Brushes.Yellow;
         _console.Text = "Execution started:\n";
         var code = this._textEditor.Text;
         var ast  = RegexpParser.parseRegexpFromString(code);
         var task = new Task(() => Interpreter.run(ast));
         task.ContinueWith(t =>
                           Dispatcher.UIThread.Post(() =>
         {
             _runBtn.IsEnabled = true;
             if (isSuccessfulRun)
             {
                 _executionStatus.Background = Brushes.Green;
             }
             _console.Text += "\n" + "Execution finished.";
         }));
         task.Start();
     }
     catch (Exception exception)
     {
         _console.Text += exception.Message;
         _console.Text += "\n" + "Execution finished.";
         _executionStatus.Background = Brushes.Red;
         _runBtn.IsEnabled           = true;
         isSuccessfulRun             = false;
     }
 }
        public ActionResult SeoAnalysis(string textOrUrl,
                                        bool eachWordOnPage           = false,
                                        bool eachWordOnPageInMetaTags = false,
                                        bool externalLinks            = false)
        {
            ViewData["StopWords"] = RegexpParser.stopWords;
            IGetText getText;
            string   currentDomain;
            string   text = "";

            //getText instance depends upon the text we entered
            if (RegexpParser.IsUrl(textOrUrl.Trim()))
            {
                getText = new TextFromUrl();
                Uri uri = new Uri(textOrUrl.Trim());
                currentDomain = uri.Host.ToString();
            }
            else
            {
                currentDomain = "localhost";
                getText       = new SimpleText();
            }
            //get full bare text
            try
            {
                text = getText.GetText(textOrUrl.Trim());
            }
            catch (Exception ex)
            {
                return(RedirectToAction("Error", new { error = ex.Message }));
            }


            #region Find all external links
            //find all hrefs
            IList <string> listHrefs  = RegexpParser.ParseTags(text);
            List <string>  innerLinks = null;
            outerLinks = null;
            if (externalLinks)
            {
                innerLinks = new List <string>();
                outerLinks = new List <string>();
                foreach (string link in listHrefs)
                {
                    // if our href is fully qualified url
                    if (RegexpParser.IsUrl(link.Trim()))
                    {
                        Uri    uri  = new Uri(link.Trim());
                        string host = uri.Host.ToString();
                        if (host.Equals(currentDomain))
                        {
                            // adding absolute inner link
                            innerLinks.Add(link);
                        }
                        else
                        {
                            // oops, this link's domain name doesn't equal our domain name
                            outerLinks.Add(link);
                        }
                    }
                    else
                    {
                        // adding  inner link
                        innerLinks.Add(link);
                    }
                }
            }

            ViewData["ExternalLinks"] = outerLinks;
            #endregion


            #region Find all stop-words matches in meta-tags
            IList <string> metaTagsContent;
            IList <string> stopWordsInMetaList = null;
            if (eachWordOnPageInMetaTags)
            {
                metaTagsContent = RegexpParser.ParseTags(text, true);
                string stopWordsInMetaTags = "";
                foreach (string val in metaTagsContent)
                {
                    stopWordsInMetaTags += val;
                }
                stopWordsInMetaList = RegexpParser.FindStopWords(stopWordsInMetaTags);
            }

            stopWordsInMetaDict = new Dictionary <string, int>();
            if (stopWordsInMetaList != null)
            {
                var result = stopWordsInMetaList.GroupBy(wrd => wrd.ToLower());
                foreach (var item in result)
                {
                    stopWordsInMetaDict.Add(item.Key, item.Count());
                }
            }
            ViewData["StopWordsInMetaTags"] = stopWordsInMetaDict;

            #endregion


            #region Find all stop-words matches in text

            IList <string> stopWords = null;
            if (eachWordOnPage)
            {
                stopWords = RegexpParser.FindStopWords(text);
            }

            stopWordsDict = new Dictionary <string, int>();
            if (stopWords != null)
            {
                var result = stopWords.GroupBy(wrd => wrd.ToLower());
                foreach (var item in result)
                {
                    //stop-word/entries count
                    stopWordsDict.Add(item.Key.ToLower(), item.Count());
                }
                // if (!stopWordsDict.ContainsKey(word))
                //stopWordsDict.Add(word, count);
            }
            ViewData["StopWordsOnPage"] = stopWordsDict;
            #endregion


            // return RedirectToAction("Index", new { stopWordsOnPage = stopWords });
            return(View("Index"));
        }