public BVParameters()
 {
     ContentType = new BVContentType(BVContentType.REVIEWS);
     SubjectType = new BVSubjectType(BVSubjectType.PRODUCT);
 }
Exemple #2
0
 public BVParameters()
 {
     ContentType = new BVContentType(BVContentType.REVIEWS);
     SubjectType = new BVSubjectType(BVSubjectType.PRODUCT);
 }
Exemple #3
0
        public String getSeoWithSdk(HttpRequest request)
        {
            BVConfiguration bvConfig = new BVSdkConfiguration();
            bvConfig.addProperty(BVClientConfig.CLOUD_KEY, _seoKey);
            bvConfig.addProperty(BVClientConfig.BV_ROOT_FOLDER, _deploymentZoneId);

            if (_botDetection)
            {
                bvConfig.addProperty(BVClientConfig.BOT_DETECTION, "true");
            }
            else
            {
                bvConfig.addProperty(BVClientConfig.BOT_DETECTION, "false");
            }

            if (!string.IsNullOrEmpty(_botRegexString))
            {
                bvConfig.addProperty(BVClientConfig.CRAWLER_AGENT_PATTERN, _botRegexString);
            }

            bvConfig.addProperty(BVClientConfig.EXECUTION_TIMEOUT, _timeoutMs.ToString());

            if (_staging)
            {
                bvConfig.addProperty(BVClientConfig.STAGING, "true");
            }
            else
            {
                bvConfig.addProperty(BVClientConfig.STAGING, "false");
            }

            if (_includeDisplayIntegrationCode)
            {
                bvConfig.addProperty(BVClientConfig.INCLUDE_DISPLAY_INTEGRATION_CODE, "true");
            }
            else
            {
                bvConfig.addProperty(BVClientConfig.INCLUDE_DISPLAY_INTEGRATION_CODE, "false");
            }

            if (!string.IsNullOrEmpty(_internalFilePath))
            {
                bvConfig.addProperty(BVClientConfig.LOAD_SEO_FILES_LOCALLY, "true");
                bvConfig.addProperty(BVClientConfig.LOCAL_SEO_FILE_ROOT, _internalFilePath);
            }
            else
            {
                bvConfig.addProperty(BVClientConfig.LOAD_SEO_FILES_LOCALLY, "false");
            }

            String subjectID = _productId;
            
            if(string.IsNullOrEmpty(_pageUrl))
                _pageUrl = request.Url.ToString();

            if (String.IsNullOrEmpty(_userAgent))
                _userAgent = request.UserAgent;

            BVContentType _contentType = new BVContentType(BVContentType.REVIEWS);
            if (!string.IsNullOrEmpty(_bvProduct))
            {
                switch (_bvProduct)
                {
                    case "reviews":
                        _contentType = new BVContentType(BVContentType.REVIEWS);
                        break;
                    case "questions":
                        _contentType = new BVContentType(BVContentType.QUESTIONS);
                        break;
                    case "stories":
                        _contentType = new BVContentType(BVContentType.STORIES);
                        break;
                }
            }

            BVSubjectType _subjectType = new BVSubjectType(BVSubjectType.PRODUCT);
            if (!string.IsNullOrEmpty(_productOrCategory))
            {
                switch (_productOrCategory)
                {
                    case "product":
                        _subjectType = new BVSubjectType(BVSubjectType.PRODUCT);
                        break;
                    case "category":
                        _subjectType = new BVSubjectType(BVSubjectType.CATEGORY);
                        break;
                    case "entry":
                        _subjectType = new BVSubjectType(BVSubjectType.ENTRY);
                        break;
                    case "detail":
                        _subjectType = new BVSubjectType(BVSubjectType.DETAIL);
                        break;
                }
            }

            BVParameters bvParam = new BVParameters();
            bvParam.UserAgent = _userAgent;
            bvParam.BaseURI = _pageUrl.Contains("?") ? _pageUrl.Substring(0, _pageUrl.IndexOf("?")) : _pageUrl;
            bvParam.PageURI = _pageUrl;
            bvParam.ContentType = _contentType;
            bvParam.SubjectType = _subjectType;
            bvParam.SubjectId = subjectID;

            BVUIContent bvOutput = new BVManagedUIContent(bvConfig);
            String outputContent = bvOutput.getContent(bvParam);

            return outputContent; 
        }
        private String getPath(BVContentType contentType, BVSubjectType subjectType, String pageNumber, String subjectId, BVContentSubType contentSubType)
        {
            StringBuilder path = new StringBuilder();
            path.Append(getRootFolder());
            path.Append(PATH_SEPARATOR);
            path.Append(contentType.uriValue());
            path.Append(PATH_SEPARATOR);

            path.Append(subjectType.uriValue());
            path.Append(PATH_SEPARATOR);
            path.Append(pageNumber);
            path.Append(PATH_SEPARATOR);

            if (contentSubType != null && !contentSubType.getContentKeyword().Equals(BVContentSubType.NONE))
            {
                path.Append(contentSubType.getContentKeyword());
                path.Append(PATH_SEPARATOR);
            }

            path.Append(subjectId);
            path.Append(HTML_EXT);

            return path.ToString();
        }
        // bvpage is present here to have back compatability support if some sites
        private Uri c2013Uri()
        {
            BVContentType contentType = null;
            BVSubjectType subjectType = null;
            String subjectId = null;

            NameValueCollection parameters = HttpUtility.ParseQueryString(_queryString, Encoding.UTF8);
            for(int i=0; i < parameters.Count; i++ )
            {
                if (parameters.Keys[i] != null && parameters.Keys[i].Equals(BV_PAGE))
                {
                    string[] tokens = parameters[parameters.Keys[i]].Split('/');
                    foreach(string token in tokens)
                    {
                        if (token.StartsWith("pg") && !IsValidPageNumber(bvParameters.PageNumber))
                        {
                            bvParameters.PageNumber = getValue(token);
                        }
                        else if (token.StartsWith("ct") )
                        {
                            contentType = new BVContentType(BVContentType.ctFromKeyWord(getValue(token)));
                        }
                        else if (token.StartsWith("st"))
                        {
                            subjectType = new BVSubjectType(BVSubjectType.subjectType(getValue(token)));
                        }
                        else if (token.StartsWith("id"))
                        {
                            subjectId = getValue(token);
                        }
                    }
                }
            }

            contentType = (contentType == null) ? bvParameters.ContentType : contentType;
            subjectType = (subjectType == null) ? bvParameters.SubjectType : subjectType;
            subjectId = (String.IsNullOrEmpty(subjectId)) ? bvParameters.SubjectId : subjectId;

            if (!IsValidPageNumber(bvParameters.PageNumber))
                bvParameters.PageNumber = NUM_ONE_STR;

            String path = getPath(contentType, subjectType, bvParameters.PageNumber, subjectId, bvParameters.ContentSubType);
            if (isContentFromFile()) {
                return fileUri(path);
            }

            return httpUri(path);
        }
        private Uri bvstateUri(String queryString)
        {
            BVContentType contentType = null;
            BVSubjectType subjectType = null;
            String subjectId = null;
            String pageNumber = null;

            NameValueCollection parameters = HttpUtility.ParseQueryString(
                queryString,
                Encoding.UTF8
            );
            for (int i = 0; i < parameters.Count; i++)
            {
                if
                (
                    parameters.Keys[i] != null &&
                    parameters.Keys[i].Equals(BV_STATE)
                )
                {
                    string[] tokens = parameters[parameters.Keys[i]].Split(BVConstant.BVSTATE_TOKEN_SEPARATOR_CHAR);
                    foreach (string token in tokens)
                    {
                        if (token.StartsWith("pg"))
                        {
                            pageNumber = extractValue(token);
                        }
                        else if (token.StartsWith("ct"))
                        {
                            String ctFromKeyword = BVContentType.ctFromBVStateKeyword(
                               extractValue(token)
                            );
                            // Ignore invalid contentTypes
                            if (ctFromKeyword != null)
                            {
                                contentType = new BVContentType(
                                    ctFromKeyword
                                );
                            }
                        }
                        else if (token.StartsWith("st"))
                        {
                            subjectType = new BVSubjectType(
                                extractValue(token)
                            );
                        }
                        else if (token.StartsWith("id"))
                        {
                            subjectId = extractValue(token);
                        }
                    }
                }
            }

            if
            (
                // Ignore bvstate if ContentType is Missing
                contentType == null ||
                // Ignore bvstate if contentType doesn't match bvParameters contentType
                (
                    bvParameters.ContentType != null &&
                    // contentType is created only if we have a valid contentType
                    !contentType.getContentType().Equals(
                        bvParameters.ContentType.getContentType(),
                        StringComparison.OrdinalIgnoreCase
                    )
                )
            )
            {
                // when no uri is returned, it falls back to legacy seo parameters
                return null;
            }

            // Defaulting logic if no subjectType is provided
            if (subjectType == null)
            {
                if
                (
                    contentType.getContentType().Equals(
                        BVContentType.SPOTLIGHTS,
                        StringComparison.OrdinalIgnoreCase
                    )
                )
                {
                    subjectType = new BVSubjectType(BVSubjectType.CATEGORY);
                }
                else
                {
                    subjectType = new BVSubjectType(BVSubjectType.PRODUCT);
                }
            }
            subjectId = (String.IsNullOrEmpty(subjectId)) ? bvParameters.SubjectId : subjectId;
            bvParameters.SubjectId = subjectId;

            if (!IsValidPageNumber(pageNumber))
            {
                pageNumber = NUM_ONE_STR;
            }
            bvParameters.PageNumber = pageNumber;

            String path = getPath(
                contentType,
                subjectType,
                bvParameters.PageNumber,
                subjectId,
                bvParameters.ContentSubType
            );
            if (isContentFromFile())
            {
                return fileUri(path);
            }

            return httpUri(path);
        }