Exemplo n.º 1
0
        /// <summary>
        /// Compute the PlacementSetting object for a specific driver result.
        /// </summary>
        /// <param name="result">The driver result.</param>
        /// <param name="context">The execution context for the driver.</param>
        /// <param name="typeName">The name of the ContentType we are processing.</param>
        /// <param name="hidden">A boolean telling whether the results should be hidden on the frontend.</param>
        /// <returns>Th PlacementSetting object for the results being processed.</returns>
        private PlacementSettings GetPlacement(
            ContentShapeResult result, BuildShapeContext context, string typeName, bool hidden = false)
        {
            if (!hidden)
            {
                return(null);         // override placement only if the part/field have to be hidden
            }
            var placement = context.FindPlacement(
                result.GetShapeType(),
                result.GetDifferentiator(),
                result.GetLocation()
                );

            string zone     = hidden ? "-" : placement.Location;
            string position = string.Empty;

            return(new PlacementSettings {
                ShapeType = result.GetShapeType(),
                Zone = zone,
                Position = position,
                Differentiator = result.GetDifferentiator() ?? string.Empty
            });
        }
Exemplo n.º 2
0
        private void ApplyImplementation(BuildShapeContext context, string displayType)
        {
            if (String.IsNullOrEmpty(_differentiator))
            {
                _differentiator = _prefix;
            }

            // Look into specific implementations of placements (like placement.info files)
            var placement = context.FindPlacement((IShape)context.Shape, _differentiator, displayType);

            // If no placement is found, use the default location
            if (placement == null)
            {
                // Look for mapped display type locations
                if (_otherLocations != null)
                {
                    _otherLocations.TryGetValue(displayType, out _defaultLocation);
                }

                placement = new Descriptors.PlacementInfo()
                {
                    Location = _defaultLocation
                };
            }

            // If there are no placement or it's explicitely noop then stop rendering execution
            if (String.IsNullOrEmpty(placement.Location) || placement.Location == "-")
            {
                return;
            }

            // Parse group placement.
            _groupId = placement.GetGroup();

            // If the shape's group doesn't match the currently rendered one, return
            if (!String.Equals(context.GroupId ?? "", _groupId ?? "", StringComparison.OrdinalIgnoreCase))
            {
                return;
            }

            var newShape = _shapeBuilder(context);

            // Ignore it if the driver returned a null shape.
            if (newShape == null)
            {
                return;
            }

            ShapeMetadata newShapeMetadata = newShape.Metadata;

            newShapeMetadata.Prefix          = _prefix;
            newShapeMetadata.DisplayType     = displayType;
            newShapeMetadata.PlacementSource = placement.Source;
            newShapeMetadata.Tab             = placement.GetTab();

            // The _processing callback is used to delay execution of costly initialization
            // that can be prevented by caching
            if (_processing != null)
            {
                newShapeMetadata.OnProcessing(_processing);
            }

            // Apply cache settings
            if (!String.IsNullOrEmpty(_cacheId) && _cache != null)
            {
                _cache(newShapeMetadata.Cache(_cacheId));
            }

            // If a specific shape is provided, remove all previous alternates and wrappers.
            if (!String.IsNullOrEmpty(placement.ShapeType))
            {
                newShapeMetadata.Type = placement.ShapeType;
                newShapeMetadata.Alternates.Clear();
                newShapeMetadata.Wrappers.Clear();
            }

            if (placement.Alternates != null)
            {
                foreach (var alternate in placement.Alternates)
                {
                    newShapeMetadata.Alternates.Add(alternate);
                }
            }

            if (placement.Wrappers != null)
            {
                foreach (var wrapper in placement.Wrappers)
                {
                    newShapeMetadata.Wrappers.Add(wrapper);
                }
            }

            dynamic parentShape = context.Shape;

            if (placement.IsLayoutZone())
            {
                parentShape = context.Layout;
            }

            var position = placement.GetPosition();
            var zones    = placement.GetZones();

            foreach (var zone in zones)
            {
                if (parentShape == null)
                {
                    break;
                }

                var zoneProperty = parentShape.Zones;
                if (zoneProperty != null)
                {
                    // parentShape is a ZoneHolding
                    parentShape = zoneProperty[zone];
                }
                else
                {
                    // try to access it as a member
                    parentShape = parentShape[zone];
                }
            }

            if (String.IsNullOrEmpty(position))
            {
                parentShape.Add(newShape);
            }
            else
            {
                parentShape.Add(newShape, position);
            }
        }
Exemplo n.º 3
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
                    }
                });
            }
        }
Exemplo n.º 4
0
        private void ApplyImplementation(BuildShapeContext 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;

            context.ContentPart = ContentPart;

            var newShape = _shapeBuilder(context);

            // Ignore it if the driver returned a null shape.
            if (newShape == null)
            {
                return;
            }

            // Add a ContentPart property to the final shape.
            if (ContentPart != null && newShape.ContentPart == null)
            {
                newShape.ContentPart = ContentPart;
            }

            // Add a ContentField property to the final shape.
            if (ContentField != null && newShape.ContentField == null)
            {
                newShape.ContentField = ContentField;
            }

            ShapeMetadata newShapeMetadata = newShape.Metadata;

            newShapeMetadata.Prefix          = _prefix;
            newShapeMetadata.DisplayType     = displayType;
            newShapeMetadata.PlacementSource = placement.Source;
            newShapeMetadata.Tab             = placement.GetTab();

            // If a specific shape is provided, remove all previous alternates and wrappers.
            if (!String.IsNullOrEmpty(placement.ShapeType))
            {
                newShapeMetadata.Type = placement.ShapeType;
                newShapeMetadata.Alternates.Clear();
                newShapeMetadata.Wrappers.Clear();
            }

            foreach (var alternate in placement.Alternates)
            {
                newShapeMetadata.Alternates.Add(alternate);
            }

            foreach (var wrapper in placement.Wrappers)
            {
                newShapeMetadata.Wrappers.Add(wrapper);
            }

            // Check if 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();

            if (String.IsNullOrEmpty(position))
            {
                parentShape.Zones[zone].Add(newShape);
            }
            else
            {
                parentShape.Zones[zone].Add(newShape, position);
            }
        }
        private void ApplyImplementation(BuildShapeContext context, string displayType)
        {
            if (!string.Equals(context.GroupId ?? "", _groupId ?? "", StringComparison.OrdinalIgnoreCase))
            {
                return;
            }

            var placement = context.FindPlacement(_shapeType, _differentiator, _defaultLocation);

            if (string.IsNullOrEmpty(placement.Location) || placement.Location == "-")
            {
                return;
            }

            dynamic parentShape = context.Shape;
            var     newShape    = _shapeBuilder(context);

            if (ContentPart != null && newShape.ContentPart == null)
            {
                newShape.ContentPart = ContentPart;
            }

            if (ContentField != null && newShape.ContentField == null)
            {
                newShape.ContentField = ContentField;
            }

            ShapeMetadata newShapeMetadata = newShape.Metadata;

            newShapeMetadata.Prefix          = _prefix;
            newShapeMetadata.DisplayType     = displayType;
            newShapeMetadata.PlacementSource = placement.Source;

            // if a specific shape is provided, remove all previous alternates and wrappers
            if (!String.IsNullOrEmpty(placement.ShapeType))
            {
                newShapeMetadata.Type = placement.ShapeType;
                newShapeMetadata.Alternates.Clear();
                newShapeMetadata.Wrappers.Clear();
            }

            foreach (var alternate in placement.Alternates)
            {
                newShapeMetadata.Alternates.Add(alternate);
            }

            foreach (var wrapper in placement.Wrappers)
            {
                newShapeMetadata.Wrappers.Add(wrapper);
            }

            var delimiterIndex = placement.Location.IndexOf(':');

            if (delimiterIndex < 0)
            {
                parentShape.Zones[placement.Location].Add(newShape);
            }
            else
            {
                var zoneName = placement.Location.Substring(0, delimiterIndex);
                var position = placement.Location.Substring(delimiterIndex + 1);
                parentShape.Zones[zoneName].Add(newShape, position);
            }
        }
Exemplo n.º 6
0
        private async Task ApplyImplementationAsync(BuildShapeContext context, string displayType)
        {
            // If no location is set from the driver, use the one from the context
            if (String.IsNullOrEmpty(_defaultLocation))
            {
                _defaultLocation = context.DefaultZone;
            }

            // Look into specific implementations of placements (like placement.json files)
            var placement = context.FindPlacement(_shapeType, _differentiator, displayType, context);

            // Look for mapped display type locations
            if (_otherLocations != null)
            {
                string displayTypePlacement;
                if (_otherLocations.TryGetValue(displayType, out displayTypePlacement))
                {
                    _defaultLocation = displayTypePlacement;
                }
            }

            // If no placement is found, use the default location
            if (placement == null)
            {
                placement = new PlacementInfo()
                {
                    Location = _defaultLocation
                };
            }

            if (placement.Location == null)
            {
                // If a placement was found without actual location, use the default.
                // It can happen when just setting alternates or wrappers for instance.
                placement.Location = _defaultLocation;
            }

            if (placement.DefaultPosition == null)
            {
                placement.DefaultPosition = context.DefaultPosition;
            }


            // If there are no placement or it's explicitely noop then stop rendering execution
            if (String.IsNullOrEmpty(placement.Location) || placement.Location == "-")
            {
                return;
            }

            // Parse group placement.
            _groupId = placement.GetGroup() ?? _groupId;

            // If the shape's group doesn't match the currently rendered one, return
            if (!String.Equals(context.GroupId ?? "", _groupId ?? "", StringComparison.OrdinalIgnoreCase))
            {
                return;
            }

            var newShape = Shape = await _shapeBuilder(context);

            // Ignore it if the driver returned a null shape.
            if (newShape == null)
            {
                return;
            }

            ShapeMetadata newShapeMetadata = newShape.Metadata;

            newShapeMetadata.Prefix          = _prefix;
            newShapeMetadata.Name            = _differentiator ?? _shapeType;
            newShapeMetadata.DisplayType     = displayType;
            newShapeMetadata.PlacementSource = placement.Source;
            newShapeMetadata.Tab             = placement.GetTab();
            newShapeMetadata.Type            = _shapeType;

            if (_displaying != null)
            {
                newShapeMetadata.OnDisplaying(_displaying);
            }

            // The _processing callback is used to delay execution of costly initialization
            // that can be prevented by caching
            if (_processing != null)
            {
                newShapeMetadata.OnProcessing(_processing);
            }

            // Apply cache settings
            if (!String.IsNullOrEmpty(_cacheId) && _cache != null)
            {
                _cache(newShapeMetadata.Cache(_cacheId));
            }

            // If a specific shape is provided, remove all previous alternates and wrappers.
            if (!String.IsNullOrEmpty(placement.ShapeType))
            {
                newShapeMetadata.Type = placement.ShapeType;
                newShapeMetadata.Alternates.Clear();
                newShapeMetadata.Wrappers.Clear();
            }

            if (placement != null)
            {
                if (placement.Alternates != null)
                {
                    newShapeMetadata.Alternates.AddRange(placement.Alternates);
                }

                if (placement.Wrappers != null)
                {
                    newShapeMetadata.Wrappers.AddRange(placement.Wrappers);
                }
            }

            dynamic parentShape = context.Shape;

            if (placement.IsLayoutZone())
            {
                parentShape = context.Layout;
            }

            var position = placement.GetPosition();
            var zones    = placement.GetZones();

            foreach (var zone in zones)
            {
                if (parentShape == null)
                {
                    break;
                }

                var zoneProperty = parentShape.Zones;
                if (zoneProperty != null)
                {
                    // parentShape is a ZoneHolding
                    parentShape = zoneProperty[zone];
                }
                else
                {
                    // try to access it as a member
                    parentShape = parentShape[zone];
                }
            }

            position = !String.IsNullOrEmpty(position) ? position : null;

            if (parentShape is ZoneOnDemand zoneOnDemand)
            {
                await zoneOnDemand.AddAsync(newShape, position);
            }
            else if (parentShape is Shape shape)
            {
                shape.Add(newShape, position);
            }
        }
Exemplo n.º 7
0
        private void ApplyImplementation(BuildShapeContext context, string displayType)
        {
            var placement = context.FindPlacement(_shapeType, _differentiator, _defaultLocation);

            if (String.IsNullOrEmpty(placement.Location) || placement.Location == "-")
            {
                return;
            }

            // Parse group placement.
            _groupId = placement.GetGroup();

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

            var newShape = _shapeBuilder(context);

            // Ignore it if the driver returned a null shape.
            if (newShape == null)
            {
                return;
            }

            ShapeMetadata newShapeMetadata = newShape.Metadata;

            newShapeMetadata.Prefix          = _prefix;
            newShapeMetadata.DisplayType     = displayType;
            newShapeMetadata.PlacementSource = placement.Source;
            newShapeMetadata.Tab             = placement.GetTab();

            // The _processing callback is used to delay execution of costly initialization
            // that can be prevented by caching
            if (_processing != null)
            {
                newShapeMetadata.OnProcessing(_processing);
            }

            // Apply cache settings
            if (!String.IsNullOrEmpty(_cacheId) && _cache != null)
            {
                _cache(newShapeMetadata.Cache(_cacheId));
            }

            // If a specific shape is provided, remove all previous alternates and wrappers.
            if (!String.IsNullOrEmpty(placement.ShapeType))
            {
                newShapeMetadata.Type = placement.ShapeType;
                newShapeMetadata.Alternates.Clear();
                newShapeMetadata.Wrappers.Clear();
            }

            foreach (var alternate in placement.Alternates)
            {
                newShapeMetadata.Alternates.Add(alternate);
            }

            foreach (var wrapper in placement.Wrappers)
            {
                newShapeMetadata.Wrappers.Add(wrapper);
            }

            dynamic parentShape = context.Shape;

            if (placement.IsLayoutZone())
            {
                parentShape = context.Layout;
            }

            var position = placement.GetPosition();
            var zones    = placement.GetZones();

            foreach (var zone in zones)
            {
                parentShape = parentShape.Zones[zone];
            }

            if (String.IsNullOrEmpty(position))
            {
                parentShape.Add(newShape);
            }
            else
            {
                parentShape.Add(newShape, position);
            }
        }
Exemplo n.º 8
0
        private void ApplyImplementation(BuildShapeContext context, string displayType)
        {
            if (!string.Equals(context.GroupId ?? "", _groupId ?? "", StringComparison.OrdinalIgnoreCase))
            {
                return;
            }

            var placement = context.FindPlacement(_shapeType, _differentiator, _defaultLocation);

            if (string.IsNullOrEmpty(placement.Location) || placement.Location == "-")
            {
                return;
            }

            dynamic parentShape = context.Shape;

            context.ContentPart = ContentPart;

            var newShape = _shapeBuilder(context);

            // ignore it if the driver returned a null shape
            if (newShape == null)
            {
                return;
            }

            // add a ContentPart property to the final shape
            if (ContentPart != null && newShape.ContentPart == null)
            {
                newShape.ContentPart = ContentPart;
            }

            // add a ContentField property to the final shape
            if (ContentField != null && newShape.ContentField == null)
            {
                newShape.ContentField = ContentField;
            }

            ShapeMetadata newShapeMetadata = newShape.Metadata;

            newShapeMetadata.Prefix          = _prefix;
            newShapeMetadata.DisplayType     = displayType;
            newShapeMetadata.PlacementSource = placement.Source;

            // if a specific shape is provided, remove all previous alternates and wrappers
            if (!String.IsNullOrEmpty(placement.ShapeType))
            {
                newShapeMetadata.Type = placement.ShapeType;
                newShapeMetadata.Alternates.Clear();
                newShapeMetadata.Wrappers.Clear();
            }

            foreach (var alternate in placement.Alternates)
            {
                newShapeMetadata.Alternates.Add(alternate);
            }

            foreach (var wrapper in placement.Wrappers)
            {
                newShapeMetadata.Wrappers.Add(wrapper);
            }

            // copy the current location for further processing
            var localPlacement = placement.Location;

            // the zone name is in reference of Layout, e.g. /AsideSecond
            if (placement.Location.StartsWith("/"))
            {
                localPlacement = placement.Location.Substring(1);
                parentShape    = context.Layout;
            }

            var delimiterIndex = localPlacement.IndexOf(':');

            if (delimiterIndex < 0)
            {
                parentShape.Zones[localPlacement].Add(newShape);
            }
            else
            {
                var zoneName = localPlacement.Substring(0, delimiterIndex);
                var position = localPlacement.Substring(delimiterIndex + 1);
                parentShape.Zones[zoneName].Add(newShape, position);
            }
        }
Exemplo n.º 9
0
        private void ApplyImplementation(BuildShapeContext context, string displayType)
        {
            if (!string.Equals(context.GroupId ?? "", _groupId ?? "", StringComparison.OrdinalIgnoreCase))
            {
                return;
            }

            var placement = context.FindPlacement(_shapeType, _differentiator, _defaultLocation);

            if (string.IsNullOrEmpty(placement.Location) || placement.Location == "-")
            {
                return;
            }

            dynamic parentShape = context.Shape;
            dynamic newShape;
            var     key   = _keyBuilder();
            var     cache = _cacheAccessor(key);

            if (cache.Html != null)
            {
                newShape = context.New.CachedShape(ChildContent: cache.Html);
            }
            else
            {
                newShape = _shapeBuilder(context);
                newShape.CacheMetadata = cache;
            }

            // Only need to bother with metadata if result isn't cached
            // TODO: Maybe some will end up useful anyway, e.g. placement source, displaytype
            if (cache.Html == null)
            {
                ShapeMetadata newShapeMetadata = newShape.Metadata;
                newShapeMetadata.Prefix          = _prefix;
                newShapeMetadata.DisplayType     = displayType;
                newShapeMetadata.PlacementSource = placement.Source;

                // if a specific shape is provided, remove all previous alternates and wrappers
                if (!String.IsNullOrEmpty(placement.ShapeType))
                {
                    newShapeMetadata.Type = placement.ShapeType;
                    newShapeMetadata.Alternates.Clear();
                    newShapeMetadata.Wrappers.Clear();
                }

                foreach (var alternate in placement.Alternates)
                {
                    newShapeMetadata.Alternates.Add(alternate);
                }

                foreach (var wrapper in placement.Wrappers)
                {
                    newShapeMetadata.Wrappers.Add(wrapper);
                }
            }

            var delimiterIndex = placement.Location.IndexOf(':');

            if (delimiterIndex < 0)
            {
                parentShape.Zones[placement.Location].Add(newShape);
            }
            else
            {
                var zoneName = placement.Location.Substring(0, delimiterIndex);
                var position = placement.Location.Substring(delimiterIndex + 1);
                parentShape.Zones[zoneName].Add(newShape, position);
            }
        }