コード例 #1
0
 /// <summary>
 /// This extension method can be used for easy media part creation. Adds all necessary parts and settings to the part.
 /// </summary>
 public static ContentTypeDefinitionBuilder AsMedia(this ContentTypeDefinitionBuilder builder)
 {
     return(builder
            .WithSetting("Stereotype", "Media")
            .WithPart("CommonPart")
            .WithPart("MediaPart")
            .WithPart("TitlePart"));
 }
コード例 #2
0
        public override IEnumerable <TemplateViewModel> TypeEditorUpdate(ContentTypeDefinitionBuilder builder, IUpdateModel updateModel)
        {
            var model = new ExperimentalSettings();

            updateModel.TryUpdateModel(model, "ExperimentalSettings", null, null);
            builder
            .WithSetting("ExperimentalSettings.ShowDebugLinks", model.ShowDebugLinks ? true.ToString() : null);

            yield return(DefinitionTemplate(model));
        }
コード例 #3
0
        public override IEnumerable <TemplateViewModel> TypeEditorUpdate(ContentTypeDefinitionBuilder builder, IUpdateModel updateModel)
        {
            var model = new SecurableContentItemsSettingsViewModel();

            updateModel.TryUpdateModel(model, "SecurableContentItemsSettingsViewModel", null, null);

            builder.WithSetting("ContentPermissionsTypeSettings.SecurableContentItems", model.SecurableContentItems.ToString());

            yield return(DefinitionTemplate(model));
        }
コード例 #4
0
        public override IEnumerable <TemplateViewModel> TypeEditorUpdate(ContentTypeDefinitionBuilder builder, IUpdateModel updateModel)
        {
            var model = new TypeIndexing();

            updateModel.TryUpdateModel(model, "TypeIndexing", null, null);
            builder.WithSetting("TypeIndexing.Indexes", model.Indexes);

            CreateIndexingTasks();

            yield return(DefinitionTemplate(model));
        }
コード例 #5
0
        /// <summary>
        /// Removes any custom placement for a specific shape
        /// </summary>
        public static ContentTypeDefinitionBuilder ResetPlacement(this ContentTypeDefinitionBuilder builder, PlacementType placementType, string shapeType, string differentiator)
        {
            var serializer        = new JavaScriptSerializer();
            var placementSettings = GetPlacement(builder.Build(), placementType).ToList();

            placementSettings = placementSettings.Where(x => x.ShapeType != shapeType && x.Differentiator != differentiator).ToList();

            var placement = serializer.Serialize(placementSettings.ToArray());

            return(builder.WithSetting("ContentTypeSettings.Placement." + placementType, placement));
        }
コード例 #6
0
        public override IEnumerable <TemplateViewModel> TypeEditorUpdate(ContentTypeDefinitionBuilder builder, IUpdateModel updateModel)
        {
            var model = new ContentTypeSettingsViewModel();

            updateModel.TryUpdateModel(model, "ContentTypeSettingsViewModel", null, null);

            builder.Creatable(model.Creatable);
            builder.Draftable(model.Draftable);
            builder.WithSetting("Stereotype", model.Stereotype);

            yield return(DefinitionTemplate(model));
        }
コード例 #7
0
        public override IEnumerable <TemplateViewModel> TypeEditorUpdate(ContentTypeDefinitionBuilder builder, IUpdateModel updateModel)
        {
            var settings = builder.Current.Settings;

            if (settings.ContainsKey("Stereotype") && settings["Stereotype"] == "Media")
            {
                var model = new MediaFileNameEditorSettings();
                if (updateModel.TryUpdateModel(model, "MediaFileNameEditorSettings", null, null))
                {
                    builder.WithSetting("MediaFileNameEditorSettings.ShowFileNameEditor", model.ShowFileNameEditor.ToString());
                }
            }
            return(base.TypeEditorUpdate(builder, updateModel));
        }
コード例 #8
0
        /// <summary>
        /// Merges a given content type definition provided in a XML format into a content type definition builder.
        /// </summary>
        /// <param name="element">The XML content type definition.</param>
        /// <param name="contentTypeDefinitionBuilder">The content type definition builder.</param>
        public void Merge(XElement element, ContentTypeDefinitionBuilder contentTypeDefinitionBuilder)
        {
            Argument.ThrowIfNull(element, nameof(element));
            Argument.ThrowIfNull(contentTypeDefinitionBuilder, nameof(contentTypeDefinitionBuilder));

            // Merge name
            contentTypeDefinitionBuilder.Named(XmlConvert.DecodeName(element.Name.LocalName));


            // Merge display name
            if (element.Attribute("DisplayName") != null)
            {
                contentTypeDefinitionBuilder.DisplayedAs(element.Attribute("DisplayName").Value);
            }

            // Merge settings
            foreach (var setting in _settingsFormatter.Map(element))
            {
                contentTypeDefinitionBuilder.WithSetting(setting.Key, setting.Value);
            }

            // Merge parts
            foreach (var iter in element.Elements())
            {
                var partElement = iter;
                var partName    = XmlConvert.DecodeName(partElement.Name.LocalName);
                if (partName == "remove")
                {
                    var nameAttribute = partElement.Attribute("name");
                    if (nameAttribute != null)
                    {
                        contentTypeDefinitionBuilder.RemovePart(nameAttribute.Value);
                    }
                }
                else
                {
                    contentTypeDefinitionBuilder.WithPart(
                        partName,
                        partBuilder =>
                    {
                        foreach (var setting in _settingsFormatter.Map(partElement))
                        {
                            partBuilder.WithSetting(setting.Key, setting.Value);
                        }
                    });
                }
            }
        }
コード例 #9
0
ファイル: EditorEvents.cs プロジェクト: omidam81/teeyoot.com
        public override IEnumerable <TemplateViewModel> TypeEditorUpdate(ContentTypeDefinitionBuilder builder, IUpdateModel updateModel)
        {
            var previous = builder.Current.Settings.GetModel <TypeIndexing>();

            var model = new TypeIndexing();

            updateModel.TryUpdateModel(model, "TypeIndexing", null, null);
            builder.WithSetting("TypeIndexing.Indexes", model.Indexes);

            // create indexing tasks only if settings have changed
            if (Clean(model.Indexes) != Clean(previous.Indexes))
            {
                // if a an index is added, all existing content items need to be re-indexed
                CreateIndexingTasks();
            }

            yield return(DefinitionTemplate(model));
        }
コード例 #10
0
        private PlacementSettings[] SetCurrentPlacement(
            ContentTypeDefinition contentTypeDefinition, IEnumerable <PlacementSettings> newPlacements)
        {
            var placementsArray = newPlacements.ToArray();

            if (_currentPlacement == null)
            {
                _currentPlacement = new Dictionary <string, PlacementSettings[]>();
            }
            if (_currentPlacement.ContainsKey(contentTypeDefinition.Name))
            {
                _currentPlacement.Remove(contentTypeDefinition.Name);
            }
            _currentPlacement.Add(contentTypeDefinition.Name, placementsArray);

            // write the placement settings as a setting for the type, by serializing them all
            var serializer = new JavaScriptSerializer();

            if (_typeBuilder.Current.Name == contentTypeDefinition.Name)
            {
                _typeBuilder.WithSetting("ContentTypeSettings.Placement.ProfileFrontEndEditor",
                                         serializer.Serialize(placementsArray));
            }
            else
            {
                contentTypeDefinition.Settings["ContentTypeSettings.Placement.ProfileFrontEndEditor"] =
                    serializer.Serialize(placementsArray);

                // persist changes: The type definition is persisted already after these events are processed
                _contentDefinitionManager.StoreTypeDefinition(contentTypeDefinition);
                // schedules a re-evaluation of the shell
                _settingsManagerEventHandlers.Value.Invoke(x => x.Saved(_shellSettings), Logger);
            }

            return(placementsArray);
        }
コード例 #11
0
 public static ContentTypeDefinitionBuilder Versionable(this ContentTypeDefinitionBuilder builder, bool versionable = true)
 {
     return(builder.WithSetting("Versionable", versionable.ToString()));
 }
コード例 #12
0
 public static ContentTypeDefinitionBuilder Placeable(this ContentTypeDefinitionBuilder builder, bool placeable = true)
 {
     return(builder.WithSetting("ContentTypeLayoutSettings.Placeable", placeable.ToString()));
 }
コード例 #13
0
 public static ContentTypeDefinitionBuilder Indexed(this ContentTypeDefinitionBuilder builder)
 {
     return(builder.WithSetting("TypeIndexing.Included", "true"));
 }
コード例 #14
0
 public static ContentTypeDefinitionBuilder Draftable(this ContentTypeDefinitionBuilder builder, bool draftable = true)
 {
     return(builder.WithSetting("Draftable", draftable.ToString()));
 }
コード例 #15
0
 public static ContentTypeDefinitionBuilder Stereotype(this ContentTypeDefinitionBuilder builder, string stereotype)
 {
     return(builder.WithSetting("Stereotype", stereotype));
 }
コード例 #16
0
 public static ContentTypeDefinitionBuilder Indexed(this ContentTypeDefinitionBuilder builder, params string[] indexes)
 {
     return(builder.WithSetting("TypeIndexing.Indexes", string.Join(",", indexes ?? new string[0])));
 }
コード例 #17
0
        private PlacementSettings[] SetCurrentPlacement(
            ContentTypeDefinition contentTypeDefinition, IEnumerable <PlacementSettings> newPlacements)
        {
            // create the dictioanry if it does not exist (i.e. the first time this method
            // is ever called in a request)
            if (_currentPlacement == null)
            {
                _currentPlacement = new Dictionary <string, Dictionary <string, Dictionary <string, PlacementSettings> > >();
            }
            // add a Dictionary for the ContentType we are processing
            if (!_currentPlacement.ContainsKey(contentTypeDefinition.Name))
            {
                _currentPlacement.Add(contentTypeDefinition.Name,
                                      new Dictionary <string, Dictionary <string, PlacementSettings> >());
            }
            // dictionary of placements for this type
            var placementsForType = _currentPlacement[contentTypeDefinition.Name];

            // update placements for this type
            foreach (var placement in newPlacements)
            {
                // If we already had some information for this ShapeType
                if (placementsForType.ContainsKey(placement.ShapeType))
                {
                    // update setting: we need to further drill things down on the differentiation
                    // this will generally not matter for parts, but it is required to correctly
                    // manage ContentFields, that generally share a single ShapeType.
                    var differentPlacements = placementsForType[placement.ShapeType];
                    if (differentPlacements.ContainsKey(placement.Differentiator))
                    {
                        // update
                        differentPlacements[placement.Differentiator] = placement;
                    }
                    else
                    {
                        // add
                        differentPlacements.Add(placement.Differentiator, placement);
                    }
                }
                else
                {
                    // add settings for this ShapeType
                    placementsForType.Add(placement.ShapeType,
                                          new Dictionary <string, PlacementSettings>());
                    placementsForType[placement.ShapeType].Add(placement.Differentiator, placement);
                }
            }

            // pull the settings from the dictionary: for each shapeType we have a dictionary
            // of settings
            var placementsArray = placementsForType // Dictionary<string, Dictionary<string, PlacementSettings>>
                                  .SelectMany(kvp => kvp.Value.Values)
                                  .ToArray();

            // write the placement settings as a setting for the type, by serializing them all
            var serializer = new JavaScriptSerializer();

            if (_typeBuilder.Current.Name == contentTypeDefinition.Name)
            {
                _typeBuilder.WithSetting("ContentTypeSettings.Placement.ProfileFrontEndEditor",
                                         serializer.Serialize(placementsArray));
            }
            else
            {
                contentTypeDefinition.Settings["ContentTypeSettings.Placement.ProfileFrontEndEditor"] =
                    serializer.Serialize(placementsArray);

                // persist changes: The type definition is persisted already after these events are processed
                _contentDefinitionManager.StoreTypeDefinition(contentTypeDefinition);
                // schedules a re-evaluation of the shell
                _settingsManagerEventHandlers.Value.Invoke(x => x.Saved(_shellSettings), Logger);
            }

            return(placementsArray);
        }
コード例 #18
0
        /// <summary>
        /// Defines a custom placement
        /// </summary>
        public static ContentTypeDefinitionBuilder Placement(this ContentTypeDefinitionBuilder builder, PlacementType placementType, string shapeType, string differentiator, string zone, string position)
        {
            var placement = AddPlacement(builder.Build(), placementType, shapeType, differentiator, zone, position);

            return(builder.WithSetting("ContentTypeSettings.Placement." + placementType, placement));
        }
コード例 #19
0
 public static ContentTypeDefinitionBuilder Securable(this ContentTypeDefinitionBuilder builder, bool securable = true)
 {
     return(builder.WithSetting("ContentTypeSettings.Securable", securable.ToString()));
 }
コード例 #20
0
 //todo: revisit "creatable" and "attachable", other words by be more fitting
 public static ContentTypeDefinitionBuilder Creatable(this ContentTypeDefinitionBuilder builder, bool creatable = true)
 {
     return(builder.WithSetting("ContentTypeSettings.Creatable", creatable.ToString()));
 }
コード例 #21
0
 /// <summary>
 /// Removes any custom placement
 /// </summary>
 public static ContentTypeDefinitionBuilder ResetPlacement(this ContentTypeDefinitionBuilder builder, PlacementType placementType)
 {
     return(builder.WithSetting("ContentTypeSettings.Placement." + placementType, String.Empty));
 }