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 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; }
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); }
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}"); }
private int DoCountCssResourcesRequest(string testHtml) { var req = new GetPageResponse { Content = testHtml }; var erc = new ExternalResourceCount(); return(erc.CountCssResources(req)); }
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); }
public void GetTitleRetunsEmptyStringWhenNoTitlePresent() { var req = new GetPageResponse { Content = "<html></html>" }; var pt = new PageTitle(); var res = pt.GetTitle(req); Assert.Equal("", res); }
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"]); }
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"]); }
public void GetWordDictReturnsEmptyDictGivenNoInput() { var req = new GetPageResponse { Content = "" }; var mfw = new MostFrequentWords(); var res = mfw.GetWordDict(req); Assert.Empty(res); }
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"]); }
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); }
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"]); }
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); }
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()); }
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)); }
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)); }
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); }
public string GetAsPrintableString(GetPageResponse toParse) { var title = GetTitle(toParse); return($"Page title: {title}"); }