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));
        }
        private void loadData(
            String currentUrl,
            String contentType,
            int index,
            HtmlGenericControl reviewSummaryControl,
            HtmlGenericControl reviewControl,
            HtmlGenericControl contentControl
            )
        {
            String cloudKey    = Request.QueryString["cloudkey" + index];
            String staging     = Request.QueryString["staging" + index];
            String testing     = Request.QueryString["testing" + index];
            String rootFolder  = Request.QueryString["site" + index];
            String subjectType = Request.QueryString["subjecttype" + index];
            String subjectId   = Request.QueryString["subjectid" + index];

            if (subjectType != null)
            {
                subjectType = BVSubjectType.subjectType(subjectType);
            }
            // Separate defaulting Logic for spotlight vs non-spotlight content
            if (contentType.Equals(BVContentType.SPOTLIGHTS, StringComparison.OrdinalIgnoreCase))
            {
                if (subjectId == null)
                {
                    subjectId = "category-1";
                }
                if (cloudKey == null)
                {
                    cloudKey = "spotlight-four-746e2fc1211dc8964560350c9f28b67a";
                }
                if (staging == null)
                {
                    staging = "false";
                }
                if (testing == null)
                {
                    testing = "true";
                }
                if (rootFolder == null)
                {
                    rootFolder = "Main_Site-en_US";
                }
                if (subjectType == null)
                {
                    subjectType = BVSubjectType.CATEGORY;
                }
            }
            else if (contentType.Equals(BVContentType.REVIEWS, StringComparison.OrdinalIgnoreCase))
            {
                if (subjectId == null)
                {
                    subjectId = "product1";
                }
                if (cloudKey == null)
                {
                    cloudKey = "spotlight-five-311f5a3337b8d5e0d817adb7af279b0a";
                }
                if (staging == null)
                {
                    staging = "true";
                }
                if (testing == null)
                {
                    testing = "false";
                }
                if (rootFolder == null)
                {
                    rootFolder = "Other_Zone-en_US";
                }
                if (subjectType == null)
                {
                    subjectType = BVSubjectType.PRODUCT;
                }
            }
            else if (contentType.Equals(BVContentType.QUESTIONS, StringComparison.OrdinalIgnoreCase))
            {
                if (subjectId == null)
                {
                    subjectId = "data-gen-u2y505e9u1l65i43l6zz22ve6";
                }
                if (cloudKey == null)
                {
                    cloudKey = "agileville-78B2EF7DE83644CAB5F8C72F2D8C8491";
                }
                if (staging == null)
                {
                    staging = "true";
                }
                if (testing == null)
                {
                    testing = "false";
                }
                if (rootFolder == null)
                {
                    rootFolder = "Main_Site-en_US";
                }
                if (subjectType == null)
                {
                    subjectType = BVSubjectType.PRODUCT;
                }
            }
            else
            {
                if (subjectId == null)
                {
                    subjectId = "test1";
                }
                if (cloudKey == null)
                {
                    cloudKey = "Allergan-09b83694534c0d1bcd24851e9e9d172f";
                }
                if (staging == null)
                {
                    staging = "true";
                }
                if (testing == null)
                {
                    testing = "false";
                }
                if (rootFolder == null)
                {
                    rootFolder = "8183-en_us";
                }
                if (subjectType == null)
                {
                    subjectType = BVSubjectType.PRODUCT;
                }
            }

            // Setting up BVConfiguration and BVParameters
            BVConfiguration bvConfig = new BVSdkConfiguration();

            bvConfig.addProperty(BVClientConfig.CLOUD_KEY, cloudKey);
            bvConfig.addProperty(BVClientConfig.STAGING, staging);
            bvConfig.addProperty(BVClientConfig.TESTING, testing);
            bvConfig.addProperty(BVClientConfig.BV_ROOT_FOLDER, rootFolder);
            bvConfig.addProperty(BVClientConfig.SEO_SDK_ENABLED, "true");         // use this as a kill switch
            bvConfig.addProperty(BVClientConfig.LOAD_SEO_FILES_LOCALLY, "false"); // set to false if using cloud-based content
            bvConfig.addProperty(BVClientConfig.LOCAL_SEO_FILE_ROOT, "/");
            bvConfig.addProperty(BVClientConfig.CRAWLER_AGENT_PATTERN, "yandex");
            bvConfig.addProperty(BVClientConfig.EXECUTION_TIMEOUT, "1500");
            bvConfig.addProperty(BVClientConfig.EXECUTION_TIMEOUT_BOT, "2000");

            var bvParameters = new BVParameters
            {
                BaseURI     = currentUrl,
                PageURI     = currentUrl,
                ContentType = new BVContentType(contentType),
                SubjectType = new BVSubjectType(subjectType),
                SubjectId   = subjectId
            };

            if (contentType.Equals(BVContentType.STORIES, StringComparison.OrdinalIgnoreCase))
            {
                bvParameters.ContentSubType = new BVContentSubType(BVContentSubType.STORIES_LIST);
            }

            BVUIContent bvOutput = new BVManagedUIContent(bvConfig);

            if (contentType.Equals(BVContentType.REVIEWS, StringComparison.OrdinalIgnoreCase))
            {
                reviewSummaryControl.InnerHtml = bvOutput.getAggregateRating(bvParameters);
                reviewControl.InnerHtml        = bvOutput.getReviews(bvParameters);
                contentControl.InnerHtml       = "";
            }
            else
            {
                contentControl.InnerHtml       = bvOutput.getContent(bvParameters);
                reviewSummaryControl.InnerHtml = "";
                reviewControl.InnerHtml        = "";
            }
        }
Ejemplo n.º 5
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);
        }