예제 #1
0
        protected void InitExportXDocument(string defaultLanguage, string moduleVersion)
        {
            EnsureThisIsInitialized();

            // Create XML document and declaration
            var doc = _exportDocument = new XmlBuilder().BuildDocument();

            #region Header

            var dimensions = new ZoneRuntime(ZoneId).Languages();
            var header     = new XElement(XmlConstants.Header,
                                          _isAppExport && _appStaticName != XmlConstants.AppContentGuid
                    ? new XElement(XmlConstants.App, new XAttribute(XmlConstants.Guid, _appStaticName))
                    : null,
                                          new XElement(XmlConstants.Language, new XAttribute(XmlConstants.LangDefault, defaultLanguage)),
                                          new XElement(XmlConstants.DimensionDefinition, dimensions.Select(d => new XElement(XmlConstants.DimensionDefElement,
                                                                                                                             new XAttribute(XmlConstants.DimId, d.DimensionId),
                                                                                                                             new XAttribute(XmlConstants.Name, d.Name),
                                                                                                                             new XAttribute(XmlConstants.CultureSysKey, d.Key ?? string.Empty),
                                                                                                                             new XAttribute(XmlConstants.CultureExtKey, d.EnvironmentKey ?? string.Empty),
                                                                                                                             new XAttribute(XmlConstants.CultureIsActiveAttrib, d.Active)
                                                                                                                             )))
                                          );

            #endregion

            #region Attribute Sets

            var attributeSets = new XElement(XmlConstants.AttributeSets);

            // Go through each AttributeSetID
            foreach (var attributeSetId in AttributeSetIDs)
            {
                var id         = int.Parse(attributeSetId);
                var set        = (ContentType)AppPackage.ContentTypes[id];
                var attributes = new XElement(XmlConstants.Attributes);

                // Add all Attributes to AttributeSet including meta informations
                foreach (var x in set.Attributes.OrderBy(a => a.SortOrder))
                {
                    var attribute = new XElement(XmlConstants.Attribute,
                                                 new XAttribute(XmlConstants.Static, x.Name),
                                                 new XAttribute(XmlConstants.Type, x.Type),
                                                 new XAttribute(XmlConstants.IsTitle, x.IsTitle),
                                                 // Add Attribute MetaData
                                                 from c in AppPackage.GetMetadata(Constants.MetadataForAttribute, x.AttributeId).ToList()
                                                 select GetEntityXElement(c.EntityId, c.Type.StaticName)
                                                 );

                    attributes.Add(attribute);
                }

                // Add AttributeSet / Content Type
                var attributeSet = new XElement(XmlConstants.AttributeSet,
                                                new XAttribute(XmlConstants.Static, set.StaticName),
                                                new XAttribute(XmlConstants.Name, set.Name),
                                                new XAttribute(XmlConstants.Description, set.Description),
                                                new XAttribute(XmlConstants.Scope, set.Scope),
                                                new XAttribute(XmlConstants.AlwaysShareConfig, set.AlwaysShareConfiguration),
                                                attributes);

                // Add Ghost-Info if content type inherits from another content type
                if (set.ParentId.HasValue)
                {
                    var parentStaticName = AppPackage.ContentTypes[set.ParentId.Value].StaticName;
                    attributeSet.Add(new XAttribute(XmlConstants.AttributeSetParentDef, parentStaticName));
                }

                attributeSets.Add(attributeSet);
            }

            #endregion

            #region Entities

            var entities = new XElement(XmlConstants.Entities);

            // Go through each Entity
            foreach (var entityId in EntityIDs)
            {
                var id = int.Parse(entityId);

                // Get the entity and ContentType from ContentContext add Add it to ContentItems
                var entity = AppPackage.Entities[id];
                entities.Add(GetEntityXElement(entity.EntityId, entity.Type.StaticName));
            }

            #endregion

            // init files (add to queue)
            AddFilesToExportQueue();

            // Create root node "SexyContent" and add ContentTypes, ContentItems and Templates
            doc.Add(new XElement(XmlConstants.RootNode,
                                 new XAttribute(XmlConstants.FileVersion, Settings.FileVersion),
                                 new XAttribute(XmlConstants.MinEnvVersion, Settings.MinimumRequiredVersion),
                                 new XAttribute(XmlConstants.MinModVersion, moduleVersion),
                                 new XAttribute(XmlConstants.ExportDate, DateTime.Now),
                                 header,
                                 attributeSets,
                                 entities,
                                 GetFilesXElements(),
                                 GetFoldersXElements()));
        }