public static void RestoreContext(this HtmlHelper helper, PreservedPageBuilderContext PreviousContext)
    {
        // Restore
        IHttpContextRetriever httpContextRetriever = DependencyResolver.Current.GetService <IHttpContextRetriever>();

        httpContextRetriever.GetContext().Items["Kentico.PageBuilder.DataContext"] = PreviousContext.PageBuilderContext;
        httpContextRetriever.GetContext().Items["Kentico.Content.PageDataContext"] = PreviousContext.Page;
    }
    public static void ChangeContext(this HtmlHelper helper)
    {
        IHttpContextRetriever httpContextRetriever = DependencyResolver.Current.GetService <IHttpContextRetriever>();

        httpContextRetriever.GetContext().Items["Kentico.PageBuilder.DataContext"] = new PageBuilderDataContext()
        {
            Options  = HttpContext.Current.Kentico().PageBuilder().Options,
            EditMode = false
        };
        httpContextRetriever.GetContext().Items["Kentico.Content.PageDataContext"] = null;
    }
    public static void ChangeContext(this HtmlHelper helper, TreeNode Document)
    {
        IHttpContextRetriever       httpContextRetriever       = DependencyResolver.Current.GetService <IHttpContextRetriever>();
        IPageDataContextInitializer pageDataContextInitializer = DependencyResolver.Current.GetService <IPageDataContextInitializer>();

        httpContextRetriever.GetContext().Items["Kentico.PageBuilder.DataContext"] = new PageBuilderDataContext()
        {
            Options  = HttpContext.Current.Kentico().PageBuilder().Options,
            EditMode = false
        };
        pageDataContextInitializer.Initialize(Document);
    }
Exemplo n.º 4
0
 public void ChangeContext()
 {
     httpContextRetriever.GetContext().Items["Kentico.PageBuilder.DataContext"] = new PageBuilderDataContext()
     {
         Options  = httpContext.HttpContext.Kentico().PageBuilder().Options,
         EditMode = false
     };
     httpContextRetriever.GetContext().Items["Kentico.Content.PageDataContext"] = null;
 }
        public ActionResult Index(string searchText, int page = DEFAULT_PAGE_NUMBER)
        {
            if (String.IsNullOrWhiteSpace(searchText))
            {
                var empty = new SearchResultsModel
                {
                    Items = new StaticPagedList <SearchResultItemModel>(Enumerable.Empty <SearchResultItemModel>(), page, PAGE_SIZE, 0)
                };
                return(View(empty));
            }

            // Validate page number (starting from 1)
            page = Math.Max(page, DEFAULT_PAGE_NUMBER);

            var searchParameters = SearchParameters.PrepareForPages(searchText, new[] { INDEX_NAME }, page, PAGE_SIZE, MembershipContext.AuthenticatedUser);
            var searchResults    = SearchHelper.Search(searchParameters);

            pagesActivityLogger.LogInternalSearch(searchText);

            var siteId      = siteService.CurrentSite.SiteID;
            var culture     = Thread.CurrentThread.CurrentCulture.Name;
            var uri         = retriever.GetContext().Request.Url;
            var hostAddress = retriever.GetContext().Request.UserHostAddress;

            analyticsLogger.LogInternalSearchKeywords(new AnalyticsData(siteId, searchText, culture: culture, uri: uri, hostAddress: hostAddress));

            var searchResultItemModels = searchResults.Items
                                         .Select(searchResultItem => searchItemViewModelFactory.GetTypedSearchResultItemModel(searchResultItem));

            var model = new SearchResultsModel
            {
                Items = new StaticPagedList <SearchResultItemModel>(searchResultItemModels, page, PAGE_SIZE, searchResults.TotalNumberOfResults),
                Query = searchText
            };

            return(View(model));
        }