Beispiel #1
0
 public static void Initialize(CompositionContainer container, 
                               ContentManager contentManager, 
                               AddInManager addInManager, 
                               NotificationManager notifications, 
                               TraceListener listener)
 {
     Instance = new App(container, contentManager, addInManager, notifications, listener);
 }
Beispiel #2
0
 private App(CompositionContainer container, 
             ContentManager contentManager, 
             AddInManager addInManager, 
             NotificationManager notifications, 
             TraceListener listener)
 {
     this.Container = container;
     this.Content = contentManager;
     this.AddIns = addInManager;
     this.Notifications = notifications;
     this.TraceListner = listener;
 }
Beispiel #3
0
        protected void Application_Start()
        {
            // TODO maybe put this somewhere else (not in global.asax)
            // TODO maybe move all of this into the App class with "IAppConfig"

            // initialize logger
            TraceListener traceListener =
                new TextWriterTraceListener(Path.Combine(AppConfig.LogPath, 
                                                         string.Format("repository_{0:yyyy'-'MM'-'dd__HHmmss}.log", 
                                                                       DateTime.Now)));

            // TODO introduce flags/settings for controlling logging levels, but for now include everything
            traceListener.Filter = new EventTypeFilter(SourceLevels.All);

            traceListener.TraceOutputOptions = TraceOptions.ThreadId | TraceOptions.DateTime;

            Web.TraceSources.Content.Listeners.Add(traceListener);
            Web.TraceSources.AddInManager.Listeners.Add(traceListener);
            Repository.TraceSources.ContentManagerSource.Listeners.Add(traceListener);
            Repository.TraceSources.ContentSearcherSource.Listeners.Add(traceListener);

            // this might be stupid, but it fixes things for iisexpress
            Directory.SetCurrentDirectory(HostingEnvironment.ApplicationPhysicalPath);

            // set up add-in system
            AddInSource officalSource = new AddInSource("Official LostDoc repository add-in feed", 
                                                        AppConfig.AddInRepository, 
                                                        isOfficial: true);

            // intialize MEF

            // core 'add-ins'
            var currentAssembly = Assembly.GetExecutingAssembly();
            var assemblyName = currentAssembly.GetName();
            string corePackageId = assemblyName.Name;
            string corePackageVersion = assemblyName.Version.ToString();
            AggregateCatalog catalog = new AggregateCatalog();

            // load other sources from site-settings (not config)
            AddInRepository repository = new AddInRepository(officalSource);
            AddInManager addInManager = new AddInManager(repository, 
                                                         AppConfig.AddInInstallPath, 
                                                         AppConfig.AddInPackagePath);

            // when the catalog changes, discover and route all ApiControllers
            catalog.Changed += (sender, args) => this.UpdateWebApiRegistry(args);

            //// TODO for debugging only
            //Debugger.Break();
            //Debugger.Launch();

            // now register core libs
            catalog.Catalogs.Add(new AddInCatalog(new ApplicationCatalog(), corePackageId, corePackageVersion));

            // hook event so that installed add-ins get registered in the catalog, if composition occurs after this fires
            // or if recomposition is enabled, no restart should be requried
            addInManager.Installed +=
                (sender, args) => catalog.Catalogs.Add(new AddInCatalog(new DirectoryCatalog(args.InstallationPath), 
                                                                        args.Package.Id, 
                                                                        args.Package.Version));

            // delete and redeploy all installed packages, this will trigger the Installed event ^
            // this acts as a crude "remove/overwrite plugins that were in use when un/installed" hack
            addInManager.Restore();

            // create container
            CompositionContainer container = new CompositionContainer(catalog);

            // set up template resolver
            var lazyProviders = container.GetExports<IFileProvider>(ContractNames.TemplateProvider);
            var realProviders = lazyProviders.Select(lazy => lazy.Value);
            TemplateResolver templateResolver = new TemplateResolver(realProviders.ToArray());

            // load template
            Template template = new Template(container);
            template.Load(templateResolver, AppConfig.Template);

            // set up content manager
            ContentManager contentManager = new ContentManager(new ContentSettings
                                                                   {
                                                                       ContentPath = AppConfig.ContentPath, 
                                                                       // TODO make this configurable
                                                                       IgnoreVersionComponent = VersionComponent.Patch, 
                                                                       RepositoryPath = AppConfig.RepositoryPath, 
                                                                       Template = template
                                                                   });

            // set up notifaction system
            NotificationManager notifications = new NotificationManager();

            // initialize app-singleton
            App.Initialize(container, contentManager, addInManager, notifications, traceListener);

            // MVC init
            AreaRegistration.RegisterAllAreas();
            RegisterGlobalFilters(GlobalFilters.Filters);
            RegisterRoutes(RouteTable.Routes);

            // inject our custom IControllerFactory for the Admin interface
            IControllerFactory oldControllerFactory = ControllerBuilder.Current.GetControllerFactory();
            IControllerFactory newControllerFactory = new AddInControllerFactory(AdministrationAreaRegistration.Name, 
                                                                                 container, 
                                                                                 oldControllerFactory);
            ControllerBuilder.Current.SetControllerFactory(newControllerFactory);

            // TODO figure out if we actually need this
            // hook in our MEF based IHttpController instead of the default one
            //GlobalConfiguration.Configuration.Services.Replace(typeof(IHttpControllerTypeResolver), new AddInHttpControllerTypeResolver(App.Instance.Container));
        }
 public LibraryController(ContentManager content, NotificationManager notificationManager)
 {
     this.Content = content;
     this.Notifications = notificationManager;
 }
 public ContentRepositoryController(ContentManager content, NotificationManager notifications)
 {
     this.Content = content;
     this.Notifications = notifications;
 }
 public AdminFilter(CompositionContainer container, NotificationManager notifications)
 {
     this.Notifications = notifications;
     this.Container = container;
 }