public object RoutePartial(PageData content, SegmentContext segmentContext)
        {
            if (!_externalReviewOptions.IsEnabled)
            {
                return(null);
            }

            var nextSegment = segmentContext.GetNextValue(segmentContext.RemainingPath);

            if (string.IsNullOrWhiteSpace(nextSegment.Next))
            {
                return(null);
            }

            if (!string.Equals(nextSegment.Next, _externalReviewOptions.ContentPreviewUrl, StringComparison.CurrentCultureIgnoreCase))
            {
                return(null);
            }

            nextSegment = segmentContext.GetNextValue(nextSegment.Remaining);
            var token = nextSegment.Next;

            var externalReviewLink = _externalReviewLinksRepository.GetContentByToken(token);

            if (!externalReviewLink.IsPreviewableLink())
            {
                return(null);
            }

            var contentReference = externalReviewLink.ContentLink;

            if (externalReviewLink.ProjectId.HasValue)
            {
                var contentContentLink = PreviewUrlResolver.IsGenerated(segmentContext.QueryString) ? content.ContentLink : contentReference;
                contentReference         = _projectContentResolver.GetProjectReference(contentContentLink, externalReviewLink.ProjectId.Value);
                ExternalReview.ProjectId = externalReviewLink.ProjectId;
            }

            try
            {
                var page = _contentLoader.Get <IContent>(contentReference);

                // PIN code security check, if user is not authenticated, then redirect to login page
                if (!_externalLinkPinCodeSecurityHandler.UserHasAccessToLink(externalReviewLink))
                {
                    _externalLinkPinCodeSecurityHandler.RedirectToLoginPage(externalReviewLink);
                    return(null);
                }
                segmentContext.RemainingPath = nextSegment.Remaining;
                ExternalReview.Token         = token;

                return(page);
            }
            catch (ContentNotFoundException)
            {
                return(null);
            }
        }
        public PageData TryGetProjectPageVersion(ExternalReviewLink externalReviewLink, PageData routedContent, NameValueCollection queryString)
        {
            var contentReference = externalReviewLink.ContentLink;
            var page             = _contentLoader.Get <PageData>(contentReference);

            // If not Project associate with the link then use the ContentLink stored in DDS
            if (!externalReviewLink.ProjectId.HasValue)
            {
                return(page);
            }

            // If the url is not generated, meaning
            if (!PreviewUrlResolver.IsGeneratedForProjectPreview(queryString))
            {
                return(page);
            }

            var projectReference = GetProjectReference(routedContent.ContentLink,
                                                       externalReviewLink.ProjectId.Value, page.LanguageBranch());

            if (projectReference != null)
            {
                return(_contentLoader.Get <PageData>(projectReference));
            }

            var reviewsContentLoader = ServiceLocator.Current.GetInstance <ReviewsContentLoader>();

            if (routedContent.IsPublished())
            {
                return(routedContent);
            }

            var unpublished = reviewsContentLoader.LoadUnpublishedVersion(routedContent.ContentLink);

            return(_contentLoader.Get <PageData>(unpublished));
        }
        public object RoutePartial(PageData content, SegmentContext segmentContext)
        {
            if (!_externalReviewOptions.IsEnabled)
            {
                return(null);
            }

            var nextSegment = segmentContext.GetNextValue(segmentContext.RemainingPath);

            if (string.IsNullOrWhiteSpace(nextSegment.Next))
            {
                return(null);
            }

            if (!string.Equals(nextSegment.Next, _externalReviewOptions.ContentPreviewUrl, StringComparison.CurrentCultureIgnoreCase))
            {
                return(null);
            }

            nextSegment = segmentContext.GetNextValue(nextSegment.Remaining);
            var token = nextSegment.Next;

            var externalReviewLink = _externalReviewLinksRepository.GetContentByToken(token);

            if (!externalReviewLink.IsPreviewableLink())
            {
                return(null);
            }

            if (externalReviewLink.VisitorGroups != null)
            {
                System.Web.HttpContext.Current.Items["ImpersonatedVisitorGroupsById"] = externalReviewLink.VisitorGroups;
            }

            var contentReference = externalReviewLink.ContentLink;

            if (externalReviewLink.ProjectId.HasValue)
            {
                var languageID = content.Language.Name;

                var contentContentLink = PreviewUrlResolver.IsGenerated(segmentContext.QueryString) ? content.ContentLink : contentReference;
                contentReference         = _projectContentResolver.GetProjectReference(contentContentLink, externalReviewLink.ProjectId.Value, languageID);
                ExternalReview.ProjectId = externalReviewLink.ProjectId;
            }

            try
            {
                var page = _contentLoader.Get <IContent>(contentReference, content.Language);

                // PIN code security check, if user is not authenticated, then redirect to login page
                if (!_externalLinkPinCodeSecurityHandler.UserHasAccessToLink(externalReviewLink))
                {
                    _externalLinkPinCodeSecurityHandler.RedirectToLoginPage(externalReviewLink);
                    return(null);
                }
                segmentContext.RemainingPath = nextSegment.Remaining;

                // set ContentLink in DataTokens to make IPageRouteHelper working
                segmentContext.RouteData.DataTokens[RoutingConstants.NodeKey] = page.ContentLink;
                ExternalReview.Token = token;

                return(page);
            }
            catch (ContentNotFoundException)
            {
                return(null);
            }
        }