public object Clone() { AjaxClass c = new AjaxClass(); c.Id = this.Id; c.TypeString = this.TypeString; return c; }
public object Clone() { AjaxClass c = new AjaxClass(); c.Id = this.Id; c.TypeString = this.TypeString; return(c); }
public AjaxMethod FindMethod(AjaxClass c, string methodName) { string cachekey = string.Format("{0}.{1}", c.Key, methodName); if (_methodsCache.ContainsKey(cachekey)) return _methodsCache[cachekey]; foreach (AjaxMethod m in c.Methods) { if (string.Equals(m.MethodName, methodName)) { _methodsCache[cachekey] = m; return m; } } throw new AjaxException("can't find ajax method. className:" + c.Key + " methodName: " + methodName); }
public AjaxMethod FindMethod(AjaxClass c, string methodName) { string cachekey = string.Format("{0}.{1}", c.Key, methodName); if (_methodsCache.ContainsKey(cachekey)) { return(_methodsCache[cachekey]); } foreach (AjaxMethod m in c.Methods) { if (string.Equals(m.MethodName, methodName)) { _methodsCache[cachekey] = m; return(m); } } throw new AjaxException("can't find ajax method. className:" + c.Key + " methodName: " + methodName); }
private AjaxClass GetClass(XmlNode node) { AjaxClass c = new AjaxClass(); c.Id = XmlUtil.GetStringAttribute(node, "id", Guid.NewGuid().ToString()); c.TypeString = XmlUtil.GetStringAttribute(node, "type", string.Empty); try { TypeRegistry.RegisterType(c.TypeString, c.TypeString); } catch (Exception ex) { throw new AjaxException("ajax config error. type:" + c.TypeString + " not found", ex); } foreach (XmlNode n in node.SelectNodes("ajax:method", nsmgr)) { c.Methods.Add(GetMethod(n)); } return(c); }
private AjaxClass GetClass(XmlNode node) { AjaxClass c = new AjaxClass(); c.Id = XmlUtil.GetStringAttribute(node, "id", Guid.NewGuid().ToString()); c.TypeString = XmlUtil.GetStringAttribute(node, "type", string.Empty); try { TypeRegistry.RegisterType(c.TypeString, c.TypeString); } catch (Exception ex) { throw new AjaxException("ajax config error. type:" + c.TypeString + " not found", ex); } foreach (XmlNode n in node.SelectNodes("ajax:method", nsmgr)) { c.Methods.Add(GetMethod(n)); } return c; }
void proc() { JContext jc = JContext.Current; HttpContext context = jc.Context; // set a ajax request token jc.IsAjaxRequest = true; // get querystring string qs = context.Request.Params["querystring"]; if (StringUtil.HasText(qs)) { qs = qs.TrimStart('?'); jc.QueryString.Add(StringUtil.DelimitedEquation2NVCollection("&", qs)); } if (context.Request.UrlReferrer != null) { UrlMappingModule module = UrlMappingModule.Instance; if (module != null) { UrlMappingItem mapping = null; jc.QueryString.Add(module.GetMappedQueryString(context.Request.UrlReferrer.AbsolutePath, out mapping)); if (mapping != null) { NavigationInfo navi = new NavigationInfo(); navi.Set(mapping, UrlMappingModule.GetUrlRequested(context.Request.UrlReferrer.AbsolutePath)); jc.Navigation = navi; // fire url matched event module.OnUrlMatched(); } } } // set view data UrlMappingModule.SetViewData(); string classId = context.Request.Params[CLASS_ID_PARAM]; string methodName = context.Request.Params[METHOD_NAME_PARAM]; string methodJsonArgs = context.Request.Params[METHOD_ARGS_PARAM]; string jsonp = context.Request.Params[JSONP]; object result; int cacheMinutes = -1; if (string.IsNullOrEmpty(classId) || string.IsNullOrEmpty(methodName)) { result = "null"; } else { AjaxConfiguration config = AjaxConfiguration.GetConfig(); AjaxMethod m = null; try { string id = jc.Navigation.Id; if (id.Contains(":")) { id = id.Substring(id.IndexOf(":") + 1); } AjaxClass c = config.FindClass(classId, id); m = config.FindMethod(c, methodName); if (string.Equals("Post", m.AjaxType, StringComparison.InvariantCultureIgnoreCase)) { cacheMinutes = -1; } else if (StringUtil.HasText(m.CacheTest)) { cacheMinutes = methodJsonArgs.Equals(m.CacheTest) ? cacheMinutes : -1; } // before execute BeforeExecuteEventArgs e = new BeforeExecuteEventArgs() { JContext = jc, TypeName = c.Key, MethodName = m.MethodName }; OnBeforeExecute(e); if (e.PreventDefault) { result = e.ReturnValue; goto response; } if (c.Type != null) { result = m.Invoke(c.Type, methodJsonArgs); } else { result = m.Invoke(c.TypeString, methodJsonArgs); } } catch (Exception ex) { LogManager.GetLogger <AjaxController>().Error("ajax handler error." + ExceptionUtil.WriteException(ex)); AjaxServerException ajaxEx = null; if (m != null) { ajaxEx = m.Exception; } if (ajaxEx != null) { result = ajaxEx.ToJson(); } else { result = null; } } } goto response; response: OnAfterExecute(result); ResponseUtil.OutputJson(context.Response, result, cacheMinutes, jsonp); ContentType = context.Response.ContentType; }
public void findAjaxMethods(IEnumerable<Type> types) { foreach (Type t in types) { AjaxClass ac = new AjaxClass(); ac.Id = "gAjax"; ac.Type = t; foreach (MethodInfo mi in t.GetMethods(BindingFlags.Public | BindingFlags.Static | BindingFlags.NonPublic | BindingFlags.Instance)) { object[] ajaxattrs = mi.GetCustomAttributes(typeof(AjaxMethodAttribute), true); if (ajaxattrs != null && ajaxattrs.Length == 1) { AjaxMethodAttribute am = ajaxattrs[0] as AjaxMethodAttribute; AjaxMethod ajaxMethod = new AjaxMethod(); ajaxMethod.MethodName = mi.Name; ajaxMethod.AjaxType = am.Type.ToString(); ajaxMethod.CacheMinutes = am.CacheMinutes; ajaxMethod.Exception = new AjaxServerException() { Action = am.OnExceptionAction, Parameter = am.OnExceptionParameter }; foreach (ParameterInfo param in mi.GetParameters()) { string paramType = string.Empty; if (param.ParameterType == typeof(long)) paramType = "long"; else if (param.ParameterType == typeof(int)) paramType = "int"; else if (param.ParameterType == typeof(double)) paramType = "double"; else if (param.ParameterType == typeof(bool)) paramType = "bool"; else if (param.ParameterType == typeof(string[])) paramType = "strings"; else if (param.ParameterType == typeof(int[])) paramType = "ints"; else paramType = param.ParameterType.Name; ajaxMethod.Params.Add(new AjaxParam() { ParamType = paramType, ParamName = param.Name }); } ac.Methods.Add(ajaxMethod); } } AjaxConfiguration.ControllerAjax[t] = ac; } }
private static void AppendClassScript(AjaxClass c, ref StringBuilder script) { script.AppendFormat("function {0}Class()", c.Id); script.Append("{};"); script.AppendFormat("{0}Class.prototype=", c.Id); script.Append("{"); for (int i = 0; i < c.Methods.Count; i++) { if (i > 0) script.Append(","); AppendMethodScript(c.Id, c.Methods[i], ref script); } script.Append("};"); script.AppendFormat("var {0}=new {0}Class();", c.Id); }