Exemple #1
0
        /// <summary>
        /// Sets up & initializes the tests.
        /// </summary>
        protected override void Init()
        {
            Piranha.App.Init();
            Piranha.App.Fields.Register <MyFirstField>();

            fields.Register <MyFirstField>();
            fields.Register <MyThirdField>();
        }
Exemple #2
0
        /// <summary>
        /// Sets up & initializes the tests.
        /// </summary>
        protected override void Init()
        {
            using (var api = new Api(GetDb(), new ContentServiceFactory(services), storage)) {
                Piranha.App.Init(api);
                Piranha.App.Fields.Register <MyFirstField>();

                fields.Register <MyFirstField>();
                fields.Register <MyThirdField>();
            }
        }
Exemple #3
0
        /// <summary>
        /// Sets up & initializes the tests.
        /// </summary>
        protected override void Init()
        {
            using (var api = CreateApi())
            {
                Piranha.App.Init(api);
                Piranha.App.Fields.Register <MyFirstField>();

                fields.Register <MyFirstField>();
                fields.Register <MyThirdField>();
            }
        }
Exemple #4
0
        /// <summary>
        /// Initializes the application object.
        /// </summary>
        /// <param name="api">The current api</param>
        private void Initialize(Api api)
        {
            if (!isInitialized)
            {
                lock (mutex) {
                    if (!isInitialized)
                    {
                        // Configure object mapper
                        var mapperConfig = new MapperConfiguration(cfg => {
                            cfg.CreateMap <Data.Page, Models.PageBase>()
                            .ForMember(p => p.TypeId, o => o.MapFrom(m => m.PageTypeId));
                            cfg.CreateMap <Models.PageBase, Data.Page>()
                            .ForMember(p => p.PageTypeId, o => o.MapFrom(m => m.TypeId))
                            .ForMember(p => p.Fields, o => o.Ignore())
                            .ForMember(p => p.Created, o => o.Ignore())
                            .ForMember(p => p.LastModified, o => o.Ignore());
                            cfg.CreateMap <Data.Page, Models.SitemapItem>()
                            .ForMember(p => p.MenuTitle, o => o.Ignore())
                            .ForMember(p => p.Level, o => o.Ignore())
                            .ForMember(p => p.Items, o => o.Ignore())
                            .ForMember(p => p.Permalink, o => o.MapFrom(d => string.IsNullOrWhiteSpace(d.ParentId) && d.SortOrder == 0 ? "/" : d.Slug));
                        });
                        mapperConfig.AssertConfigurationIsValid();
                        mapper = mapperConfig.CreateMapper();

                        // Compose field types
                        fields.Register <Extend.Fields.HtmlField>();
                        fields.Register <Extend.Fields.MarkdownField>();
                        fields.Register <Extend.Fields.StringField>();
                        fields.Register <Extend.Fields.TextField>();

                        // Create markdown converter
                        markdown = new Markdown();

                        // Initialize all modules
                        foreach (var module in this.modules)
                        {
                            module.Instance.Init();
                        }

                        isInitialized = true;
                    }
                }
            }
        }
Exemple #5
0
        /// <summary>
        /// Initializes the application object.
        /// </summary>
        /// <param name="api">The current api</param>
        private void Initialize(IApi api)
        {
            if (!isInitialized)
            {
                lock (mutex) {
                    if (!isInitialized)
                    {
                        // Configure object mapper
                        var mapperConfig = new MapperConfiguration(cfg => {
                            cfg.CreateMap <Data.MediaFolder, Models.MediaStructureItem>()
                            .ForMember(f => f.Level, o => o.Ignore())
                            .ForMember(f => f.Items, o => o.Ignore());
                            cfg.CreateMap <Data.Page, Models.PageBase>()
                            .ForMember(p => p.TypeId, o => o.MapFrom(m => m.PageTypeId));
                            cfg.CreateMap <Models.PageBase, Data.Page>()
                            .ForMember(p => p.PageTypeId, o => o.MapFrom(m => m.TypeId))
                            .ForMember(p => p.Fields, o => o.Ignore())
                            .ForMember(p => p.Created, o => o.Ignore())
                            .ForMember(p => p.LastModified, o => o.Ignore());
                            cfg.CreateMap <Data.Page, Models.SitemapItem>()
                            .ForMember(p => p.MenuTitle, o => o.Ignore())
                            .ForMember(p => p.Level, o => o.Ignore())
                            .ForMember(p => p.Items, o => o.Ignore())
                            .ForMember(p => p.Permalink, o => o.MapFrom(d => string.IsNullOrWhiteSpace(d.ParentId) && d.SortOrder == 0 ? "/" : "/" + d.Slug));
                        });
                        mapperConfig.AssertConfigurationIsValid();
                        mapper = mapperConfig.CreateMapper();

                        // Setup media types
                        mediaTypes.Documents.Add(".pdf", "application/pdf");
                        mediaTypes.Images.Add(".jpg", "image/jpeg");
                        mediaTypes.Images.Add(".jpeg", "image/jpeg");
                        mediaTypes.Images.Add(".png", "image/png");
                        mediaTypes.Videos.Add(".mp4", "video/mp4");

                        // Compose field types
                        fields.Register <Extend.Fields.DateField>();
                        fields.Register <Extend.Fields.HtmlField>();
                        fields.Register <Extend.Fields.ImageField>();
                        fields.Register <Extend.Fields.MarkdownField>();
                        fields.Register <Extend.Fields.StringField>();
                        fields.Register <Extend.Fields.TextField>();

                        // Compose serializers
                        serializers.Register <Extend.Fields.DateField>(new DateFieldSerializer());
                        serializers.Register <Extend.Fields.HtmlField>(new StringFieldSerializer <Extend.Fields.HtmlField>());
                        serializers.Register <Extend.Fields.MarkdownField>(new StringFieldSerializer <Extend.Fields.MarkdownField>());
                        serializers.Register <Extend.Fields.StringField>(new StringFieldSerializer <Extend.Fields.StringField>());
                        serializers.Register <Extend.Fields.TextField>(new StringFieldSerializer <Extend.Fields.TextField>());
                        serializers.Register <Extend.Fields.ImageField>(new ImageFieldSerializer());

                        // Create markdown converter
                        markdown = new DefaultMarkdown();

                        // Initialize all modules
                        foreach (var module in modules)
                        {
                            module.Instance.Init();
                        }

                        isInitialized = true;
                    }
                }
            }
        }
Exemple #6
0
        /// <summary>
        /// Initializes the application object.
        /// </summary>
        /// <param name="api">The current api</param>
        private void Initialize()
        {
            if (!_isInitialized)
            {
                lock (_mutex)
                {
                    if (!_isInitialized)
                    {
                        // Configure object mapper
                        var mapperConfig = new MapperConfiguration(cfg =>
                        {
                            cfg.CreateMap <Data.Alias, Data.Alias>()
                            .ForMember(a => a.Id, o => o.Ignore())
                            .ForMember(a => a.Created, o => o.Ignore());
                            cfg.CreateMap <Data.Category, Data.Category>()
                            .ForMember(c => c.Id, o => o.Ignore())
                            .ForMember(c => c.Created, o => o.Ignore());
                            cfg.CreateMap <Data.MediaFolder, Data.MediaFolder>()
                            .ForMember(f => f.Id, o => o.Ignore())
                            .ForMember(f => f.Created, o => o.Ignore())
                            .ForMember(f => f.Media, o => o.Ignore());
                            cfg.CreateMap <Data.MediaFolder, Models.MediaStructureItem>()
                            .ForMember(f => f.Level, o => o.Ignore())
                            .ForMember(f => f.Items, o => o.Ignore());
                            cfg.CreateMap <Data.Page, Models.PageBase>()
                            .ForMember(p => p.TypeId, o => o.MapFrom(m => m.PageTypeId))
                            .ForMember(p => p.Permalink, o => o.MapFrom(m => "/" + m.Slug))
                            .ForMember(p => p.Blocks, o => o.Ignore());
                            cfg.CreateMap <Models.PageBase, Data.Page>()
                            .ForMember(p => p.PageTypeId, o => o.MapFrom(m => m.TypeId))
                            .ForMember(p => p.Blocks, o => o.Ignore())
                            .ForMember(p => p.Fields, o => o.Ignore())
                            .ForMember(p => p.Created, o => o.Ignore())
                            .ForMember(p => p.LastModified, o => o.Ignore())
                            .ForMember(p => p.PageType, o => o.Ignore())
                            .ForMember(p => p.Site, o => o.Ignore())
                            .ForMember(p => p.Parent, o => o.Ignore());
                            cfg.CreateMap <Data.Page, Models.SitemapItem>()
                            .ForMember(p => p.MenuTitle, o => o.Ignore())
                            .ForMember(p => p.Level, o => o.Ignore())
                            .ForMember(p => p.Items, o => o.Ignore())
                            .ForMember(p => p.PageTypeName, o => o.Ignore())
                            .ForMember(p => p.Permalink, o => o.MapFrom(d => !d.ParentId.HasValue && d.SortOrder == 0 ? "/" : "/" + d.Slug));
                            cfg.CreateMap <Data.Param, Data.Param>()
                            .ForMember(p => p.Id, o => o.Ignore())
                            .ForMember(p => p.Created, o => o.Ignore());
                            cfg.CreateMap <Data.Post, Models.PostBase>()
                            .ForMember(p => p.TypeId, o => o.MapFrom(m => m.PostTypeId))
                            .ForMember(p => p.Permalink, o => o.MapFrom(m => "/" + m.Blog.Slug + "/" + m.Slug))
                            .ForMember(p => p.Blocks, o => o.Ignore());
                            cfg.CreateMap <Models.PostBase, Data.Post>()
                            .ForMember(p => p.PostTypeId, o => o.MapFrom(m => m.TypeId))
                            .ForMember(p => p.CategoryId, o => o.MapFrom(m => m.Category.Id))
                            .ForMember(p => p.Blocks, o => o.Ignore())
                            .ForMember(p => p.Fields, o => o.Ignore())
                            .ForMember(p => p.Created, o => o.Ignore())
                            .ForMember(p => p.LastModified, o => o.Ignore())
                            .ForMember(p => p.PostType, o => o.Ignore())
                            .ForMember(p => p.Blog, o => o.Ignore())
                            .ForMember(p => p.Category, o => o.Ignore())
                            .ForMember(p => p.Tags, o => o.Ignore());
                            cfg.CreateMap <Data.Site, Data.Site>()
                            .ForMember(s => s.Id, o => o.Ignore())
                            .ForMember(s => s.Created, o => o.Ignore());
                            cfg.CreateMap <Data.Site, Models.SiteContentBase>()
                            .ForMember(s => s.TypeId, o => o.MapFrom(m => m.SiteTypeId));
                            cfg.CreateMap <Models.SiteContentBase, Data.Site>()
                            .ForMember(s => s.SiteTypeId, o => o.Ignore())
                            .ForMember(s => s.InternalId, o => o.Ignore())
                            .ForMember(s => s.Description, o => o.Ignore())
                            .ForMember(s => s.Hostnames, o => o.Ignore())
                            .ForMember(s => s.IsDefault, o => o.Ignore())
                            .ForMember(s => s.Fields, o => o.Ignore())
                            .ForMember(s => s.Created, o => o.Ignore())
                            .ForMember(s => s.LastModified, o => o.Ignore());
                            cfg.CreateMap <Data.Tag, Data.Tag>()
                            .ForMember(t => t.Id, o => o.Ignore())
                            .ForMember(t => t.Created, o => o.Ignore());
                        });
                        mapperConfig.AssertConfigurationIsValid();
                        _mapper = mapperConfig.CreateMapper();

                        // Setup media types
                        _mediaTypes.Documents.Add(".pdf", "application/pdf");
                        _mediaTypes.Images.Add(".jpg", "image/jpeg");
                        _mediaTypes.Images.Add(".jpeg", "image/jpeg");
                        _mediaTypes.Images.Add(".png", "image/png");
                        _mediaTypes.Videos.Add(".mp4", "video/mp4");

                        // Compose content types
                        _contentTypes.Register <Models.IPage>("Page", "Page");
                        _contentTypes.Register <Models.IBlogPage>("Blog", "Archive", true);

                        // Compose field types
                        _fields.Register <Extend.Fields.CheckBoxField>();
                        _fields.Register <Extend.Fields.DateField>();
                        _fields.Register <Extend.Fields.DocumentField>();
                        _fields.Register <Extend.Fields.HtmlField>();
                        _fields.Register <Extend.Fields.ImageField>();
                        _fields.Register <Extend.Fields.MarkdownField>();
                        _fields.Register <Extend.Fields.MediaField>();
                        _fields.Register <Extend.Fields.NumberField>();
                        _fields.Register <Extend.Fields.PageField>();
                        _fields.Register <Extend.Fields.PostField>();
                        _fields.Register <Extend.Fields.StringField>();
                        _fields.Register <Extend.Fields.TextField>();
                        _fields.Register <Extend.Fields.VideoField>();

                        // Compose block types
                        _blocks.Register <Extend.Blocks.HtmlBlock>();
                        _blocks.Register <Extend.Blocks.HtmlColumnBlock>();
                        _blocks.Register <Extend.Blocks.ImageBlock>();
                        _blocks.Register <Extend.Blocks.QuoteBlock>();
                        _blocks.Register <Extend.Blocks.TextBlock>();

                        // Compose serializers
                        _serializers.Register <Extend.Fields.CheckBoxField>(new CheckBoxFieldSerializer <Extend.Fields.CheckBoxField>());
                        _serializers.Register <Extend.Fields.DateField>(new DateFieldSerializer());
                        _serializers.Register <Extend.Fields.DocumentField>(new DocumentFieldSerializer());
                        _serializers.Register <Extend.Fields.HtmlField>(new StringFieldSerializer <Extend.Fields.HtmlField>());
                        _serializers.Register <Extend.Fields.MarkdownField>(new StringFieldSerializer <Extend.Fields.MarkdownField>());
                        _serializers.Register <Extend.Fields.MediaField>(new MediaFieldSerializer());
                        _serializers.Register <Extend.Fields.NumberField>(new IntegerFieldSerializer <Extend.Fields.NumberField>());
                        _serializers.Register <Extend.Fields.PageField>(new PageFieldSerializer());
                        _serializers.Register <Extend.Fields.PostField>(new PostFieldSerializer());
                        _serializers.Register <Extend.Fields.StringField>(new StringFieldSerializer <Extend.Fields.StringField>());
                        _serializers.Register <Extend.Fields.TextField>(new StringFieldSerializer <Extend.Fields.TextField>());
                        _serializers.Register <Extend.Fields.ImageField>(new ImageFieldSerializer());
                        _serializers.Register <Extend.Fields.VideoField>(new VideoFieldSerializer());

                        // Create markdown converter
                        _markdown = new DefaultMarkdown();

                        // Register permissions
                        _permissions["Core"].Add(new PermissionItem
                        {
                            Name  = Permission.PagePreview,
                            Title = "Page Preview"
                        });
                        _permissions["Core"].Add(new PermissionItem
                        {
                            Name  = Permission.PostPreview,
                            Title = "Post Preview"
                        });

                        // Initialize all modules
                        foreach (var module in _modules)
                        {
                            module.Instance.Init();
                        }

                        _isInitialized = true;
                    }
                }
            }
        }
Exemple #7
0
        /// <summary>
        /// Initializes the application object.
        /// </summary>
        /// <param name="api">The current api</param>
        private void Initialize(IApi api)
        {
            if (!isInitialized)
            {
                lock (mutex) {
                    if (!isInitialized)
                    {
                        // Configure object mapper
                        var mapperConfig = new MapperConfiguration(cfg => {
                            cfg.CreateMap <Data.Alias, Data.Alias>()
                            .ForMember(a => a.Id, o => o.Ignore())
                            .ForMember(a => a.Created, o => o.Ignore());
                            cfg.CreateMap <Data.Category, Data.Category>()
                            .ForMember(c => c.Id, o => o.Ignore())
                            .ForMember(c => c.Created, o => o.Ignore());
                            cfg.CreateMap <Data.MediaFolder, Data.MediaFolder>()
                            .ForMember(f => f.Id, o => o.Ignore())
                            .ForMember(f => f.Created, o => o.Ignore())
                            .ForMember(f => f.Media, o => o.Ignore());
                            cfg.CreateMap <Data.MediaFolder, Models.MediaStructureItem>()
                            .ForMember(f => f.Level, o => o.Ignore())
                            .ForMember(f => f.Items, o => o.Ignore());
                            cfg.CreateMap <Data.Page, Models.PageBase>()
                            .ForMember(p => p.TypeId, o => o.MapFrom(m => m.PageTypeId))
                            .ForMember(p => p.Permalink, o => o.MapFrom(m => "/" + m.Slug));
                            cfg.CreateMap <Models.PageBase, Data.Page>()
                            .ForMember(p => p.PageTypeId, o => o.MapFrom(m => m.TypeId))
                            .ForMember(p => p.Fields, o => o.Ignore())
                            .ForMember(p => p.Created, o => o.Ignore())
                            .ForMember(p => p.LastModified, o => o.Ignore())
                            .ForMember(p => p.PageType, o => o.Ignore())
                            .ForMember(p => p.Site, o => o.Ignore())
                            .ForMember(p => p.Parent, o => o.Ignore());
                            cfg.CreateMap <Data.Page, Models.SitemapItem>()
                            .ForMember(p => p.MenuTitle, o => o.Ignore())
                            .ForMember(p => p.Level, o => o.Ignore())
                            .ForMember(p => p.Items, o => o.Ignore())
                            .ForMember(p => p.PageTypeName, o => o.Ignore())
                            .ForMember(p => p.Permalink, o => o.MapFrom(d => !d.ParentId.HasValue && d.SortOrder == 0 ? "/" : "/" + d.Slug));
                            cfg.CreateMap <Data.Param, Data.Param>()
                            .ForMember(p => p.Id, o => o.Ignore())
                            .ForMember(p => p.Created, o => o.Ignore());
                            cfg.CreateMap <Data.Post, Models.PostBase>()
                            .ForMember(p => p.TypeId, o => o.MapFrom(m => m.PostTypeId))
                            .ForMember(p => p.Permalink, o => o.MapFrom(m => "/" + m.Blog.Slug + "/" + m.Slug));
                            cfg.CreateMap <Models.PostBase, Data.Post>()
                            .ForMember(p => p.PostTypeId, o => o.MapFrom(m => m.TypeId))
                            .ForMember(p => p.CategoryId, o => o.MapFrom(m => m.Category.Id))
                            .ForMember(p => p.Fields, o => o.Ignore())
                            .ForMember(p => p.Created, o => o.Ignore())
                            .ForMember(p => p.LastModified, o => o.Ignore())
                            .ForMember(p => p.PostType, o => o.Ignore())
                            .ForMember(p => p.Blog, o => o.Ignore())
                            .ForMember(p => p.Category, o => o.Ignore())
                            .ForMember(p => p.Tags, o => o.Ignore());
                            cfg.CreateMap <Data.Site, Data.Site>()
                            .ForMember(s => s.Id, o => o.Ignore())
                            .ForMember(s => s.Created, o => o.Ignore());
                            cfg.CreateMap <Data.Tag, Data.Tag>()
                            .ForMember(t => t.Id, o => o.Ignore())
                            .ForMember(t => t.Created, o => o.Ignore());
                        });
                        mapperConfig.AssertConfigurationIsValid();
                        mapper = mapperConfig.CreateMapper();

                        // Setup media types
                        mediaTypes.Documents.Add(".pdf", "application/pdf");
                        mediaTypes.Images.Add(".jpg", "image/jpeg");
                        mediaTypes.Images.Add(".jpeg", "image/jpeg");
                        mediaTypes.Images.Add(".png", "image/png");
                        mediaTypes.Videos.Add(".mp4", "video/mp4");

                        // Compose content types
                        contentTypes.Register <Models.IPage>("Page", "Page");
                        contentTypes.Register <Models.IBlogPage>("Blog", "Archive", true);

                        // Compose field types
                        fields.Register <Extend.Fields.DateField>();
                        fields.Register <Extend.Fields.DocumentField>();
                        fields.Register <Extend.Fields.HtmlField>();
                        fields.Register <Extend.Fields.ImageField>();
                        fields.Register <Extend.Fields.MarkdownField>();
                        fields.Register <Extend.Fields.MediaField>();
                        fields.Register <Extend.Fields.PageField>();
                        fields.Register <Extend.Fields.PostField>();
                        fields.Register <Extend.Fields.StringField>();
                        fields.Register <Extend.Fields.TextField>();
                        fields.Register <Extend.Fields.VideoField>();

                        // Compose serializers
                        serializers.Register <Extend.Fields.DateField>(new DateFieldSerializer());
                        serializers.Register <Extend.Fields.DocumentField>(new DocumentFieldSerializer());
                        serializers.Register <Extend.Fields.HtmlField>(new StringFieldSerializer <Extend.Fields.HtmlField>());
                        serializers.Register <Extend.Fields.MarkdownField>(new StringFieldSerializer <Extend.Fields.MarkdownField>());
                        serializers.Register <Extend.Fields.MediaField>(new MediaFieldSerializer());
                        serializers.Register <Extend.Fields.PageField>(new PageFieldSerializer());
                        serializers.Register <Extend.Fields.PostField>(new PostFieldSerializer());
                        serializers.Register <Extend.Fields.StringField>(new StringFieldSerializer <Extend.Fields.StringField>());
                        serializers.Register <Extend.Fields.TextField>(new StringFieldSerializer <Extend.Fields.TextField>());
                        serializers.Register <Extend.Fields.ImageField>(new ImageFieldSerializer());
                        serializers.Register <Extend.Fields.VideoField>(new VideoFieldSerializer());

                        // Create markdown converter
                        markdown = new DefaultMarkdown();

                        // Initialize all modules
                        foreach (var module in modules)
                        {
                            module.Instance.Init();
                        }

                        isInitialized = true;
                    }
                }
            }
        }