Ejemplo n.º 1
0
        public ActionResult WordCloud(WordCloudViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            ModelState.Clear();

            var wcFunctions = new Captec.Functions.WordCloudFunctions();

            try
            {
                string sourceData = wcFunctions.GetSourceData(model.URL);

                List <string> wordsToRemove = wcFunctions.GetExclusions();

                Dictionary <string, int> wordCounter = wcFunctions.CreateWordCloudDictionary(sourceData, wordsToRemove, model.Occurrences);

                model.WordCloud = wcFunctions.CreateWordCloud(wordCounter);
            }
            catch (Exception ex)
            {
                TempData["ErrorMessage"] = "Sorry, we were unable to generate a word cloud for this URL. Please check the URL is valid and try again.";
                return(RedirectToAction("WordCloud"));
            }

            if (MvcHtmlString.IsNullOrEmpty(model.WordCloud))
            {
                model.ErrorMessage = "Sorry, we were unable to generate a word cloud for this URL. Please check the URL is valid and try again.";
            }

            return(View(model));
        }
Ejemplo n.º 2
0
        public ActionResult WordCloud(string url, bool verbOnly)
        {
            WordCloudViewModel wordCloudView = new WordCloudViewModel();

            wordCloudView.url = url;

            List <SiteWord> siteWords = generateWordsForSite(url, 100, verbOnly);

            wordCloudView.Words = siteWords;

            storeSiteWords(siteWords);

            return(View(wordCloudView));
        }
Ejemplo n.º 3
0
        public void WordCloudInvalidURL()
        {
            HomeController controller = new HomeController();

            // invalid url entered.
            var model = new WordCloudViewModel();

            model.URL = "https://www.captec.com";

            var redirectResult = controller.WordCloud(model) as RedirectToRouteResult;
            var viewResult     = controller.WordCloud() as ViewResult;

            Assert.IsNotNull(redirectResult);
            Assert.AreEqual("WordCloud", redirectResult.RouteValues["action"]);
            Assert.IsNotNull(viewResult);
            Assert.AreEqual("Sorry, we were unable to generate a word cloud for this URL. Please check the URL is valid and try again.", viewResult.TempData.Values.ElementAt(0));
        }
Ejemplo n.º 4
0
        public void WordCloudValidURL()
        {
            HomeController controller = new HomeController();

            // valid url entered.
            var model = new WordCloudViewModel();

            model.URL = "https://www.captecsystems.com";

            var result    = controller.WordCloud(model) as ViewResult;
            var viewmodel = (WordCloudViewModel)result.ViewData.Model;

            Assert.IsNotNull(result);
            Assert.IsNull(viewmodel.ErrorMessage);
            Assert.IsNotNull(viewmodel.WordCloud);
            Assert.AreEqual(30, viewmodel.Occurrences);
            Assert.AreEqual("https://www.captecsystems.com", viewmodel.URL);
        }