在主界面框架中,我们依靠第三方控件库"ModernUI"来实现界面,并对"ModernUI"做深入的定制。在界面框架插件引用该控件时,首先,我们需要将该插件添加到Manifest.xml作为本地程序集,即界面框架插件在运行时需要与该程序集一起才能够正常运行。
- var bundleRuntime = new BundleRuntime();
- bundleRuntime.AddService();
- bundleRuntime.Start();
注意:主程序在BundleRuntime.Start方法调用前注册的服务,插件在启动时即可获取。这时候,插件可以在激活器中直接获取到该服务了。
- public class Activator : IBundleActivator
- {
- public void Start(IBundleContext context)
- {
- var sayHelloService = context.GetFirstOrDefaultService();
- sayHelloService.Hell("Lorry Chen");
- }
- public void Stop(IBundleContext context)
- {
- }
- }
using System;using System.Collections.Generic;using System.Configuration;using System.Data;using System.Linq;using System.Threading.Tasks;using System.Windows;using UIShell.OSGi;using UIShell.PageFlowService;using UIShell.OSGi.Logging;using UIShell.iOpenWorks.Bootstrapper;namespace UIShell.iOpenWorks.WPF{ /// <summary> /// WPF startup class. /// </summary> public partial class App : Application { // Use object type to avoid load UIShell.OSGi.dll before update. private object _bundleRuntime; public App() { UpdateCore(); StartBundleRuntime(); } void UpdateCore() // Update Core Files, including BundleRepositoryOpenAPI, PageFlowService and OSGi Core assemblies. { if (AutoUpdateCoreFiles) { new CoreFileUpdater().UpdateCoreFiles(CoreFileUpdateCheckType.Daily); } } void StartBundleRuntime() // Start OSGi Core. { var bundleRuntime = new BundleRuntime(); bundleRuntime.AddService<Application>(this); bundleRuntime.Start(); Startup = App_Startup; Exit = App_Exit; _bundleRuntime = bundleRuntime; } void App_Startup(object sender, StartupEventArgs e) { Application app = Application.Current; var bundleRuntime = _bundleRuntime as BundleRuntime; app.ShutdownMode = ShutdownMode.OnLastWindowClose; #region Get the main window var pageFlowService = bundleRuntime.GetFirstOrDefaultService<IPageFlowService>(); if (pageFlowService == null) { throw new Exception("The page flow service is not installed."); } if (pageFlowService.FirstPageNode == null || string.IsNullOrEmpty(pageFlowService.FirstPageNode.Value)) { throw new Exception("There is not first page node defined."); } var windowType = pageFlowService.FirstPageNodeOwner.LoadClass(pageFlowService.FirstPageNode.Value); if (windowType == null) { throw new Exception(string.Format("Can not load Window type '{0}' from Bundle '{1}'.", pageFlowService.FirstPageNode.Value, pageFlowService.FirstPageNodeOwner.SymbolicName)); } app.MainWindow = System.Activator.CreateInstance(windowType) as Window; #endregion app.MainWindow.Show(); } void App_Exit(object sender, ExitEventArgs e) { if (_bundleRuntime != null) { var bundleRuntime = _bundleRuntime as BundleRuntime; bundleRuntime.Stop(); _bundleRuntime = null; } } #region Settings /// <summary> /// 日志级别。 /// </summary> private static LogLevel LogLevel { get { string level = ConfigurationSettings.AppSettings["LogLevel"]; if (!string.IsNullOrEmpty(level)) { try { object result = Enum.Parse(typeof(LogLevel), level); if (result != null) { return (LogLevel)result; } } catch { } } return LogLevel.Debug; } } /// <summary> /// 日志文件限制的大小。 /// </summary> private static int MaxLogFileSize { get { string size = ConfigurationSettings.AppSettings["MaxLogFileSize"]; if (!string.IsNullOrEmpty(size)) { try { return int.Parse(size); } catch { } } return 10; } } /// <summary> /// 当日志大小超过限制时,是否新建一个。 /// </summary> private static bool CreateNewLogFileOnMaxSize { get { string createNew = ConfigurationSettings.AppSettings["CreateNewLogFileOnMaxSize"]; if (!string.IsNullOrEmpty(createNew)) { try { return bool.Parse(createNew); } catch { } } return false; } } /// <summary> /// 当日志大小超过限制时,是否新建一个。 /// </summary> private static bool AutoUpdateCoreFiles { get { string autoUpdateCoreFiles = ConfigurationSettings.AppSettings["AutoUpdateCoreFiles"]; if (!string.IsNullOrEmpty(autoUpdateCoreFiles)) { try { return bool.Parse(autoUpdateCoreFiles); } catch { } } return false; } } #endregion }}
评论