Exemple #1
0
        protected override void OnStartup(StartupEventArgs e)
        {
            var wordsCounterView      = new WordCounterView();
            var wordsCounterViewModel = new WordCounterViewModel();

            wordsCounterView.DataContext = wordsCounterViewModel;
            wordsCounterView.Show();
        }
        public async Task <ActionResult> CountWords(WordCounterViewModel model)
        {
            var result = new WordCounterResultViewModel();

            result.ResponseStatus    = Status.NotSpecified;
            result.ResponseStatusMsg = string.Empty;
            if (!string.IsNullOrEmpty(model.Text))
            {
                result.WordsFrequencies = wordService.GetWordsFrequenciesFromText(model.Text);
            }
            else if (!string.IsNullOrEmpty(model.ExternlLink))
            {
                result.ExternalSourceUrl = model.ExternlLink;
                var source = await wordService.GetRemoteData(model.ExternlLink);

                result.ResponseStatus    = source.Status;
                result.ResponseStatusMsg = source.StatusMsg;
                if (result.ResponseStatus == Status.Success)
                {
                    result.WordsFrequencies = wordService.GetWordsFrequenciesFromExternalSource(source.Document);
                    if (model.CountWordsInMeta)
                    {
                        result.MetaKeywordsFrequencies = wordService.GetMetaKeywordsFrequencies(source.Document, result.WordsFrequencies);
                    }

                    if (model.IncludeExternalLinks)
                    {
                        result.ExternalLinks = wordService.GetExternalLinks(model.ExternlLink, source.Document);
                    }
                }
            }

            var jsonResult = this.responseFormatHelper.GetJsonParsedModel(result);

            return(this.Json(jsonResult));
        }
        public async Task <IActionResult> Index(string urlToSearch)
        {
            try
            {
                var wordCounts = await _textSplitterService.GetWordsFromUrlAsync(urlToSearch, 100);

                _wordCounterService.StoreWordCounts(wordCounts, 100);

                var viewModel = new WordCounterViewModel
                {
                    Url              = urlToSearch,
                    CountedWords     = wordCounts,
                    CountedWordsJson = Json(wordCounts)
                };
                return(View(viewModel));
            }
            catch (Exception e)
            {
                ViewData["ErrorMessage"] = e.Message;
                ViewData["ErrorStack"]   = e.StackTrace;
                ViewData["ErrorInner"]   = e.InnerException?.Message;
                return(View("Error"));
            }
        }