public static void SynchronizePageTypes() { using (var context = new DataContext()) { var fetchStrategy = new FetchStrategy { MaxFetchDepth = 1 }; fetchStrategy.LoadWith <PageTypeEntity>(pt => pt.Properties); fetchStrategy.LoadWith <PropertyEntity>(p => p.PropertyType); context.FetchStrategy = fetchStrategy; var pageTypeEntities = context.PageTypes.ToList(); var pageTypes = new List <PageType>(); var typesWithAttribute = AttributeReader.GetTypesWithAttribute(typeof(PageTypeAttribute)).ToList(); foreach (var type in typesWithAttribute) { var attribute = AttributeReader.GetAttribute <PageTypeAttribute>(type); var pageTypeEntity = pageTypeEntities.SingleOrDefault(pt => pt.Name == attribute.Name); if (pageTypeEntity == null) { pageTypeEntity = new PageTypeEntity(); pageTypeEntities.Add(pageTypeEntity); } pageTypeEntity.DefaultChildSortDirection = attribute.DefaultChildSortDirection; pageTypeEntity.DefaultChildSortOrder = attribute.DefaultChildSortOrder; pageTypeEntity.DisplayName = attribute.DisplayName; pageTypeEntity.Name = attribute.Name; pageTypeEntity.PageTemplate = attribute.PageTemplate; pageTypeEntity.PageTypeDescription = attribute.PageTypeDescription; if (pageTypeEntity.PageTypeId == 0) { context.Add(pageTypeEntity); } context.SaveChanges(); var pageType = Mapper.Map <PageTypeEntity, PageType>(pageTypeEntity); pageType.Type = type; pageType.AllowedTypes = attribute.AllowedTypes; pageType.PreviewImage = attribute.PreviewImage; pageType.Instance = (CmsPage)Activator.CreateInstance(type); pageTypes.Add(pageType); SynchronizeProperties(context, pageType, type, pageTypeEntity.Properties); } PageType.PageTypes = pageTypes; } }
public static void SynchronizePageTypes() { using (var context = new DataContext()) { var fetchStrategy = new FetchStrategy {MaxFetchDepth = 1}; fetchStrategy.LoadWith<PageTypeEntity>(pt => pt.Properties); fetchStrategy.LoadWith<PropertyEntity>(p => p.PropertyType); context.FetchStrategy = fetchStrategy; var pageTypeEntities = context.PageTypes.ToList(); var pageTypes = new List<PageType>(); var typesWithAttribute = AttributeReader.GetTypesWithAttribute(typeof(PageTypeAttribute)).ToList(); foreach (var type in typesWithAttribute) { var attribute = AttributeReader.GetAttribute<PageTypeAttribute>(type); var pageTypeEntity = pageTypeEntities.SingleOrDefault(pt => pt.Name == attribute.Name); if (pageTypeEntity == null) { pageTypeEntity = new PageTypeEntity(); pageTypeEntities.Add(pageTypeEntity); } pageTypeEntity.DefaultChildSortDirection = attribute.DefaultChildSortDirection; pageTypeEntity.DefaultChildSortOrder = attribute.DefaultChildSortOrder; pageTypeEntity.DisplayName = attribute.DisplayName; pageTypeEntity.Name = attribute.Name; pageTypeEntity.PageTemplate = attribute.PageTemplate; pageTypeEntity.PageTypeDescription = attribute.PageTypeDescription; if (pageTypeEntity.PageTypeId == 0) { context.Add(pageTypeEntity); } context.SaveChanges(); var pageType = Mapper.Map<PageTypeEntity, PageType>(pageTypeEntity); pageType.Type = type; pageType.AllowedTypes = attribute.AllowedTypes; pageType.PreviewImage = attribute.PreviewImage; pageType.Instance = (CmsPage)Activator.CreateInstance(type); pageTypes.Add(pageType); SynchronizeProperties(context, pageType, type, pageTypeEntity.Properties); } PageType.PageTypes = pageTypes; } }
public async Task Page() { var siteTypeId = $"MySiteType-{Guid.NewGuid():N}"; var pageTypeId = $"MyPageType-{Guid.NewGuid():N}"; using ISession session = _sessionFactory.OpenSession(); using ITransaction txn = session.BeginTransaction(); var siteType = new SiteTypeEntity() { Id = siteTypeId, Created = DateTime.Now, LastModified = DateTime.Now }; var site = new SiteEntity { Culture = "en-NZ", Description = "My site", Hostnames = "example.org", InternalId = $"{Guid.NewGuid():N}", SiteTypeId = siteTypeId, Title = "Welcome to Example.org" }; var pageType = new PageTypeEntity { Id = pageTypeId, Created = DateTime.Now, LastModified = DateTime.Now }; var page = new PageEntity { Created = DateTime.Now, LastModified = DateTime.Now, Title = "Home page", PageType = pageType, Site = site, ContentType = "Page" }; var retrievedSiteTypeId = await session.SaveAsync(siteType).ConfigureAwait(false); var siteId = await session.SaveAsync(site).ConfigureAwait(false); var retrievedPageTypeId = await session.SaveAsync(pageType).ConfigureAwait(false); var pageId = await session.SaveAsync(page).ConfigureAwait(false); await txn.CommitAsync().ConfigureAwait(false); }
public async Task PageType() { var pageTypeId = $"MyPageType-{Guid.NewGuid():N}"; using ISession session = _sessionFactory.OpenSession(); using ITransaction txn = session.BeginTransaction(); var pageType = new PageTypeEntity { Id = pageTypeId, Created = DateTime.Now, LastModified = DateTime.Now }; var retrievedPageTypeId = await session.SaveAsync(pageType).ConfigureAwait(false); await txn.CommitAsync().ConfigureAwait(false); }