Esempio n. 1
0
        private XmlExporter GenerateExportXml(bool includeContentGroups, bool resetAppGuid)
        {
            // Get Export XML
            var attributeSets = new AppRuntime(_zoneId, _appId).ContentTypes.FromScope(includeAttributeTypes: true);

            attributeSets = attributeSets.Where(a => !((IContentTypeShareable)a).AlwaysShareConfiguration);

            var attributeSetIds = attributeSets.Select(p => p.ContentTypeId.ToString()).ToArray();
            var templateTypeId  = SystemRuntime.GetMetadataType(Settings.TemplateContentType);
            var entities        =
                DataSource.GetInitialDataSource(_zoneId, _appId).Out["Default"].List.Where(
                    e => e.Value.Metadata.TargetType != templateTypeId &&
                    e.Value.Metadata.TargetType != Constants.MetadataForAttribute).ToList();

            if (!includeContentGroups)
            {
                entities = entities.Where(p => p.Value.Type.StaticName != _sexycontentContentgroupName).ToList();
            }

            var entityIds = entities
                            .Select(e => e.Value.EntityId.ToString()).ToArray();

            var xmlExport = Factory.Resolve <XmlExporter>()
                            .Init(_zoneId, _appId, true, attributeSetIds, entityIds);

            // var xmlExport = Factory.Container.Resolve<XmlExporter>(new ParameterOverrides { { "zoneId", _zoneId }, { "appId", _appId}, {"appExport", true}, { "contentTypeIds", attributeSetIds }, {"entityIds", entityIds} });
            // new ToSxcXmlExporter(_zoneId, _appId, true, attributeSetIds, entityIds);

            #region reset App Guid if necessary

            if (resetAppGuid)
            {
                var root    = xmlExport.ExportXDocument; //.Root;
                var appGuid = root.XPathSelectElement("/SexyContent/Header/App").Attribute("Guid");
                appGuid.Value = _blankGuid;
            }
            return(xmlExport);

            #endregion
        }
        public dynamic GetContentInfo(int appId, int zoneId, string scope)
        {
            Log.Add($"get content info for z#{zoneId}, a#{appId}, scope:{scope} super?:{UserInfo.IsSuperUser}");
            var appWrapper = AppBasedOnUserPermissions(appId, zoneId);

            var contentTypes = new AppRuntime(appWrapper.App, Log).ContentTypes.FromScope(scope);
            var entities     = appWrapper.GetEntities();
            var templates    = appWrapper.GetTemplates();

            return(new
            {
                ContentTypes = contentTypes.Select(c => new
                {
                    Id = c.ContentTypeId,
                    c.Name,
                    c.StaticName,
                    Templates = templates.Where(t => t.ContentTypeStaticName == c.StaticName).Select(t => new
                    {
                        Id = t.TemplateId,
                        t.Name
                    }),
                    Entities = entities
                               .Where(e => e.Value.Type.ContentTypeId == c.ContentTypeId)
                               .Select(e => new
                    {
                        Title = e.Value.GetBestTitle(),
                        Id = e.Value.EntityId
                    })
                }),
                TemplatesWithoutContentTypes = templates.Where(t => !string.IsNullOrEmpty(t.ContentTypeStaticName)).Select(t => new
                {
                    Id = t.TemplateId,
                    t.Name
                })
            });
        }