DriverResult IContentPartDriver.UpdateEditor(UpdateEditorContext context)
        {
            var part = context.ContentItem.As <TContent>();

            if (part == null)
            {
                return(null);
            }

            // Checking if the editor needs to be updated (e.g. if any of the shapes were not hidden).
            DriverResult editor = Editor(part, context.New);
            IEnumerable <ContentShapeResult> contentShapeResults = editor.GetShapeResults();

            if (contentShapeResults.Any(contentShapeResult =>
                                        contentShapeResult == null || contentShapeResult.WasDisplayed(context)))
            {
                DriverResult result = Editor(part, context.Updater, context.New);

                if (result != null)
                {
                    result.ContentPart = part;
                }

                return(result);
            }

            return(editor);
        }
예제 #2
0
        private static IEnumerable <ContentShapeResult> GetShapeResults(DriverResult driverResult)
        {
            if (driverResult is CombinedResult)
            {
                return(((CombinedResult)driverResult).GetResults().Select(result => result as ContentShapeResult));
            }

            return(new[] { driverResult as ContentShapeResult });
        }
예제 #3
0
        DriverResult IContentPartDriver.UpdateEditor(UpdateEditorContext context)
        {
            var part = context.ContentItem.As <TContent>();

            if (part == null)
            {
                return(null);
            }

            // checking if the editor needs to be updated (e.g. if it was not hidden)
            var editor = Editor(part, context.New) as ContentShapeResult;

            if (editor != null)
            {
                ShapeDescriptor descriptor;
                if (context.ShapeTable.Descriptors.TryGetValue(editor.GetShapeType(), out descriptor))
                {
                    var placementContext = new ShapePlacementContext {
                        Content        = part.ContentItem,
                        ContentType    = part.ContentItem.ContentType,
                        Differentiator = editor.GetDifferentiator(),
                        DisplayType    = null,
                        Path           = context.Path
                    };

                    var location = descriptor.Placement(placementContext).Location;

                    if (String.IsNullOrEmpty(location) || location == "-")
                    {
                        return(editor);
                    }

                    var editorGroup  = editor.GetGroup() ?? "";
                    var contextGroup = context.GroupId ?? "";

                    if (!String.Equals(editorGroup, contextGroup, StringComparison.OrdinalIgnoreCase))
                    {
                        return(editor);
                    }
                }
            }

            DriverResult result = Editor(part, context.Updater, context.New);

            if (result != null)
            {
                result.ContentPart = part;
            }

            return(result);
        }
        DriverResult IContentFieldDriver.BuildEditorShape(BuildEditorContext context)
        {
            return(Process(context.ContentItem, (part, field) => {
                DriverResult result = Editor(part, field, context.New);

                if (result != null)
                {
                    result.ContentPart = part;
                    result.ContentField = field;
                }

                return result;
            }, context.Logger));
        }
        DriverResult IContentFieldDriver.BuildDisplayShape(BuildDisplayContext context)
        {
            return(Process(context.ContentItem, (part, field) => {
                DriverResult result = Display(part, field, context.DisplayType, context.New);

                if (result != null)
                {
                    result.ContentPart = part;
                    result.ContentField = field;
                }

                return result;
            }, context.Logger));
        }
예제 #6
0
        DriverResult IContentFieldDriver.UpdateEditorShape(UpdateEditorContext context)
        {
            return(Process(context.ContentItem, (part, field) => {
                DriverResult result = Editor(part, field, context.Updater, context.New);

                if (result != null)
                {
                    result.ContentPart = part;
                    result.ContentField = field;
                }

                return result;
            }));
        }
예제 #7
0
        private DriverResult Filter(DriverResult driverResult, ContentField field) {
            DriverResult result = null;
            var combinedResult = driverResult as CombinedResult;
            var contentShapeResult = driverResult as ContentShapeResult;

            if (combinedResult != null) {
                result = combinedResult.GetResults().SingleOrDefault(x => x.ContentField != null && x.ContentField.Name == field.Name);
            }
            else if (contentShapeResult != null) {
                result = contentShapeResult.ContentField != null && contentShapeResult.ContentField.Name == field.Name ? contentShapeResult : driverResult;
            }

            return result;
        }
예제 #8
0
        DriverResult IContentPartDriver.BuildEditor(BuildEditorContext context)
        {
            var part = context.ContentItem.As <TContent>();

            if (part == null)
            {
                return(null);
            }

            DriverResult result = Editor(part, context.New);

            if (result != null)
            {
                result.ContentPart = part;
            }

            return(result);
        }
예제 #9
0
        DriverResult IContentPartDriver.BuildDisplay(BuildDisplayContext context)
        {
            var part = context.ContentItem.As <TContent>();

            if (part == null)
            {
                return(null);
            }

            DriverResult result = Display(part, context.DisplayType, context.New);

            if (result != null)
            {
                result.ContentPart = part;
            }

            return(result);
        }
        DriverResult IContentFieldDriver.UpdateEditorShape(UpdateEditorContext context)
        {
            return(Process(context.ContentItem, (part, field) => {
                // Checking if the editor needs to be updated (e.g. if any of the shapes were not hidden).
                DriverResult editor = Editor(part, field, context.New);
                IEnumerable <ContentShapeResult> contentShapeResults = editor.GetShapeResults();

                if (contentShapeResults.Any(contentShapeResult =>
                                            contentShapeResult == null || contentShapeResult.WasDisplayed(context)))
                {
                    DriverResult result = Editor(part, field, context.Updater, context.New);

                    if (result != null)
                    {
                        result.ContentPart = part;
                        result.ContentField = field;
                    }

                    return result;
                }

                return editor;
            }, context.Logger));
        }
예제 #11
0
        DriverResult IContentPartDriver.UpdateEditor(UpdateEditorContext context)
        {
            var part = context.ContentItem.As <TContent>();

            if (part == null)
            {
                return(null);
            }

            // checking if the editor needs to be updated (e.g. if any of the shapes were not hidden)
            DriverResult editor = Editor(part, context.New);
            IEnumerable <ContentShapeResult> contentShapeResults = GetShapeResults(editor);

            if (contentShapeResults.Any(contentShapeResult => {
                if (contentShapeResult == null)
                {
                    return(true);
                }

                ShapeDescriptor descriptor;
                if (context.ShapeTable.Descriptors.TryGetValue(contentShapeResult.GetShapeType(), out descriptor))
                {
                    var placementContext = new ShapePlacementContext {
                        Content = part.ContentItem,
                        ContentType = part.ContentItem.ContentType,
                        Differentiator = contentShapeResult.GetDifferentiator(),
                        DisplayType = null,
                        Path = context.Path
                    };

                    var placementInfo = descriptor.Placement(placementContext);

                    var location = placementInfo.Location;

                    if (String.IsNullOrEmpty(location) || location == "-")
                    {
                        return(false);
                    }

                    var editorGroup = contentShapeResult.GetGroup();
                    if (string.IsNullOrEmpty(editorGroup))
                    {
                        editorGroup = placementInfo.GetGroup() ?? "";
                    }
                    var contextGroup = context.GroupId ?? "";

                    if (!String.Equals(editorGroup, contextGroup, StringComparison.OrdinalIgnoreCase))
                    {
                        return(false);
                    }
                }

                return(true);
            }))
            {
                DriverResult result = Editor(part, context.Updater, context.New);

                if (result != null)
                {
                    result.ContentPart = part;
                }

                return(result);
            }

            return(editor);
        }
예제 #12
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
                    }
                };
            }
        }