public virtual IActionResult Run(string command) { Response.Headers.Add("Cache-Control", "no-cache"); try { MDataAdapter da = GetDataAdapter(command); if (da == null) { throw new Exception($@"Дата адаптер ""{command}"" не найден."); } da.Context = HttpContext; // Если в параметрах запроса стоит save=1 то считается что мы имеем дело с сохранением изменений if (Request.Query["save"] == "1") { return(Json(da.Save(Model, Request.Path.Value, Request.QueryString.Value), MJsonDataConverter.GetSettings(Model))); } if (Request.Query["commands"] == "1") { return(Json(da.GetCommands(Model), MJsonDataConverter.GetSettings(Model))); } else { if (!MJsonDataConverter.IsCached) { MJsonDataConverter.Reload(); } return(Json(MJsonData.Create(da.Run(Model, Request.Path.Value, Request.QueryString.Value)), MJsonDataConverter.GetSettings(Model))); } } catch (Exception e) { MJsonData jd = MJsonData.Create(e); return(Json(jd)); } }
public IActionResult CfgDic() { Response.Headers.Add("Cache-Control", "no-cache"); try { List <object> l = new List <object>(); foreach (Type t in Model.MainDic.Keys) { if (t.GetTypeInfo().IsSubclassOf(typeof(MEDMCfgObj))) { foreach (object o in Model.MainDic[t].Values) { l.Add(o); } } } return(Json(MJsonData.Create(l), MJsonDataConverter.GetSettings(Model))); } catch (Exception e) { MJsonData jd = MJsonData.Create(e); return(Json(jd)); } }
/// <summary> /// Вернуть описание модели в формате JS /// /// { /// имя папки: { /// _type:'folder' /// _header: 'заголовок' /// имя класса: { /// _type:'class' /// _header: 'заголовок' /// имя свойства: { /// _type:'class', /// _header: 'заголовок', /// _datatype: 'тип данных', /// _element: { /// описателе для elements в формах /// } /// _column: { /// описателе для columns в таблицах и т.д. /// } /// }, /// ... /// имя свойства: { /// описатель свойства /// } /// }, /// ... /// имя класса: { /// описатель класса /// } /// }, /// ... /// имя папки: { /// описатель папки /// } /// } /// /// Папки могут быть вложенные и используются просто для структурирования. /// При описании классов и свойств можно использовать макро /// </summary> /// <returns></returns> public IActionResult ModelClasses() { /* * string model = ""; * try * { * foreach (string filename in Directory.GetFiles(ModelPath, "*.js", SearchOption.AllDirectories)) * { * model += System.IO.File.ReadAllText(filename) + "\r\n"; * } * } * catch (Exception e) * { * model = $@"{{'_error_': 'Ошибки при начитке модели ({e})'}} "; * } * Response.Headers.Add("Cache-Control", "no-cache"); * return Content(model, "application/javascript", Encoding.UTF8); */ JObject stub = new JObject(); try { // Набрать все классы какие есть HashSet <Type> classes = new HashSet <Type>(); foreach (Type t in Model.MainDic.Keys) { Type t1 = t; while (t1 != null && !t1.GetTypeInfo().IsAbstract&& !classes.Contains(t1)) { classes.Add(t1); t1 = t1.GetTypeInfo().BaseType; } } // Проход по классам foreach (Type t in classes) { TypeInfo ti = t.GetTypeInfo(); DbTableAttribute ta = ti.GetCustomAttribute <DbTableAttribute>(); EDMClassAttribute ca = ti.GetCustomAttribute <EDMClassAttribute>(); if (ti.IsSubclassOf(typeof(MEDMObj))) { JObject jclass = new JObject(); jclass.Add("_mtype", new JValue("class")); jclass.Add("_header", new JValue(ca.Header)); jclass.Add("_base", new JValue(ti.BaseType.Name)); // Проход по свойствам foreach (PropertyInfo pi in t.GetProperties()) { DbColumnAttribute da = pi.GetCustomAttribute <DbColumnAttribute>(); EDMPropertyAttribute pa = pi.GetCustomAttribute <EDMPropertyAttribute>(); if (da != null || pa != null) { string n = JFunc.WebixName(pi.Name); try { TypeInfo pt = pi.PropertyType.GetTypeInfo(); if (pi.GetCustomAttribute(typeof(JsonIgnoreAttribute)) == null && pi.GetCustomAttribute(typeof(IgnoreAttribute)) == null) { JObject jprop = new JObject(); jprop.Add("_mtype", new JValue("prop")); if (pa != null) { jprop.Add("_header", new JValue(pa.Header)); jprop.Add("_type", new JValue(pa.ItemType.Name)); jprop.Add("_ptype", new JValue(pa.PropType)); jprop.Add("_default", new JValue(MJsonDataConverter.GetDefaulValue(pi.PropertyType))); jprop.Add("_visible", new JValue(true)); } else { jprop.Add("_default", new JValue(MJsonDataConverter.GetDefaulValue(pi.PropertyType))); jprop.Add("_visible", new JValue(false)); } jclass.Add(JFunc.WebixName(n), jprop); } } catch (Exception e1) { stub = JObject.Parse($@"{{'_error_': ' Ошибки при формировании базовых классов модели [{t.Name}({n})] ({e1})'}} "); } } } stub.Add(ti.Name, jclass); } } } catch (Exception e) { string mess = e.Message.Replace(@"\", @"\\").Replace(@"'", @"\'"); stub = JObject.Parse($@"{{'_error_': 'Ошибки при формировании базовых классов модели ({e})'}} "); } Response.Headers.Add("Cache-Control", "no-cache"); return(Json(stub)); }