Beispiel #1
0
        public void SetupDynamicTypes()
        {
            var fullDynamicTypeId = Guid.NewGuid();

            var repositories = new RepositoryMetadataManager();

            repositories.Save(new RepositoryMetdata
            {
                CustomRepositoryName = "Article",
                IsDynamic            = true,
                ApiId = fullDynamicTypeId
            });

            var mgr  = new ContentInterfaceRepository();
            var ext1 = new ContentInterface
            {
                ContentTypeId = fullDynamicTypeId,
                InterfaceName = KnownTypeExtensionNames.CustomFields
            };
            var ext2 = new ContentInterface
            {
                ContentTypeId = fullDynamicTypeId,
                InterfaceName = "SomePluginInfo"
            };

            mgr.Save(ext1);
            mgr.Save(ext2);

            var extension = mgr.GetCustomFieldsTypeExtension(fullDynamicTypeId);

            extension.InterfaceFields.Add(new ChoiceInterfaceField
            {
                PropertyName     = "IsFeatured",
                PropertyTypeName = typeof(bool).FullName
            });

            mgr.Save(extension);

            var repo = RepositoryActivator.ActivateRepository <ISupportsCmsForms>(fullDynamicTypeId);

            repo.Save(new DynamicVersionedContent(fullDynamicTypeId));
            //var drafts = repo.FindContentVersions("", ContentEnvironment.Draft);
            //if (!drafts.Any())
            //    throw new Exception();
        }
Beispiel #2
0
        public void SetupCustomFields()
        {
            var mgr       = new ContentInterfaceRepository();
            var extension = mgr.GetCustomFieldsTypeExtension(new Guid(CmsPage.ApiId));

            extension.InterfaceFields.Add(new ChoiceInterfaceField
            {
                PropertyName     = "DisplayInNav",
                PropertyTypeName = typeof(bool).FullName
            });

            mgr.Save(extension);
        }
Beispiel #3
0
        public static void RegisterExtensibleTypesWithApi(AppDomain domain)
        {
            var assemblies = domain.GetAssemblies();
            var allTypes   = assemblies.SelectMany(x => x.GetTypes()).ToList();

            var repositoryDescriptions = TypeSearcher.FindRepositoriesKnownToWarpCore(allTypes);

            foreach (var repositoryDescription in repositoryDescriptions)
            {
                BuildUpRepositoryMetadata(repositoryDescription);
            }

            //Break this one out later.
            var entities = TypeSearcher.FindEntitiesKnownToWarpCore(allTypes);

            var contentTypeMetadataRepository = new ContentTypeMetadataRepository();

            var typeExtensionRepo = new ContentInterfaceRepository();

            foreach (var entityType in entities)
            {
                var repositoryUid = entityType.GetCustomAttribute <WarpCoreEntityAttribute>();

                var preexistingContentType = contentTypeMetadataRepository.Find().SingleOrDefault(x => x.TypeResolverId == repositoryUid.TypeExtensionUid);
                if (preexistingContentType == null)
                {
                    preexistingContentType = new DynamicContentType
                    {
                        TypeResolverId = repositoryUid.TypeExtensionUid,
                    }
                }
                ;

                preexistingContentType.ContentNameSingular = repositoryUid.ContentNameSingular;
                preexistingContentType.ContentNamePlural   = repositoryUid.ContentNamePlural;

                if (string.IsNullOrWhiteSpace(preexistingContentType.ContentNameSingular))
                {
                    preexistingContentType.ContentNameSingular = entityType.Name;
                }

                if (string.IsNullOrWhiteSpace(preexistingContentType.ContentNamePlural))
                {
                    //todo: replace
                    //PluralizationService.CreateService(CultureInfo.CurrentCulture)
                    //    .Pluralize(preexistingContentType.ContentNameSingular);
                }
                preexistingContentType.SupportsCustomFields = repositoryUid.SupportsCustomFields;
                preexistingContentType.TitleProperty        = repositoryUid.TitleProperty;

                contentTypeMetadataRepository.Save(preexistingContentType);

                if (preexistingContentType.SupportsCustomFields)
                {
                    var preexisting = typeExtensionRepo.Find().SingleOrDefault(x =>
                                                                               x.ContentTypeId == repositoryUid.TypeExtensionUid &&
                                                                               x.InterfaceName == KnownTypeExtensionNames.CustomFields);
                    if (preexisting == null)
                    {
                        typeExtensionRepo.Save(new ContentInterface
                        {
                            ContentTypeId = repositoryUid.TypeExtensionUid,
                            InterfaceName = KnownTypeExtensionNames.CustomFields
                        });
                    }
                }
            }
        }