public void ResolveContents_ErrorableContentsResolver_ExceptionNotThrowed() { using ( var db = new Db { new DbItem("RenderedItem") }) { var renderedItem = db.GetItem("/sitecore/content/RenderedItem"); var configurationResolver = Substitute.For <IConfigurationResolver>(); var args = new GetLayoutServiceContextArgs { RenderedItem = renderedItem, RenderingConfiguration = new DefaultRenderingConfiguration(), ContextData = { { "_sign", 1 } } }; IGetLayoutServiceContextProcessor contextProcessor = new ErrorableGetLayoutServiceContextProcessor(configurationResolver); contextProcessor.Process(args); object resultObject = args.ContextData["_sign"]; var value = Assert.IsType <int>(resultObject); Assert.Equal(1, value); } }
protected override void DoProcess(GetLayoutServiceContextArgs args, AppConfiguration application) { if (facetService == null) { Log.Fatal("GetLayoutServiceContext.EventInfo processor terimates. Must have an instance of IStringValueListFacetService resolved", this); return; } if (args.RenderedItem.TemplateID.Equals(Wellknown.TemplateIds.Event)) { var eventId = args.RenderedItem.ID.Guid.ToString("D"); try { var favorited = facetService.ContainsValue(FacetIDs.FavoriteEvents, eventId); var registered = facetService.ContainsValue(FacetIDs.RegisteredEvents, eventId); var subscribed = facetService.ContainsValue(FacetIDs.Subscriptions, eventId); args.ContextData.Add("event", new { favorited, subscribed, registered }); } catch (Exception ex) { args.ContextData.Add("event", new { }); Log.Error("GetLayoutServiceContext.EventInfo processor terimates.", ex, this); } } }
protected override void DoProcess(GetLayoutServiceContextArgs args, AppConfiguration application) { var renderedItem = args.RenderedItem; var database = renderedItem?.Database; if (renderedItem == null || database == null) { return; } var outputObject = new CurrentItemModel { ItemId = renderedItem.ID.ToString(), Name = renderedItem.Name, DisplayName = renderedItem.DisplayName, Path = renderedItem.Paths.Path, TemplateName = renderedItem.TemplateName, CreatedBy = renderedItem.Statistics.CreatedBy, UpdatedBy = renderedItem.Statistics.UpdatedBy, CountOfVersions = renderedItem.Versions.Count, CurrentVersion = renderedItem.Version.Number, IsPublished = !renderedItem.Publishing.NeverPublish, WorkflowState = renderedItem.GetWorkflowState() }; args.ContextData.Add(CurrentItemObjectKey, outputObject); }
protected override void DoProcess(GetLayoutServiceContextArgs args, AppConfiguration application) { args.ContextData.Add("membership", new { level = "Silver", authenticated = Sitecore.Context.IsLoggedIn }); }
public void Process(GetLayoutServiceContextArgs args) { Assert.ArgumentNotNull((object)args, nameof(args)); var options = LinkManager.GetDefaultUrlBuilderOptions(); options.AlwaysIncludeServerUrl = true; string link = LinkManager.GetItemUrl(Context.Item, options); args.ContextData.Add(Key, link); }
protected override void DoProcessSafe(GetLayoutServiceContextArgs args, AppConfiguration application) { ProductModel model = this.catalogRepository.GetCurrentProduct(); if (model != null) { this.analyticsRepository.RaiseProductVisitedEvent(model); } args.ContextData.Add("product", model); }
protected override void DoProcessSafe(GetLayoutServiceContextArgs args, AppConfiguration application) { var result = this.catalogService.GetCurrentCategory(); if (result.Success && result.Data != null) { this.analyticsService.RaiseCategoryVisitedEvent(result.Data); } args.ContextData.Add("category", result.Data); }
protected override void DoProcess(GetLayoutServiceContextArgs args, AppConfiguration application) { try { this.DoProcessSafe(args, application); } catch (Exception e) { Log.Error("Unexpected error during JSS context resolving.", e, this.GetType()); } }
protected override void DoProcessSafe(GetLayoutServiceContextArgs args, AppConfiguration application) { var imageFallbackSettings = this.siteSettingsProvider.GetSetting <ImageFallbackSettings>(new ID(ImageFallbackSettings.TemplateId)); if (imageFallbackSettings == null) { return; } args.ContextData.Add( Constants.Context.FallbackImageUrlPropertyName, imageFallbackSettings.FallbackImage.Src); }
protected override void DoProcess(GetLayoutServiceContextArgs args, AppConfiguration application) { var contact = GetContact(); if (contact != null) { args.ContextData.Add("contact", new { identification = contact.IdentificationLevel.ToString(), isNew = contact.IsNew, visits = contact.System.VisitCount, value = contact.System.Value, }); } }
protected override void DoProcessSafe(GetLayoutServiceContextArgs args, AppConfiguration application) { string productColorMappingQuery = $"{application.SitecorePath.TrimEnd('/')}/Settings/*[@@templateid='{ID.Parse(ProductColorMappingFolder.TemplateId)}']"; var productColorMapping = this.sitecoreContext.QuerySingle <IProductColorMappingFolder>(productColorMappingQuery); var dictionary = new Dictionary <string, string>(); if (productColorMapping?.Mappings != null) { foreach (IProductColorMapping colorMapping in productColorMapping.Mappings) { dictionary.Add(colorMapping.ColorName, colorMapping.ColorHEX); } } args.ContextData.Add("productColors", dictionary); }
protected override void DoProcessSafe(GetLayoutServiceContextArgs args, AppConfiguration application) { if (args.RenderedItem == null) { return; } var currentItem = args.RenderedItem; // Trying to get original url path var itemPath = HttpContext.Current.Request.Url.ParseQueryString()?["item"]; var urlSegments = itemPath?.Trim('/').Split('/'); if (args.RenderedItem == null) { return; } this.catalogItemResolver.ProcessItemAndApplyContext(currentItem, urlSegments); }
public void Process(GetLayoutServiceContextArgs args) { Assert.IsNotNull(args, "args is null"); if (args.RenderedItem == null) { Log.Warn("args.RenderedItem is null in ResolveLayout", this); return; } var layout = args.RenderedItem.Visualization.Layout; IDictionary <string, object> contextData = args.ContextData; var data = new { name = layout.Name, id = layout.ID.ToString() }; contextData.Add(_key, (object)data); }
protected override void DoProcess(GetLayoutServiceContextArgs args, AppConfiguration application) { Assert.ArgumentNotNull(args, "args"); if (!string.IsNullOrEmpty(configItemPath) || !string.IsNullOrEmpty(startDateFieldName) || !string.IsNullOrEmpty(pageTitleFIeldName)) { Assert.IsNotNull(configItemPath, "No config item path or field names in parameter"); } Item eventItem = args?.RenderedItem?.Database?.GetItem(configItemPath); if (eventItem == null) { return; } args.ContextData.Add("EventInfo", new { StartDate = eventItem?.Fields[startDateFieldName]?.Value, TitlePrefix = eventItem?.Fields[pageTitleFIeldName]?.Value }); }
protected override void DoProcess(GetLayoutServiceContextArgs args, AppConfiguration application) { var renderedItem = args.RenderedItem; var database = renderedItem?.Database; if (renderedItem == null || database == null) { return; } var current = new TreeItemModel { key = renderedItem.ID.ToShortID().ToString(), parent = renderedItem.ParentID.ToShortID().ToString(), title = string.IsNullOrWhiteSpace(renderedItem.DisplayName) ? renderedItem.Name : renderedItem.DisplayName, path = renderedItem.GetItemRelativeURL(), icon = "/temp/IconCache/" + renderedItem.Appearance.Icon, workflow = renderedItem.GetWorkflowState(), template = renderedItem.TemplateName }; var result = new List <TreeItemModel> { current }; result.AddRange( database.SelectItems(renderedItem.Paths.FullPath + "//*").Where(q => q.DoesItemHasPresentationDetails()).Select( q => new TreeItemModel { key = q.ID.ToShortID().ToString(), parent = q.ParentID.ToShortID().ToString(), title = string.IsNullOrWhiteSpace(q.DisplayName) ? q.Name : q.DisplayName, path = q.GetItemRelativeURL(), icon = "/temp/IconCache/" + q.Appearance.Icon, workflow = q.GetWorkflowState(), template = q.TemplateName })); args.ContextData.Add(objectKey, result); }
protected override void DoProcess(GetLayoutServiceContextArgs args, AppConfiguration application) { if (args.RenderedItem != null) { Sitecore.Layouts.RenderingReference[] renderings = args.RenderedItem.Visualization.GetRenderings(Sitecore.Context.Device, false); var personalizedRenderings = renderings .Where(i => i.Settings?.Rules?.Count > 0) .Select(i => new { i.Placeholder, i.RenderingID, uid = Guid.TryParse(i.UniqueId, out _) ? Guid.Parse(i.UniqueId).ToString("D").ToLower() : Guid.Empty.ToString("D"), i.Settings.DataSource, i.Settings.Parameters, RenderingPlaceholder = i.RenderingItem.Placeholder }) .ToList(); args.ContextData.Add("personalization", new { personalizedRenderings = personalizedRenderings }); } }
protected abstract void DoProcessSafe(GetLayoutServiceContextArgs args, AppConfiguration application);
protected override void DoProcessSafe(GetLayoutServiceContextArgs args, AppConfiguration application) { args.ContextData.Add("breadcrumb", this.breadcrumbService.GenerateBreadcrumb()); }
protected override void DoProcessSafe(GetLayoutServiceContextArgs args, AppConfiguration application) { args.ContextData.Add("productColors", this.productColorMappingsServices.GetProductColorMappings()); }
protected override void DoProcess(GetLayoutServiceContextArgs args, AppConfiguration application) { args.ContextData.Add("breadcrumb", GetBreadcrumb(args.RenderedItem, Context.Site)); }
protected override void DoProcessSafe(GetLayoutServiceContextArgs args, AppConfiguration application) { var model = this.visitorContext.CurrentUser; args.ContextData.Add(Constants.Context.CommerceUserPropertyName, model); }
public void Process(GetLayoutServiceContextArgs args) { Sitecore.Diagnostics.Log.Info("layoutService patch executes!", this); }
protected override void DoProcessSafe(GetLayoutServiceContextArgs args, AppConfiguration application) { CommerceUserModel model = this.visitorContext.CurrentUser; args.ContextData.Add("commerceUser", model); }
protected override void DoProcessSafe(GetLayoutServiceContextArgs args, AppConfiguration application) { throw new Exception("The test shouldnot show this exception!"); }