public void Unload(string ID) { try { if (AddInManager.AppDomains.ContainsKey(ID)) { AddInManager.UnloadAddIn(ID); AddInManager.AppDomains.Remove(ID); if (AddInManager.Loaders.ContainsKey(ID)) { AddInManager.Loaders.Remove(ID); } HttpContext.Current.Response.Write("插件域 " + ID + " 卸载成功!"); } else { HttpContext.Current.Response.Write("插件域 " + ID + " 并未加载!"); } } catch (Exception ex) { HttpContext.Current.Response.Write(ex.Message); } }
public ActionResult Unload() { HttpRequest request = HttpContext.Current.Request; ActionResult result; try { string value = request.Form["Params"]; dynamic param = JsonConvert.DeserializeObject(value); string appDomainID = param.AppDomainID; SqlHelper sqlHelper = new SqlHelper(); DataTable dataTable = sqlHelper.ExecuteDataTable("select * from T_AddIn where F_ID =" + appDomainID, new SqlParameter[0]); string appDomianName = (dataTable != null && dataTable.Rows.Count > 0) ? dataTable.Rows[0]["F_AppDomain_Name"].ToString() : ""; if (appDomianName != "") { if (AddInManager.AppDomains.ContainsKey(appDomianName)) { AddInManager.UnloadAddIn(appDomianName); AddInManager.AppDomains.Remove(appDomianName); if (AddInManager.Loaders.ContainsKey(appDomianName)) { AddInManager.Loaders.Remove(appDomianName); } sqlHelper.ExecuteNonQuery("update T_AddIn set F_Status = 0 where F_ID=" + appDomainID, new SqlParameter[0]); result = this.Json(new { errcode = 0, errmsg = "OK", msgdoc = string.Concat(new object[] { "http://", request.Url.Host, ":", request.Url.Port, "/AddInsDomain/help/doc" }) }, JsonRequestBehavior.DenyGet); } else { result = this.Json(new { errcode = 40003, errmsg = "尝试卸载未加载的插件域!", msgdoc = string.Concat(new object[] { "http://", request.Url.Host, ":", request.Url.Port, "/AddInsDomain/help/doc" }) }, JsonRequestBehavior.DenyGet); } } else { result = this.Json(new { errcode = 40004, errmsg = "参数错误:ID!", msgdoc = string.Concat(new object[] { "http://", request.Url.Host, ":", request.Url.Port, "/AddInsDomain/help/doc" }) }, JsonRequestBehavior.DenyGet); } } catch (Exception ex) { Log.log(ex.ToString()); result = this.Json(new { errcode = -1, errmsg = ex.Message, msgdoc = string.Concat(new object[] { "http://", request.Url.Host, ":", request.Url.Port, "/AddInsDomain/help/doc" }) }, JsonRequestBehavior.DenyGet); } return(result); }