protected void Application_Start() { AreaRegistration.RegisterAllAreas(); GlobalConfiguration.Configure(WebApiConfig.Register); FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters); RouteConfig.RegisterRoutes(RouteTable.Routes); BundleConfig.RegisterBundles(BundleTable.Bundles); ModelsConfig.Deserialze(); }
/// <summary> /// Initializes a new instance of the <see cref="AETConfig"/> class. /// </summary> /// <param name="aetConfigType">Type of application entity configuration.</param> /// <param name="modelsConfig">The models configuration required if it is not feedback</param> /// <exception cref="ArgumentNullException"> /// Model configuration null /// </exception> /// <exception cref="ArgumentException"> /// calledAET /// or /// modelConfig /// </exception> public AETConfig( AETConfigType aetConfigType, IReadOnlyList <ModelConstraintsConfig> modelsConfig) { AETConfigType = aetConfigType; if (NeedsModelConfig(aetConfigType)) { ModelsConfig = modelsConfig ?? throw new ArgumentNullException(nameof(modelsConfig)); if (!ModelsConfig.Any()) { throw new ArgumentException("You must specify at least 1 ModelConstraintConfig", nameof(modelsConfig)); } } // If this is not a model AET config type the models config should be null if (!NeedsModelConfig(aetConfigType) && modelsConfig != null) { throw new ArgumentException("This config type does not require a ModelConstraintsConfig", nameof(modelsConfig)); } }
public override List <Dictionary <string, object> > GetListData(FilterGroup filter) { List <Dictionary <string, object> > list = new List <Dictionary <string, object> >(); ModelsConfig modelsConfig = ServiceHelper.GetModelsConfig(); using (List <string> .Enumerator enumerator = modelsConfig.models.Select(m => m.moduleName).Distinct <string>().ToList <string>().GetEnumerator()) { while (enumerator.MoveNext()) { string module = enumerator.Current; if ((module != "null") && (module != null)) { string str = modelsConfig.models.Where(a => (a.moduleName == module) && (a.moduleTitle != null)).Select(m => m.moduleTitle).FirstOrDefault <string>(); Dictionary <string, object> item = new Dictionary <string, object>(); item.Add("ModuleName", module); item.Add("ModuleTitle", str); item.Add("ID", module); list.Add(item); } } } return(list); }
/// <summary> /// 获取model 改为直接从列表中读出,不再直接从数据库读取 /// </summary> /// <param name="filter"></param> /// <returns></returns> public override List <Dictionary <string, object> > GetListData(FilterGroup filter) { List <Dictionary <string, object> > list = new List <Dictionary <string, object> >(); ModelsConfig modelsConfig = ServiceHelper.GetModelsConfig(); string str = null; if (filter.groups.Any() && filter.groups[0].rules.Any()) { str = filter.groups[0].rules[0].value.ToString(); } foreach (DevDB.Model.Config.Model model in modelsConfig.models) { if ((str == null) || (model.moduleName == str)) { Dictionary <string, object> item = new Dictionary <string, object>(); item.Add("ModelName", model.name); item.Add("ModelTitle", model.title); item.Add("ID", model.name); list.Add(item); } } return(list); }
public static ModelsConfig GetModelsConfig() { if (SysContext.IsDev) { DbContext currentDb = SysContext.GetCurrentDb(); List <string> list = currentDb.Fetch <string>("select ModelName from core_model", new object[0]); ModelsConfig modelsConfig = new ModelsConfig(); foreach (string item in list) { modelsConfig.models.Add(GetModelByName(item)); } return(modelsConfig); } else { string modelsPath = new HttpServerUtility(HttpContext.Current).MapPath("~/Service/models.xml"); if (EnabledCache) { ModelsConfig modelsConfig = CacheHelper.GetCache("models.xml") as ModelsConfig; if (modelsConfig != null) { return(modelsConfig); } } if (!File.Exists(modelsPath)) { return(null); } string modelsContent = File.ReadAllText(modelsPath); ModelsConfig modelsConfig2 = XmlHelper.XmlDeserialize <ModelsConfig>(modelsContent, Encoding.UTF8); if (EnabledCache) { CacheHelper.SetCache("models.xml", (object)modelsConfig2, new CacheDependency(modelsPath)); } return(modelsConfig2); } }
public static ServiceConfig GetServiceConfig(string model) { if (SysContext.IsDev) { #region 如果是开发过程 DbContext currentDb = SysContext.GetCurrentDb(); core_model core_model = currentDb.FirstOrDefault <core_model>("where ModelName = @0", new object[1] { model }); if (core_model == null) { return(null); } List <core_modelField> list = GetModelFieldsByModelId(currentDb, core_model.ID); core_module core_module = null; if (!string.IsNullOrEmpty(core_model.ModuleID)) { core_module = currentDb.FirstOrDefault <core_module>("where ID = @0", new object[1] { core_model.ModuleID }); } string textField = "ID"; core_modelField core_modelField = list.Where(f => f.IsTextField == 1).FirstOrDefault(); if (core_modelField != null) { textField = core_modelField.FieldName; } else { core_modelField = list.Where(f => f.FieldType == "string").FirstOrDefault(); if (core_modelField != null) { textField = core_modelField.FieldName; } } ServiceConfig serviceConfig = new ServiceConfig(); List <string> lstMany2One = new List <string>(); List <string> lstMany2Many = new List <string>(); List <string> lstOne2Many = new List <string>(); serviceConfig.model.name = core_model.ModelName; serviceConfig.model.title = core_model.ModelTitle; serviceConfig.model.textField = textField; if (((int?)core_model.NotIncludeSysFields).HasValue && core_model.NotIncludeSysFields.Value == 1) { serviceConfig.model.notIncludeSysFields = "Y"; } try { serviceConfig.model.dbName = currentDb.ExecuteScalar <string>("select DbName from core_model where ModelName = @0", new object[1] { model }); } catch { } if (core_module != null) { serviceConfig.model.moduleName = core_module.ModuleName; serviceConfig.model.moduleTitle = core_module.ModuleTitle; } foreach (core_modelField item in list) { Field field = new Field(); field.name = item.FieldName; field.title = item.FieldTitle; field.type = item.FieldType; field.dbName = item.DbName; try { if (currentDb.ExecuteScalar <string>("select IsPK from core_modelField where id = @0", new object[1] { item.ID }) == "1") { field.isPK = "Y"; } else { field.isPK = "N"; } } catch { } if (item.FieldLength.HasValue) { field.length = item.FieldLength.Value.ToStr(); } field.relationField = item.RelationField; field.relationModel = item.RelationModel; serviceConfig.fields.Add(field); if (item.IsFormField != 1) { if (item.FieldType == "many2one") { lstMany2One.Add(item.FieldName); } if (item.FieldType == "many2many") { lstMany2Many.Add(item.FieldName); } if (item.FieldType == "one2many") { lstOne2Many.Add(item.FieldName); } } if (item.IsSearchField == 1) { field.enabledSearch = "Y"; } } serviceConfig.getlist.many2one = string.Join(",", lstMany2One); serviceConfig.getlist.many2many = string.Join(",", lstMany2Many); serviceConfig.getlist.one2many = string.Join(",", lstOne2Many); serviceConfig.getpageddata.many2one = string.Join(",", lstMany2One); serviceConfig.getpageddata.many2many = string.Join(",", lstMany2Many); serviceConfig.getpageddata.one2many = string.Join(",", lstOne2Many); return(serviceConfig); #endregion } else { #region 如果是运行端 string serviceFileName = new HttpServerUtility(HttpContext.Current).MapPath(string.Format("~/Service/{0}/service.xml", model)); if (EnabledCache) { ServiceConfig serviceConfig = CacheHelper.GetCache("service." + model) as ServiceConfig; if (serviceConfig != null) { return(serviceConfig); } } if (!File.Exists(serviceFileName)) { ModelsConfig modelsConfig = GetModelsConfig(); string text2 = null; if (modelsConfig != null && modelsConfig.models != null) { text2 = (from a in modelsConfig.models where string.Compare(a.name, model, true) == 0 select a).Select(m => m.moduleName).FirstOrDefault(); } if (string.IsNullOrEmpty(text2)) { text2 = "others"; } serviceFileName = new HttpServerUtility(HttpContext.Current).MapPath(string.Format("~/Service/{0}/service.xml", model)); if (!File.Exists(serviceFileName)) { serviceFileName = new HttpServerUtility(HttpContext.Current).MapPath(string.Format("~/Service/{0}/{1}/service.xml", text2, model)); } if (!File.Exists(serviceFileName)) { return(null); } } string text3 = File.ReadAllText(serviceFileName); ServiceConfig rev = XmlHelper.XmlDeserialize <ServiceConfig>(text3, Encoding.UTF8); if (EnabledCache) { CacheHelper.SetCache("service." + model, (object)rev, new CacheDependency(serviceFileName)); } return(rev); #endregion } }
private static FastDev.DevDB.Model.Config.Model GetModelByModelName(string mName) { ModelsConfig modelsConfig = GetModelsConfig(); return(modelsConfig.models.FirstOrDefault((FastDev.DevDB.Model.Config.Model a) => string.Compare(a.name, mName, true) == 0)); }
public ActionResult Index() { string text = "<div style='font-size:12px;'>"; DbContext currentDb = SysContext.GetCurrentDb(); bool flag = false; try { currentDb.ExecuteScalar <string>("select id from core_user", new object[0]); text += "数据库测试成功<br />"; } catch (Exception ex) { flag = true; text = text + "数据库测试不成功,错误信息:" + ex.Message + "<br />"; } try { FileInfo fileInfo = new FileInfo(Server.MapPath("~/bin/ne.model.dll")); if (fileInfo != null) { text = text + "FastDev.Model.dll更新时间:" + fileInfo.LastWriteTime.ToString() + "<br>"; } } catch { } try { string text2 = ConfigurationManager.AppSettings["ProjectPath"]; string text3 = ConfigurationManager.AppSettings["MSBuildPath"]; if (!text2.EndsWith("\\")) { text2 += "\\"; } text2 = text2.Replace("#ROOT#", GetRootPath()); text3 = text3.Replace("#ROOT#", GetRootPath()); text = text + "ProjectPath:" + text2 + "<br />"; if (!Directory.Exists(text2)) { text += "ProjectPath配置路径不存在,请检查<br />"; } text = text + "MSBuildPath:" + text3 + "<br />"; if (!System.IO.File.Exists(text3)) { text += "MSBuildPath配置路径不存在,请检查<br />"; } string text4 = CompileProject(text3, text2 + "FastDev.Model\\FastDev.Model.csproj"); if (!string.IsNullOrEmpty(text4)) { if (text4.Length < 2000) { text = text + "<b>实体类编译信息:</b><br>" + text4 + "<br>"; } } else { text += "实体类编译成功<br>"; } text3 = "C:\\Windows\\Microsoft.NET\\Framework\\v4.0.30319\\MSBuild.exe"; if (System.IO.File.Exists(text3)) { text4 = CompileProject(text3, text2 + "FastDev.Model\\FastDev.Model.csproj"); if (!string.IsNullOrEmpty(text4)) { if (text4.Length < 2000) { text = text + "<b>实体类编译信息2:</b><br>" + text4 + "<br>"; } } else { text += "实体类编译成功2<br>"; } } } catch { } try { FileInfo fileInfo = new FileInfo(Server.MapPath("~/bin/ne.model.dll")); Assembly assembly = Assembly.Load("FastDev.Model"); ModelsConfig modelsConfig = ServiceHelper.GetModelsConfig(); foreach (FastDev.DevDB.Model.Config.Model model in modelsConfig.models) { try { ServiceConfig serviceConfig = ServiceHelper.GetServiceConfig(model.name); if (serviceConfig != null && !flag) { List <string> list = currentDb.Fetch <string>("select name from syscolumns where id=object_id('" + model.name + "')", new object[0]); bool flag2 = assembly.GetTypes().Any((Type a) => a.FullName.EndsWith("." + model.name)); int num = 0; if (flag2) { num = assembly.GetTypes().FirstOrDefault((Type a) => a.FullName.EndsWith("." + model.name)).GetProperties() .Count(); } text += string.Format("<b>【{0}】【{1}】(包括{2}个字段)(包括{3}个DB字段)【状态:{4}】</b><br>", model.moduleName, model.name, serviceConfig.fields.Count, list.Count, flag2 ? "正常" : "未编译"); if (!ExistSql(currentDb, "SELECT\r\ncount(*),\r\ntbl.name AS [Name]\r\nFROM sys.tables AS tbl\r\nWHERE (tbl.name=N'" + model.name + "' and SCHEMA_NAME(tbl.schema_id)=N'dbo')")) { text += "不存在于数据库 <br>"; } string text5 = Server.MapPath(string.Format("~/UI/{0}/{1}/", model.moduleName, model.name)); if (Directory.Exists(text5)) { string[] files = Directory.GetFiles(text5); text += "包括以下界面:<br>"; string[] array = files; foreach (string text6 in array) { string text7 = text6.Replace(text5, ""); if (!text7.StartsWith("service_")) { text = text + text7 + "<br>"; } } } foreach (Field field in serviceConfig.fields) { if (!IsMatch(field.name, "^[a-zA-Z][a-zA-Z0-9_]+$")) { text = text + "字段" + field.name + "命名不规范<br>"; } if (field.type == "many2one") { if (!list.Any((string a) => a == field.dbName)) { text = text + "数据库缺少字段" + field.dbName + "<br>"; } } else if (!field.type.Contains("2") && !list.Any((string a) => a == field.name)) { text = text + "数据库缺少字段" + field.name + "<br>"; } if (flag2) { Type type = assembly.GetTypes().FirstOrDefault((Type a) => a.FullName.EndsWith("." + model.name)); if (field.type == "many2one") { if (!type.GetProperties().Any((PropertyInfo a) => a.Name == field.dbName)) { text = text + "缺少字段" + field.name + "<br>"; } } else if (!field.type.Contains("2") && !type.GetProperties().Any((PropertyInfo a) => a.Name == field.name)) { text = text + "缺少字段" + field.name + "<br>"; } } } } } catch (Exception ex) { if (model != null) { string text8 = text; text = text8 + "<b>模型" + model.name + "</b>检查出错:" + ex.Message + "<br>"; } } } } catch (Exception) { } text += "</div>"; return(Content(text, "text/html")); }