Esempio n. 1
0
        private void context_BundleStateChanged(object sender, BundleStateChangedEventArgs e)
        {
            BundleRuntime runtime    = BundleRuntime.Instance;
            BundleData    bundleData = runtime.GetFirstOrDefaultService <IBundleInstallerService>()
                                       .GetBundleDataByName(e.Bundle.SymbolicName);

            if (bundleData == null)
            {
                return;
            }

            bool needLoad = e.CurrentState == BundleState.Active;

            if (needLoad)
            {
                RegisterBundle(e.Bundle);
            }
            else if (e.CurrentState == BundleState.Stopping)
            {
                //如果插件正在停止,就不需要更新ContainerBuilder了,因为这个服务即将不可用。
                if (BundleRuntime.Instance.State == BundleRuntimeState.Stopping)
                {
                    return;
                }
                Assembly[] assemblies;
                if (_registerHostory.TryGetValue(e.Bundle.BundleID, out assemblies))
                {
                    IServiceResolver newResolver = UnRegisterBundleAndGetControllerResolver(assemblies);
                    ServiceResolver = newResolver;
                }
            }
        }
Esempio n. 2
0
        //通过插件获取到菜单项
        private IEnumerable <NavigationNode> NavigationInitialize()
        {
            INavigationService service = BundleRuntime.GetFirstOrDefaultService <INavigationService>();

            if (service == null)
            {
                return(new List <NavigationNode>());
            }
            return(service.NavgationNodes);
        }
        public static void Complete(this BundleRuntime runtime)
        {
            var containerBuilder = runtime.GetFirstOrDefaultService <ContainerBuilder>();

            if (containerBuilder == null)
            {
                return;
            }

            if (runtime.GetFirstOrDefaultService <IContainer>() != null)
            {
                return;
            }

            lock (containerBuilder)
            {
                var container = containerBuilder.Build();
                runtime.AddService(typeof(IContainer), container);
            }
        }
Esempio n. 4
0
        protected override void OnStartup(StartupEventArgs e)
        {
            this.ShutdownMode = ShutdownMode.OnMainWindowClose;

            using (BundleRuntime runtime = new BundleRuntime())
            {
                runtime.Start();
                Window win = runtime.GetFirstOrDefaultService <IWindow>() as Window;
                win.ShowDialog();
                runtime.Stop();
            }

            base.OnStartup(e);
        }
Esempio n. 5
0
 private static void Main(string[] args)
 {
     //创建OSGi内核
     using (var runtime = new BundleRuntime())
     {
         //启动内核,加载插件
         runtime.Start();
         //显示主窗口
         var form = runtime.GetFirstOrDefaultService <Form>();
         if (form == null)
         {
             return;
         }
         Application.Run(form);
     }
 }
Esempio n. 6
0
        protected override IServiceResolver ComplateAndGetControllerResolver()
        {
            BundleRuntime runtime   = BundleRuntime.Instance;
            IContainer    container = runtime.GetFirstOrDefaultService <IContainer>();

            if (container == null)
            {
                lock (_builder)
                {
                    container = _builder.Build();
                    runtime.AddService <IContainer>(container);
                }
            }
            runtime.AddService <IContainer>(container);
            //注入创建者
            IServiceResolver resolver = new ServiceResolver(container);

            return(resolver);
        }
Esempio n. 7
0
        private static void RunApplication()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);

            const string PAGE_NAME_LOGIN = "******";

            FileLogUtility.SetFileLogEnabled(true);
            FileLogUtility.SetLogFileName("log.txt");
            FileLogUtility.SetLogLevel(LogLevel);
            FileLogUtility.SetMaxFileSizeByMB(MaxLogFileSize);
            FileLogUtility.SetCreateNewFileOnMaxSize(CreateNewLogFileOnMaxSize);

            using (BundleRuntime bundleRuntime = new BundleRuntime())
            {
                bundleRuntime.Start();

                // Get the page flow service.
                IPageFlowService pageFlowService = bundleRuntime.GetFirstOrDefaultService <IPageFlowService>();

                if (pageFlowService == null)
                {
                    throw new Exception(Resources.IPageFlowServiceServiceNotFound);
                }

                // Assert the first page node.
                if (string.IsNullOrEmpty(pageFlowService.FirstPageNodeValue) ||
                    string.IsNullOrEmpty(pageFlowService.FirstPageNodeName) ||
                    pageFlowService.FirstPageNodeOwner == null)
                {
                    throw new Exception(Resources.CanNotFindAnAvailablePageNode);
                }

                // Load the form type of first page node.
                Type formType = pageFlowService.FirstPageNodeOwner.LoadClass(pageFlowService.FirstPageNodeValue);
                if (formType == null)
                {
                    throw new Exception(string.Format(Resources.CanNotLoadTypeFromBundle, pageFlowService.FirstPageNodeValue, pageFlowService.FirstPageNodeOwner.SymbolicName));
                }

                // Create the form instance of first page node and show it.
                Form formInstance = System.Activator.CreateInstance(formType) as Form;

                if (formInstance == null)
                {
                    throw new Exception(string.Format(Resources.TypeIsNotWindowsFormType, pageFlowService.FirstPageNodeValue, pageFlowService.FirstPageNodeOwner.SymbolicName));
                }

                // If first page node name is 'Login' then, show the dialog and then run application.
                if (pageFlowService.FirstPageNodeName.Equals(PAGE_NAME_LOGIN))
                {
                    DialogResult result = formInstance.ShowDialog();
                    if (result == DialogResult.OK || result == DialogResult.Yes)
                    {
                        PageNode nextNode = pageFlowService.GetNextPageNode(pageFlowService.FirstPageNodeName);
                        if (nextNode != null)
                        {
                            Type mainPageFormType = nextNode.Bundle.LoadClass(nextNode.Value);
                            if (mainPageFormType == null)
                            {
                                throw new Exception(string.Format(Resources.CanNotLoadTypeFromBundle, nextNode.Value, nextNode.Bundle.SymbolicName));
                            }
                            Form mainPageForm = System.Activator.CreateInstance(mainPageFormType) as Form;
                            Application.Run(mainPageForm);
                        }
                    }
                }
                else // Run the application directly.
                {
                    Application.Run(formInstance);
                }
            }
        }
Esempio n. 8
0
        private static void RunApplication()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);

            const string PAGE_NAME_LOGIN = "******";

            FileLogUtility.SetFileLogEnabled(true);
            FileLogUtility.SetLogFileName("log.txt");
            FileLogUtility.SetLogLevel(LogLevel);
            FileLogUtility.SetMaxFileSizeByMB(MaxLogFileSize);
            FileLogUtility.SetCreateNewFileOnMaxSize(CreateNewLogFileOnMaxSize);

            using (BundleRuntime bundleRuntime = new BundleRuntime())
            {
                bundleRuntime.Start();

                // Get the page flow service.
                IPageFlowService pageFlowService = bundleRuntime.GetFirstOrDefaultService<IPageFlowService>();

                if (pageFlowService == null)
                {
                    throw new Exception(Resources.IPageFlowServiceServiceNotFound);
                }

                // Assert the first page node.
                if (string.IsNullOrEmpty(pageFlowService.FirstPageNodeValue) ||
                    string.IsNullOrEmpty(pageFlowService.FirstPageNodeName) ||
                    pageFlowService.FirstPageNodeOwner == null)
                {
                    throw new Exception(Resources.CanNotFindAnAvailablePageNode);
                }

                // Load the form type of first page node.
                Type formType = pageFlowService.FirstPageNodeOwner.LoadClass(pageFlowService.FirstPageNodeValue);
                if (formType == null)
                {
                    throw new Exception(string.Format(Resources.CanNotLoadTypeFromBundle, pageFlowService.FirstPageNodeValue, pageFlowService.FirstPageNodeOwner.SymbolicName));
                }

                // Create the form instance of first page node and show it.
                Form formInstance = System.Activator.CreateInstance(formType) as Form;

                if (formInstance == null)
                {
                    throw new Exception(string.Format(Resources.TypeIsNotWindowsFormType, pageFlowService.FirstPageNodeValue, pageFlowService.FirstPageNodeOwner.SymbolicName));
                }

                // If first page node name is 'Login' then, show the dialog and then run application.
                if (pageFlowService.FirstPageNodeName.Equals(PAGE_NAME_LOGIN))
                {
                    DialogResult result = formInstance.ShowDialog();
                    if (result == DialogResult.OK || result == DialogResult.Yes)
                    {
                        PageNode nextNode = pageFlowService.GetNextPageNode(pageFlowService.FirstPageNodeName);
                        if (nextNode != null)
                        {
                            Type mainPageFormType = nextNode.Bundle.LoadClass(nextNode.Value);
                            if (mainPageFormType == null)
                            {
                                throw new Exception(string.Format(Resources.CanNotLoadTypeFromBundle, nextNode.Value, nextNode.Bundle.SymbolicName));
                            }
                            Form mainPageForm = System.Activator.CreateInstance(mainPageFormType) as Form;
                            Application.Run(mainPageForm);
                        }
                    }
                }
                else // Run the application directly.
                {
                    Application.Run(formInstance);
                }
            }
        }