private void Update(Dictionary <string, object> newValues)
        {
            var cgApp = ((ContentBlockBase)SxcContext.ContentBlock).Parent.App;
            var eavDc = EavDataController.Instance(cgApp.ZoneId, cgApp.AppId);

            eavDc.Entities.UpdateEntity(Math.Abs(SxcContext.ContentBlock.ContentBlockId), newValues);

            //((ContentBlockBase)SxcContext.ContentBlock).Parent.App
            //    .Data.Update(Math.Abs(SxcContext.ContentBlock.ContentBlockId), newValues);
        }
Ejemplo n.º 2
0
        public void UpdateTemplate(int?templateId)
        {
            var values = new Dictionary <string, object>
            {
                { "Template", templateId.HasValue ? new[] { templateId.Value } : new int[] {} }
            };

            var context = EavDataController.Instance(_zoneId, _appId).Entities; // EavContext.Instance(_zoneId, _appId);

            context.UpdateEntity(_contentGroupEntity.EntityGuid, values);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Creates an app and then imports the xml
        /// </summary>
        /// <returns>AppId of the new imported app</returns>
        public bool ImportApp(int zoneId, XDocument doc, out int?appId)
        {
            // Increase script timeout to prevent timeouts
            HttpContext.Current.Server.ScriptTimeout = 300;

            appId = new int?();

            if (!IsCompatible(doc))
            {
                ImportLog.Add(new ExportImportMessage("The import file is not compatible with the installed version of 2sxc.", ExportImportMessage.MessageTypes.Error));
                return(false);
            }

            // Get root node "SexyContent"
            var xmlSource = doc.Element(XmlConstants.RootNode);
            var xApp      = xmlSource?.Element(XmlConstants.Header)?.Element(XmlConstants.App);

            var appGuid = xApp?.Attribute(XmlConstants.Guid).Value;

            if (appGuid == null)
            {
                ImportLog.Add(new ExportImportMessage("Something is wrong in the xml structure, can't get an app-guid", ExportImportMessage.MessageTypes.Error));
                return(false);
            }

            if (appGuid != XmlConstants.AppContentGuid)
            {
                // Build Guid (take existing, or create a new)
                if (IsNullOrEmpty(appGuid) || appGuid == new Guid().ToString())
                {
                    appGuid = Guid.NewGuid().ToString();
                }

                // Adding app to EAV
                var eavDc = EavDataController.Instance(zoneId, null);
                var app   = eavDc.App.AddApp(appGuid);
                eavDc.SqlDb.SaveChanges();

                appId = app.AppID;
            }
            else
            {
                appId = _appId;
            }

            if (appId <= 0)
            {
                ImportLog.Add(new ExportImportMessage("App was not created. Please try again or make sure the package you are importing is correct.", ExportImportMessage.MessageTypes.Error));
                return(false);
            }

            return(ImportXml(zoneId, appId.Value, doc));
        }
Ejemplo n.º 4
0
        // 2016-09-24 2dm seems unused now
        //public Template GetTemplate(Guid templateGuid)
        //{
        //    return
        //        TemplateDataSource()
        //            .List.Where(t => t.Value.EntityGuid == templateGuid)
        //            .Select(t => new Template(t.Value))
        //            .FirstOrDefault();
        //}

        public bool DeleteTemplate(int templateId)
        {
            var template   = GetTemplate(templateId);
            var eavContext = EavDataController.Instance(_zoneId, _appId).Entities; //EavContext.Instance(_zoneId, _appId);
            var canDelete  = eavContext.CanDeleteEntity(template.TemplateId);

            if (!canDelete.Item1)
            {
                throw new Exception(canDelete.Item2);
            }
            return(eavContext.DeleteEntity(template.TemplateId));
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Will create a new app in the system and initialize the basic settings incl. the
        /// app-definition
        /// </summary>
        /// <param name="zoneId"></param>
        /// <param name="appName"></param>
        /// <param name="ownerPS"></param>
        /// <returns></returns>
        internal static App AddBrandNewApp(int zoneId, string appName, PortalSettings ownerPS)
        {
            if (appName == Constants.ContentAppName || appName == "Default" || String.IsNullOrEmpty(appName) || !Regex.IsMatch(appName, "^[0-9A-Za-z -_]+$"))
            {
                throw new ArgumentOutOfRangeException("appName '" + appName + "' not allowed");
            }

            // Adding app to EAV
            var eavContext = EavDataController.Instance(zoneId, AppHelpers.GetDefaultAppId(zoneId));
            var app        = eavContext.App.AddApp(Guid.NewGuid().ToString());

            eavContext.SqlDb.SaveChanges();

            EnsureAppIsConfigured(zoneId, app.AppID, appName);

            return(new App(zoneId, app.AppID, ownerPS));
        }
Ejemplo n.º 6
0
        public Guid CreateNewContentGroup(int?templateId)
        {
            var context     = EavDataController.Instance(_zoneId, _appId).Entities;
            var contentType = DataSource.GetCache(_zoneId, _appId).GetContentType(ContentGroupTypeName);

            var values = new Dictionary <string, object>
            {
                { "Template", templateId.HasValue ? new [] { templateId.Value } : new int[] {} },
                { "Content", new int[] {} },
                { "Presentation", new int[] {} },
                { "ListContent", new int[] {} },
                { "ListPresentation", new int[] {} }
            };

            var entity = context.AddEntity(contentType.AttributeSetId, values, null, null);

            return(entity.EntityGUID);
        }
Ejemplo n.º 7
0
        /// <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 = EavDataController.Instance(zoneId, AppHelpers.GetDefaultAppId(zoneId)).Dimensions.GetLanguages();
            // var AvailableEAVLanguages = new SxcInstance(zoneId, AppHelpers.GetDefaultAppId(zoneId)).EavAppContext.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());
        }
Ejemplo n.º 8
0
        /// <summary>
        /// Adds or updates a template - will create a new template if templateId is not specified
        /// </summary>
        public void UpdateTemplate(int?templateId, string name, string path, string contentTypeStaticName,
                                   int?contentDemoEntity, string presentationTypeStaticName, int?presentationDemoEntity,
                                   string listContentTypeStaticName, int?listContentDemoEntity, string listPresentationTypeStaticName,
                                   int?listPresentationDemoEntity, string templateType, bool isHidden, string location, bool useForList,
                                   bool publishData, string streamsToPublish, int?pipelineEntity, string viewNameInUrl)
        {
            var values = new Dictionary <string, object>
            {
                { "Name", name },
                { "Path", path },
                { "ContentTypeStaticName", contentTypeStaticName },
                { "ContentDemoEntity", contentDemoEntity.HasValue ? new[] { contentDemoEntity.Value } : new int[] {} },
                { "PresentationTypeStaticName", presentationTypeStaticName },
                { "PresentationDemoEntity", presentationDemoEntity.HasValue ? new[] { presentationDemoEntity.Value } : new int[] {} },
                { "ListContentTypeStaticName", listContentTypeStaticName },
                { "ListContentDemoEntity", listContentDemoEntity.HasValue ? new[] { listContentDemoEntity.Value } : new int[] {} },
                { "ListPresentationTypeStaticName", listPresentationTypeStaticName },
                { "ListPresentationDemoEntity", listPresentationDemoEntity.HasValue ? new[] { listPresentationDemoEntity.Value } : new int[] {} },
                { "Type", templateType },
                { "IsHidden", isHidden },
                { "Location", location },
                { "UseForList", useForList },
                { "PublishData", publishData },
                { "StreamsToPublish", streamsToPublish },
                { "Pipeline", pipelineEntity.HasValue ? new[] { pipelineEntity } : new int?[] {} },
                { "ViewNameInUrl", viewNameInUrl }
            };

            var context = EavDataController.Instance(_zoneId, _appId).Entities;// EavContext.Instance(_zoneId, _appId);

            if (templateId.HasValue)
            {
                context.UpdateEntity(templateId.Value, values);
            }
            else
            {
                var contentType = DataSource.GetCache(_zoneId, _appId).GetContentType(TemplateTypeName);
                context.AddEntity(contentType.AttributeSetId, values, null, null);
            }
        }
Ejemplo n.º 9
0
        private Entity CreateItemAndAddToList(int parentId, string field, int sortOrder, string contentTypeName,
                                              Dictionary <string, object> values)
        {
            var cgApp = SxcContext.App;
            var eavDc = EavDataController.Instance(cgApp.ZoneId, cgApp.AppId);

            eavDc.UserName = Environment.Dnn7.UserIdentity.CurrentUserIdentityToken;

            #region create the new entity --> note that it's the sql-type entity, not a standard ientity

            var contentType =
                DataSource.GetCache(cgApp.ZoneId, cgApp.AppId)
                .GetContentType(contentTypeName);

            var entity = eavDc.Entities.AddEntity(contentType.AttributeSetId, values, null, null);

            #endregion

            #region attach to the current list of items

            var cbEnt = SxcContext.App.Data["Default"].List[parentId];
            // ((EntityContentBlock) SxcContext.ContentBlock).ContentBlockEntity;
            var blockList = ((Eav.Data.EntityRelationship)cbEnt.GetBestValue(field)).ToList() ?? new List <IEntity>();

            var intList = blockList.Select(b => b.EntityId).ToList();
            if (sortOrder > intList.Count)
            {
                sortOrder = intList.Count;
            }
            intList.Insert(sortOrder, entity.EntityID);

            var updateDic = new Dictionary <string, int[]> {
                { field, intList.ToArray() }
            };
            eavDc.Entities.UpdateEntity(cbEnt.EntityGuid, updateDic);

            #endregion

            return(entity);
        }
Ejemplo n.º 10
0
        private void SaveChangedLists(Dictionary <string, int?[]> values)
        {
            // ensure that there are never more presentations than values
            if (values.ContainsKey(cPresentation))
            {
                var contentCount = Content.Count;
                if (values.ContainsKey(cContent))
                {
                    contentCount = values[cContent].Length;
                }
                if (values[cPresentation].Length > contentCount)
                {
                    throw new Exception("Presentation may not contain more items than Content.");
                }
            }

            var context = EavDataController.Instance(_zoneId, _appId).Entities; // EavContext.Instance(_zoneId, _appId);

            context.UpdateEntity(_contentGroupEntity.EntityGuid, values);

            // Refresh content group entity (ensures contentgroup is up to date)
            _contentGroupEntity =
                new ContentGroupManager(_zoneId, _appId).GetContentGroup(_contentGroupEntity.EntityGuid)._contentGroupEntity;
        }
Ejemplo n.º 11
0
        /// <summary>
        /// Create app-describing entity for configuration and add Settings and Resources Content Type
        /// </summary>
        /// <param name="zoneId"></param>
        /// <param name="appId"></param>
        internal static void EnsureAppIsConfigured(int zoneId, int appId, string appName = null)
        {
            var appMetaData  = DataSource.GetMetaDataSource(zoneId, appId).GetAssignedEntities(ContentTypeHelpers.AssignmentObjectTypeIDSexyContentApp, appId, Settings.AttributeSetStaticNameApps).FirstOrDefault();
            var appResources = DataSource.GetMetaDataSource(zoneId, appId).GetAssignedEntities(ContentTypeHelpers.AssignmentObjectTypeIDSexyContentApp, appId, Settings.AttributeSetStaticNameAppResources).FirstOrDefault();
            var appSettings  = DataSource.GetMetaDataSource(zoneId, appId).GetAssignedEntities(ContentTypeHelpers.AssignmentObjectTypeIDSexyContentApp, appId, Settings.AttributeSetStaticNameAppSettings).FirstOrDefault();

            // Get appName from cache
            var eavAppName = ((BaseCache)DataSource.GetCache(zoneId, null)).ZoneApps[zoneId].Apps[appId];

            if (eavAppName == Constants.DefaultAppName)
            {
                return;
            }

            var EavContext = EavDataController.Instance(zoneId, appId);

            if (appMetaData == null)
            {
                // Add app-describing entity
                var appAttributeSet = EavContext.AttribSet.GetAttributeSet(Settings.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", "" }
                };
                EavContext.Entities.AddEntity(appAttributeSet, values, null, appId, ContentTypeHelpers.AssignmentObjectTypeIDSexyContentApp);
            }

            if (appSettings == null)
            {
                AttributeSet settingsAttributeSet;
                // Add new (empty) ContentType for Settings
                if (!EavContext.AttribSet.AttributeSetExists(Settings.AttributeSetStaticNameAppSettings, appId))
                {
                    settingsAttributeSet = EavContext.AttribSet.AddAttributeSet(Settings.AttributeSetStaticNameAppSettings,
                                                                                "Stores settings for an app", Settings.AttributeSetStaticNameAppSettings, Settings.AttributeSetScopeApps);
                }
                else
                {
                    settingsAttributeSet = EavContext.AttribSet.GetAttributeSet(Settings.AttributeSetStaticNameAppSettings);
                }

                DataSource.GetCache(zoneId, appId).PurgeCache(zoneId, appId);
                EavContext.Entities.AddEntity(settingsAttributeSet, new OrderedDictionary(), null, appId, ContentTypeHelpers.AssignmentObjectTypeIDSexyContentApp);
            }

            if (appResources == null)
            {
                AttributeSet resourcesAttributeSet;

                // Add new (empty) ContentType for Resources
                if (!EavContext.AttribSet.AttributeSetExists(Settings.AttributeSetStaticNameAppResources, appId))
                {
                    resourcesAttributeSet = EavContext.AttribSet.AddAttributeSet(
                        Settings.AttributeSetStaticNameAppResources, "Stores resources like translations for an app",
                        Settings.AttributeSetStaticNameAppResources, Settings.AttributeSetScopeApps);
                }
                else
                {
                    resourcesAttributeSet = EavContext.AttribSet.GetAttributeSet(Settings.AttributeSetStaticNameAppResources);
                }

                DataSource.GetCache(zoneId, appId).PurgeCache(zoneId, appId);
                EavContext.Entities.AddEntity(resourcesAttributeSet, new OrderedDictionary(), null, appId, ContentTypeHelpers.AssignmentObjectTypeIDSexyContentApp);
            }

            if (appMetaData == null || appSettings == null || appResources == null)
            {
                DataSource.GetCache(zoneId, appId).PurgeCache(zoneId, appId);
            }
        }
Ejemplo n.º 12
0
        private int CreateItemAndAddToList(int parentId, string field, int sortOrder, string contentTypeName,
                                           Dictionary <string, object> values, Guid?newGuid)
        {
            var cgApp = SxcContext.App;
            var eavDc = EavDataController.Instance(cgApp.ZoneId, cgApp.AppId);

            eavDc.UserName = Environment.Dnn7.UserIdentity.CurrentUserIdentityToken;

            #region create the new entity --> note that it's the sql-type entity, not a standard ientity

            var contentType =
                DataSource.GetCache(cgApp.ZoneId, cgApp.AppId)
                .GetContentType(contentTypeName);

            int entityId;
            // check that it doesn't exist yet...
            if (newGuid.HasValue && eavDc.Entities.EntityExists(newGuid.Value))
            {
                // check if it's deleted - if yes, resurrect
                var existingEnt = eavDc.Entities.GetEntitiesByGuid(newGuid.Value).First();
                if (existingEnt.ChangeLogDeleted != null)
                {
                    existingEnt.ChangeLogDeleted = null;
                }

                entityId = existingEnt.EntityID;
                // todo: check if it exists on this list, or elsewhere. if it's elsewhere, then map it
                // throw new Exception("can't create this - already exists");
            }
            else
            {
                var entity = eavDc.Entities.AddEntity(contentType.AttributeSetId, values, null, null, entityGuid: newGuid);
                entityId = entity.EntityID;
            }

            #endregion

            #region attach to the current list of items

            var cbEnt = SxcContext.App.Data["Default"].List[parentId];
            // ((EntityContentBlock) SxcContext.ContentBlock).ContentBlockEntity;
            var blockList = ((Eav.Data.EntityRelationship)cbEnt.GetBestValue(field)).ToList() ?? new List <IEntity>();

            var intList = blockList.Select(b => b.EntityId).ToList();
            // add only if it's not already in the list (could happen if http requests are run again)
            if (!intList.Contains(entityId))
            {
                if (sortOrder > intList.Count)
                {
                    sortOrder = intList.Count;
                }
                intList.Insert(sortOrder, entityId);
            }
            var updateDic = new Dictionary <string, int[]> {
                { field, intList.ToArray() }
            };
            eavDc.Entities.UpdateEntity(cbEnt.EntityGuid, updateDic);

            #endregion

            return(entityId);
        }
Ejemplo n.º 13
0
        public static List <Zone> GetZones()
        {
            return(EavDataController.Instance(Constants.DefaultZoneId, AppHelpers.GetDefaultAppId(Constants.DefaultZoneId)).Zone.GetZones());

            //return new SxcInstance(Constants.DefaultZoneId, AppHelpers.GetDefaultAppId(Constants.DefaultZoneId)).EavAppContext.Zone.GetZones();
        }
Ejemplo n.º 14
0
        /// <summary>
        /// Do the import
        /// </summary>
        public bool ImportXml(int zoneId, int appId, XDocument doc, bool leaveExistingValuesUntouched = true)
        {
            //_sexy = new SxcInstance(zoneId, appId); // 2016-03-26 2dm this used to have a third parameter false = don't enable caching, which hasn't been respected for a while; removed it
            // App = new App(zoneId, appId, PortalSettings.Current); // 2016-04-07 2dm refactored this out of this, as using App had side-effects
            _eavContext = EavDataController.Instance(zoneId, appId);

            _appId  = appId;
            _zoneId = zoneId;

            if (!IsCompatible(doc))
            {
                ImportLog.Add(new ExportImportMessage("The import file is not compatible with the installed version of 2sxc.", ExportImportMessage.MessageTypes.Error));
                return(false);
            }

            // Get root node "SexyContent"
            var xmlSource = doc.Element(XmlConstants.RootNode);

            if (xmlSource == null)
            {
                ImportLog.Add(new ExportImportMessage("Xml doesn't have expected root node: " + XmlConstants.RootNode, ExportImportMessage.MessageTypes.Error));
                return(false);
            }
            PrepareFolderIdCorrectionListAndCreateMissingFolders(xmlSource);
            PrepareFileIdCorrectionList(xmlSource);

            #region Prepare dimensions
            _sourceDimensions = xmlSource.Element(XmlConstants.Header)?.Element(XmlConstants.Dimensions)?.Elements(XmlConstants.Dim).Select(p => new Dimension
            {
                DimensionID = int.Parse(p.Attribute(XmlConstants.DimId).Value),
                Name        = p.Attribute("Name").Value,
                SystemKey   = p.Attribute("SystemKey").Value,
                ExternalKey = p.Attribute("ExternalKey").Value,
                Active      = Parse(p.Attribute("Active").Value)
            }).ToList();

            _sourceDefaultLanguage = xmlSource.Element(XmlConstants.Header)?.Element(XmlConstants.Language)?.Attribute(XmlConstants.LangDefault).Value;
            if (_sourceDimensions == null || _sourceDefaultLanguage == null)
            {
                ImportLog.Add(new ExportImportMessage("Cant find source dimensions or source-default language.", ExportImportMessage.MessageTypes.Error));
                return(false);
            }

            _sourceDefaultDimensionId = _sourceDimensions.Any() ?
                                        _sourceDimensions.FirstOrDefault(p => p.ExternalKey == _sourceDefaultLanguage)?.DimensionID
                                : new int?();

            _targetDimensions = _eavContext.Dimensions.GetDimensionChildren("Culture");
            if (_targetDimensions.Count == 0)
            {
                _targetDimensions.Add(new Dimension
                {
                    Active      = true,
                    ExternalKey = DefaultLanguage,
                    Name        = "(added by import System, default language " + DefaultLanguage + ")",
                    SystemKey   = "Culture"
                });
            }
            #endregion

            var atsNodes = xmlSource.Element(XmlConstants.AttributeSets)?.Elements(XmlConstants.AttributeSet);
            var entNodes = xmlSource.Elements(XmlConstants.Entities).Elements(XmlConstants.Entity);

            var importAttributeSets = GetImportAttributeSets(atsNodes);
            var importEntities      = GetImportEntities(entNodes, ContentTypeHelpers.AssignmentObjectTypeIDDefault);

            var import = new Import(_zoneId, _appId, UserName, leaveExistingValuesUntouched);
            import.RunImport(importAttributeSets, importEntities);
            ImportLog.AddRange(GetExportImportMessagesFromImportLog(import.ImportLog));

            if (xmlSource.Elements(XmlConstants.Templates).Any())
            {
                ImportXmlTemplates(xmlSource);
            }

            return(true);
        }