internal static int GetAppIdFromGuidName(int zoneId, string appName, bool alsoCheckFolderName = false) { // ToDo: Fix issue in EAV (cache is only ensured when a CacheItem-Property is accessed like LastRefresh) var baseCache = ((BaseCache)DataSource.GetCache(Constants.DefaultZoneId, Constants.MetaDataAppId)); // ReSharper disable once UnusedVariable var dummy = baseCache.CacheLastRefresh; if (IsNullOrEmpty(appName)) { return(0); } var appId = baseCache.ZoneApps[zoneId].Apps .Where(p => p.Value == appName).Select(p => p.Key).FirstOrDefault(); // optionally check folder names if (appId == 0 && alsoCheckFolderName) { var nameLower = appName.ToLower(); foreach (var p in baseCache.ZoneApps[zoneId].Apps) { var mds = DataSource.GetMetaDataSource(zoneId, p.Key); var appMetaData = mds .GetAssignedEntities(SystemRuntime.GetMetadataType(Constants.AppAssignmentName), p.Key, Settings.AttributeSetStaticNameApps) .FirstOrDefault(); string folder = appMetaData?.GetBestValue("Folder").ToString(); if (!IsNullOrEmpty(folder) && folder.ToLower() == nameLower) { return(p.Key); } } } return(appId > 0 ? appId : Settings.DataIsMissingInDb); }
/// <summary> /// Assign all kinds of metadata / resources / settings (App-Mode only) /// </summary> private void InitializeResourcesSettingsAndMetadata(bool allowSideEffects) { Log.Add($"init app resources allowSE:{allowSideEffects}"); _env = new Environment.DnnEnvironment(Log); if (allowSideEffects) { // if it's a real App (not content/default), do more AppManagement.EnsureAppIsConfigured(ZoneId, AppId, parentLog: Log); // make sure additional settings etc. exist } // Get app-describing entity var appAssignmentId = SystemRuntime.GetMetadataType(Eav.Constants.AppAssignmentName); var mds = DataSource.GetMetaDataSource(ZoneId, AppId); var appMetaData = mds .GetAssignedEntities(appAssignmentId, AppId, SexyContent.Settings.AttributeSetStaticNameApps) .FirstOrDefault(); var appResources = mds .GetAssignedEntities(appAssignmentId, AppId, SexyContent.Settings.AttributeSetStaticNameAppResources) .FirstOrDefault(); var appSettings = mds .GetAssignedEntities(appAssignmentId, AppId, SexyContent.Settings.AttributeSetStaticNameAppSettings) .FirstOrDefault(); dynamic appMetaDataDynamic = appMetaData != null ? new DynamicEntity(appMetaData, new[] { Thread.CurrentThread.CurrentCulture.Name }, null) : null; Name = appMetaDataDynamic?.DisplayName ?? "Error"; Folder = appMetaDataDynamic?.Folder ?? "Error"; Configuration = appMetaDataDynamic; Resources = appResources != null ? new DynamicEntity(appResources, new[] { Thread.CurrentThread.CurrentCulture.Name }, null) : null; Settings = appResources != null ? new DynamicEntity(appSettings, new[] { Thread.CurrentThread.CurrentCulture.Name }, null) : null; Hidden = appMetaDataDynamic?.Hidden ?? false; }
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 }
/// <summary> /// Returns an EAV import entity /// </summary> /// <param name="entityNode">The xml-Element of the entity to import</param> /// <param name="assignmentObjectTypeId">assignmentObjectTypeId</param> /// <returns></returns> private IEntity GetImportEntity(XElement entityNode, int assignmentObjectTypeId) { #region retrieve optional metadata keys in the import - must happen before we apply corrections like AppId Guid?keyGuid = null; var maybeGuid = entityNode.Attribute(XmlConstants.KeyGuid); if (maybeGuid != null) { keyGuid = Guid.Parse(maybeGuid.Value); } int?keyNumber = null; var maybeNumber = entityNode.Attribute(XmlConstants.KeyNumber); if (maybeNumber != null) { keyNumber = int.Parse(maybeNumber.Value); } var keyString = entityNode.Attribute(XmlConstants.KeyString)?.Value; #endregion #region check if the xml has an own assignment object type (then we wouldn't use the default) switch (entityNode.Attribute(XmlConstants.KeyTargetType)?.Value) { // Special case: App AttributeSets must be assigned to the current app case XmlConstants.App: keyNumber = AppId; assignmentObjectTypeId = SystemRuntime.GetMetadataType(Constants.AppAssignmentName); break; case XmlConstants.Entity: case "Data Pipeline": // 2dm: this was an old value, 2017-08-11 this was still used in the old Employees directory app v. 1.02 assignmentObjectTypeId = Constants.MetadataForEntity; break; case XmlConstants.ContentType: assignmentObjectTypeId = Constants.MetadataForContentType; break; case XmlConstants.CmsObject: assignmentObjectTypeId = Constants.MetadataForContentType; if (keyString == null) { throw new Exception("found cms object, but couldn't find metadata-key of type string, will abort"); } var newKey = GetMappedLink(keyString); if (newKey != null) { keyString = newKey; } break; } #endregion // Special case #2: Corrent values of Template-Describing entities, and resolve files foreach (var sourceValue in entityNode.Elements(XmlConstants.ValueNode)) { var sourceValueString = sourceValue.Attribute(XmlConstants.ValueAttr).Value; // Correct FileId in Hyperlink fields (takes XML data that lists files) if (!String.IsNullOrEmpty(sourceValueString) && sourceValue.Attribute(XmlConstants.EntityTypeAttribute).Value == XmlConstants.ValueTypeLink) { string newValue = GetMappedLink(sourceValueString); if (newValue != null) { sourceValue.Attribute(XmlConstants.ValueAttr).SetValue(newValue); } } } var importEntity = _xmlBuilder.BuildEntityFromXml(entityNode, /*_targetDimensions, _sourceDimensions, _sourceDefaultDimensionId, DefaultLanguage,*/ new Metadata { TargetType = assignmentObjectTypeId, KeyNumber = keyNumber, KeyGuid = keyGuid, KeyString = keyString }); return(importEntity); }
/// <summary> /// Create app-describing entity for configuration and add Settings and Resources Content Type /// </summary> /// <param name="zoneId"></param> /// <param name="appId"></param> /// <param name="appName"></param> internal static void EnsureAppIsConfigured(int zoneId, int appId, Log parentLog, string appName = null) { var appAssignment = SystemRuntime.GetMetadataType(Constants.AppAssignmentName); var scope = Settings.AttributeSetScopeApps; var mds = DataSource.GetMetaDataSource(zoneId, appId); var appMetaData = mds.GetAssignedEntities(appAssignment, appId, Settings.AttributeSetStaticNameApps).FirstOrDefault(); var appResources = mds.GetAssignedEntities(appAssignment, appId, Settings.AttributeSetStaticNameAppResources).FirstOrDefault(); var appSettings = mds.GetAssignedEntities(appAssignment, appId, Settings.AttributeSetStaticNameAppSettings).FirstOrDefault(); // Get appName from cache - stop if it's a "Default" app var eavAppName = new ZoneRuntime(zoneId, parentLog).GetName(appId);// State.GetAppName(zoneId, appId); if (eavAppName == Eav.Constants.DefaultAppName) { return; } var appMan = new AppManager(zoneId, appId); if (appMetaData == null) { appMan.MetadataEnsureTypeAndSingleEntity(scope, Settings.AttributeSetStaticNameApps, "App Metadata", appAssignment, new Dictionary <string, object>() { { "DisplayName", IsNullOrEmpty(appName) ? eavAppName : appName }, { "Folder", IsNullOrEmpty(appName) ? eavAppName : RemoveIllegalCharsFromPath(appName) }, { "AllowTokenTemplates", "False" }, { "AllowRazorTemplates", "False" }, { "Version", "00.00.01" }, { "OriginalId", "" } }); } // Add new (empty) ContentType for Settings if (appSettings == null) { appMan.MetadataEnsureTypeAndSingleEntity(scope, Settings.AttributeSetStaticNameAppSettings, "Stores settings for an app", appAssignment, null); } // add new (empty) ContentType for Resources if (appResources == null) { appMan.MetadataEnsureTypeAndSingleEntity(scope, Settings.AttributeSetStaticNameAppResources, "Stores resources like translations for an app", appAssignment, null); } if (appMetaData == null || appSettings == null || appResources == null) { SystemManager.Purge(zoneId, appId); } }