public override void Displaying(ShapeDisplayingContext context) {
            context.ShapeMetadata.OnDisplaying(displayedContext => {
                // We don't want the "Widget" content item itself, but the content item that consists of the Widget part (e.g. Parts.Blogs.RecentBlogPosts)
                if (displayedContext.ShapeMetadata.Type != "Widget") {
                    // look for ContentItem property
                    ContentItem contentItem = displayedContext.Shape.ContentItem;

                    // if not, check for ContentPart 
                    if (contentItem == null) {
                        ContentPart contentPart = displayedContext.Shape.ContentPart;
                        if (contentPart != null) {
                            contentItem = contentPart.ContentItem;
                        }
                    } 
                    
                    if (contentItem != null) {
                        // Is the contentItem a widget? (we could probably test for the stereotype setting, don't know if that is more efficient than selecting the WidgetPart)
                        var widgetPart = contentItem.As<WidgetPart>();
                        if (widgetPart != null) {
                            var zoneName = widgetPart.Zone;
                            var shapeName = displayedContext.ShapeMetadata.Type;
                            var contentTypeName = contentItem.ContentType;

                            // Add 2 alternates for flexible widget shape naming:
                            // [ShapeName]-[ZoneName].cshtml: (e.g. "Parts.Blogs.RecentBlogPosts-myZoneName.cshtml")
                            // [ShapeName]-[ContentTypeName]-[ZoneName].cshtml: (e.g. "Parts.Common.Body-RecentBlogPosts-myZoneName.cshtml")
                            displayedContext.ShapeMetadata.Alternates.Add(shapeName + "__" + contentTypeName + "__" + zoneName);
                            displayedContext.ShapeMetadata.Alternates.Add(shapeName + "__" + zoneName);
                        }
                    }
                }
            });

        }
        public override void Displaying(ShapeDisplayingContext context)
        {
            if (context.ShapeMetadata.Type != "Weather")
                return;

            context.Shape.WeatherInfo = _weatherService.GetTodaysWeather();
        }
        public override void Displaying(ShapeDisplayingContext context) {
            context.ShapeMetadata.OnDisplaying(displayedContext => {
                if (!IsActivable()) {
                    return;
                }

                if (context.ShapeMetadata.Type != "EditorTemplate" &&
                    context.ShapeMetadata.Type != "Zone")
                    return;

                ContentItem contentItem = context.Shape.ContentItem;

                // if not, check for ContentPart 
                if (contentItem == null) {
                    ContentPart contentPart = context.Shape.ContentPart;
                    if (contentPart != null) {
                        contentItem = contentPart.ContentItem;
                    }
                }

                var className = "content-" + _workContext.GetTextDirection(contentItem);

                if (!_workContext.Layout.Content.Classes.Contains(className))
                    _workContext.Layout.Content.Classes.Add(className);
            });
        }
        public void Displaying(ShapeDisplayingContext context) {
            var shape = context.Shape;
            var content = shape.ContentItem as IContent;
            if (content == null)
                return;

            if (!IsActivable(content)) {
                return;
            }
            
            var shapeMetadata = (ShapeMetadata) context.Shape.Metadata;

            if (shapeMetadata.Wrappers.Contains("InlineShapeWrapper"))
                return;

            if (shapeMetadata.Type != "Widget"
                && shapeMetadata.Type != "EditorTemplate") {

                var currentTheme = _themeManager.GetRequestTheme(_workContext.HttpContext.Request.RequestContext);
                var shapeTable = _shapeTableManager.GetShapeTable(currentTheme.Id);

                foreach (var alternate in shapeMetadata.Alternates) {
                    if (shapeTable.Descriptors.ContainsKey(alternate + "_InlineEdit")) {
                        shapeMetadata.Wrappers.Add("InlineShapeWrapper");
                        return;
                    }
                }

                if (shapeTable.Descriptors.ContainsKey(shapeMetadata.Type + "_InlineEdit")) {
                    shapeMetadata.Wrappers.Add("InlineShapeWrapper");
                }
                
            }
        }
        public override void Displaying(ShapeDisplayingContext context) {

            context.ShapeMetadata.OnDisplaying(displayedContext => {

                if (_urlAlternates.Value == null || !_urlAlternates.Value.Any()) {
                    return;
                }

                // prevent applying alternate again, c.f. http://orchard.codeplex.com/workitem/18298
                if(displayedContext.ShapeMetadata.Alternates.Any(x => x.Contains("__url__"))) {
                    return;
                }

                // appends Url alternates to current ones
                displayedContext.ShapeMetadata.Alternates = displayedContext.ShapeMetadata.Alternates.SelectMany(
                    alternate => new [] { alternate }.Union(_urlAlternates.Value.Select(a => alternate + "__url__" + a))
                    ).ToList();

                // appends [ShapeType]__url__[Url] alternates
                displayedContext.ShapeMetadata.Alternates = _urlAlternates.Value.Select(url => displayedContext.ShapeMetadata.Type + "__url__" + url)
                    .Union(displayedContext.ShapeMetadata.Alternates)
                    .ToList();
            });

        }
        private static void Ajaxify(ShapeDisplayingContext context, string ajaxifiedShapeType) {
            var ajaxifyPart = ((IContent)context.Shape.ContentItem).As<AjaxifyPart>();

            if (ajaxifyPart == null || !ajaxifyPart.Ajaxify || context.Shape.Ajaxified == true)
                return;

            context.ShapeMetadata.Type = ajaxifiedShapeType;
        }
        public override void Displaying(ShapeDisplayingContext context)
        {
            var routeValues = new RouteValueDictionary(mWorkContextAccessor.GetContext().HttpContext.Request.RequestContext.RouteData.Values);
            var list = new List<string> { TakeValue(routeValues, "area"), TakeValue(routeValues, "controller"), TakeValue(routeValues, "action") };

            list.AddRange(routeValues.OrderBy(x => x.Key).Select(x => (string)x.Value));
            AddAlternates(context.ShapeMetadata, list);
        }
        public void Displaying(ShapeDisplayingContext context) {
            var processors = BuildShapeProcessors();
            Func<dynamic, IHtmlString> processor;

            if (processors.TryGetValue(context.ShapeMetadata.Type, out processor)) {
                context.ChildContent = processor(context.Shape);
            }
        }
예제 #9
0
 public void CKEditor_Config_Displaying(ShapeDisplayingContext displaying)
 {
     // Build other key/value pairs
     var context = new CKEditorConfigContext();
     foreach (var provider in _ckEditorConfigProviders.Value) {
         provider.PopulateConfiguration(context);
     }
     displaying.Shape.ConfigPairs = context.Config.Values;
 }
 public override void Displaying(ShapeDisplayingContext context) {
     context.ShapeMetadata.OnDisplaying(displayedContext => {
         if (displayedContext.ShapeMetadata.Type == "Layout" && IsActivable()) {
             var supportedCultures = _cultureManager.ListCultures().ToList();
             if (supportedCultures.Count() > 1) {
                 _workContext.Layout.Header.Add(Shape.AdminCultureSelector(SupportedCultures: supportedCultures));
             }
         }
     });
 }
예제 #11
0
        private void AddShapeWrapper(ShapeDisplayingContext shapeDisplayingContext, string wrapperName, bool includeUniqueIndentifier = true)
        {
            var settings = _orchardServices.WorkContext.CurrentSite.As<DisqusSettingsPart>();
            shapeDisplayingContext.Shape.DisqusSettings = settings;
            shapeDisplayingContext.ShapeMetadata.Wrappers.Add(wrapperName);

            if (includeUniqueIndentifier)
            {
                shapeDisplayingContext.Shape.DisqusUniqueId = GetUniqueIdentifier(shapeDisplayingContext.Shape.ContentPart.ContentItem);
            }
        }
        public override void Displaying(ShapeDisplayingContext context) {
            if (String.CompareOrdinal(context.ShapeMetadata.Type, "Body_Editor") != 0) {
                return;
            }

            if (!String.Equals(context.Shape.EditorFlavor, "html", StringComparison.InvariantCultureIgnoreCase)) {
                return;
            }

            context.Shape.Language = GetTinyMceLanguageIdentifier();
        }
        public override void Displaying(ShapeDisplayingContext context) {

            context.ShapeMetadata.OnDisplaying(displayedContext => {
                // appends Url alternates to current ones
                displayedContext.ShapeMetadata.Alternates = displayedContext.ShapeMetadata.Alternates.SelectMany(
                    alternate => new [] { alternate }.Union(_urlAlternates.Select(a => alternate + "__url__" + a))
                    ).ToList();

                // appends [ShapeType]__url__[Url] alternates
                displayedContext.ShapeMetadata.Alternates = _urlAlternates.Select(url => displayedContext.ShapeMetadata.Type + "__url__" + url)
                    .Union(displayedContext.ShapeMetadata.Alternates)
                    .ToList();
            });

        }
        public void Displaying(ShapeDisplayingContext context)
        {
            if(!IsMobileDevice())
            {
                return;
            }

            var shapeMetadata = context.ShapeMetadata;
            if (shapeMetadata.Type != "HeadLinks" && shapeMetadata.Type != "Metas") return;

            var workContext = _workContextAccessor.GetContext(_httpContextAccessor.Current());
            var resourceManager = workContext.Resolve<IResourceManager>();

            if (shapeMetadata.Type == "HeadLinks")
            {
                // <link rel="alternate" type="text/html" media="handheld" href="" />
                var handheldLink = new LinkEntry
                                        {
                                            Type = "text/html",
                                            Rel = "alternate",
                                            Href = ""
                                        };

                handheldLink.AddAttribute("media", "handheld");

                resourceManager.RegisterLink(handheldLink);

                // Set the transcoding protection http response headers
                workContext.HttpContext.Response.Cache.SetNoTransforms();
                workContext.HttpContext.Response.AppendHeader("Vary", "User-Agent");
            }
            else if (shapeMetadata.Type == "Metas")
            {
                resourceManager.SetMeta(new MetaEntry
                                            {
                                                // HACK: Orchard doesn't allow metas without a name.
                                                Name = "no-transform", 
                                                HttpEquiv = "Cache-control",
                                                Content = "no-transform"
                                            });
            }
        }
        public void Displaying(ShapeDisplayingContext context)
        {
            if (context.ShapeMetadata.IsCached && context.ChildContent == null)
            {
                var cacheContext = context.ShapeMetadata.Cache();
                var cacheEntries = GetCacheEntries(cacheContext).ToList();
                string cacheKey = GetCacheKey(cacheContext.CacheId, cacheEntries);

                var content = GetDistributedCache(cacheKey);
                if (content != null)
                {
                    if (ProcessESIs(ref content, GetDistributedCache))
                    {
                        _cached.Add(cacheContext);
                        var contexts = String.Join(ContextSeparator.ToString(), cacheContext.Contexts.ToArray());
                        context.ChildContent = new HtmlString($"[[cache id='{cacheContext.CacheId}' contexts='{contexts}']]");
                    }
                }
            }
        }
        private void ConfigureMenuShape(ShapeDisplayingContext context)
        {
            var widget = (ContentItem)context.Shape.MenuWidget;

            // Check if the Menu or Breadcrumb shape was created by a MenuWidget.
            if (widget == null)
                return;

            var widgetPart = widget.As<WidgetPart>();
            var menuWidgetPart = widget.As<MenuWidgetPart>();
            var menuName = (string)context.Shape.SafeMenuName;
            var widgetName = widgetPart.Name;
            var shapeType = context.ShapeMetadata.Type;

            if (!String.IsNullOrWhiteSpace(widgetName))
            {
                context.ShapeMetadata.Alternates.Add($"{shapeType}__WidgetName__{widgetName}");
                context.ShapeMetadata.Alternates.Add($"{shapeType}__WidgetName__{widgetName}__MenuLevel{menuWidgetPart.StartLevel}");
            }

            context.ShapeMetadata.Alternates.Add($"{shapeType}__MenuName__{menuName}");
            context.ShapeMetadata.Alternates.Add($"{shapeType}__MenuLevel__Level{menuWidgetPart.StartLevel}");
            context.ShapeMetadata.Alternates.Add($"{shapeType}__MenuName__{menuName}__MenuLevel{menuWidgetPart.StartLevel}");

            ApplyRecursively(context.Shape.Items, (Action<dynamic>)(menuItemShape =>
            {
                var level = menuItemShape.Level;
                menuItemShape.Metadata.Alternates.Add($"MenuItem__Level{level}");

                if (!String.IsNullOrWhiteSpace(widgetName))
                {
                    menuItemShape.Metadata.Alternates.Add($"MenuItem__WidgetName__{widgetName}");
                    menuItemShape.Metadata.Alternates.Add($"MenuItem__WidgetName__{widgetName}__Level{level}");
                }

                menuItemShape.Metadata.Alternates.Add($"MenuItem__MenuName__{menuName}");
                menuItemShape.Metadata.Alternates.Add($"MenuItem__MenuName__{menuName}__Level{level}");
            }));
        }
예제 #17
0
 public virtual void Displaying(ShapeDisplayingContext context) { }
        public void Displaying(ShapeDisplayingContext context)
        {
            if (context.ShapeMetadata.Type != "DocumentZone" || context.Shape.ZoneName != "Head") return;

            var httpContext = _hca.Current();
            if (httpContext == null) return;
            if (AdminFilter.IsApplied(httpContext.Request.RequestContext)) return;

            var resourceManager = _resourceManagerWork.Value;

            var overrides = _themeOverrideService.GetOverrides();
            if (overrides.FaviconUri != null)
            {
                resourceManager.RegisterLink(new LinkEntry { Type = "image/x-icon", Rel = "shortcut icon", Href = overrides.FaviconUri.ToString() });
            }

            if (overrides.StylesheetUris.Any())
            {
                foreach (var uri in overrides.StylesheetUris)
                {
                    var url = uri.ToString();
                    resourceManager.Include("stylesheet", url, url);
                }
            }

            if (overrides.CustomStyles.Uri != null)
            {
                var url = overrides.CustomStyles.Uri.ToString();
                resourceManager.Include("stylesheet", url, url);
            }

            if (overrides.HeadScriptUris.Any())
            {
                foreach (var uri in overrides.HeadScriptUris)
                {
                    var url = uri.ToString();
                    resourceManager.Include("script", url, url).AtHead();
                }
            }

            if (overrides.CustomHeadScript.Uri != null)
            {
                var url = overrides.CustomHeadScript.Uri.ToString();
                resourceManager.Include("script", url, url).AtHead();
            }

            if (overrides.FootScriptUris.Any())
            {
                foreach (var uri in overrides.FootScriptUris)
                {
                    var url = uri.ToString();
                    resourceManager.Include("script", url, url).AtFoot();
                }
            }

            if (overrides.CustomFootScript.Uri != null)
            {
                var url = overrides.CustomFootScript.Uri.ToString();
                resourceManager.Include("script", url, url).AtFoot();
            }
        }
예제 #19
0
        public IHtmlString Execute(DisplayContext context)
        {
            var shape = _convertAsShapeCallsite.Target(_convertAsShapeCallsite, context.Value);

            // non-shape arguments are returned as a no-op
            if (shape == null)
                return CoerceHtmlString(context.Value);

            var shapeMetadata = shape.Metadata;
            // can't really cope with a shape that has no type information
            if (shapeMetadata == null || string.IsNullOrEmpty(shapeMetadata.Type))
                return CoerceHtmlString(context.Value);

            var workContext = _workContextAccessor.GetContext();
            // CurrentTheme is now available in the background, so here we no longer use IsBackgroundContext().
            // We only do a null check, so we can render in the background a view that only exists in the theme.
            var shapeTable = _httpContextAccessor.Current() != null
                ? _shapeTableLocator.Value.Lookup(workContext.CurrentTheme.Id)
                : _shapeTableLocator.Value.Lookup(null);

            var displayingContext = new ShapeDisplayingContext {
                Shape = shape,
                ShapeMetadata = shapeMetadata
            };
            _shapeDisplayEvents.Invoke(sde => sde.Displaying(displayingContext), Logger);

            // find base shape association using only the fundamental shape type.
            // alternates that may already be registered do not affect the "displaying" event calls
            ShapeBinding shapeBinding;
            if (TryGetDescriptorBinding(shapeMetadata.Type, Enumerable.Empty<string>(), shapeTable, out shapeBinding)) {
                shapeBinding.ShapeDescriptor.Displaying.Invoke(action => action(displayingContext), Logger);

                // copy all binding sources (all templates for this shape) in order to use them as Localization scopes
                shapeMetadata.BindingSources = shapeBinding.ShapeDescriptor.BindingSources.Where(x => x != null).ToList();
                if (!shapeMetadata.BindingSources.Any()) {
                    shapeMetadata.BindingSources.Add(shapeBinding.ShapeDescriptor.BindingSource);
                }
            }

            // invoking ShapeMetadata displaying events
            shapeMetadata.Displaying.Invoke(action => action(displayingContext), Logger);

            // use pre-fectched content if available (e.g. coming from specific cache implmentation)
            if ( displayingContext.ChildContent != null ) {
                shape.Metadata.ChildContent = displayingContext.ChildContent;
            }
            else {
                // now find the actual binding to render, taking alternates into account
                ShapeBinding actualBinding;
                if ( TryGetDescriptorBinding(shapeMetadata.Type, shapeMetadata.Alternates, shapeTable, out actualBinding) ) {
                    shape.Metadata.ChildContent = Process(actualBinding, shape, context);
                }
                else {
                    throw new OrchardException(T("Shape type {0} not found", shapeMetadata.Type));
                }
            }

            foreach (var frameType in shape.Metadata.Wrappers) {
                ShapeBinding frameBinding;
                if (TryGetDescriptorBinding(frameType, Enumerable.Empty<string>(), shapeTable, out frameBinding)) {
                    shape.Metadata.ChildContent = Process(frameBinding, shape, context);
                }
            }

            var displayedContext = new ShapeDisplayedContext {
                Shape = shape,
                ShapeMetadata = shape.Metadata,
                ChildContent = shape.Metadata.ChildContent,
            };

            _shapeDisplayEvents.Invoke(sde => {
                var prior = displayedContext.ChildContent = displayedContext.ShapeMetadata.ChildContent;
                sde.Displayed(displayedContext);
                // update the child content if the context variable has been reassigned
                if (prior != displayedContext.ChildContent)
                    displayedContext.ShapeMetadata.ChildContent = displayedContext.ChildContent;
            }, Logger);

            if (shapeBinding != null) {
                shapeBinding.ShapeDescriptor.Displayed.Invoke(action => {
                    var prior = displayedContext.ChildContent = displayedContext.ShapeMetadata.ChildContent;
                    action(displayedContext);
                    // update the child content if the context variable has been reassigned
                    if (prior != displayedContext.ChildContent)
                        displayedContext.ShapeMetadata.ChildContent = displayedContext.ChildContent;
                }, Logger);
            }

            // invoking ShapeMetadata displayed events
            shapeMetadata.Displayed.Invoke(action => action(displayedContext), Logger);

            return shape.Metadata.ChildContent;
        }
예제 #20
0
        public IHtmlString Execute(DisplayContext context)
        {
            var shape = _convertAsShapeCallsite.Target(_convertAsShapeCallsite, context.Value);

            // non-shape arguments are returned as a no-op
            if (shape == null)
            {
                return(CoerceHtmlString(context.Value));
            }

            var shapeMetadata = shape.Metadata;

            // can't really cope with a shape that has no type information
            if (shapeMetadata == null || string.IsNullOrEmpty(shapeMetadata.Type))
            {
                return(CoerceHtmlString(context.Value));
            }

            var workContext = _workContextAccessor.GetContext();
            // CurrentTheme is now available in the background, so here we no longer use IsBackgroundContext().
            // We only do a null check, so we can render in the background a view that only exists in the theme.
            var shapeTable = _httpContextAccessor.Current() != null
                ? _shapeTableLocator.Value.Lookup(workContext.CurrentTheme.Id)
                : _shapeTableLocator.Value.Lookup(null);

            var displayingContext = new ShapeDisplayingContext {
                Shape         = shape,
                ShapeMetadata = shapeMetadata
            };

            _shapeDisplayEvents.Invoke(sde => sde.Displaying(displayingContext), Logger);

            // find base shape association using only the fundamental shape type.
            // alternates that may already be registered do not affect the "displaying" event calls
            ShapeBinding shapeBinding;

            if (TryGetDescriptorBinding(shapeMetadata.Type, Enumerable.Empty <string>(), shapeTable, shapeMetadata.BindingType, out shapeBinding))
            {
                shapeBinding.ShapeDescriptor.Displaying.Invoke(action => action(displayingContext), Logger);

                // copy all binding sources (all templates for this shape) in order to use them as Localization scopes
                shapeMetadata.BindingSources = shapeBinding.ShapeDescriptor.BindingSources.Where(x => x != null).ToList();
                if (!shapeMetadata.BindingSources.Any())
                {
                    shapeMetadata.BindingSources.Add(shapeBinding.ShapeDescriptor.BindingSource);
                }
            }

            // invoking ShapeMetadata displaying events
            shapeMetadata.Displaying.Invoke(action => action(displayingContext), Logger);

            // use pre-fectched content if available (e.g. coming from specific cache implmentation)
            if (displayingContext.ChildContent != null)
            {
                shape.Metadata.ChildContent = displayingContext.ChildContent;
            }
            else
            {
                // now find the actual binding to render, taking alternates into account
                ShapeBinding actualBinding;
                if (TryGetDescriptorBinding(shapeMetadata.Type, shapeMetadata.Alternates, shapeTable, shapeMetadata.BindingType, out actualBinding))
                {
                    shape.Metadata.ChildContent = Process(actualBinding, shape, context);
                }
                else
                {
                    throw new OrchardException(T("Shape type {0} not found", shapeMetadata.Type));
                }
            }

            foreach (var frameType in shape.Metadata.Wrappers)
            {
                ShapeBinding frameBinding;
                if (TryGetDescriptorBinding(frameType, Enumerable.Empty <string>(), shapeTable, shapeMetadata.BindingType, out frameBinding))
                {
                    shape.Metadata.ChildContent = Process(frameBinding, shape, context);
                }
            }

            var displayedContext = new ShapeDisplayedContext {
                Shape         = shape,
                ShapeMetadata = shape.Metadata,
                ChildContent  = shape.Metadata.ChildContent,
            };

            _shapeDisplayEvents.Invoke(sde => {
                var prior = displayedContext.ChildContent = displayedContext.ShapeMetadata.ChildContent;
                sde.Displayed(displayedContext);
                // update the child content if the context variable has been reassigned
                if (prior != displayedContext.ChildContent)
                {
                    displayedContext.ShapeMetadata.ChildContent = displayedContext.ChildContent;
                }
            }, Logger);

            if (shapeBinding != null)
            {
                shapeBinding.ShapeDescriptor.Displayed.Invoke(action => {
                    var prior = displayedContext.ChildContent = displayedContext.ShapeMetadata.ChildContent;
                    action(displayedContext);
                    // update the child content if the context variable has been reassigned
                    if (prior != displayedContext.ChildContent)
                    {
                        displayedContext.ShapeMetadata.ChildContent = displayedContext.ChildContent;
                    }
                }, Logger);
            }

            // invoking ShapeMetadata displayed events
            shapeMetadata.Displayed.Invoke(action => action(displayedContext), Logger);

            return(shape.Metadata.ChildContent);
        }
예제 #21
0
        public async Task <IHtmlContent> ExecuteAsync(DisplayContext context)
        {
            var shape = context.Value as IShape;

            // non-shape arguments are returned as a no-op
            if (shape == null)
            {
                return(CoerceHtmlString(context.Value));
            }

            var shapeMetadata = shape.Metadata;

            // can't really cope with a shape that has no type information
            if (shapeMetadata == null || string.IsNullOrEmpty(shapeMetadata.Type))
            {
                return(CoerceHtmlString(context.Value));
            }

            var theme = await _themeManager.GetThemeAsync();

            var shapeTable = _shapeTableManager.GetShapeTable(theme?.Id);

            var displayingContext = new ShapeDisplayingContext
            {
                Shape          = shape,
                ShapeMetadata  = shapeMetadata,
                DisplayContext = context
            };

            // Evaluate global Shape Display Events
            _shapeDisplayEvents.Invoke(sde => sde.Displaying(displayingContext), _logger);

            // Find base shape association using only the fundamental shape type.
            // Alternates that may already be registered do not affect the "displaying" event calls.
            ShapeBinding shapeBinding;

            if (TryGetDescriptorBinding(shapeMetadata.Type, Enumerable.Empty <string>(), shapeTable, out shapeBinding))
            {
                shapeBinding.ShapeDescriptor.Displaying.Invoke(action => action(displayingContext), _logger);

                // copy all binding sources (all templates for this shape) in order to use them as Localization scopes
                shapeMetadata.BindingSources = shapeBinding.ShapeDescriptor.BindingSources.Where(x => x != null).ToList();
                if (!shapeMetadata.BindingSources.Any())
                {
                    shapeMetadata.BindingSources.Add(shapeBinding.ShapeDescriptor.BindingSource);
                }
            }

            // invoking ShapeMetadata displaying events
            shapeMetadata.Displaying.Invoke(action => action(displayingContext), _logger);

            // use pre-fectched content if available (e.g. coming from specific cache implementation)
            if (displayingContext.ChildContent != null)
            {
                shape.Metadata.ChildContent = displayingContext.ChildContent;
            }
            else
            {
                // now find the actual binding to render, taking alternates into account
                ShapeBinding actualBinding;
                if (TryGetDescriptorBinding(shapeMetadata.Type, shapeMetadata.Alternates, shapeTable, out actualBinding))
                {
                    shapeBinding.ShapeDescriptor.Processing.Invoke(action => action(displayingContext), _logger);

                    // invoking ShapeMetadata processing events
                    await shapeMetadata.Processing.InvokeAsync(processing => processing(shape), _logger);

                    shape.Metadata.ChildContent = await ProcessAsync(actualBinding, shape, context);
                }
                else
                {
                    throw new OrchardException(T("Shape type {0} not found", shapeMetadata.Type));
                }
            }

            foreach (var frameType in shape.Metadata.Wrappers)
            {
                ShapeBinding frameBinding;
                if (TryGetDescriptorBinding(frameType, Enumerable.Empty <string>(), shapeTable, out frameBinding))
                {
                    shape.Metadata.ChildContent = await ProcessAsync(frameBinding, shape, context);
                }
            }

            var displayedContext = new ShapeDisplayedContext
            {
                Shape          = shape,
                ShapeMetadata  = shape.Metadata,
                ChildContent   = shape.Metadata.ChildContent,
                DisplayContext = context
            };

            _shapeDisplayEvents.Invoke(sde =>
            {
                var prior = displayedContext.ChildContent = displayedContext.ShapeMetadata.ChildContent;
                sde.Displayed(displayedContext);
                // update the child content if the context variable has been reassigned
                if (prior != displayedContext.ChildContent)
                {
                    displayedContext.ShapeMetadata.ChildContent = displayedContext.ChildContent;
                }
            }, _logger);

            if (shapeBinding != null)
            {
                shapeBinding.ShapeDescriptor.Displayed.Invoke(action =>
                {
                    var prior = displayedContext.ChildContent = displayedContext.ShapeMetadata.ChildContent;
                    action(displayedContext);
                    // update the child content if the context variable has been reassigned
                    if (prior != displayedContext.ChildContent)
                    {
                        displayedContext.ShapeMetadata.ChildContent = displayedContext.ChildContent;
                    }
                }, _logger);
            }

            // invoking ShapeMetadata displayed events
            shapeMetadata.Displayed.Invoke(action => action(displayedContext), _logger);

            return(shape.Metadata.ChildContent);
        }
예제 #22
0
        public async Task<IHtmlContent> ExecuteAsync(DisplayContext context)
        {
            var shape = context.Value as IShape;

            // non-shape arguments are returned as a no-op
            if (shape == null)
                return CoerceHtmlString(context.Value);

            var shapeMetadata = shape.Metadata;
            // can't really cope with a shape that has no type information
            if (shapeMetadata == null || string.IsNullOrEmpty(shapeMetadata.Type))
                return CoerceHtmlString(context.Value);

            var theme = await _themeManager.GetThemeAsync();
            var shapeTable = _shapeTableManager.GetShapeTable(theme?.Id);

            var displayingContext = new ShapeDisplayingContext
            {
                Shape = shape,
                ShapeMetadata = shapeMetadata,
                DisplayContext = context
            };

            // Evaluate global Shape Display Events
            _shapeDisplayEvents.Invoke(sde => sde.Displaying(displayingContext), _logger);

            // Find base shape association using only the fundamental shape type.
            // Alternates that may already be registered do not affect the "displaying" event calls.
            ShapeBinding shapeBinding;
            if (TryGetDescriptorBinding(shapeMetadata.Type, Enumerable.Empty<string>(), shapeTable, out shapeBinding))
            {
                shapeBinding.ShapeDescriptor.Displaying.Invoke(action => action(displayingContext), _logger);

                // copy all binding sources (all templates for this shape) in order to use them as Localization scopes
                shapeMetadata.BindingSources = shapeBinding.ShapeDescriptor.BindingSources.Where(x => x != null).ToList();
                if (!shapeMetadata.BindingSources.Any())
                {
                    shapeMetadata.BindingSources.Add(shapeBinding.ShapeDescriptor.BindingSource);
                }
            }

            // invoking ShapeMetadata displaying events
            shapeMetadata.Displaying.Invoke(action => action(displayingContext), _logger);

            // use pre-fectched content if available (e.g. coming from specific cache implementation)
            if (displayingContext.ChildContent != null)
            {
                shape.Metadata.ChildContent = displayingContext.ChildContent;
            }
            else
            {
                // now find the actual binding to render, taking alternates into account
                ShapeBinding actualBinding;
                if (TryGetDescriptorBinding(shapeMetadata.Type, shapeMetadata.Alternates, shapeTable, out actualBinding))
                {
                    shapeBinding.ShapeDescriptor.Processing.Invoke(action => action(displayingContext), _logger);

                    // invoking ShapeMetadata processing events
                    await shapeMetadata.Processing.InvokeAsync(processing => processing(shape), _logger);

                    shape.Metadata.ChildContent = await ProcessAsync(actualBinding, shape, context);
                }
                else
                {
                    throw new OrchardException(T("Shape type {0} not found", shapeMetadata.Type));
                }
            }

            foreach (var frameType in shape.Metadata.Wrappers)
            {
                ShapeBinding frameBinding;
                if (TryGetDescriptorBinding(frameType, Enumerable.Empty<string>(), shapeTable, out frameBinding))
                {
                    shape.Metadata.ChildContent = await ProcessAsync(frameBinding, shape, context);
                }
            }

            var displayedContext = new ShapeDisplayedContext
            {
                Shape = shape,
                ShapeMetadata = shape.Metadata,
                ChildContent = shape.Metadata.ChildContent,
                DisplayContext = context
            };

            _shapeDisplayEvents.Invoke(sde =>
            {
                var prior = displayedContext.ChildContent = displayedContext.ShapeMetadata.ChildContent;
                sde.Displayed(displayedContext);
                // update the child content if the context variable has been reassigned
                if (prior != displayedContext.ChildContent)
                    displayedContext.ShapeMetadata.ChildContent = displayedContext.ChildContent;
            }, _logger);

            if (shapeBinding != null)
            {
                shapeBinding.ShapeDescriptor.Displayed.Invoke(action =>
                {
                    var prior = displayedContext.ChildContent = displayedContext.ShapeMetadata.ChildContent;
                    action(displayedContext);
                    // update the child content if the context variable has been reassigned
                    if (prior != displayedContext.ChildContent)
                        displayedContext.ShapeMetadata.ChildContent = displayedContext.ChildContent;
                }, _logger);
            }

            // invoking ShapeMetadata displayed events
            shapeMetadata.Displayed.Invoke(action => action(displayedContext), _logger);

            return shape.Metadata.ChildContent;
        }
예제 #23
0
        public void OnDisplaying(ShapeDisplayingContext context) {
            if (!IsActivable()) {
                return;
            }

            var shape = context.Shape;
            var shapeMetadata = (ShapeMetadata) context.Shape.Metadata;
            var currentTheme = _themeManager.GetRequestTheme(_workContext.HttpContext.Request.RequestContext);
            var shapeTable = _shapeTableManager.GetShapeTable(currentTheme.Id);

            if (!shapeMetadata.Wrappers.Contains("ShapeTracingWrapper")) {
                return;
            }

            var descriptor = shapeTable.Descriptors[shapeMetadata.Type];

            // dump the Shape's content
            var dump = new ObjectDumper(6).Dump(context.Shape, "Model");

            var sb = new StringBuilder();
            ObjectDumper.ConvertToJSon(dump, sb);
            shape._Dump = sb.ToString();

            shape.Template = null;
            shape.OriginalTemplate = descriptor.BindingSource;

            foreach (var extension in new[] { ".cshtml", ".aspx" }) {
                foreach (var alternate in shapeMetadata.Alternates.Reverse().Concat(new [] {shapeMetadata.Type}) ) {
                    var alternateFilename = FormatShapeFilename(alternate, shapeMetadata.Type, shapeMetadata.DisplayType, currentTheme.Location + "/" + currentTheme.Id, extension);
                    if (_webSiteFolder.FileExists(alternateFilename)) {
                        shape.Template = alternateFilename;
                    }
                }
            }

            if(shape.Template == null) {
                shape.Template = descriptor.BindingSource;
            }

            if(shape.Template == null) {
                shape.Template = descriptor.Bindings.Values.FirstOrDefault().BindingSource;
            }

            if (shape.OriginalTemplate == null) {
                shape.OriginalTemplate = descriptor.Bindings.Values.FirstOrDefault().BindingSource;
            }

            try {
                // we know that templates are classes if they contain ':'
                if (!shape.Template.Contains(":") && _webSiteFolder.FileExists(shape.Template)) {
                    shape.TemplateContent = _webSiteFolder.ReadFile(shape.Template);
                }
            }
            catch {
                // the url might be invalid in case of a code shape
            }

            if (shapeMetadata.PlacementSource != null && _webSiteFolder.FileExists(shapeMetadata.PlacementSource)) {
                context.Shape.PlacementContent = _webSiteFolder.ReadFile(shapeMetadata.PlacementSource);
            }

            // Inject the Zone name
            if(shapeMetadata.Type == "Zone") {
                shape.Hint = ((Zone) shape).ZoneName;
            }

            shape.ShapeId = _shapeId++;
        }
예제 #24
0
 public virtual void Displaying(ShapeDisplayingContext context)
 {
 }