void StartBundleRuntime() // Start OSGi Core. { FileLogUtility.SetLogLevel(LogLevel.Debug); FileLogUtility.SetMaxFileSizeByMB(10); FileLogUtility.SetCreateNewFileOnMaxSize(true); var st = new Stopwatch(); st.Start(); var setting = new AddinEngineStartUpSetting(); AddinEngineHost.InitializeBundleRuntime(setting); SplashWindow.Instance.Show(); var bundleRuntime = AddinEngineHost.Runtime; bundleRuntime.AddService <Application>(this); AddinEngineHost.StartRuntime(); Exit += AppExit; _bundleRuntime = bundleRuntime; st.Stop(); MessageService.Instance.SendMessage("StartRuntime takes " + st.ElapsedMilliseconds + "ms"); StartupWorkbench(); }
public void Start(IBundleContext context) { BundleRuntime runtime = BundleRuntime.Instance; context.BundleStateChanged += context_BundleStateChanged; //注册宿主程序 if (HostingAssemblyFunc != null) { Assembly[] hostingAssemblies = HostingAssemblyFunc(); RegisterAssemblies(hostingAssemblies); } //注册激活的插件的依赖项 foreach (IBundle bundle in context.Framework.Bundles) { if (bundle.State == BundleState.Active) { RegisterBundle(bundle); } } if (runtime.State == BundleRuntimeState.Starting) { context.FrameworkStateChanged += context_FrameworkStateChanged; } else { Complate(); } }
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; } } }
/// <summary> /// 当应用停止时,停止Bundle运行时。 /// </summary> /// <param name="sender">Sender。</param> /// <param name="e">事件参数。</param> protected virtual void Application_End(object sender, EventArgs e) { FileLogUtility.Debug("Framework is stopping."); StateTimeoutToRestart(BundleRuntimeState.Stopped); BundleRuntime.Stop(); FileLogUtility.Debug("Framework is stopped."); FileLogUtility.Debug("WebSite is stopped."); }
protected override BundleRuntime CreateBundleRuntime() { BundleRuntime br = base.CreateBundleRuntime(); br.EnableBundleClassLoaderCache = true; br.EnableGlobalAssemblyFeature = true; return(br); }
void App_Exit(object sender, ExitEventArgs e) { if (_bundleRuntime != null) { _bundleRuntime.Stop(); _bundleRuntime = null; } }
public static ContainerBuilder Initialize(this BundleRuntime runtime) { //provide the container builder so that each plugin can register the dependancy when starting. var containerBuilder = new ContainerBuilder(); runtime.AddService(typeof(ContainerBuilder), containerBuilder); return(containerBuilder); }
public MainForm() { InitializeComponent(); using (bundleRuntime = new BundleRuntime())//使用using结束时,回收所有using段内的内存 { bundleRuntime.Start(); HandleExtension(); } }
public App() { _bundleRuntime = new BundleRuntime(); _bundleRuntime.AddService<Application>(this); _bundleRuntime.Start(); Startup += App_Startup; Exit += App_Exit; }
void AppExit(object sender, ExitEventArgs e) { if (_bundleRuntime != null) { var bundleRuntime = _bundleRuntime as BundleRuntime; bundleRuntime.Stop(); _bundleRuntime = null; } }
/// <summary> /// 创建插件运行时<see cref="BundleRuntime"/>实例 /// </summary> /// <returns></returns> protected virtual BundleRuntime CreateBundleRuntime() { BundleRuntime runtime = new BundleRuntime(); #if DEBUG runtime.EnableAssemblyShadowCopy = true; #endif return(runtime); }
//通过插件获取到菜单项 private IEnumerable <NavigationNode> NavigationInitialize() { INavigationService service = BundleRuntime.GetFirstOrDefaultService <INavigationService>(); if (service == null) { return(new List <NavigationNode>()); } return(service.NavgationNodes); }
void StartBundleRuntime() // Start OSGi Core. { var bundleRuntime = new BundleRuntime(); bundleRuntime.AddService <Application>(this); bundleRuntime.Start(); Startup += App_Startup; Exit += App_Exit; _bundleRuntime = bundleRuntime; }
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); }
public virtual void StartBundleRuntime() { FileLogUtility.Debug("WebSite is starting."); AddPreDefinedRefAssemblies(); AppDomain.CurrentDomain.SetData("SQLServerCompactEditionUnderWebHosting", true); BundleRuntime = CreateBundleRuntime(); BundleRuntime.Instance.Framework.EventManager.AddBundleEventListener(new EventHandler <BundleStateChangedEventArgs>( BundleRuntimeHttpHostHelper.RefreshBundleTopLevelReferencedAssembliesByEvent), true); FileLogUtility.Debug("Framework is starting."); BundleRuntime.Start(); ControllerBuilder.Current.SetControllerFactory(new BundleRuntimeControllerFactory()); RegisterGlobalFilters(GlobalFilters.Filters); FileLogUtility.Debug("Framework is started."); }
void StartBundleRuntime() // Start OSGi Core. { FileLogUtility.SetLogLevel(LogLevel); FileLogUtility.SetMaxFileSizeByMB(MaxLogFileSize); FileLogUtility.SetCreateNewFileOnMaxSize(CreateNewLogFileOnMaxSize); var bundleRuntime = new BundleRuntime(); bundleRuntime.AddService <Application>(this); bundleRuntime.Start(); Startup += App_Startup; Exit += App_Exit; _bundleRuntime = bundleRuntime; }
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); } }
public void StartBundleRuntime() { FileLogUtility.SetLogLevel(LogLevel); FileLogUtility.SetMaxFileSizeByMB(MaxLogFileSize); FileLogUtility.SetCreateNewFileOnMaxSize(CreateNewLogFileOnMaxSize); FileLogUtility.Debug("WebSite is starting."); PropertyInfo buildManagerProp = typeof(BuildManager).GetProperty("TheBuildManager", BindingFlags.NonPublic | BindingFlags.Static | BindingFlags.GetProperty); if (buildManagerProp != null) { BuildManager buildManager = buildManagerProp.GetValue(null, null) as BuildManager; if (buildManager != null) { PropertyInfo toplevelAssembliesProp = typeof(BuildManager).GetProperty("TopLevelReferencedAssemblies", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.GetProperty); if (toplevelAssembliesProp != null) { _topLevelReferencedAssemblies = toplevelAssembliesProp.GetValue(buildManager, null) as IList <Assembly>; } } } if (_topLevelReferencedAssemblies == null) { throw new Exception("Retrieve top level referenced assembiles of BuildManager failed."); } AddPreDefinedRefAssemblies(); // Set SQLCE compact before BundleRuntime starting. AppDomain.CurrentDomain.SetData("SQLServerCompactEditionUnderWebHosting", true); InitPhysicalPaths(); BundleRuntime = CreateBundleRuntime(); BundleRuntime.Instance.Framework.EventManager.AddBundleEventListener(BundleEventListener, true); FileLogUtility.Debug("Framework is starting."); StateTimeoutToRestart(BundleRuntimeState.Started); BundleRuntime.Start(); FileLogUtility.Debug("Framework is started."); FileLogUtility.Debug("WebSite is started."); ControllerBuilder.Current.SetControllerFactory(new BundleRuntimeControllerFactory()); RegisterGlobalFilters(GlobalFilters.Filters); }
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); }
protected void Page_Load(object sender, EventArgs e) { BundleRuntime br = BundleRuntime.Instance; BundleRuntimeState state = br.State; switch (state) { case BundleRuntimeState.Started: case BundleRuntimeState.Starting: hintLabel.Text = "系统正在启动,请稍等片刻,然后点击“返回首页”按钮再次访问。"; break; case BundleRuntimeState.Stopped: case BundleRuntimeState.Stopping: case BundleRuntimeState.Disposed: hintLabel.Text = "系统正在终止运行或已经停止运行,请稍等片刻,然后点击“返回首页”按钮再次访问。"; break; } }
/// <summary> /// 应用启动时处理函数。该函数用于初始化TopLevelReferncedAssemblies,并将UIShell.OSGi和UIShell.OSGi.WebExtension这两个程序集添加到该属性。 /// 同时,启动Bundle运行时。 /// </summary> /// <param name="sender">Sender。</param> /// <param name="e">事件参数。</param> protected virtual void Application_Start(object sender, EventArgs e) { FileLogUtility.Init(LogName, LogLocation); FileLogUtility.SetLogLevel(LogLevel); FileLogUtility.SetMaxFileSizeByMB(MaxLogFileSize); FileLogUtility.SetCreateNewFileOnMaxSize(CreateNewLogFileOnMaxSize); FileLogUtility.Debug("WebSite is starting."); AddPreDefinedRefAssemblies(); AppDomain.CurrentDomain.SetData("SQLServerCompactEditionUnderWebHosting", true); BundleRuntime = CreateBundleRuntime(); BundleRuntime.Instance.Framework.EventManager.AddBundleEventListener( new EventHandler <BundleStateChangedEventArgs>(BundleRuntimeHttpHostHelper.RefreshBundleTopLevelReferencedAssembliesByEvent), true); FileLogUtility.Debug("Framework is starting."); StateTimeoutToRestart(BundleRuntimeState.Started); BundleRuntime.Start(); FileLogUtility.Debug("Framework is started."); FileLogUtility.Debug("WebSite is started."); }
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); } }
public void StartBundleRuntime() { FileLogUtility.Debug("WebSite is starting."); AddPreDefinedRefAssemblies(); // Set SQLCE compact before BundleRuntime starting. AppDomain.CurrentDomain.SetData("SQLServerCompactEditionUnderWebHosting", true); BundleRuntime = CreateBundleRuntime(); FileLogUtility.Debug("Framework is starting."); BundleRuntime.Start(); //force to start all plugins LoadBundleResources(); FileLogUtility.Debug("Framework is started."); ControllerBuilder.Current.SetControllerFactory(new BundleRuntimeControllerFactory()); RegisterGlobalFilters(GlobalFilters.Filters); }
private void StartBundleRuntime() // Start OSGi Core. { FileLogUtility.SetLogLevel(LogLevel); FileLogUtility.SetMaxFileSizeByMB(MaxLogFileSize); FileLogUtility.SetCreateNewFileOnMaxSize(CreateNewLogFileOnMaxSize); var bundleRuntime = new BundleRuntime(); bundleRuntime.EnableAssemblyMultipleVersions = false; bundleRuntime.Framework.EventManager.AddBundleEventListener(BundleStateChangedHandler, true); bundleRuntime.Framework.EventManager.AddFrameworkEventListener(FrameworkStateChangedHandler); bundleRuntime.AddService <Application>(this); bundleRuntime.Start(); bundleRuntime.Framework.EventManager.RemoveBundleEventListener(BundleStateChangedHandler, true); bundleRuntime.Framework.EventManager.RemoveFrameworkEventListener(FrameworkStateChangedHandler); Startup += App_Startup; Exit += App_Exit; _bundleRuntime = bundleRuntime; }
// Start OSGi Core. void StartBundleRuntime() { FileLogUtility.SetLogLevel(LogLevel); FileLogUtility.SetMaxFileSizeByMB(MaxLogFileSize); FileLogUtility.SetCreateNewFileOnMaxSize(CreateNewLogFileOnMaxSize); var bundleRuntime = new BundleRuntime(); bundleRuntime.AddService<Application>(this); bundleRuntime.Start(); Startup += App_Startup; Exit += App_Exit; _bundleRuntime = bundleRuntime; }
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); } } }
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); } } }
/// <summary> /// 将插件的一个ASP.NET页面编译并构建成一个IHttpHandler实例。 /// </summary> /// <param name="context">HttpContext。</param> /// <param name="requestType">请求类型。</param> /// <param name="virtualPath">页面虚拟路径。</param> /// <param name="path">页面物理路径。</param> /// <returns>IHttpHandler实例。</returns> public override IHttpHandler GetHandler(HttpContext context, string requestType, string virtualPath, string path) { BundleRuntime instance = BundleRuntime.Instance; if (instance.State != BundleRuntimeState.Started) { try { FileLogUtility.Debug(string.Format("Framework is not in 'Started' state when access page '{0}'.", path)); return(base.GetHandler(context, requestType, FrameworkBusyHandlerPage, "")); } catch (Exception ex) { FileLogUtility.Warn("Failed to redirect framework Busy Handler page when Framework is not in 'Started'."); FileLogUtility.Warn(ex); } return(null); } string value = string.Empty; IBundleRuntimeHttpHost bundleRuntimeHttpHost = (IBundleRuntimeHttpHost)context.ApplicationInstance; BundleData bundleData = bundleRuntimeHttpHost.BundleRuntime.GetFirstOrDefaultService <IBundleInstallerService>() .FindBundleContainPath(Directory.GetParent(path).FullName); if (bundleData != null) { value = bundleData.SymbolicName; } if (string.IsNullOrEmpty(value)) { FileLogUtility.Debug(string.Format( "Failed to get the bundle contains requested page '{0}' and just compile this page into IHttpHandler. Just compile the page directly.", path)); return(SafelyGetHandler(context, requestType, virtualPath, path)); } IBundle bundle = bundleRuntimeHttpHost.BundleRuntime.Framework.GetBundle(bundleData.Path); if (bundle == null) { return(SafelyGetHandler(context, requestType, virtualPath, path)); } FileLogUtility.Debug(string.Format("The bundle state of requested page '{0}' is '{1}'.", path, bundle.State)); switch (bundle.State) { case BundleState.Installed: case BundleState.Resolved: { object syncObject; Monitor.Enter(syncObject = _syncObject); try { bundle.Start(BundleStartOptions.General); bundleRuntimeHttpHost.AddReferencedAssemblies(bundleData.SymbolicName); } finally { Monitor.Exit(syncObject); } return(SafelyGetHandler(context, requestType, virtualPath, path)); } case BundleState.Starting: { object syncObject2; Monitor.Enter(syncObject2 = _syncObject); try { bundleRuntimeHttpHost.AddReferencedAssemblies(bundleData.SymbolicName); } finally { Monitor.Exit(syncObject2); } return(SafelyGetHandler(context, requestType, virtualPath, path)); } case BundleState.Active: return(SafelyGetHandler(context, requestType, virtualPath, path)); case BundleState.Stopping: return(HandleException(context, requestType, new HttpException("Access denied, for the bundle is stopping."))); case BundleState.Uninstalled: return(HandleException(context, requestType, new HttpException("Access denied, for the bundle is uninstalled."))); default: throw new NotSupportedException(); } }