Ejemplo n.º 1
0
        public string GetTokenizedHtml(Content content, int clientId, int templateId, int campaignId)
        {
            var urls = FindLinks(content.Text).Distinct().ToArray();
            //insures all instances of href are lower case. Don't know why, but Filitrac process does this and it's cheap on resources anyway
            var result = new StringBuilder(Regex.Replace(StripToBody(content.Text), "href", "href", RegexOptions.IgnoreCase));

            if (urls.Any())
            {
                var stat = _statsProvider.StartNewInstance("ReplaceUrls");
                var contentRedirects = _warmingRepository.GetContentRedirects().Where(c => c.ContentId == content.ContentId).ToArray();
                var redirectData = _redirectLinkService.GetRedirectData(campaignId);

                foreach (var u in urls.Where(s => !string.IsNullOrWhiteSpace(s)))
                {
                    var subStat = _statsProvider.StartNewInstance("GetContentRedirect");
                    var contentRedirect = contentRedirects.FirstOrDefault(c => String.Equals(c.Url, u, StringComparison.CurrentCultureIgnoreCase)) ??
                                          CreateContentRedirect(content.ContentId, u, clientId, templateId);

                    subStat.Completed();
                    subStat = _statsProvider.StartNewInstance("GetRedirectUrl");
                    result.Replace(u, _redirectLinkService.GetRedirectUrl(contentRedirect.RedirectId, redirectData));
                    subStat.Completed();
                }
                stat.Completed();
            }

            return result.ToString();
        }
Ejemplo n.º 2
0
        public bool IsValid(Content content)
        {

            if (content == null || string.IsNullOrWhiteSpace(content.Text))
            {
                return false;
            }

            if (ValidationRegexes.Any(vr => !Regex.IsMatch(content.Text, vr, RegexOptions.IgnoreCase)))
            {
                return false;
            }

            if ((from Match m in LinkHrefRegEx.Matches(content.Text) select m)
                 .Any(m =>
                    !m.Success || !m.Groups["Url"].Success || string.IsNullOrWhiteSpace(m.Groups["Url"].Value) || m.Groups["Url"].Value.Length > 500 ||
                    !m.Groups["Inner"].Success || string.IsNullOrWhiteSpace(m.Groups["Inner"].Value) ||
                    HasUrlRegEx.IsMatch(m.Groups["Inner"].Value)
                ))
            {
                return false;
            }

            return true;
        }