Exemple #1
0
        protected virtual void InitializeComponents()
        {
            if (ServiceProvider == null)
            {
                // if we have a kernel, then let's create a "depency-injection service provider".
                if (Kernel != null)
                {
                    ServiceProvider = new DIServiceProvider(Kernel);
                }

                // otherwise, create a regular, plain service provider
                else
                {
                    ServiceProvider = new ServiceProvider();
                }
            }

            if (PresentationController == null)
            {
                PresentationController = new PresentationController();
            }
            if (ApplicationModuleManager == null)
            {
                ApplicationModuleManager = new ApplicationModuleManager();
            }

            ApplicationModuleManager.PresentationController = PresentationController;

            // if the Kernel is present, then link both module managers (from Foundation and from Ninject).
            if (Kernel != null)
            {
                ApplicationModuleManager.ModuleManager = Kernel.Components.ModuleManager;
            }
        }
Exemple #2
0
        /// <summary>
        /// Starts the application.  That method should be one of the first being called when the program starts. The method
        /// accepts an existing configuration object.  See <see cref="StartApplication()"/> for default configuration.
        /// </summary>
        /// <param name="config">Loaded application object.</param>
        public void StartApplication(ApplicationConfiguration config)
        {
            Logger.Info("Starting application...");
            _config = config;

            InitializeComponents();

            // Load services and modules from the config file.
            Logger.Info("Loading services and modules from config.");
            if (_config != null)
            {
                ConfigManager.LoadAndConfigureServices(ServiceProvider, _config);
                ConfigManager.LoadModules(ApplicationModuleManager, _config);
            }

            // start services
            Logger.Info("Starting services.");
            foreach (IService service in ServiceProvider.AllServices)
            {
                IStartable startable;
                startable = service as IStartable;
                if (startable != null)
                {
                    startable.Start();
                }
            }

            // Display the Shell, if any.
            if (Shell != null)
            {
                Logger.Info("Displaying the Shell.");
                foreach (IViewController ctrl in Shell.CreateViewControllers())
                {
                    PresentationController.RegisterViewController(ctrl);
                }
                foreach (IPresenter presenter in Shell.CreatePresenters())
                {
                    PresentationController.RegisterPresenter(presenter);
                }
                Shell.Show();
            }

            // Activate modules
            Logger.Info("Activating modules.");
            ApplicationModuleManager.ActivateAll();

            _started = true;
            Logger.Info("Application started.");
        }
        /// <summary>
        /// Closes the application.  Generally, that should lead to the process being terminated.
        /// </summary>
        /// <remarks>
        /// All services that implement <see cref="IStartable"/> are stopped here, in reverse order that they 
        /// have been started.
        /// </remarks>
        public virtual void CloseApplication()
        {
            // Deactivate and unload all modules
            ApplicationModuleManager.DeactivateAll();
            ApplicationModuleManager.UnloadAll();

            // Stop all services
            foreach (IService service in ServiceProvider.AllServices.Reverse())
            {
                IStartable startable;
                startable = service as IStartable;
                if (startable != null) startable.Stop();
            }

            // Clean containers
            // todo: something else to clean?
            ServiceProvider.Clear();

            _started = false;
        }
        protected virtual void InitializeComponents()
        {
            if (Logger == null)
            {
                TextLogWriter writer = new TextLogWriter(new System.IO.MemoryStream());
                writer.AutoflushLevel = LogLevel.Fatal;
                writer.IsEnabled      = false;
                Logger = new StandardLogger(writer);
            }
            if (ServiceProvider == null)
            {
                //if we have a kernel, then let's create a "depency-injection service provider".
                if (Kernel != null)
                {
                    ServiceProvider = new DIServiceProvider(Kernel);
                }
                //otherwise, create a regular, plain service provider
                else
                {
                    ServiceProvider = new ServiceProvider();
                }
            }
            if (PresentationController == null)
            {
                PresentationController = new PresentationController();
            }
            if (ApplicationModuleManager == null)
            {
                ApplicationModuleManager = new ApplicationModuleManager();
            }

            ApplicationModuleManager.PresentationController = PresentationController;
            //if the Kernel is present, then link both module managers (from Foundation and from Ninject).
            if (Kernel != null)
            {
                ApplicationModuleManager.ModuleManager = Kernel.Components.ModuleManager;
            }
        }