Пример #1
0
        private void BindPlacement(ModelShapeContext context, string displayType, string stereotype, string contentType)
        {
            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   = context,
                        Stereotype     = stereotype,
                        DisplayType    = displayType,
                        Differentiator = differentiator,
                        ContentType    = String.IsNullOrWhiteSpace(contentType)?context.Model.GetType().Name:contentType,
                        // Get the current app-relative path, i.e. ~/my-blog/foo
                        // TODO: This is for Url placement to work. It'd be far better if we could just inject any old strings into a properties dictionary,
                        // or even a dictionary of LazyFields, so work like this doesn't have to happen. Not sure how long ToAppRelative takes but it's
                        // getting called for every single placement op and might never get used...
                        Path = VirtualPathUtility.AppendTrailingSlash(_virtualPathProvider.ToAppRelative(request.Path))
                    };

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

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