private Dictionary <string, XpmRegionData> CollectNativeRegions()
        {
            Dictionary <string, XpmRegionData> nativeRegions = new Dictionary <string, XpmRegionData>();

            RepositoryItemsFilter filter = new RepositoryItemsFilter(Session)
            {
                SchemaPurposes = new[] { SchemaPurpose.Region },
                ItemTypes      = new[] { ItemType.Schema },
                Recursive      = true
            };

            IEnumerable <Schema> regionSchemas = Publication.GetItems(filter).Cast <Schema>();

            foreach (Schema schema in regionSchemas)
            {
                dynamic regionDefinition = schema.RegionDefinition;

                string regionSchemaId = schema.Id.ItemId.ToString();
                if (nativeRegions.All(nr => nr.Key != regionSchemaId))
                {
                    XpmRegionData nativeRegion = new XpmRegionData
                    {
                        Region               = regionSchemaId,
                        ComponentTypes       = GetComponentTypeConstraints(regionDefinition),
                        OccurrenceConstraint = GetOccurrenceConstraint(regionDefinition)
                    };
                    nativeRegions.Add(regionSchemaId, nativeRegion);
                }
                else
                {
                    Logger.Debug($"Region {regionSchemaId} has already been added. Skipping.");
                }
            }
            return(nativeRegions);
        }
        private Binary PublishXpmRegionConfiguration(StructureGroup structureGroup, Component relatedComponent)
        {
            IDictionary <string, XpmRegionData> xpmRegions = new Dictionary <string, XpmRegionData>();

            foreach (ComponentTemplate ct in Publication.GetComponentTemplates())
            {
                string regionName = GetRegionName(ct);

                XpmRegionData xpmRegion;
                if (!xpmRegions.TryGetValue(regionName, out xpmRegion))
                {
                    xpmRegion = new XpmRegionData {
                        Region = regionName, ComponentTypes = new List <XpmComponentTypeData>()
                    };
                    xpmRegions.Add(regionName, xpmRegion);
                }

                string templateId = ct.Id.GetVersionlessUri().ToString();

                IEnumerable <XpmComponentTypeData> allowedComponentTypes = ct.RelatedSchemas.Select(
                    schema => new XpmComponentTypeData
                {
                    Schema   = schema.Id.GetVersionlessUri().ToString(),
                    Template = templateId
                }
                    );

                xpmRegion.ComponentTypes.AddRange(allowedComponentTypes);
            }

            return(AddJsonBinary(xpmRegions.Values, relatedComponent, structureGroup, "regions"));
        }
Esempio n. 3
0
        private Dictionary <string, XpmRegionData> CollectNativeRegions()
        {
            Dictionary <string, XpmRegionData> nativeRegions = new Dictionary <string, XpmRegionData>();

            RepositoryItemsFilter filter = new RepositoryItemsFilter(Session)
            {
                SchemaPurposes = new[] { SchemaPurpose.Region },
                ItemTypes      = new[] { ItemType.Schema },
                Recursive      = true
            };

            IEnumerable <Schema> regionSchemas = Publication.GetItems(filter).Cast <Schema>();

            foreach (Schema schema in regionSchemas)
            {
                dynamic regionDefinition     = schema.RegionDefinition;
                dynamic schemasNestedRegions = regionDefinition.NestedRegions;

                if (schemasNestedRegions != null)
                {
                    foreach (dynamic nestedRegionDefinition in schemasNestedRegions)
                    {
                        string regionName = nestedRegionDefinition.RegionName;
                        if (nativeRegions.All(nr => nr.Key != regionName))
                        {
                            XpmRegionData nativeRegion = new XpmRegionData
                            {
                                Region         = regionName,
                                ComponentTypes = new List <XpmComponentTypeData>
                                {
                                    new XpmComponentTypeData {
                                        Schema = "*", Template = "*"
                                    }                                                       // Allow all schemas/templates
                                }
                            };
                            nativeRegions.Add(regionName, nativeRegion);
                        }
                        else
                        {
                            // TODO : Should be revisited in context of the story CMF1-259
                            Logger.Debug($"Region {regionName} has already been added. Skipping.");
                        }
                    }
                }
            }
            return(nativeRegions);
        }
        private Binary PublishXpmRegionConfiguration(StructureGroup structureGroup, Component relatedComponent)
        {
            IDictionary<string, XpmRegionData> xpmRegions = new Dictionary<string, XpmRegionData>();

            foreach (ComponentTemplate ct in Publication.GetComponentTemplates())
            {
                string regionName = GetRegionName(ct);

                XpmRegionData xpmRegion;
                if (!xpmRegions.TryGetValue(regionName, out xpmRegion))
                {
                    xpmRegion = new XpmRegionData { Region = regionName, ComponentTypes = new List<XpmComponentTypeData>() };
                    xpmRegions.Add(regionName, xpmRegion);
                }

                string templateId = ct.Id.GetVersionlessUri().ToString();

                IEnumerable<XpmComponentTypeData> allowedComponentTypes = ct.RelatedSchemas.Select(
                    schema => new XpmComponentTypeData
                    {
                        Schema = schema.Id.GetVersionlessUri().ToString(),
                        Template = templateId
                    }
                    );

                xpmRegion.ComponentTypes.AddRange(allowedComponentTypes);
            }

            return AddJsonBinary(xpmRegions.Values, relatedComponent, structureGroup, "regions");
        }