Exemplo n.º 1
0
		/// <summary>
		/// Initializes the application.
		/// </summary>
		private void Initialize() {
			if (!IsInitialized) {
				lock (mutex) {
					if (!IsInitialized) {
						var catalog = new AggregateCatalog() ;

						// Register IoC container
						if (Hooks.App.Init.CreateContainer != null)
							IoCContainer = Hooks.App.Init.CreateContainer();
						else IoCContainer = new IoC.TinyIoCContainer();

						// Register log provider
						if (Hooks.App.Init.RegisterLog != null)
							Hooks.App.Init.RegisterLog(IoCContainer);
						else IoCContainer.RegisterSingleton<Log.ILogProvider, Log.LocalLogProvider>();

						// Regsiter cache provider
						if (Hooks.App.Init.RegisterCache != null)
							Hooks.App.Init.RegisterCache(IoCContainer);
						else IoCContainer.RegisterSingleton<Cache.ICacheProvider, Cache.WebCacheProvider>();

						// Register media provider
						if (Hooks.App.Init.RegisterMedia != null)
							Hooks.App.Init.RegisterMedia(IoCContainer);
						else IoCContainer.RegisterSingleton<IO.IMediaProvider, IO.LocalMediaProvider>();

						// Register media cache provider
						if (Hooks.App.Init.RegisterMediaCache != null)
							Hooks.App.Init.RegisterMediaCache(IoCContainer);
						else IoCContainer.RegisterSingleton<IO.IMediaCacheProvider, IO.LocalMediaCacheProvider>();

						// Register user provider
						IoCContainer.RegisterSingleton<Security.IUserProvider, Security.LocalUserProvider>();

						// Register additional types
						if (Hooks.App.Init.Register != null)
							Hooks.App.Init.Register(IoCContainer);

						// Compose parts
						if (HttpContext.Current != null) {
							catalog.Catalogs.Add(new DirectoryCatalog("Bin")) ;
						} else { 
							catalog.Catalogs.Add(new DirectoryCatalog(AppDomain.CurrentDomain.BaseDirectory));
						}
						Container = new CompositionContainer(catalog) ;
						Container.ComposeParts(this) ;

						// Register default handlers
						RegisterHandlers() ;

						// Create the extension manager
						ExtensionManager = new Extend.ExtensionManager();

						// Set application state
						IsInitialized = true;
					}
				}
			}
		}
Exemplo n.º 2
0
        /// <summary>
        /// Initializes the application instance.
        /// </summary>
        private void Initialize(Config config)
        {
            if (!IsInitialized)
            {
                lock (mutex) {
                    if (!IsInitialized)
                    {
                        // Get temporary log query
                        var queue = (Log.LogQueue) this.config.Log;

                        // Register logger
                        if (config.Log == null)
                        {
                            config.Log = new Log.FileLog();
                        }
                        Logger.Log(Log.LogLevel.INFO, "App.Init: Starting application");

                        // Store configuration
                        this.config = config;

                        // Dump queued log messages
                        queue.Dump(config.Log);

                        // Configure auto mapper
                        Mapper.CreateMap <Models.Comment, Client.Models.CommentModel>()
                        .ForMember(m => m.Ratings, o => o.Ignore());
                        Mapper.CreateMap <Models.Page, Client.Models.PageModel>()
                        .ForMember(m => m.Type, o => o.MapFrom(p => p.Type.Slug))
                        .ForMember(m => m.Route, o => o.MapFrom(p => !String.IsNullOrEmpty(p.Route) ? p.Route : p.Type.Route))
                        .ForMember(m => m.View, o => o.MapFrom(p => !String.IsNullOrEmpty(p.View) ? p.View : p.Type.View))
                        .ForMember(m => m.Ratings, o => o.Ignore());
                        Mapper.CreateMap <Models.Post, Client.Models.PostModel>()
                        .ForMember(m => m.Type, o => o.MapFrom(p => p.Type.Slug))
                        .ForMember(m => m.Route, o => o.MapFrom(p => !String.IsNullOrEmpty(p.Route) ? p.Route : p.Type.Route))
                        .ForMember(m => m.View, o => o.MapFrom(p => !String.IsNullOrEmpty(p.View) ? p.View : p.Type.View))
                        .ForMember(m => m.Comments, o => o.Ignore())
                        .ForMember(m => m.Ratings, o => o.Ignore());
                        Mapper.CreateMap <Models.PostType, Client.Models.ArchiveModel>()
                        .ForMember(m => m.Keywords, o => o.MapFrom(t => t.MetaKeywords))
                        .ForMember(m => m.Description, o => o.MapFrom(t => t.MetaDescription))
                        .ForMember(m => m.View, o => o.MapFrom(t => t.ArchiveView))
                        .ForMember(m => m.Title, o => o.MapFrom(t => t.ArchiveTitle))
                        .ForMember(m => m.Year, o => o.Ignore())
                        .ForMember(m => m.Month, o => o.Ignore())
                        .ForMember(m => m.Page, o => o.Ignore())
                        .ForMember(m => m.TotalPages, o => o.Ignore())
                        .ForMember(m => m.Posts, o => o.Ignore());

                        Mapper.AssertConfigurationIsValid();

                        // Check environment
                        if (config.Env == null)
                        {
                            Logger.Log(Log.LogLevel.INFO, "App.Init: No runtime environment specified");
                        }

                        // Register the security provider
                        Logger.Log(Log.LogLevel.INFO, "App.Init: Registering security provider");
                        if (config.Security == null)
                        {
                            config.Security = new Security.NoSecurity();
                            Logger.Log(Log.LogLevel.WARNING, "App.Init: No security provider specified. Disabling security");
                        }
                        else
                        {
                            Logger.Log(Log.LogLevel.INFO, "App.Init: Registered " + config.Security.GetType().FullName);
                        }

                        // Register the cache provider
                        Logger.Log(Log.LogLevel.INFO, "App.Init: Registering cache provider");
                        if (config.Cache == null)
                        {
                            config.Cache = new Cache.NoCache();
                            Logger.Log(Log.LogLevel.WARNING, "App.Init: No cache provider specified. Disabling cache");
                        }
                        else
                        {
                            Logger.Log(Log.LogLevel.INFO, "App.Init: Registered " + config.Cache.GetType().FullName);
                        }

                        // Register the media provider
                        Logger.Log(Log.LogLevel.INFO, "App.Init: Registering media provider");
                        if (config.Media == null)
                        {
                            config.Media = new IO.FileMedia();
                        }
                        Logger.Log(Log.LogLevel.INFO, "App.Init: Registered " + config.Media.GetType().FullName);

                        // Register custom slug generation
                        if (config.GenerateSlug != null)
                        {
                            Logger.Log(Log.LogLevel.INFO, "App.Init: Registering custom slug generation");
                        }

                        // Create the model cache
                        Logger.Log(Log.LogLevel.INFO, "App.Init: Creating model cache");
                        modelCache = new Piranha.Cache.ModelCache(config.Cache);

                        // Register cache models
                        Logger.Log(Log.LogLevel.INFO, "App.Init: Registering default model types in the cache");
                        modelCache.RegisterCache <Models.Alias>(a => a.Id, a => a.OldUrl);
                        modelCache.RegisterCache <Models.Block>(b => b.Id, b => b.Slug);
                        modelCache.RegisterCache <Models.Media>(m => m.Id, m => m.Slug);
                        modelCache.RegisterCache <Client.Models.PageModel>(p => p.Id, p => p.Slug);
                        modelCache.RegisterCache <Models.Param>(p => p.Id, p => p.Name);
                        modelCache.RegisterCache <Models.Post>(p => p.Id, p => p.TypeId.ToString() + "_" + p.Slug);
                        modelCache.RegisterCache <Models.PostType>(p => p.Id, p => p.Slug);

                        // Create the handler collection
                        handlers = new Server.HandlerCollection();

                        // Create the extension manager
                        Logger.Log(Log.LogLevel.INFO, "App.Init: Creating extension manager");
                        extensions = new Extend.ExtensionManager();

                        // Seed default data
                        if (config.Store != null)
                        {
                            Logger.Log(Log.LogLevel.INFO, "App.Init: Seeding default data");
                            using (var api = new Api()) {
                                Data.Seed.Params(api);
                            }
                        }
                        IsInitialized = true;
                    }
                }
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// Initializes the application.
        /// </summary>
        private void Initialize()
        {
            if (!IsInitialized)
            {
                lock (mutex) {
                    if (!IsInitialized)
                    {
                        var catalog = new AggregateCatalog();

                        // Register IoC container
                        if (Hooks.App.Init.CreateContainer != null)
                        {
                            IoCContainer = Hooks.App.Init.CreateContainer();
                        }
                        else
                        {
                            IoCContainer = new IoC.TinyIoCContainer();
                        }

                        // Register log provider
                        if (Hooks.App.Init.RegisterLog != null)
                        {
                            Hooks.App.Init.RegisterLog(IoCContainer);
                        }
                        else
                        {
                            IoCContainer.RegisterSingleton <Log.ILogProvider, Log.LocalLogProvider>();
                        }

                        // Regsiter cache provider
                        if (Hooks.App.Init.RegisterCache != null)
                        {
                            Hooks.App.Init.RegisterCache(IoCContainer);
                        }
                        else
                        {
                            IoCContainer.RegisterSingleton <Cache.ICacheProvider, Cache.WebCacheProvider>();
                        }

                        // Register media provider
                        if (Hooks.App.Init.RegisterMedia != null)
                        {
                            Hooks.App.Init.RegisterMedia(IoCContainer);
                        }
                        else
                        {
                            IoCContainer.RegisterSingleton <IO.IMediaProvider, IO.LocalMediaProvider>();
                        }

                        // Register media cache provider
                        if (Hooks.App.Init.RegisterMediaCache != null)
                        {
                            Hooks.App.Init.RegisterMediaCache(IoCContainer);
                        }
                        else
                        {
                            IoCContainer.RegisterSingleton <IO.IMediaCacheProvider, IO.LocalMediaCacheProvider>();
                        }

                        // Register user provider
                        IoCContainer.RegisterSingleton <Security.IUserProvider, Security.LocalUserProvider>();

                        // Register additional types
                        if (Hooks.App.Init.Register != null)
                        {
                            Hooks.App.Init.Register(IoCContainer);
                        }

                        // Compose parts
                        if (HttpContext.Current != null)
                        {
                            catalog.Catalogs.Add(Config.DisableCatalogSearch ? new DirectoryCatalog("Bin", "Piranha*.dll") : new DirectoryCatalog("Bin"));
                        }
                        else
                        {
                            catalog.Catalogs.Add(Config.DisableCatalogSearch ? new DirectoryCatalog(AppDomain.CurrentDomain.BaseDirectory, "Piranha*.dll") : new DirectoryCatalog(AppDomain.CurrentDomain.BaseDirectory));
                        }

                        Container = new CompositionContainer(catalog);
                        Container.ComposeParts(this);

                        // Register default handlers
                        RegisterHandlers();

                        // Create the extension manager
                        ExtensionManager = new Extend.ExtensionManager();

                        // Set application state
                        IsInitialized = true;
                    }
                }
            }
        }