Exemplo n.º 1
0
        /// <summary>
        /// Initializes the application object.
        /// </summary>
        /// <param name="modules">The modules to use</param>
        private void Initialize(IApi api, Extend.IModule[] modules = null)
        {
            if (!isInitialized)
            {
                lock (mutex) {
                    if (!isInitialized)
                    {
                        // Compose field types
                        fields.Register <Extend.Fields.HtmlField>();
                        fields.Register <Extend.Fields.StringField>();
                        fields.Register <Extend.Fields.TextField>();

                        // Get types
                        pageTypes  = api.PageTypes.Get();
                        blockTypes = api.BlockTypes.Get();

                        // Add ad-hoc modules
                        foreach (var module in modules)
                        {
                            this.modules.Add(module);
                        }

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

                        isInitialized = true;
                    }
                }
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Initializes the application object.
        /// </summary>
        /// <param name="api">The current api</param>
        /// <param name="modules">The modules to use</param>
        private void Initialize(IApi api, IConfigurationRoot config, Extend.IModule[] modules = null)
        {
            if (!isInitialized)
            {
                lock (mutex) {
                    if (!isInitialized)
                    {
                        // Setup media types
                        if (config != null && config.GetSection("Piranha:MediaTypes") != null)
                        {
                            instance.mediaTypes = new MediaTypes()
                            {
                                Documents = config.GetSection("Piranha:MediaTypes:Documents").GetChildren().Select(c => c.Value).ToList(),
                                Images    = config.GetSection("Piranha:MediaTypes:Images").GetChildren().Select(c => c.Value).ToList(),
                                Videos    = config.GetSection("Piranha:MediaTypes:Videos").GetChildren().Select(c => c.Value).ToList(),
                            };
                        }

                        // Register default markdown converter
                        markdown = new Extend.MarkdownSharp();

                        // Compose field types
                        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>();

                        // Get types
                        pageTypes  = api.PageTypes.Get();
                        blockTypes = api.BlockTypes.Get();

                        // Add ad-hoc modules
                        InitializeModules(modules);

                        isInitialized = true;
                    }
                }
            }
        }