private static void OnStarting(string[] args) { Starting?.Invoke(null, EventArgs.Empty); //激发当前上下文的“Starting”事件 _context.RaiseStarting(args); }
public static void Start(PluginApplicationContext context, params string[] args) { if (context == null) { throw new ArgumentNullException("context"); } if (_isStarted != 0) { return; } //激发“Starting”事件 OnStarting(context); //激发应用上下文对象的“Starting”事件 context.RaiseStarting(args); #if !DEBUG try #endif { context.PluginContext.PluginTree.Loader.Loaded += delegate { //插件树加载完成即保存当前应用上下文 _context = context; //将应用上下文对象挂载到插件结构中 _context.PluginContext.PluginTree.Mount(_context.PluginContext.Settings.ApplicationContextPath, _context); //将应用上下文对象注册到默认服务容器中 if (_context.ServiceFactory != null && _context.ServiceFactory.Default != null) { _context.ServiceFactory.Default.Register("ApplicationContext", _context); } }; //初始化全局模块 InitializeGlobalModules(context); //加载插件树 context.PluginContext.PluginTree.Load(); //初始化插件模块 InitializePluginModules(context, context.PluginContext.PluginTree.Plugins); //激发应用上下文对象的“Initializing”事件 context.RaiseInitializing(args); //如果工作台对象不为空则运行工作台 if (context.GetWorkbench(args) != null) { //激发应用上下文对象的“Initialized”事件 context.RaiseInitialized(args); //注意:因为工作台很可能会阻塞当前主线程,所以需要利用其Opened事件进行注册 context.Workbench.Opened += delegate { //激发应用启动完成事件 RaiseStarted(args); }; context.Workbench.Closed += delegate { Exit(); }; //启动工作台 context.Workbench.Open(args); } //激发应用启动完成事件 RaiseStarted(args); } #if !DEBUG catch (Exception ex) { //应用无法启动,写入日志 Zongsoft.Diagnostics.Logger.Fatal(ex); //重抛异常 throw; } #endif }