예제 #1
0
        /// <summary>
        /// Add new Content Types for Pipeline Designer
        /// </summary>
        /// <remarks>Some Content Types are defined in EAV but some only in 2sxc. EAV.VersionUpgrade ensures Content Types are shared across all Apps.</remarks>
        private static void EnsurePipelineDesignerAttributeSets()
        {
            // Ensure DnnSqlDataSource Configuration
            var dsrcSqlDataSource = Eav.Import.AttributeSet.SystemAttributeSet("|Config ToSic.SexyContent.DataSources.DnnSqlDataSource", "used to configure a DNN SqlDataSource",
                                                                               new List <Eav.Import.Attribute>
            {
                Eav.Import.Attribute.StringAttribute("ContentType", "ContentType", null, true),
                Eav.Import.Attribute.StringAttribute("SelectCommand", "SelectCommand", null, true, rowCount: 10)
            });

            // Collect AttributeSets for use in Import
            var attributeSets = new List <Eav.Import.AttributeSet>
            {
                dsrcSqlDataSource
            };
            var import = new Eav.Import.Import(DataSource.DefaultZoneId, DataSource.MetaDataAppId, SexyContent.InternalUserName);

            import.RunImport(attributeSets, null);

            var metaDataCtx = EavContext.Instance(DataSource.DefaultZoneId, DataSource.MetaDataAppId);

            metaDataCtx.GetAttributeSet(dsrcSqlDataSource.StaticName).AlwaysShareConfiguration = true;
            metaDataCtx.SaveChanges();

            // Run EAV Version Upgrade (also ensures Content Type sharing)
            var eavVersionUpgrade = new VersionUpgrade(SexyContent.InternalUserName);

            eavVersionUpgrade.EnsurePipelineDesignerAttributeSets();
        }
예제 #2
0
 /// <summary>
 /// Create a simple data controller to create, update and delete entities.
 /// </summary>
 /// <param name="zoneId">Zone ID</param>
 /// <param name="appId">App ID</param>
 /// <param name="userName">Name of user loged in</param>
 /// <param name="defaultLanguageCode">Default language of system</param>
 public SimpleDataController(int zoneId, int appId, string userName, string defaultLanguageCode)
 {
     this._zoneId              = zoneId;
     this._appId               = appId;
     this._userName            = userName;
     this._defaultLanguageCode = defaultLanguageCode;
     this._contentContext      = EavContext.Instance(zoneId, appId);
 }
예제 #3
0
        public void DimensionsCacheTest()
        {
            var Context = new EavContext();
            var dim = Context.DimCommands;
            var Entity1 = dim.GetLanguages();
            var Entity2 = dim.GetLanguages();
            var Entity3 = dim.GetLanguages();

            //Context.UpdateEntity();
        }
예제 #4
0
        /// <summary>
        /// Provides appropriate context based on route data.
        /// </summary>
        public EavContext CreateContext()
        {
            var connectionName = (string)_httpContextAccessor.HttpContext.GetRouteData().Values["db"];

            if (!_contexts.TryGetValue(connectionName, out var context))
            {
                var connection = _configuration.GetConnectionString(connectionName);
                if (connection == null)
                {
                    throw new System.Exception($"Unknown database {connectionName} passed.");
                }
                var options = new DbContextOptionsBuilder().UseSqlServer(connection).Options;
                context = new EavContext(options);
                context.Database.EnsureCreated();
            }

            return(context);
        }
예제 #5
0
        private static Import.ImportEntity GetSampleNewsEntity(EavContext db, Guid? entityGuid)
        {
            var attributeSetStaticName = db.AttributeSets.Where(a => a.AppID == db.AppId && a.Name == "News").Select(a => a.StaticName).Single();

            var entity = new Import.ImportEntity
            {
                EntityGuid = entityGuid,
                AttributeSetStaticName = attributeSetStaticName,
                AssignmentObjectTypeId = Constants.DefaultAssignmentObjectTypeId
            };

            entity.Values = new Dictionary<string, List<IValueImportModel>>
            {
                {"Title", new List<IValueImportModel>
                {
                    new ValueImportModel<string>(entity)
                    {
                        Value = "Fivth News en",
                        ValueDimensions = new List<Import.ValueDimension>
                        {
                            new Import.ValueDimension {DimensionExternalKey = "en-us", ReadOnly = false},
                        }
                    },
                    new ValueImportModel<string>(entity)
                    {
                        Value = "Fünfte News de",
                        ValueDimensions = new List<Import.ValueDimension>
                        {
                            new Import.ValueDimension {DimensionExternalKey = "de-ch", ReadOnly = false},
                        }
                    }
                }},
                {"Date", new List<IValueImportModel>
                {
                    new ValueImportModel<DateTime?>(entity)
                    {
                        Value = new DateTime(2014,3,18),
                        ValueDimensions = new List<Import.ValueDimension>
                        {
                            new Import.ValueDimension{ DimensionExternalKey = "en-US", ReadOnly = false},
                            new Import.ValueDimension{ DimensionExternalKey = "de-CH", ReadOnly = true},
                        }
                    }
                }},
                {"Short", new List<IValueImportModel>
                {
                    new ValueImportModel<string>(entity)
                    {
                        Value = "Third news short",
                        ValueDimensions = new List<Import.ValueDimension>{ new Import.ValueDimension{ DimensionExternalKey = "en-US", ReadOnly = false}}
                    },
                    new ValueImportModel<string>(entity)
                    {
                        Value = "Dritte News kurz",
                        ValueDimensions = new List<Import.ValueDimension>{ new Import.ValueDimension{ DimensionExternalKey = "de-CH", ReadOnly = false}}
                    }
                }},
                {"Long", new List<IValueImportModel>
                {
                    new ValueImportModel<string>(entity)
                    {
                        Value = "Third news long",
                        ValueDimensions = new List<Import.ValueDimension>{ new Import.ValueDimension{ DimensionExternalKey = "en-US", ReadOnly = false}}
                    },
                    new ValueImportModel<string>(entity)
                    {
                        Value = "Dritte News lang",
                        ValueDimensions = new List<Import.ValueDimension>{ new Import.ValueDimension{ DimensionExternalKey = "de-CH", ReadOnly = false}}
                    }
                }},
            };

            return entity;
        }
예제 #6
0
        public void UpdateExistingData()
        {
            // Update Attribute Set
            const string attributeSetStaticName = "AttributeSet_181655_1";
            const string now = "181655";
            var attributeSet = new Import.ImportAttributeSet
            {
                Attributes = GetAttributes(1, now),
                Description = "New Description",
                Name = "New Name",
                Scope = "New Scope",
                StaticName = attributeSetStaticName,
            };
            attributeSet.Attributes.Add(new Import.ImportAttribute { StaticName = "AttributeAddedLater", Type = "String" });
            attributeSet.TitleAttribute = attributeSet.Attributes.Last();

            const bool overwriteExistingEntityValues = true;
            var import = new Import.Import(2, 2, "ImportTest2", overwriteExistingEntityValues);
            var attributeSets = new List<Import.ImportAttributeSet> { attributeSet };

            // Update Entity
            const int entityId = 5483;
            var db = new EavContext();
            var entityGuid = db.Entities.Where(e => e.EntityID == entityId).Select(e => e.EntityGUID).Single();

            var entity = new Import.ImportEntity
            {
                EntityGuid = entityGuid,
                AttributeSetStaticName = attributeSetStaticName,
                KeyNumber = 999,
                AssignmentObjectTypeId = Constants.DefaultAssignmentObjectTypeId
            };
            entity.Values = GetEntityValues(entity, attributeSet, isUpdate: true, now: DateTime.Now.ToLongTimeString().Replace(":", ""));
            var entities = new List<Import.ImportEntity> { entity };

            import.RunImport(null, entities);

            Assert.IsEmpty(import.ImportLog);
            Assert.IsFalse(import.ImportLog.Any(l => l.EntryType == EventLogEntryType.Error));
        }
예제 #7
0
 public EntityFrameworkEavRepository(ContextFactory contextFactory, IEntityConverter entityConverter)
 {
     _context         = contextFactory.CreateContext();
     _entityConverter = entityConverter;
 }
예제 #8
0
        public void DimensionsTest()
        {
            var Context = new EavContext();
            var DbS = new DbShortcuts(Context);

            var Entity = DbS.GetEntity(277);

            //Context.UpdateEntity();
        }
예제 #9
0
        public void TestCache()
        {
            var Context = new EavContext();
            //Context.ItemCachingEnabled = true;

            for (int i = 0; i < 10000; i++)
            {
                //Context.GetItems(new List<int>() { 274, 275, 276 });
                //Context.GetItems(new List<int>() { 273 });
                //Context.GetItems(new List<int>() { 272 });
            }

            Context.SaveChanges();
        }
예제 #10
0
        public void GetDataForCache2()
        {
            var db = new EavContext();

            var appId = 1;
            var entitiesValues = from e in db.Entities
                                 where !e.ChangeLogIDDeleted.HasValue && e.Set.AppID == appId
                                 select new
                                 {
                                     e.EntityID,
                                     e.EntityGUID,
                                     e.AttributeSetID,
                                     e.KeyGuid,
                                     e.KeyNumber,
                                     e.KeyString,
                                     e.AssignmentObjectTypeID,
                                     RelatedEntities = from r in e.EntityParentRelationships
                                                       group r by r.AttributeID into rg
                                                       select new
                                                       {
                                                           AttributeID = rg.Key,
                                                           AttributeName = rg.Select(a => a.Attribute.StaticName).FirstOrDefault(),
                                                           IsTitle = rg.Any(v1 => v1.Attribute.AttributesInSets.Any(s => s.IsTitle)),
                                                           Childs = rg.OrderBy(c => c.SortOrder).Select(c => c.ChildEntityID)
                                                       },
                                     Attributes = from v in e.Values
                                                  where !v.ChangeLogIDDeleted.HasValue
                                                  group v by v.AttributeID into vg
                                                  select new
                                                  {
                                                      AttributeID = vg.Key,
                                                      AttributeName = vg.Select(v1 => v1.Attribute.StaticName).FirstOrDefault(),
                                                      AttributeType = vg.Select(v1 => v1.Attribute.Type).FirstOrDefault(),
                                                      IsTitle = vg.Any(v1 => v1.Attribute.AttributesInSets.Any(s => s.IsTitle)),
                                                      Values = from v2 in vg
                                                               orderby v2.ChangeLogIDCreated
                                                               select new
                                                               {
                                                                   v2.ValueID,
                                                                   v2.Value,
                                                                   Languages = from l in v2.ValuesDimensions select new { DimensionId = l.DimensionID, ReadOnly = l.ReadOnly, Key = l.Dimension.ExternalKey },
                                                                   v2.ChangeLogIDCreated
                                                               }
                                                  }
                                 };
            entitiesValues.ToList();
        }