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 PublishSemanticSchemas(StructureGroup structureGroup, Component relatedComponent)
        {
            RepositoryItemsFilter schemasFilter = new RepositoryItemsFilter(Session)
            {
                Recursive      = true,
                ItemTypes      = new[] { ItemType.Schema },
                SchemaPurposes = new[] { SchemaPurpose.Component, SchemaPurpose.Multimedia, SchemaPurpose.Metadata, SchemaPurpose.Region }
            };

            IEnumerable <Schema> schemas = Publication.GetItems(schemasFilter).Cast <Schema>();

            SemanticSchemaData[] semanticSchemas = schemas.Select(GetSemanticSchema).ToArray();

            return(AddJsonBinary(semanticSchemas, relatedComponent, structureGroup, "schemas", variantId: "semantic-schemas"));
        }
Exemple #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 PublishSemanticVocabularies(StructureGroup structureGroup, Component relatedComponent)
        {
            ApplicationData vocabularyAppData = Session.SystemManager.LoadGlobalApplicationData(VocabulariesAppDataId);

            if (vocabularyAppData == null)
            {
                throw new DxaException("No Vocabularies are defined in Global Application Data: " + VocabulariesAppDataId);
            }

            XElement vocabulariesXml = XElement.Parse(Encoding.Unicode.GetString(vocabularyAppData.Data));

            List <VocabularyData> vocabularies = vocabulariesXml.Elements()
                                                 .Select(vocabElement => new VocabularyData {
                Prefix = vocabElement.Attribute("prefix").Value, Vocab = vocabElement.Attribute("name").Value
            })
                                                 .ToList();

            if (_retrofitMode)
            {
                Logger.Info("Retrofit mode is enabled; generating semantic vocabularies for each (non-embedded) Schema.");
                RepositoryItemsFilter schemasFilter = new RepositoryItemsFilter(Session)
                {
                    Recursive      = true,
                    ItemTypes      = new[] { ItemType.Schema },
                    SchemaPurposes = new[] { SchemaPurpose.Component, SchemaPurpose.Multimedia, SchemaPurpose.Metadata, SchemaPurpose.Region }
                };
                IEnumerable <Schema> schemas = Publication.GetItems(schemasFilter).Cast <Schema>();
                vocabularies.AddRange(schemas.Select(schema => new VocabularyData {
                    Prefix = GetDefaultVocabularyPrefix(schema), Vocab = schema.NamespaceUri
                }));
            }

            if (!vocabularies.Any(vocab => vocab.Prefix == CoreVocabularyPrefix))
            {
                VocabularyData coreVocabulary = new VocabularyData {
                    Prefix = CoreVocabularyPrefix, Vocab = CoreVocabulary
                };
                vocabularies.Add(coreVocabulary);
            }

            return(AddJsonBinary(vocabularies, relatedComponent, structureGroup, "vocabularies"));
        }
        private Binary PublishPageIncludes(StructureGroup structureGroup, Component relatedComponent)
        {
            IDictionary <string, string[]> pageIncludes = new Dictionary <string, string[]>();

            RepositoryItemsFilter pageTemplatesFilter = new RepositoryItemsFilter(Session)
            {
                ItemTypes = new[] { ItemType.PageTemplate },
                Recursive = true
            };

            IEnumerable <PageTemplate> pageTemplates = Publication.GetItems(pageTemplatesFilter).Cast <PageTemplate>();

            foreach (PageTemplate pt in pageTemplates.Where(pt => pt.MetadataSchema != null && pt.Metadata != null))
            {
                ItemFields ptMetadataFields = new ItemFields(pt.Metadata, pt.MetadataSchema);
                string[]   includes         = ptMetadataFields.GetTextValues("includes").Select(id => GetPublishPath(id)).ToArray();
                pageIncludes.Add(pt.Id.ItemId.ToString(), includes);
            }

            return(AddJsonBinary(pageIncludes, relatedComponent, structureGroup, "includes"));
        }