Example #1
0
        public async Task <GetPageResponse> GetPageAsync(int id, string languageCode = "en-gb")
        {
            var response = new GetPageResponse();

            //try
            //{
            //    var pageVersion = await this.pageVersionRepository.GetSingleAsync(q => q.Where(x => x.PageId == id && x.LanguageCode == languageCode).FirstOrDefault());
            //    if (pageVersion != null)
            //    {
            //        response.Page = new PageDto
            //        {
            //            Title = pageVersion.Title,
            //            Description = pageVersion.Description,
            //            Keywords = pageVersion.Keywords
            //        };
            //        response.Status = StatusCode.OK;
            //    }
            //    else
            //    {
            //        response.Status = StatusCode.NotFound;
            //    }
            //}
            //catch (Exception ex)
            //{
            //    this.exceptionHandler.HandleException(ex);
            //    response.Status = StatusCode.InternalServerError;
            //}

            return(response);
        }
Example #2
0
        public GetPageResponse GetPage(int id, string languageCode = "en-gb")
        {
            var response = new GetPageResponse();

            try
            {
                //var pageVersion = this.pageVersionRepository.Get().SingleOrDefault(x => x.PageId == id && x.LanguageCode == languageCode);
                //if (pageVersion != null)
                //{
                //    response.Page = new PageDto
                //    {
                //        Title = pageVersion.Title,
                //        Description = pageVersion.Description,
                //        Keywords = pageVersion.Keywords
                //    };
                //    response.Status = StatusCode.OK;
                //}
                //else
                //{
                //    response.Status = StatusCode.NotFound;
                //}
            }
            catch (Exception ex)
            {
                this.exceptionHandler.HandleException(ex);
                response.Status = StatusCode.InternalServerError;
            }

            return response;
        }
Example #3
0
        public GetPageResponse GetPage(int id, string languageCode = "en-gb")
        {
            var response = new GetPageResponse();

            try
            {
                //var pageVersion = this.pageVersionRepository.Get().SingleOrDefault(x => x.PageId == id && x.LanguageCode == languageCode);
                //if (pageVersion != null)
                //{
                //    response.Page = new PageDto
                //    {
                //        Title = pageVersion.Title,
                //        Description = pageVersion.Description,
                //        Keywords = pageVersion.Keywords
                //    };
                //    response.Status = StatusCode.OK;
                //}
                //else
                //{
                //    response.Status = StatusCode.NotFound;
                //}
            }
            catch (Exception ex)
            {
                this.exceptionHandler.HandleException(ex);
                response.Status = StatusCode.InternalServerError;
            }

            return(response);
        }
Example #4
0
        public async Task<GetPageResponse> GetPageAsync(int id, string languageCode = "en-gb")
        {
            var response = new GetPageResponse();

            //try
            //{
            //    var pageVersion = await this.pageVersionRepository.GetSingleAsync(q => q.Where(x => x.PageId == id && x.LanguageCode == languageCode).FirstOrDefault());
            //    if (pageVersion != null)
            //    {
            //        response.Page = new PageDto
            //        {
            //            Title = pageVersion.Title,
            //            Description = pageVersion.Description,
            //            Keywords = pageVersion.Keywords
            //        };
            //        response.Status = StatusCode.OK;
            //    }
            //    else
            //    {
            //        response.Status = StatusCode.NotFound;
            //    }
            //}
            //catch (Exception ex)
            //{
            //    this.exceptionHandler.HandleException(ex);
            //    response.Status = StatusCode.InternalServerError;
            //}

            return response;
        }
        public string GetAsPrintableString(GetPageResponse toParse)
        {
            var scriptCount = CountScriptResources(toParse);
            var cssCount    = CountCssResources(toParse);

            return($"Num of scripts: {scriptCount}\n" +
                   $"Num of css files: {cssCount}");
        }
Example #6
0
        private int DoCountCssResourcesRequest(string testHtml)
        {
            var req = new GetPageResponse
            {
                Content = testHtml
            };
            var erc = new ExternalResourceCount();

            return(erc.CountCssResources(req));
        }
Example #7
0
        public void GetTitleRetunsTitleFromHeadTag()
        {
            var req = new GetPageResponse {
                Content = "<html><head><title>test title</title></head></html>"
            };
            var pt  = new PageTitle();
            var res = pt.GetTitle(req);

            Assert.Equal("test title", res);
        }
Example #8
0
        public void GetTitleRetunsEmptyStringWhenNoTitlePresent()
        {
            var req = new GetPageResponse {
                Content = "<html></html>"
            };
            var pt  = new PageTitle();
            var res = pt.GetTitle(req);

            Assert.Equal("", res);
        }
Example #9
0
        public void GetWordDictRemovesCapitalization()
        {
            var req = new GetPageResponse {
                Content = "<html><body><p>TEsT</p></body></html>"
            };
            var mfw = new MostFrequentWords();
            var res = mfw.GetWordDict(req);

            Assert.Equal(1, res["test"]);
        }
Example #10
0
        public void GetWordDictPicksUpWordsInMultipleTags()
        {
            var req = new GetPageResponse {
                Content = "<html><body><p>test</p><a>test</a><span>test</span></body></html>"
            };
            var mfw = new MostFrequentWords();
            var res = mfw.GetWordDict(req);

            Assert.Equal(3, res["test"]);
        }
Example #11
0
        public void GetWordDictReturnsEmptyDictGivenNoInput()
        {
            var req = new GetPageResponse {
                Content = ""
            };
            var mfw = new MostFrequentWords();
            var res = mfw.GetWordDict(req);

            Assert.Empty(res);
        }
Example #12
0
        public void GetWordDictReturnsDictWithSingleEntry()
        {
            var req = new GetPageResponse {
                Content = "<html><body><p>testword</p></body></html>"
            };
            var mfw = new MostFrequentWords();
            var res = mfw.GetWordDict(req);

            Assert.Equal(1, res["testword"]);
        }
Example #13
0
        public string GetTitle(GetPageResponse toParse)
        {
            var titleNode = toParse.HtmlContent.DocumentNode.SelectSingleNode("//head/title");

            if (titleNode != null)
            {
                return(titleNode.InnerText);
            }
            return("");
        }
        public int CountScriptResources(GetPageResponse toParse)
        {
            var scriptTags = toParse.HtmlContent.DocumentNode.SelectNodes("//script/@src");

            if (scriptTags != null)
            {
                return(scriptTags.Count);
            }
            return(0);
        }
Example #15
0
        public void GetWordDictBreaksDownSentance()
        {
            var req = new GetPageResponse {
                Content = "<html><body><p>this is a test</p></body></html>"
            };
            var mfw = new MostFrequentWords();
            var res = mfw.GetWordDict(req);

            Assert.Equal(4, res.Count);
            Assert.Equal(1, res["test"]);
        }
Example #16
0
        public void GetWordDictResultIsSorted()
        {
            var req = new GetPageResponse
            {
                Content = "<html><body><p>1 2 2 3 3 3</p></body></html>"
            };
            var mfw = new MostFrequentWords();
            var res = mfw.GetWordDict(req);

            Assert.Equal("3", res.First().Key);
        }
Example #17
0
        public void GetWordDictRemovesSpecialChars()
        {
            var req = new GetPageResponse
            {
                Content = "<html><body><p>\n | ( ) - +</p></body></html>"
            };
            var mfw = new MostFrequentWords();
            var res = mfw.GetWordDict(req);

            Assert.Empty(res);
        }
        public string GetAsPrintableString(GetPageResponse toParse)
        {
            var words = GetWordDict(toParse);
            var sb    = new StringBuilder();

            sb.AppendLine($"Most frequent words:\n");
            foreach (var kv in words)
            {
                sb.AppendLine($"{kv.Key}: {kv.Value}");
            }
            return(sb.ToString());
        }
Example #19
0
        public IActionResult Getall()
        {
            GenericResponse response      = new GenericResponse();
            GetPageResponse _Pageresponse = new GetPageResponse();

            response.FillSuccess();
            int totalCount = 0;
            var PageModel  = _service_Privillige.GetPage(1, int.MaxValue, out totalCount);

            _Pageresponse.totalCount = totalCount;
            _Pageresponse.PageModel  = PageModel;
            response.data            = _Pageresponse;
            return(Ok(response));
        }
Example #20
0
        public IActionResult GetPaged(int page, int pagesize)
        {
            GenericResponse response      = new GenericResponse();
            GetPageResponse _Pageresponse = new GetPageResponse();

            response.FillSuccess();
            int totalCount = 0;
            var PageModel  = _service_Group.GetPage(page, pagesize, out totalCount).ToList();

            _Pageresponse.totalCount = totalCount;
            _Pageresponse.PageModel  = PageModel;
            response.data            = _Pageresponse;
            return(Ok(response));
        }
Example #21
0
        public PaginatedListDto <ColorDto, ColorOrders> GetPaged(PaginatedListRequest <ColorOrders> request)
        {
            GetPageResponse <Color, ColorFilter, ColorOrder> countries = _coloresRepository.GetPaged
                                                                         (
                new GetPageRequest <Color, ColorFilter, ColorOrder>()
            {
                PageNumber = request.CurrentPage,
                PageSize   = request.PageSize,
                Filter     = new ColorFilter(request.MultiSearch ?? string.Empty),
                Order      = new ColorOrder(request.OrderList),
            }
                                                                         );

            return(new PaginatedListDto <ColorDto, ColorOrders>(_mapper.Map <List <Color>, List <ColorDto> >(countries.Entities.ToList()), countries.NumPages, countries.NumTotalEntities, request));
        }
        public Dictionary <string, int> GetWordDict(GetPageResponse toParse)
        {
            var wordDict = new Dictionary <string, int>();

            foreach (HtmlNode node in GetAllTextNodes(toParse.HtmlContent))
            {
                var words = node.InnerText.Split(_wordSplitChars, StringSplitOptions.RemoveEmptyEntries);
                foreach (var word in words)
                {
                    var cleanedWord = CleanWord(word);
                    AddWordToDict(wordDict, cleanedWord);
                }
            }
            return(wordDict.OrderByDescending(x => x.Value).ToDictionary(y => y.Key, y => y.Value));
        }
        public int CountCssResources(GetPageResponse toParse)
        {
            var cssLinks = toParse.HtmlContent.DocumentNode.SelectNodes("//link");

            if (cssLinks == null)
            {
                return(0);
            }

            var res = 0;

            foreach (var node in cssLinks)
            {
                if (node.GetAttributeValue("rel", "") == "stylesheet" &&
                    !String.IsNullOrEmpty(node.GetAttributeValue("href", "")))
                {
                    res++;
                }
            }

            return(res);
        }
Example #24
0
        public string GetAsPrintableString(GetPageResponse toParse)
        {
            var title = GetTitle(toParse);

            return($"Page title: {title}");
        }