private void SetParts(BuildShapeContext context)
        {
            var tempPartTemp = context.ContentItem.As <TeamPart>();

            if (tempPartTemp != null)
            {
                this.teamPart = tempPartTemp;
            }

            var tempBusinessUnitPart = context.ContentItem.As <BusinessUnitPart>();

            if (tempBusinessUnitPart != null)
            {
                this.businessUnitPart = tempBusinessUnitPart;
            }

            var tempTicketPart = context.ContentItem.As <TicketPart>();

            if (tempTicketPart != null)
            {
                this.ticketPart = tempTicketPart;
            }

            if (this.contentItem == null)
            {
                this.contentItem = context.ContentItem;
            }

            var contentItemPermissionPart = context.ContentItem.As <ContentItemPermissionPart>();

            if (contentItemPermissionPart != null)
            {
                this.permissionParts.Add(contentItemPermissionPart);
            }
        }
コード例 #2
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);
            //}
        }
コード例 #3
0
        private async Task BindPlacementAsync(BuildShapeContext context, string displayType, string stereotype)
        {
            var theme = await _themeManager.GetThemeAsync();

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

            context.FindPlacement = (partShapeType, differentiator, defaultLocation) => {
                ShapeDescriptor descriptor;
                if (shapeTable.Descriptors.TryGetValue(partShapeType, out descriptor))
                {
                    var placementContext = new ShapePlacementContext
                    {
                        Shape = context.Shape
                    };

                    // 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
                });
            };
        }
コード例 #4
0
        private static object AddAlternates(dynamic shape, BuildShapeContext ctx, string differentiator)
        {
            // automatically add shape alternates for shapes added by fields
            // for fields on dynamic parts the part name is the same as the content type name

            ShapeMetadata metadata = shape.Metadata;

            // if no ContentItem property has been set, assign it
            if (shape.ContentItem == null)
            {
                shape.ContentItem = ctx.ContentItem;
            }

            var    shapeType   = metadata.Type;
            var    fieldName   = differentiator ?? String.Empty;
            var    partName    = ctx.ContentPart.PartDefinition.Name;
            string contentType = shape.ContentItem.ContentType;

            // whether the content type has been created dynamically or not
            var dynamicType = String.Equals(partName, contentType, StringComparison.Ordinal);

            // [ShapeType__FieldName] e.g. Fields/Common.Text-Teaser
            if (!String.IsNullOrEmpty(fieldName))
            {
                metadata.Alternates.Add(shapeType + "__" + EncodeAlternateElement(fieldName));
            }

            // [ShapeType__PartName] e.g. Fields/Common.Text-TeaserPart
            if (!String.IsNullOrEmpty(partName))
            {
                metadata.Alternates.Add(shapeType + "__" + EncodeAlternateElement(partName));
            }

            // [ShapeType]__[ContentType]__[PartName] e.g. Fields/Common.Text-Blog-TeaserPart
            if (!String.IsNullOrEmpty(partName) && !String.IsNullOrEmpty(contentType) && !dynamicType)
            {
                metadata.Alternates.Add(EncodeAlternateElement(shapeType + "__" + contentType + "__" + partName));
            }

            // [ShapeType]__[PartName]__[FieldName] e.g. Fields/Common.Text-TeaserPart-Teaser
            if (!String.IsNullOrEmpty(partName) && !String.IsNullOrEmpty(fieldName))
            {
                metadata.Alternates.Add(EncodeAlternateElement(shapeType + "__" + partName + "__" + fieldName));
            }

            // [ShapeType]__[ContentType]__[FieldName] e.g. Fields/Common.Text-Blog-Teaser
            if (!String.IsNullOrEmpty(contentType) && !String.IsNullOrEmpty(fieldName))
            {
                metadata.Alternates.Add(EncodeAlternateElement(shapeType + "__" + contentType + "__" + fieldName));
            }

            // [ShapeType]__[ContentType]__[PartName]__[FieldName] e.g. Fields/Common.Text-Blog-TeaserPart-Teaser
            if (!String.IsNullOrEmpty(contentType) && !String.IsNullOrEmpty(partName) && !String.IsNullOrEmpty(fieldName) && !dynamicType)
            {
                metadata.Alternates.Add(EncodeAlternateElement(shapeType + "__" + contentType + "__" + partName + "__" + fieldName));
            }

            return(shape);
        }
コード例 #5
0
 /// <summary>
 /// Binds a default placement to the context for a part's driver execution.
 /// </summary>
 /// <param name="context">The execution context.</param>
 /// <param name="defaultSettings">PlacementSetting objects to fall back on.</param>
 private void BindPlacement(
     BuildShapeContext context, IEnumerable <PlacementSettings> defaultSettings)
 {
     context.FindPlacement = (partShapeType, differentiator, defaultLocation) => {
         var mockSetting = new PlacementSettings {
             ShapeType      = partShapeType,
             Differentiator = differentiator
         };
         var defaultSetting = defaultSettings.FirstOrDefault(ps => ps.IsSameAs(mockSetting));
         defaultLocation = defaultSetting == null ? defaultLocation :                                  //may still end up with a null defaultLocation
                           defaultSetting.Zone + (string.IsNullOrEmpty(defaultSetting.Position) ? "" : ":" + defaultSetting.Position);
         defaultLocation = string.IsNullOrWhiteSpace(defaultLocation) ? "Content:1" : defaultLocation; //avoid null fallbacks
         return(new PlacementInfo {
             Location = defaultLocation,
             Source = string.Empty
         });
     };
 }
コード例 #6
0
        private static dynamic AddAlternates(dynamic shape, BuildShapeContext ctx)
        {
            ShapeMetadata metadata = shape.Metadata;

            // if no ContentItem property has been set, assign it
            if (shape.ContentItem == null)
            {
                shape.ContentItem = ctx.ContentItem;
            }

            var shapeType = metadata.Type;

            // [ShapeType]__[Id] e.g. Parts/Common.Metadata-42
            metadata.Alternates.Add(shapeType + "__" + ctx.ContentItem.Id.ToString(CultureInfo.InvariantCulture));

            // [ShapeType]__[ContentType] e.g. Parts/Common.Metadata-BlogPost
            metadata.Alternates.Add(shapeType + "__" + ctx.ContentItem.ContentType);

            return(shape);
        }
コード例 #7
0
 /// <summary>
 /// Extract the PlacementSetting objects for the shapes returned by a driver.
 /// </summary>
 /// <param name="result">The result of executing a Driver.BuildEditor method.</param>
 /// <param name="context">The execution context for the driver.</param>
 /// <param name="typeName">The name of the ContentType we are processing.</param>
 /// <returns>The PlacementSetting objects for the results of the driver.</returns>
 private IEnumerable <PlacementSettings> ProcessEditDriverResult(
     DriverResult result, BuildShapeContext context, string typeName)
 {
     if (result is CombinedResult)
     {
         foreach (var subResult in ((CombinedResult)result).GetResults())
         {
             foreach (var placement in ProcessEditDriverResult(subResult, context, typeName))
             {
                 yield return(placement);
             }
         }
     }
     else if (result is ContentShapeResult)
     {
         var part = result.ContentPart;
         if (part != null)   // sanity check: should always be true
         {
             var  typePartDefinition = part.TypePartDefinition;
             bool hidePlacement      = false;
             if (_frontEndProfileService.MayAllowPartEdit(typePartDefinition, typeName))
             {
                 var field = result.ContentField;
                 if (field != null)   // we ran a driver for a ContentField rather than a ContentPart
                 {
                     hidePlacement = !(_frontEndProfileService.MayAllowFieldEdit(field.PartFieldDefinition));
                 }
             }
             else
             {
                 // don't show anything of this part
                 hidePlacement = true;
             }
             if (hidePlacement)   // Override placement only if the part/field have to be hidden
             {
                 yield return(GetPlacement((ContentShapeResult)result, context, typeName, hidePlacement));
             }
         }
     }
 }
コード例 #8
0
ファイル: PlacementService.cs プロジェクト: zaieda/Coevery
        private void BindPlacement(BuildShapeContext context, string displayType, string stereotype)
        {
            context.FindPlacement = (partShapeType, differentiator, defaultLocation) =>
            {
                var theme      = _siteThemeService.GetSiteTheme();
                var shapeTable = _shapeTableLocator.Lookup(theme.Id);

                var request = _requestContext.HttpContext.Request;

                ShapeDescriptor descriptor;
                if (shapeTable.Descriptors.TryGetValue(partShapeType, out descriptor))
                {
                    var placementContext = new ShapePlacementContext
                    {
                        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
                });
            };
        }
コード例 #9
0
 /// <summary>
 /// Extract the PlacementSetting objects for the shapes returned by a driver.
 /// </summary>
 /// <param name="result">The result of executing a Driver.BuildEditor method.</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="showEditor">A boolean telling whether the results being processed should appear on the frontend.</param>
 /// <returns>The PlacementSetting objects for the results of the driver.</returns>
 private IEnumerable <PlacementSettings> ProcessEditDriverResult(
     DriverResult result, BuildShapeContext context, string typeName, bool showEditor = true)
 {
     if (result is CombinedResult)
     {
         foreach (var subResult in ((CombinedResult)result).GetResults())
         {
             foreach (var placement in ProcessEditDriverResult(subResult, context, typeName, showEditor))
             {
                 yield return(placement);
             }
         }
     }
     else if (result is ContentShapeResult)
     {
         var part = result.ContentPart;
         if (part != null && !showEditor)   // sanity check: part should always be true; override placement only if the part/field have to be hidden
         {
             yield return(GetPlacement((ContentShapeResult)result, context, typeName, !showEditor));
         }
     }
 }
コード例 #10
0
        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
                });
            };
        }
コード例 #11
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
            });
        }
コード例 #12
0
        private void BindPlacement(BuildShapeContext context, string displayType, string stereotype, ModelShapeContext modelContext)
        {
            context.FindPlacement = (partShapeType, differentiator, defaultLocation) =>
            {
                var theme      = _themeService.Value.GetRequestTheme(_requestContext);
                var shapeTable = _shapeTableManager.GetShapeTable(theme.Id);
                var request    = _requestContext.HttpContext.Request;

                ShapeDescriptor descriptor;
                if (shapeTable.Descriptors.TryGetValue(partShapeType, out descriptor))
                {
                    var placementContext = new ModelShapePlacementContext
                    {
                        ModelContext   = modelContext,
                        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
                    };

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

                // Default
                return(new PlacementInfo
                {
                    Location = defaultLocation,
                    Source = String.Empty
                });
            };
        }
コード例 #13
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);
            }
        }
コード例 #14
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
                    }
                });
            }
        }
コード例 #15
0
 private static void SetModelProperties(BuildShapeContext context, BlogPostPart blogPost)
 {
     context.Shape.Blog = blogPost.BlogPart;
 }
コード例 #16
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);
            }
        }
コード例 #17
0
ファイル: PostPartHandler.cs プロジェクト: YSRE/SuperRocket
 private void SetModelProperties(BuildShapeContext context, PostPart postPart)
 {
     context.Shape.Thread = postPart.ThreadPart;
 }
コード例 #18
0
 private static void SetModelProperties(BuildShapeContext context, CasePostPart CasePost)
 {
     context.Shape.Case = CasePost.CasePart;
     var casat = CasePost.Get <CasePostAttribPart>();
 }
コード例 #19
0
ファイル: ContentShapeResult.cs プロジェクト: wangan/Orchard2
        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);
            }
        }
コード例 #20
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);
            }
        }
コード例 #21
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);
            }
        }
コード例 #22
0
ファイル: ThreadPartHandler.cs プロジェクト: six006/NGM.Forum
 private void SetModelProperties(BuildShapeContext context, ThreadPart threadPart)
 {
     context.Shape.Forum       = threadPart.ForumPart;
     context.Shape.StickyClass = threadPart.IsSticky ? "Sticky" : string.Empty;
 }
コード例 #23
0
        private static object CreateShape(BuildShapeContext context, string shapeType)
        {
            IShapeFactory shapeFactory = context.New;

            return(shapeFactory.Create(shapeType));
        }
コード例 #24
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);
            }
        }
コード例 #25
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);
            }
        }