Mini.Crm/Mini.Web/Areas/Admin/Controllers/SysController.cs

133 lines
5.2 KiB
C#

using Microsoft.AspNetCore.Mvc;
using Mini.Common;
using Mini.Web.WebHelper;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Xml;
namespace Mini.Web.Areas.Admin.Controllers
{
public class SysController : BaseController
{
ValidationErrors errors = new ValidationErrors();
#region
/// <summary>
///缓存列表
/// </summary>
/// <returns></returns>
[AuthorizeRedirect(Roles = InitRights.CONST_清除缓存)]
public ActionResult CacheIndex()
{
ToolBar tool = new ToolBar();
// tool.AllowButton("Other1");
string[] toolbtn = new ToolButtonView().ToolButtonRight(InitRights., userRightId);
tool.AllowButton(toolbtn);
tool.AddOtherButton("Other1", "清除缓存", "icon-remove", "DeleteCache_Click", true);
tool.AddOtherButton("Other2", "刷新", "icon-reload", "Reload_Click", true);
ViewBag.ToolBar = tool;
string tableId = "tablist";
Table tab = new Table(tableId);
tab.isCheckbox = true;
tab.AddHeadCol("CacheKey", "20%", "名称");
tab.AddHeadCol("Content", "", "描述");
tab.AddHeadRow();
ViewBag.gridTable = tab.GetHead();
return View();
}
#region
[HttpPost]
/// <summary>
/// 按照条件获取数据
/// </summary>
/// <param name="pager"></param>
/// <param name="queryStr"></param>
/// <returns></returns>
[AuthorizeRedirect(Roles = InitRights.CONST_清除缓存)]
public JsonResult GetCaheHtmlList(string columns)
{
Table table = new Table(columns, true);
XmlDocument doc = new XmlDocument();
doc.Load(Server.MapPath("~/Xml/CacheConfig.xml"));
XmlNode node = doc.DocumentElement;
string cacheKey = Request.Params["cacheKey"];
cacheKey = string.IsNullOrEmpty(cacheKey) ? "" : cacheKey;
IDictionaryEnumerator dicCache = HttpRuntime.Cache.GetEnumerator();
List<string> cacheList = new List<string>();
while (dicCache.MoveNext())
{
if (dicCache.Key.ToString().IndexOf("Cache_UserInfo_") == -1)
cacheList.Add(dicCache.Key.ToString());
}
Dictionary<string, string> dicXml = new Dictionary<string, string>();
foreach (XmlNode childNode in node.ChildNodes)
{
dicXml.Add(childNode.Attributes["key"].Value, childNode.InnerText);
}
table.isCheckbox = true;
string cacheName = string.Empty;
string cacheDes = string.Empty;
foreach (XmlNode childNode in node.ChildNodes)
{
cacheName = string.IsNullOrEmpty(cacheKey) ? childNode.Attributes["key"].Value : childNode.Attributes["key"].Value.Replace(cacheKey, "<span style='color:red;font-weight:bold;'>" + cacheKey + "</span>");
table.AddCol("text-align:left;padding-left:10px;", "", cacheName);
cacheDes = string.IsNullOrEmpty(cacheKey) ? childNode.InnerText : childNode.InnerText.Replace(cacheKey, "<span style='color:red;font-weight:bold;'>" + cacheKey + "</span>");
table.AddCol("text-align:left;padding-left:10px;", "", cacheDes);
table.AddRow();
}
//foreach (string cache in cacheList)
//{
// if (dicXml.Keys.Contains(cache))
// continue;
// cacheName = string.IsNullOrEmpty(cacheKey) ? cache : cache.Replace(cacheKey, "<span style='color:red;font-weight:bold;'>" + cacheKey + "</span>");
// table.AddCol("text-align:left;padding-left:10px;", "", cacheName);
// if (dicXml.Keys.Contains(cache))
// {
// cacheDes = string.IsNullOrEmpty(cacheKey) ? dicXml[cache] : dicXml[cache].Replace(cacheKey, "<span style='color:red;font-weight:bold;'>" + cacheKey + "</span>");
// table.AddCol("text-align:left;padding-left:10px;", "", cacheDes);
// }
// else
// table.AddCol("");
// table.AddRow();
//}
var json = new
{
rowsList = table.GetRows()
};
return Json(json, JsonRequestBehavior.AllowGet);
}
#endregion
[AuthorizeToolBar(InitRights.CONST_清除缓存, InitToolBar.CONST_Other1)]
public JsonResult DeleteChache(string CacheKey)
{
if (string.IsNullOrWhiteSpace(CacheKey))
{
return JsonHandler.ManageMessage("参数不能为空!", false);
}
bool result = true;
try
{
string[] cacheKyes = CacheKey.Split(',');
foreach (string chache in cacheKyes)
{
CacheHelper.Remove(chache);
}
}
catch (Exception ex) { result = false; errors.Add(ex.ToString()); }
return JsonHandler.DeleteMessage(errors, result);
}
#endregion
}
}