protected void Page_Load(object sender, EventArgs e) { hlkCancel.NavigateUrl = Globals.NavigateURL(TabId, "", null); _appId = AppId.Value; _zoneId = ZoneId.Value; if (UserInfo.IsSuperUser) { _scope = !String.IsNullOrEmpty(Request.QueryString["Scope"]) ? Request.QueryString["Scope"] : "2SexyContent"; _appId = !String.IsNullOrEmpty(Request.QueryString["AppId"]) ? int.Parse(Request.QueryString["AppId"]) : _appId; _zoneId = !String.IsNullOrEmpty(Request.QueryString["ZoneId"]) ? int.Parse(Request.QueryString["ZoneId"]) : _zoneId; _sexy = new SexyContent(_zoneId, _appId); } else { _sexy = Sexy; } var contentTypes = _sexy.GetAvailableContentTypes(_scope, true); var templates = _sexy.Templates.GetAllTemplates(); var entities = DataSource.GetInitialDataSource(_zoneId, _appId, false); var language = Thread.CurrentThread.CurrentCulture.Name; var data = new { contentTypes = contentTypes.Select(c => new { Id = c.AttributeSetId, c.Name, c.StaticName, Templates = templates.Where(t => t.ContentTypeStaticName == c.StaticName).Select(p => new { p.TemplateId, p.ContentTypeStaticName, p.Name }), Entities = entities.List.Where(en => en.Value.Type.AttributeSetId == c.AttributeSetId).Select(en => _sexy.GetDictionaryFromEntity(en.Value, language)) }), templatesWithoutContentType = templates.Where(p => !String.IsNullOrEmpty(p.ContentTypeStaticName)).Select(t => new { t.TemplateId, t.Name }) }; pnlExportView.Attributes.Add("ng-init", "init(" + JsonConvert.SerializeObject(data) + ");"); }
public SxcHelper(SexyContent sexy) { Sexy = sexy; }
protected void UpdateModuleTitleIfNecessary(Entity entity) { // Creating new Context, because EntityTitle gets not refreshed otherwise var sexyContext = new SexyContent(ZoneId, AppId, true); // Get ContentGroup var listContentGroupItem = ContentGroup.ListContent; var entityModel = new DbLoadIntoEavDataStructure(sexyContext.ContentContext).GetEavEntity(entity.EntityID); // sexyContext.ContentContext.GetEntityModel(entity.EntityID); // If this is the list title, or no list-title exists, set module title if (ItemType == "ListContent" || (listContentGroupItem == null && ItemType == "Content" && SortOrder == 0) && entityModel.IsPublished) { var languages = Sexy.ContentContext.Dimensions.GetLanguages(); // Find Module for default language var moduleController = new ModuleController(); var originalModule = moduleController.GetModule(ModuleID); // Update Original Module if no languages active if (languages.Count == 0) { // Get Title value of Entitiy in current language var titleValue = entityModel.Title[0].ToString(); originalModule.ModuleTitle = titleValue; moduleController.UpdateModule(originalModule); } foreach (var dimension in languages) { // Get Title value of Entitiy in current language var titleValue = entityModel.Title[dimension.DimensionID].ToString(); if(!originalModule.IsDefaultLanguage) originalModule = originalModule.DefaultLanguageModule; // Break if default language module is null if (originalModule == null) return; // Find module for given Culture var moduleByCulture = moduleController.GetModuleByCulture(originalModule.ModuleID, originalModule.TabID, PortalId, LocaleController.Instance.GetLocale(dimension.ExternalKey)); // Break if no module found if (moduleByCulture == null) return; moduleByCulture.ModuleTitle = titleValue; moduleController.UpdateModule(moduleByCulture); } } }
/// <summary> /// Constructor with EntityModel and DimensionIds /// </summary> public DynamicEntity(IEntity entityModel, string[] dimensions, SexyContent sexy) { Entity = entityModel; _dimensions = dimensions; SexyContext = sexy; }
public static void SetAppIdForModule(ModuleInfo module, int? appId) { var moduleController = new ModuleController(); // Reset temporary template ContentGroups.DeletePreviewTemplateId(module.ModuleID); // ToDo: Should throw exception if a real ContentGroup exists var zoneId = GetZoneID(module.OwnerPortalID); if (appId == 0 || !appId.HasValue) moduleController.DeleteModuleSetting(module.ModuleID, AppNameString); else { var appName = ((BaseCache) DataSource.GetCache(0, 0)).ZoneApps[zoneId.Value].Apps[appId.Value]; moduleController.UpdateModuleSetting(module.ModuleID, AppNameString, appName); } // Change to 1. available template if app has been set if (appId.HasValue) { var sexyForNewApp = new SexyContent(zoneId.Value, appId.Value, false); var templates = sexyForNewApp.GetAvailableTemplatesForSelector(module).ToList(); if (templates.Any()) sexyForNewApp.ContentGroups.SetPreviewTemplateId(module.ModuleID, templates.First().TemplateId); } }
/// <summary> /// Returns all DNN Cultures with active / inactive state /// </summary> public static List<CulturesWithActiveState> GetCulturesWithActiveState(int portalId, int zoneId) { //var DefaultLanguageID = ContentContext.GetLanguageId(); var AvailableEAVLanguages = new SexyContent(zoneId, GetDefaultAppId(zoneId)).ContentContext.Dimensions.GetLanguages(); var DefaultLanguageCode = new PortalSettings(portalId).DefaultLanguage; var DefaultLanguage = AvailableEAVLanguages.Where(p => p.ExternalKey == DefaultLanguageCode).FirstOrDefault(); var DefaultLanguageIsActive = DefaultLanguage != null && DefaultLanguage.Active; return (from c in LocaleController.Instance.GetLocales(portalId) select new CulturesWithActiveState { Code = c.Value.Code, Text = c.Value.Text, Active = AvailableEAVLanguages.Any(a => a.Active && a.ExternalKey == c.Value.Code && a.ZoneID == zoneId), // Allow State Change only if // 1. This is the default language and default language is not active or // 2. This is NOT the default language and default language is active AllowStateChange = (c.Value.Code == DefaultLanguageCode && !DefaultLanguageIsActive) || (DefaultLanguageIsActive && c.Value.Code != DefaultLanguageCode) }).OrderByDescending(c => c.Code == DefaultLanguageCode).ThenBy(c => c.Code).ToList(); }
/// <summary> /// Create app-describing entity for configuration and add Settings and Resources Content Type /// </summary> /// <param name="zoneId"></param> /// <param name="appId"></param> public static void EnsureAppIsConfigured(int zoneId, int appId, string appName = null) { var appMetaData = DataSource.GetMetaDataSource(zoneId, appId).GetAssignedEntities(AssignmentObjectTypeIDSexyContentApp, appId, AttributeSetStaticNameApps).FirstOrDefault(); var appResources = DataSource.GetMetaDataSource(zoneId, appId).GetAssignedEntities(AssignmentObjectTypeIDSexyContentApp, appId, AttributeSetStaticNameAppResources).FirstOrDefault(); var appSettings = DataSource.GetMetaDataSource(zoneId, appId).GetAssignedEntities(AssignmentObjectTypeIDSexyContentApp, appId, AttributeSetStaticNameAppSettings).FirstOrDefault(); // Get appName from cache var eavAppName = ((BaseCache)DataSource.GetCache(zoneId, null)).ZoneApps[zoneId].Apps[appId]; if (eavAppName == Constants.DefaultAppName) return; var appContext = new SexyContent(zoneId, appId); if (appMetaData == null) { // Add app-describing entity var appAttributeSet = appContext.ContentContext.AttribSet.GetAttributeSet(AttributeSetStaticNameApps).AttributeSetID; var values = new OrderedDictionary { {"DisplayName", String.IsNullOrEmpty(appName) ? eavAppName : appName }, {"Folder", String.IsNullOrEmpty(appName) ? eavAppName : RemoveIllegalCharsFromPath(appName) }, {"AllowTokenTemplates", "False"}, {"AllowRazorTemplates", "False"}, {"Version", "00.00.01"}, {"OriginalId", ""} }; appContext.ContentContext.Entities.AddEntity(appAttributeSet, values, null, appId, AssignmentObjectTypeIDSexyContentApp); } if(appSettings == null) { AttributeSet settingsAttributeSet; // Add new (empty) ContentType for Settings if (!appContext.ContentContext.AttribSet.AttributeSetExists(AttributeSetStaticNameAppSettings, appId)) settingsAttributeSet = appContext.ContentContext.AttribSet.AddAttributeSet(AttributeSetStaticNameAppSettings, "Stores settings for an app", AttributeSetStaticNameAppSettings, AttributeSetScopeApps); else settingsAttributeSet = appContext.ContentContext.AttribSet.GetAttributeSet(AttributeSetStaticNameAppSettings); DataSource.GetCache(zoneId, appId).PurgeCache(zoneId, appId); appContext.ContentContext.Entities.AddEntity(settingsAttributeSet, new OrderedDictionary(), null, appId, AssignmentObjectTypeIDSexyContentApp); } if(appResources == null) { AttributeSet resourcesAttributeSet; // Add new (empty) ContentType for Resources if (!appContext.ContentContext.AttribSet.AttributeSetExists(AttributeSetStaticNameAppResources, appId)) resourcesAttributeSet = appContext.ContentContext.AttribSet.AddAttributeSet( AttributeSetStaticNameAppResources, "Stores resources like translations for an app", AttributeSetStaticNameAppResources, AttributeSetScopeApps); else resourcesAttributeSet = appContext.ContentContext.AttribSet.GetAttributeSet(AttributeSetStaticNameAppResources); DataSource.GetCache(zoneId, appId).PurgeCache(zoneId, appId); appContext.ContentContext.Entities.AddEntity(resourcesAttributeSet, new OrderedDictionary(), null, appId, AssignmentObjectTypeIDSexyContentApp); } if (appMetaData == null || appSettings == null || appResources == null) DataSource.GetCache(zoneId, appId).PurgeCache(zoneId, appId); }
public static App AddApp(int zoneId, string appName, PortalSettings ownerPS) { if(appName == "Content" || appName == "Default" || String.IsNullOrEmpty(appName) || !Regex.IsMatch(appName, "^[0-9A-Za-z -_]+$")) throw new ArgumentOutOfRangeException("appName '" + appName + "' not allowed"); // Adding app to EAV var sexy = new SexyContent(zoneId, GetDefaultAppId(zoneId)); var app = sexy.ContentContext.App.AddApp(Guid.NewGuid().ToString()); sexy.ContentContext.SqlDb.SaveChanges(); EnsureAppIsConfigured(zoneId, app.AppID, appName); return GetApp(zoneId, app.AppID, ownerPS); }