protected void btnRestart_Click(object sender, EventArgs e) { IBundleRuntimeHttpHost host = Context.ApplicationInstance as IBundleRuntimeHttpHost; host.RestartAppDomain(); }
/// <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(); } }