protected override void BuildDisplayShape(BuildDisplayContext context)
        {
            if (context.ContentItem.TypeDefinition.Settings.ContainsKey("Stereotype"))
            {
                

                  if (context.ContentItem.TypeDefinition.Settings["Stereotype"] == "Widget" && context.ContentItem.Has(typeof(CustomStyle))) {
                    var cssPart = context.ContentItem.As<CustomStyle>();
                    var customcssstyle = cssPart.CssStyle;
                    if (!string.IsNullOrWhiteSpace(customcssstyle)) {

                        context.Shape.CustomCssStyle = customcssstyle;
                    }
 
                }

            base.BuildDisplayShape(context);

            }
                
                
                
                 
              
        }
 protected override void BuildDisplayShape(BuildDisplayContext context) {
     if (context.DisplayType == "Detail" && context.ContentItem.Has(typeof(CustomCss))) {
         var customCss = context.ContentItem.As<CustomCss>();
         var classes = customCss.CssClass;
         if (!String.IsNullOrWhiteSpace(classes)) {
             foreach (var cssClass in classes.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries)) {
                 context.Shape.Classes.Add(cssClass);
             }
         }
         var id = customCss.CustomId;
         if (!String.IsNullOrWhiteSpace(id)) {
             context.Shape.Attributes.Add("id", id);
         }
         var scripts = (customCss.Scripts ?? String.Empty)
             .Split(new[] {' ', '\r', '\n'}, StringSplitOptions.RemoveEmptyEntries);
         foreach (var script in scripts) {
             if (script.EndsWith(".js", StringComparison.OrdinalIgnoreCase)) {
                 _resourceManager.Value.Include("script", script, null);
             }
             else {
                 _resourceManager.Value.Require("script", script);
             }
         }
     }
     base.BuildDisplayShape(context);
 }
Example #3
0
        public IEnumerable<DriverResultPlacement> GetDisplayPlacement(string contentType) {
            var content = _contentManager.New(contentType);
            const string actualDisplayType = "Detail";

            dynamic itemShape = CreateItemShape("Content");
            itemShape.ContentItem = content;
            itemShape.Metadata.DisplayType = actualDisplayType;

            var context = new BuildDisplayContext(itemShape, content, actualDisplayType, String.Empty, _shapeFactory);
            var workContext = _workContextAccessor.GetContext(_requestContext.HttpContext);
            context.Layout = workContext.Layout;

            BindPlacement(context, actualDisplayType, "Content");

            var placementSettings = new List<DriverResultPlacement>();

            _contentPartDrivers.Invoke(driver => {
                var result = driver.BuildDisplay(context);
                if (result != null) {
                    placementSettings.AddRange(ExtractPlacement(result, context));
                }
            }, Logger);

            _contentFieldDrivers.Invoke(driver => {
                var result = driver.BuildDisplayShape(context);
                if (result != null) {
                    placementSettings.AddRange(ExtractPlacement(result, context));
                }
            }, Logger);

            foreach (var placementSetting in placementSettings) {
                yield return placementSetting;    
            }
        }
 public override void BuildDisplay(BuildDisplayContext context) {
     _drivers.Invoke(driver => {
         var result = driver.BuildDisplay(context);
         if (result != null)
             result.Apply(context);
     }, Logger);
 }
Example #5
0
 protected override void BuildDisplayShape(BuildDisplayContext context)
 {
     if (context.ContentItem.ContentType == "Movie" && context.DisplayType == "Detail") {
         var relatedMovies = GetRelatedMovies(context.ContentItem);
         if (relatedMovies.Any()) {
             context.Shape.SimilarMovies = context.New.SimilarMovies(Movies: relatedMovies);
         }
     }
 }
        protected override void BuildDisplayShape(BuildDisplayContext context)
        {
            var workContext = _workContextAccessor.GetContext();
            var contentItems = workContext.GetState<List<IContent>>("ContentItems");
            if (contentItems == null)
            {
                workContext.SetState("ContentItems", contentItems = new List<IContent>());
            }

            contentItems.Add(context.ContentItem);
        }
        public override void BuildDisplay(BuildDisplayContext context) {
            _drivers.Invoke(driver => {
                var key = "Driver:"+driver.GetType().FullName;
                _profiler.StepStart(key, String.Format("ContentPartDriver: {0}", driver.GetType().FullName));
                var result = driver.BuildDisplay(context);

                if (result != null) {
                    var key2 = "DriverApply:" + driver.GetType().FullName;
                    _profiler.StepStart(key2, String.Format("ApplyDriver", driver.GetType().FullName));
                    result.Apply(context);
                    _profiler.StepStop(key2);
                }

                _profiler.StepStop(key);
                
            }, Logger);
        }
        private void ApplyImplementation(BuildDisplayContext context, string displayType) 
        {
            var placement = context.FindPlacement(_shapeType, _differentiator, _defaultLocation);
            if (string.IsNullOrEmpty(placement.Location) || placement.Location == "-")
                return;

            // parse group placement
            var group = placement.GetGroup();
            if (!String.IsNullOrEmpty(group))
            {
                _groupId = group;
            }

            if (!string.Equals(context.GroupId ?? "", _groupId ?? "", StringComparison.OrdinalIgnoreCase))
                return;

            dynamic parentShape = context.Shape;
            // the zone name is in reference of Layout, e.g. /AsideSecond
            if (placement.IsLayoutZone())
            {
                parentShape = context.Layout;
            }

            var position = placement.GetPosition();
            var zone = placement.GetZone();

            var cachedModel = _cacheService.Get<OutputCachedPartsModel>(_cachedPartMetadata.CacheKey);

            if (cachedModel != null)
            {
                if (String.IsNullOrEmpty(position))
                {
                    parentShape.Zones[zone].Add(context.New.CachedHtml(cachedModel: cachedModel, cacheKey: _cachedPartMetadata.CacheKey));
                }
                else
                {
                    parentShape.Zones[zone].Add(context.New.CachedHtml(cachedModel: cachedModel, cacheKey: _cachedPartMetadata.CacheKey), position);
                }

                return;
            }

            //if we have got this far, then the output does not exist in the cache
            _outputCachedPartsContext.PutCachedPartMetadata(ContentPart, _cachedPartMetadata);
            _driverResultFactory().Apply(context);
        }
Example #9
0
        // TODO: Slight changes made to ApplyDisplay need applying to Editor/Update also
        public void ApplyDisplay(BuildDisplayContext driverContext) {
            var rootShape = driverContext.Shape;
            var content = driverContext.Content;
            var displayType = driverContext.DisplayType;
            var groupId = driverContext.GroupId;
            SocketParentContext parentContext = null;

            var origamiContext = driverContext as BuildContentDisplayContext;
            if (origamiContext != null) {
                if (origamiContext.ParentContext != null) {
                    origamiContext.ParentContext.With<SocketParentContext>(s => {
                        parentContext = s;
                    });
                }
            }

            // Discover if this item has been displayed further up the chain. This prevents recursion.
            if (parentContext!=null && CheckRecursion(content,parentContext,displayType)) {
                var builder1 = _origami.BuildDisplayShape(new RecursionPreventedModel(content), "", displayType, "Sockets", content.ContentItem.ContentType, parentContext.ModelContext);
                _origami.Build(builder1, rootShape);
                return;
            }

            var prefix = "Sockets";
            if (parentContext != null && !String.IsNullOrWhiteSpace(parentContext.Prefix))
            {
                prefix = parentContext.Prefix + "." + prefix;
            }

            // Build Sockets model
            var model = new SocketsModel(content, displayType, parentContext);

            var builder = _origami.Builder(model)
                .WithMode("Display")
                .WithUpdater(null, prefix)
                .WithDisplayType(displayType)
                .WithStereotype("Sockets")
                .WithContentType(content.ContentItem.ContentType)
                    .WithGroup(groupId);
            if (origamiContext != null) {
                builder.WithParent(origamiContext.ParentContext);
                builder.WithParadigms(origamiContext.ParentContext.Paradigms);
            }

            _origami.Build(builder, rootShape);
        }
        protected override void BuildDisplayShape(BuildDisplayContext context) {
            if (context.DisplayType == "Detail" && context.ContentItem.Has(typeof(CustomCss))) {
                var customCss = context.ContentItem.As<CustomCss>();
                var settings = customCss.Settings.GetModel<CustomCssSettings>();
                var classes = customCss.CssClass;
                if (String.IsNullOrWhiteSpace(classes)) {
                    classes = settings.CssClass;
                }
                if (!String.IsNullOrWhiteSpace(classes)) {
                    foreach (var cssClass in classes.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries)) {
                        context.Shape.Classes.Add(cssClass);
                    }
                }
                var id = customCss.CustomId;
                if (String.IsNullOrWhiteSpace(id)) {
                    id = settings.CustomId;
                }
                if (!String.IsNullOrWhiteSpace(id)) {
                    context.Shape.Id = id;
                    context.Shape.Attributes.Add("id", id);
                }
                var scriptList = customCss.Scripts;
                if (String.IsNullOrWhiteSpace(scriptList)) {
                    scriptList = settings.Scripts;
                }
                var scripts = (scriptList ?? String.Empty)
                    .Split(new[] {' ', '\r', '\n'}, StringSplitOptions.RemoveEmptyEntries);
                foreach (var script in scripts) {
                    if (script.EndsWith(".js", StringComparison.OrdinalIgnoreCase)) {
                        _resourceManager.Value.Include("script", script, null);
                    }

                    else if (script.EndsWith(".css", StringComparison.OrdinalIgnoreCase)) {
                        _resourceManager.Value.Include("stylesheet", script, null);
                    }

                    else {
                        var scriptsByName = _resourceManager.Value.FindResource(new RequireSettings() { Name = script, Type = "script" });
                        var stylesByName = _resourceManager.Value.FindResource(new RequireSettings() { Name = script, Type = "stylesheet" });
                        if (scriptsByName != null) _resourceManager.Value.Require("script", script);
                        if (stylesByName != null) _resourceManager.Value.Require("stylesheet", script);
                    }
                }
            }
            base.BuildDisplayShape(context);
        }
        public override void Apply(BuildDisplayContext context) {
            foreach (var result in _results) {

                // copy the ContentPart which was used to render this result to its children
                // so they can assign it to the concrete shapes
                if (result.ContentPart == null && ContentPart != null) {
                    result.ContentPart = ContentPart;
                }

                // copy the ContentField which was used to render this result to its children
                // so they can assign it to the concrete shapes
                if (result.ContentField == null && ContentField != null) {
                    result.ContentField = ContentField;
                }

                result.Apply(context);
            }
        }
        private void SetMessagesRead(BuildDisplayContext ctx, ConversationPart part) {

            if (ctx.DisplayType != "Detail")
                return;

            var user = _workContextAccessor.GetContext().CurrentUser;
            if (user == null)
                return;

            // Get all messages of the conversation where the target is current user
            var messages = _conversationService
                .GetUnreadMessagesQuery(user.Id, part.Id);    

            // Set all to read
            foreach (var message in messages.List()) {
                message.IsRead = true;
            }
        }
        public override void BuildDisplay(BuildDisplayContext context) {
            _drivers.Invoke(driver => {
                var timedResult = _performanceMonitor.Time(() => {
                    var result = driver.BuildDisplay(context);
                    var publish = result != null;
                    if (publish)
                    {
                        result.Apply(context);
                    }

                    return publish;
                });

                if (timedResult.ActionResult && context.ContentPart!=null)
                {
                    _performanceMonitor.PublishMessage(new TimelineMessage
                    {
                        Duration = timedResult.TimerResult.Duration,
                        Offset = timedResult.TimerResult.Offset,
                        StartTime = timedResult.TimerResult.StartTime,
                        EventName = "Driver Build Display",
                        EventCategory = TimelineCategories.Parts.ToGlimpseTimelineCategoryItem(),
                        EventSubText = context.ContentPart.PartDefinition.Name
                    });

                    string stereotype;
                    if (!context.ContentItem.TypeDefinition.Settings.TryGetValue("Stereotype", out stereotype))
                    {
                        stereotype = "Content";
                    }

                    _performanceMonitor.PublishMessage(new PartMessage
                    {
                        ContentItemName = context.ContentItem.GetContentName(),
                        ContentItemType = context.ContentItem.ContentType,
                        ContentItemStereotype = stereotype,
                        ContentItemId = context.ContentItem.Id,
                        Fields = context.ContentPart.Fields,
                        ContentPartType = context.ContentPart.PartDefinition.Name,
                        Duration = timedResult.TimerResult.Duration
                    });
                }
            }, Logger);
        }
        public dynamic BuildDisplay(IContent content, string displayType, string groupId) {
            var contentTypeDefinition = content.ContentItem.TypeDefinition;
            string stereotype;
            if (!contentTypeDefinition.Settings.TryGetValue("Stereotype", out stereotype))
                stereotype = "Content";

            var actualShapeType = stereotype;
            var actualDisplayType = string.IsNullOrWhiteSpace(displayType) ? "Detail" : displayType;

            dynamic itemShape = CreateItemShape(actualShapeType);
            itemShape.ContentItem = content.ContentItem;
            itemShape.Metadata.DisplayType = actualDisplayType;

            var context = new BuildDisplayContext(itemShape, content, actualDisplayType, groupId, _shapeFactory);
            BindPlacement(context, actualDisplayType, stereotype);

            _handlers.Value.Invoke(handler => handler.BuildDisplay(context), Logger);
            return context.Shape;
        }
Example #15
0
        public BuildDisplayContext BuildDisplayContext(IContent content, string displayType, string groupId) {
            var contentTypeDefinition = content.ContentItem.TypeDefinition;
            string stereotype;
            if (!contentTypeDefinition.Settings.TryGetValue("Stereotype", out stereotype))
                stereotype = DefaultStereotype;

            var actualShapeType = stereotype;
            var actualDisplayType = String.IsNullOrWhiteSpace(displayType) ? "Detail" : displayType;
            var itemShape = CreateItemShape(actualShapeType);

            itemShape.ContentItem = content.ContentItem;
            itemShape.Metadata.DisplayType = actualDisplayType;

            var context = new BuildDisplayContext(itemShape, content, actualDisplayType, groupId, _shapeFactory);
            var workContext = _workContextAccessor.GetContext(_requestContext.HttpContext);
            context.Layout = workContext.Layout;

            BindPlacement(context, actualDisplayType, stereotype);

            return context;
        }
 protected override void BuildDisplayShape(BuildDisplayContext context)
    {                       
     base.BuildDisplayShape(context);
         if (context.ContentItem.ContentType == "SummaryWidget")
         {
             // TODO: Bind cart model w custom binder in module (difficult), so we can get current cart more elegantly than through the helper
             CartPart cart = CartHelper.GetCart();                    
             dynamic summaryDisplay = context.New.CartSummary(
                 TotalItems: cart.TotalItemsInCart(),
                 TotalValue: cart.ComputeTotalValue()
             );
             // Check if we are showing the cart - if not, display the widget
             // Matching for string "Cart" will also remove widget from checkout view
             string url =  HttpContext.Current.Request.Url.ToString();
             if (!url.Contains("Cart"))
             {
                 context.Shape.Zones["Content"].Add(summaryDisplay);
             }
             
         }
    }
        protected override void BuildDisplayShape(BuildDisplayContext context) {

            // TODO: Adding these attributes onto *all* items could be seen as a bad thing.
            // But realistically there are tons of situations where it'll be useful. So review this and decide (maybe only if admin?)

            if (context.Shape.ContentItem != null) {
                ContentItem content = context.Shape.ContentItem;
                if (content!=null) {
                    context.Shape.Attributes["data-content-item-id"]=content.Id.ToString();
                    if (content.VersionRecord != null) {
                        context.Shape.Attributes["data-content-item-version-id"] = content.VersionRecord.Id.ToString();
                    }
                    if (Services.Authorizer.Authorize(Permissions.EditContent, content)) {
                        context.Shape.Attributes["data-content-editable"] = "true";
                    }
                    context.Shape.Attributes["data-content-type"] = content.ContentType;
                    var connector = content.As<ConnectorPart>();
                    if (connector != null)
                    {
                        context.Shape.Attributes["data-right-content-type"] = connector.RightContent.ContentItem.ContentType;
                    }
                }
            }
        }
 protected override void BuildDisplayShape(BuildDisplayContext context) {
     if (context.DisplayType == "Detail") {
         _contentTypes.Add(context.ContentItem.ContentType);
     }
 }
 protected override void BuildDisplayShape(BuildDisplayContext context) {
     _itemIds.Add(context.Content.Id);
 }
Example #20
0
 public virtual void BuildDisplay(BuildDisplayContext context)
 {
 }
 public override void Apply(BuildDisplayContext context) {
     foreach (var result in _results) {
         result.Apply(context);
     }
 }
 protected override void BuildDisplayShape(BuildDisplayContext context) {
     _displayed = context.ContentItem;
 }
Example #23
0
 public virtual void Apply(BuildDisplayContext context) { }
Example #24
0
 protected override void BuildDisplayShape(BuildDisplayContext context, TContent instance)
 {
 }
Example #25
0
 protected override void BuildDisplayShape(BuildDisplayContext context) {
     var experimentalSettings = context.ContentItem.TypeDefinition.Settings.GetModel<Settings.ExperimentalSettings>();
     if (experimentalSettings.ShowDebugLinks)
         context.Shape.Zones["Recap"].Add(new ShowDebugLink { ContentItem = context.ContentItem }, "9999");
 }
 public void BuildDisplay(BuildDisplayContext context)
 {
 }
Example #27
0
 public override void Apply(BuildDisplayContext context) {
     ApplyImplementation(context, context.DisplayType);
 }
Example #28
0
 protected virtual void BuildDisplayShape(BuildDisplayContext context)
 {
 }
Example #29
0
        private IEnumerable<DriverResultPlacement> ExtractPlacement(DriverResult result, BuildShapeContext context)
        {
            if (result is CombinedResult)
            {
                foreach (var subResult in ((CombinedResult)result).GetResults())
                {
                    foreach (var placement in ExtractPlacement(subResult, context))
                    {
                        yield return placement;
                    }
                }
            }
            else if (result is ContentShapeResult)
            {
                var contentShapeResult = (ContentShapeResult)result;

                var placement = context.FindPlacement(
                    contentShapeResult.GetShapeType(),
                    contentShapeResult.GetDifferentiator(),
                    contentShapeResult.GetLocation()
                    );

                string zone = placement.Location;
                string position = String.Empty;

                // if no placement is found, it's hidden, e.g., no placement was found for the specific ContentType/DisplayType
                if (placement.Location != null)
                {
                    var delimiterIndex = placement.Location.IndexOf(':');
                    if (delimiterIndex >= 0)
                    {
                        zone = placement.Location.Substring(0, delimiterIndex);
                        position = placement.Location.Substring(delimiterIndex + 1);
                    }
                }

                var content = _contentManager.New(context.ContentItem.ContentType);

                dynamic itemShape = CreateItemShape("Content_Edit");
                itemShape.ContentItem = content;

                if (context is BuildDisplayContext)
                {
                    var newContext = new BuildDisplayContext(itemShape, content, "Detail", "", context.New);
                    BindPlacement(newContext, "Detail", "Content");
                    contentShapeResult.Apply(newContext);
                }
                else
                {
                    var newContext = new BuildEditorContext(itemShape, content, "", context.New);
                    BindPlacement(newContext, null, "Content");
                    contentShapeResult.Apply(newContext);
                }


                yield return new DriverResultPlacement
                {
                    Shape = itemShape.Content,
                    ShapeResult = contentShapeResult,
                    PlacementSettings = new PlacementSettings
                    {
                        ShapeType = contentShapeResult.GetShapeType(),
                        Zone = zone,
                        Position = position,
                        Differentiator = contentShapeResult.GetDifferentiator() ?? String.Empty
                    }
                };
            }
        }
 public override void Apply(BuildDisplayContext context) {
     var templateShape = context.New.DisplayTemplate(TemplateName: TemplateName, Model: Model, Prefix: Prefix);
     context.Shape.Zones[Zone].Add(templateShape, Position);
 }