Пример #1
0
        public void MultipleInits()
        {
            IFrameworkFactory factory = new CFrameworkFactory();
            IFramework        fwk     = factory.NewFramework(null);

            fwk.Init();

            IBundleContext ctx = fwk.getBundleContext();

            Expect.Exactly(2).On(mock_fwk_listener)
            .Method("FrameworkEvent")
            .With(new FrameworkEvent(FrameworkEvent.Type.STARTED, fwk, null));
            ctx.AddFrameworkListener(mock_fwk_listener);

            fwk.Start();
            fwk.Stop();
            fwk.WaitForStop(0);
            Assert.AreEqual(fwk.getState(), BundleState.RESOLVED);

            fwk.Init();
            fwk.getBundleContext().AddFrameworkListener(mock_fwk_listener);
            fwk.Start();
            Assert.AreEqual(fwk.getState(), BundleState.ACTIVE);
            fwk.Stop();
            fwk.WaitForStop(0);
            Assert.AreEqual(fwk.getState(), BundleState.RESOLVED);

            mocks.VerifyAllExpectationsHaveBeenMet();
        }
Пример #2
0
        public void InitShutdown()
        {
            IFrameworkFactory factory = new CFrameworkFactory();

            IFramework fwk = factory.NewFramework(null);

            Assert.IsNotNull(fwk);
            Assert.AreEqual(fwk.getState(), BundleState.INSTALLED);

            fwk.Init();
            Assert.AreEqual(fwk.getState(), BundleState.STARTING);

            IBundleContext ctx = fwk.getBundleContext();

            Assert.IsNotNull(ctx);
            Assert.AreEqual(ctx.getBundle(), fwk);

            Expect.Once.On(mock_fwk_listener)
            .Method("FrameworkEvent")
            .With(new FrameworkEvent(FrameworkEvent.Type.STARTED, fwk, null));
            ctx.AddFrameworkListener(mock_fwk_listener);


            fwk.Start();
            Assert.AreEqual(fwk.getState(), BundleState.ACTIVE);

            fwk.Stop();
            Assert.AreEqual(fwk.getState(), BundleState.STOPPING);

            fwk.WaitForStop(0);
            Assert.AreEqual(fwk.getState(), BundleState.RESOLVED);

            mocks.VerifyAllExpectationsHaveBeenMet();
        }
Пример #3
0
        static void Main(string[] args)
        {
            try
            {
                IFrameworkFactory factory = new CFrameworkFactory();
                IFramework        fwk     = factory.NewFramework(null);
                fwk.Init();
                fwk.Start();

                IBundleContext ctx     = fwk.getBundleContext();
                IBundle        console = ctx.InstallBundle("framework_console");
                console.Start();

                fwk.Stop();
                fwk.WaitForStop(0);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.ToString());
            }
        }
Пример #4
0
        /// <summary>
        /// 运行
        /// </summary>
        private void Run()
        {
            try
            {
                SubscribeSystemEvents();

                // 系统预检查
                PreCheck();

                // 注册COM控件。
                RegisterCOM();

                InitializeLogSystem();

                GlobalMessageBus.SubscribeApplicationExiting(OnProcessKillingForcedly);

                _framework.Init();
                _framework.Start();
                _framework.WaitForStop();
            }
            catch (TargetInvocationException ex)
            {
                LogManager.GetLogger(LoggerNames.Platform).Error(ex.InnerException);
                MessageBox.Show(ex.InnerException.Message, "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            catch (Exception ex)
            {
                LogManager.GetLogger(LoggerNames.Platform).Error(ex);
                MessageBox.Show(ex.Message, "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            finally
            {
                LocalMessageBus.Current.RemoveAll();
                ShutdownLogSystem();
                ThreadProxy.Shutdown();
                System.Diagnostics.Process.GetCurrentProcess().Kill();
            }
        }