Esempio n. 1
0
        private void ApplyImplementation(BuildShapeContext context, string displayType)
        {
            //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;
            }

            //ShapeMetadata newShapeMetadata = newShape.Metadata;
            //newShapeMetadata.Prefix = _prefix;
            //newShapeMetadata.DisplayType = displayType;

            //if (String.IsNullOrEmpty(position))
            //{
            //    parentShape.Zones[zone].Add(newShape);
            //}
            //else
            //{
            //    parentShape.Zones[zone].Add(newShape, position);
            //}
        }
Esempio n. 2
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;
            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);
            }
        }
 private static void SetModelProperties(BuildShapeContext context, BlogPostPart blogPost) {
     context.Shape.Blog = blogPost.BlogPart;
 }
        private void BindPlacement(BuildShapeContext context, string displayType, string stereotype) {
            context.FindPlacement = (partShapeType, differentiator, defaultLocation) => {

                var workContext = _workContextAccessor.GetContext(_requestContext.HttpContext);

                var theme = workContext.CurrentTheme;
                var shapeTable = _shapeTableLocator.Value.Lookup(theme.Id);

                var request = _requestContext.HttpContext.Request;

                ShapeDescriptor descriptor;
                if (shapeTable.Descriptors.TryGetValue(partShapeType, out descriptor)) {
                    var placementContext = new ShapePlacementContext {
                        Content = context.ContentItem,
                        ContentType = context.ContentItem.ContentType,
                        Stereotype = stereotype,
                        DisplayType = displayType,
                        Differentiator = differentiator,
                        Path = VirtualPathUtility.AppendTrailingSlash(_virtualPathProvider.ToAppRelative(request.Path)) // get the current app-relative path, i.e. ~/my-blog/foo
                    };

                    // define which location should be used if none placement is hit
                    descriptor.DefaultPlacement = defaultLocation;

                    var placement = descriptor.Placement(placementContext);
                    if (placement != null) {
                        placement.Source = placementContext.Source;
                        return placement;
                    }
                }

                return new PlacementInfo {
                    Location = defaultLocation,
                    Source = String.Empty
                };
            };
        }
Esempio n. 5
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
                    }
                };
            }
        }
        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;
            
            // 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);
            }

            // 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);
            }
        }
Esempio n. 7
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);
            }
        }
        //private void UpdateHotelCount(HotelPart hotelPart)
        //{
        //    var commonPart = hotelPart.As<CommonPart>();
        //    if (commonPart != null && commonPart.Record.Container != null)
        //    {

        //        var destinationPart = hotelPart.DestinationPart
        //                              ??
        //                              this.destinationService.Get(commonPart.Record.Container.Id, VersionOptions.Published).
        //                                  As<DestinationPart>();

        //        // Ensure the "right" set of published posts for the blog is obtained
        //        destinationPart.ContentItem.ContentManager.Flush();
        //        destinationPart.PostCount = hotelService.PostCount(destinationPart);
        //    }
        //}

        private static void SetModelProperties(BuildShapeContext context, HotelPart hotelPart)
        {
            context.Shape.Blog = hotelPart.DestinationPart;
        }
 private void SetModelProperties(BuildShapeContext context, ThreadPart threadPart)
 {
     context.Shape.Forum = threadPart.ForumPart;
 }
Esempio n. 10
0
 private void SetModelProperties(BuildShapeContext context, PostPart postPart) {
     context.Shape.Thread = postPart.ThreadPart;
     if (context.Shape.Metadata.DisplayType != null)
     {
         if (context.Shape.Metadata.DisplayType == "Editor")
         {
             context.Shape.EditorFlavor = GetFlavor(postPart);
             context.Shape.ReturnUrl = HttpContext.Current.Request.UrlReferrer.AbsoluteUri;
         }
     }
 }
Esempio n. 11
0
 private static void SetModelProperties(BuildShapeContext context, RoutePart2 route) {
     context.Shape.Title = route.Record.Title;
     // todo: .Path used to be here, what was this for?
 }
 private static void SetModelProperties(BuildShapeContext context, TimetableAppointmentPart TimetableAppointment) {
     context.Shape.Timetable = TimetableAppointment.TimetablePart;
 }
Esempio n. 13
0
 private static void SetModelProperties(BuildShapeContext context, RoutePart routable) {
     var item = context.Shape;
     item.Title = routable.Title;
     item.Slug = routable.Slug;
     item.Path = routable.Path;
 }
Esempio n. 14
0
 private void SetModelProperties(BuildShapeContext context, PostPart postPart) {
     context.Shape.Thread = postPart.ThreadPart;
 }
        private void BindPlacement(BuildShapeContext context, string displayType, string stereotype, string bindingType) {
            context.FindPlacement = (partShapeType, differentiator, defaultLocation) => {

                var workContext = _workContextAccessor.GetContext(_requestContext.HttpContext);

                var theme = workContext.CurrentTheme;
                var shapeTable = _shapeTableLocator.Value.Lookup(theme.Id);

                ShapeDescriptor descriptor;
                if (shapeTable.Descriptors.TryGetValue(partShapeType, out descriptor)) {
                    var placementContext = new ShapePlacementContext {
                        Content = context.ContentItem,
                        ContentType = context.ContentItem.ContentType,
                        Stereotype = stereotype,
                        DisplayType = displayType,
                        BindingType = bindingType,
                        Differentiator = differentiator,
                        Path = GetPath()
                    };

                    // define which location should be used if none placement is hit
                    descriptor.DefaultPlacement = defaultLocation;

                    var placement = descriptor.Placement(placementContext);
                    if (placement != null) {
                        placement.Source = placementContext.Source;
                        return placement;
                    }
                }

                return new PlacementInfo {
                    Location = defaultLocation,
                    Source = String.Empty
                };
            };
        }
Esempio n. 16
0
 private void SetModelProperties(BuildShapeContext context, ThreadPart threadPart) {
     context.Shape.Forum = threadPart.ForumPart;
     context.Shape.StickyClass = threadPart.IsSticky ? "Sticky" : string.Empty;
 }
Esempio n. 17
0
 private static void SetModelProperties(BuildShapeContext context, EntryPart entryPart)
 {
     context.Shape.Category = entryPart.CategoryPart;
     context.Shape.Company = entryPart.Company;
 }