public virtual ActionResult _ModelManage(string chkType = "") { if (!Request.Path.ToLower().StartsWith("/sys/")) { return(Content("access /sys/_ModelManage")); } var currentType = CRLModelTypeForCheck(); string html = @"<h2>对象管理</h2>"; html += "<a href='_CacheManage'>缓存管理</a>"; if (currentType == null) { return(Content("请重写CRLModelTypeForCheck以获取反射的MODEL")); } var findTypes = CRL.Base.GetAllModel(currentType); if (!string.IsNullOrEmpty(chkType)) { var find = findTypes.Keys.Where(b => b.Type.FullName == chkType).FirstOrDefault(); if (find != null) { var db = findTypes[find]; object obj = System.Activator.CreateInstance(find.Type); CRL.IModel b = obj as CRL.IModel; var msg = b.CreateTable(db); html += "<h4 style='color:red'>检查结构" + find.Type + "" + (string.IsNullOrEmpty(msg) ? "成功" : msg) + "</h4>"; } } html += @" <table border='1' style=''> <tr> <td>名称</td> <td>表名</td> <td>主键</td> <td width='40'>操作</td> </tr>"; foreach (var kv in findTypes) { var item = kv.Key; string part = @"<tr> <td>{0}</td> <td>{1}</td> <td>{2}</td> <td><a href='?chkType={0}'>检查结构</a></td> </tr>"; var primaryKey = item.GetPrimaryKey(); part = string.Format(part, item.Type.FullName, item.TableName, primaryKey.GetMemberName() + "(" + primaryKey.PropertyType + ")"); html += part; } return(Content(html)); }
/// <summary> /// 检测所有对象 /// </summary> /// <param name="helper"></param> /// <param name="baseType"></param> /// <returns></returns> public static string CheckAllModel(DBExtend helper, Type baseType) { string msg = ""; //var dbcontext = new DbContext(dbHelper,null); //var helper = new CRL.DBExtend(dbcontext); var assembyle = System.Reflection.Assembly.GetAssembly(baseType); Type[] types = assembyle.GetTypes(); List <Type> findTypes = new List <Type>(); var typeCRL = typeof(CRL.IModel); foreach (var type in types) { if (type.IsClass) { var type1 = type.BaseType; while (type1.BaseType != null) { if (type1.BaseType == typeCRL || type1 == typeCRL) { findTypes.Add(type); break; } type1 = type1.BaseType; } } } try { foreach (var type in findTypes) { try { object obj = System.Activator.CreateInstance(type); CRL.IModel b = obj as CRL.IModel; msg += b.CreateTable(helper); } catch { } } } catch (Exception ero) { } CoreHelper.EventLog.Log(msg); return(msg); }