Exemplo n.º 1
0
        /// <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()
        {
            foreach (IService service in ServiceProvider.AllServices.Reverse <IService>())
            {
                IStartable startable;
                startable = service as IStartable;
                if (startable != null)
                {
                    startable.Stop();
                }
            }

            ServiceProvider.Clear();
            PresentationController.ViewControllers.Clear();
            ObjectContainer.Clear();

            _started = false;
        }
Exemplo n.º 2
0
        public static void TestAll()
        {
            SystemConfiguration.UseMultiThread = false;

            //if (MessageForm.ShowYesNo("Operate Data?"))
            {
                operateData = true;
            }

            m_stringExceptionProcess.Clear();

            var instance = DefaultServiceProvider.Instance;
            IExceptionProcess defaultEp = null;
            IMessageBox       defaultMb = null;

            if (instance != null)
            {
                defaultEp = ServiceProvider.GetService <IExceptionProcess>();
                instance.SetDefaultService <IExceptionProcess>(m_stringExceptionProcess);
                defaultMb = ServiceProvider.GetService <IMessageBox>();
                instance.SetDefaultService <IMessageBox>(m_emptyMessageBox);
                ServiceProvider.Clear();
            }

            IList <MenuInfo> menuInfos = ADInfoBll.Instance.GetTopMenuInfos();

            foreach (MenuInfo info in menuInfos)
            {
                TestMenu(info);
            }

            if (instance != null)
            {
                instance.SetDefaultService <IExceptionProcess>(defaultEp);
                instance.SetDefaultService <IMessageBox>(defaultMb);
                ServiceProvider.Clear();
            }

            SystemConfiguration.UseMultiThread = true;

            ErrorReport errorReport = new ErrorReport("测试中的异常,请见详细内容。", "测试信息", MessageImage.Information, m_stringExceptionProcess.Exceptions);

            errorReport.ShowDialog();
        }
        public void OnGet_WithAddInstance_Clear_ItShouldResolveTheSameInstance()
        {
            //Arrange
            var subject          = new ServiceProvider();
            var expectedInstance = new Test3();

            subject.Add <ITest1, Test1>();
            subject.Add <ITest2, Test2>();
            subject.Add <ITest3, Test3>();
            subject.Get <ITest1>();
            subject.Add <ITest3>(expectedInstance);

            //Act
            subject.Clear();
            var result = subject.Get <ITest1>();


            //Assert
            Assert.Same(expectedInstance, result.Test2.Test3);
        }
        /// <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;
        }