public void SerializeToString()
        {
            var content = new TestPageContent
            {
                Title = "page",
                Header = new PageHeaderContent { Title = "header" },
                Headers = new List<PageHeaderContent> { new PageHeaderContent { Title = "header" } }
            };
            var contentMetadata = metadataManager.GetMetadata(content.GetType());
            var contentData = contentMetadata.ConvertContentModelToDictionary(content);

            var json = JsonContentDataSerializer.SerializeToString(contentData);
            Assert.NotNull(json);
        }
 public static ContentMetadataProvider GetMetadata(this IContentMetadataManager contentMetadataManager, object model)
 {
     if (model == null)
     {
         throw new ArgumentNullException(nameof(model));
     }
     return(contentMetadataManager.GetMetadata(model.GetType()));
 }
Ejemplo n.º 3
0
        public ContentManager(IContentStore <TEntry> store, IContentMetadataManager contentMetadataManager, IServiceProvider services)
        {
            this.contentMetadataManager = contentMetadataManager ?? throw new ArgumentNullException(nameof(contentMetadataManager));
            this.store    = store ?? throw new ArgumentNullException(nameof(store));
            this.services = services ?? throw new ArgumentNullException(nameof(services));

            modelMetadataProvider = contentMetadataManager.GetMetadata <TModel>();
        }
        public void GetMetadata()
        {
            var contentType     = typeof(TestPageContent);
            var contentMetadata = metadataManager.GetMetadata(contentType);

            Assert.NotNull(contentMetadata);
            Assert.Equal(contentMetadata.ModelType, contentType);
            Assert.Equal("TestPage", contentMetadata.Name);
            Assert.Equal(contentMetadata.Title, TestPageContent.ContentTypeTitle);
        }
        public async Task <IActionResult> ChangeModelTypeAsync([FromQuery] Guid editId, [FromQuery] string modelPath, [FromQuery] string modelType, [FromServices] IContentMetadataManager contentMetadataManager, [FromServices] Views.IViewLocator viewLocator)
        {
            if (modelType == null)
            {
                return(BadRequest());
            }

            var editSession = await pageContentService.FindEditByIdAsync(editId);

            if (editSession == null)
            {
                return(BadRequest());
            }

            var page = await pageService.FindPageByIdAsync(editSession.PageId);

            if (page == null)
            {
                return(BadRequest());
            }

            if (modelPath == null)
            {
                modelPath = string.Empty;
            }

            var newModelType = contentMetadataManager.GetMetadata(modelType);

            var pageContent = await pageContentService.GetContentAsync(editSession);

            var pageContentExplorer = ContentExplorer.Create(contentMetadataManager, pageContent);

            var contentExplorer = pageContentExplorer.Navigate(modelPath);

            if (contentExplorer == null)
            {
                return(BadRequest());
            }

            contentExplorer.Field.ChangeType(contentExplorer.Model, modelType);

            var newItem = newModelType.CreateModelInstance();
            var view    = viewLocator.FindView(newModelType.ModelType);

            if (view != null && view.DefaultModelData != null)
            {
                newItem = newModelType.ConvertDictionaryToContentModel(view.DefaultModelData);
            }

            return(Ok());
        }
Ejemplo n.º 6
0
        public static ContentExplorer Create(IContentMetadataManager metadataManager, object model)
        {
            if (metadataManager == null)
            {
                throw new ArgumentNullException(nameof(metadataManager));
            }
            if (model == null)
            {
                throw new ArgumentNullException(nameof(model));
            }

            var contentMetadata = metadataManager.GetMetadata(model.GetType());

            return(new ContentExplorer(model, contentMetadata));
        }
Ejemplo n.º 7
0
        public async Task <ContentProvider <TEntry> > CreateContentAsync <TCustomModel>(TEntry entry, CancellationToken cancellationToken = default)
            where TCustomModel : TModel
        {
            if (entry == null)
            {
                throw new ArgumentNullException(nameof(entry));
            }

            var customContentMetadataProvider = contentMetadataManager.GetMetadata <TModel>();
            var model       = customContentMetadataProvider.CreateModelInstance();
            var contentData = customContentMetadataProvider.ConvertContentModelToDictionary(model);

            await store.SetContentAsync(entry, contentData, cancellationToken);

            customContentMetadataProvider.ApplyInjections(model, services, true);

            return(ContentProvider <TEntry> .Create(entry, model, services));
        }
Ejemplo n.º 8
0
        Task IAsyncLifetime.InitializeAsync()
        {
            var contentTypeResolver = new Infrastructure.AssemblyContentTypeLocator(new System.Reflection.Assembly[] { typeof(TestPageContent).Assembly });

            var services = new ServiceCollection();

            services.AddSingleton <IContentMetadataManager, ContentMetadataManager>();
            services.AddSingleton <Infrastructure.IContentTypeLocator>(contentTypeResolver);

            serviceProvider = services.BuildServiceProvider();
            serviceScope    = serviceProvider.CreateScope();

            metadataManager = serviceScope.ServiceProvider.GetRequiredService <IContentMetadataManager>();

            var metadataProvider = metadataManager.GetMetadata <TestContent>();

            if (!metadataProvider.TryGetField("Text", out field))
            {
                throw new System.Exception();
            }

            return(Task.CompletedTask);
        }
 public static ContentMetadataProvider GetMetadata <T>(this IContentMetadataManager contentMetadataManager)
     where T : class
 {
     return(contentMetadataManager.GetMetadata(typeof(T)));
 }
        public void Properties()
        {
            var contentMetadata = metadataManager.GetMetadata <TestPageContent>();

            Assert.Equal(metadataManager, contentMetadata.Manager);
            Assert.Equal(typeof(TestPageContent), contentMetadata.ModelType);
            Assert.Equal("TestPage", contentMetadata.Name);
            Assert.Equal(contentMetadata.Name, contentMetadata.ToString());
            Assert.Equal(TestPageContent.ContentTypeTitle, contentMetadata.Title);
            Assert.Equal(TestPageContent.ContentTypeDescription, contentMetadata.Description);
            Assert.Null(contentMetadata.BaseMetadata);
            Assert.NotEmpty(contentMetadata.DerivedContents);
            Assert.NotEmpty(contentMetadata.Fields);
        }