public object ExecMethodResult(int id, string method_name) { CachedObjects.CachedEntities[id] = null; DersaSqlManager M = new DersaSqlManager(); System.Data.DataTable t = M.GetEntity(id.ToString()); if (t == null) { throw new Exception(string.Format("Table is null for entity {0}", id)); } if (t.Rows.Count < 1) { throw new Exception(string.Format("Table is empty for entity {0}", id)); } Entity ent = new Entity(t, M); CachedObjects.CachedCompiledInstances[ent.StereotypeName + id.ToString()] = null; foreach (Entity child in ent.Children) { CachedObjects.CachedCompiledInstances[child.StereotypeName + child.Id.ToString()] = null; } Logger.LogStatic("ExecMethodResult clear cache Entity" + ent.Id.ToString()); //Type nType = Type.GetType("DersaStereotypes." + ent.Stereotype.Name); ICompiled cInst = ent.GetCompiledInstance(); MethodInfo mi = cInst.GetType().GetMethod(method_name); if (mi == null) { string excMessage = "Method " + method_name + " not found "; Logger.LogStatic(excMessage); throw new Exception(excMessage); } //string userName = HttpContext.Current.User.Identity.Name; //System.Data.DataTable T = M.ExecuteSPWithParams("dbo.ENTITY$GetMethodParams", new object[] { id, method_name, userName, Util.GetPassword(userName) }); //string Params = ""; //if (T.Rows.Count > 0) // Params = T.Rows[0][0].ToString(); //object[] ParamValues = Util.GetMethodCallParameterValues(Params); //return mi.Invoke(cInst, ParamValues); return(mi.Invoke(cInst, new object[] {})); //object res = mi.Invoke(cInst, ParamValues); //string resultText = ""; //if (res != null) // resultText = res.ToString(); //return resultText; }
public static void SetImagePath(int id, string fileName) { string userName = HttpContext.Current.User.Identity.Name; string path = "/user_resources/" + userName + "/" + fileName; StereotypeBaseE target = StereotypeBaseE.GetSimpleInstance(id); CachedObjects.CachedEntities[id] = null; DersaSqlManager M = new DersaSqlManager(); System.Data.DataTable t = M.GetEntity(id.ToString()); if (t == null) { throw new Exception(string.Format("Table is null for entity {0}", id)); } if (t.Rows.Count < 1) { throw new Exception(string.Format("Table is empty for entity {0}", id)); } Entity ent = new Entity(t, M); CachedObjects.CachedCompiledInstances[ent.StereotypeName + id.ToString()] = null; foreach (Entity child in ent.Children) { CachedObjects.CachedCompiledInstances[child.StereotypeName + child.Id.ToString()] = null; } ICompiled cInst = ent.GetCompiledInstance(); MethodInfo mi = cInst.GetType().GetMethod("SetPath"); if (mi == null) { string excMessage = "Method SetPath not found "; Logger.LogStatic(excMessage); throw new Exception(excMessage); } object[] callParams = new object[2]; callParams[0] = userName; callParams[1] = path; mi.Invoke(cInst, callParams); }
public string GetAction(string MethodName, int id, string paramString = null) {//AllowExecuteJSMethod string userName = HttpContext.Current.User.Identity.Name; StereotypeBaseE target = StereotypeBaseE.GetSimpleInstance(id); if (!target.AllowExecuteMethod(userName, MethodName)) { return(string.Format("You are not allowed to execute method {0}", MethodName)); } CachedObjects.CachedEntities[id] = null; DersaSqlManager M = new DersaSqlManager(); System.Data.DataTable t = M.GetEntity(id.ToString()); if (t == null) { throw new Exception(string.Format("Table is null for entity {0}", id)); } if (t.Rows.Count < 1) { throw new Exception(string.Format("Table is empty for entity {0}", id)); } Entity ent = new Entity(t, M); CachedObjects.CachedCompiledInstances[ent.StereotypeName + id.ToString()] = null; foreach (Entity child in ent.Children) { CachedObjects.CachedCompiledInstances[child.StereotypeName + child.Id.ToString()] = null; } ICompiled cInst = ent.GetCompiledInstance(); MethodInfo mi = cInst.GetType().GetMethod(MethodName); if (mi == null) { string excMessage = "Method " + MethodName + " not found "; Logger.LogStatic(excMessage); throw new Exception(excMessage); } object[] externalParams = new object[0]; if (paramString != null) { externalParams = JsonConvert.DeserializeObject <object[]>(paramString); } object[] callParams = new object[externalParams.Length + 1]; callParams[0] = userName; for (int i = 0; i < externalParams.Length; i++) { callParams[i + 1] = externalParams[i]; } //Logger.LogStatic(string.Format("method {0}, params count {1}", MethodName, callParams.Length)); object result = mi.Invoke(cInst, new object[] { callParams }); if (result == null) { return(null); } if (result is string) { return(result.ToString()); } return(JsonConvert.SerializeObject(result)); }