public PageAnalysis CreatePageAnalysis(IPublishedContent node, string focusKeyword)
        {
            var pageAnalysis = new PageAnalysis();

            try
            {
                var htmlString = _htmlHelper.GetTemplateHtml(node);
                var htmlResult = _htmlHelper.GetHtmlResult(htmlString);

                pageAnalysis.Url          = node.UrlAbsolute();
                pageAnalysis.FocusKeyword = focusKeyword;
                pageAnalysis.Size         = _byteSizeHelper.GetByteSize(htmlString);

                SetAnalyzerResults(pageAnalysis, htmlResult);
            }
            catch (WebException ex)
            {
                pageAnalysis.Status = ((HttpWebResponse)ex.Response).StatusCode;
            }

            pageAnalysis.Score = _scoreService.GetScore(pageAnalysis);

            return(pageAnalysis);
        }
Beispiel #2
0
        public PageAnalysis AnalyzeWebPage(int id, string focusKeyword = null)
        {
            var pageAnalysis = new PageAnalysis();

            try
            {
                var node = _umbracoHelper.TypedContent(id);
                if (node.TemplateId == 0)
                {
                    return(null);
                }
                var htmlString = _contentHelper.GetNodeHtml(node);

                if (string.IsNullOrEmpty(focusKeyword))
                {
                    focusKeyword = GetFocusKeyword(node);
                }

                _htmlParser.LoadHtml(htmlString);

                pageAnalysis.Url          = node.UrlAbsolute();
                pageAnalysis.FocusKeyword = focusKeyword;
                pageAnalysis.Size         = Encoding.ASCII.GetByteCount(htmlString);

                var html = new HtmlResult
                {
                    Html     = htmlString,
                    Document = _htmlParser.DocumentNode
                };

                // Get all types marked with the Summary attribute
                var reflectionService = new ReflectionService();
                var types             = reflectionService.GetSummaries();

                // Instantiate the types and retrieve te results
                foreach (var type in types)
                {
                    var instance = Activator.CreateInstance(type.Type);
                    var summary  = (BaseSummary)instance;
                    summary.FocusKeyword = focusKeyword;
                    summary.HtmlResult   = html;
                    summary.Url          = pageAnalysis.Url;

                    pageAnalysis.AnalyzerResults.Add(new AnalyzerResult
                    {
                        Alias    = type.Summary.Alias,
                        Analysis = summary.GetAnalysis()
                    });
                }
            }
            catch (WebException ex)
            {
                pageAnalysis.Status = ((HttpWebResponse)ex.Response).StatusCode;
            }

            pageAnalysis.Score = _scoreService.GetScore(pageAnalysis);

            _nodeReportService.Save(id, focusKeyword, pageAnalysis);

            return(pageAnalysis);
        }