/// <summary> /// Caches a web method definition /// </summary> /// <param name="wsType"></param> /// <param name="methods"></param> /// <param name="method"></param> private void AddMethod(Type wsType, Dictionary <string, WebMethodDef> methods, MethodInfo method) { object[] wmAttribs = method.GetCustomAttributes(typeof(WebMethodAttribute), false); if (wmAttribs.Length == 0) { return; } ScriptMethodAttribute sm = null; object[] responseAttribs = method.GetCustomAttributes(typeof(ScriptMethodAttribute), false); if (responseAttribs.Length > 0) { sm = (ScriptMethodAttribute)responseAttribs[0]; } TransactionalMethodAttribute tm = null; object[] tmAttribs = method.GetCustomAttributes(typeof(TransactionalMethodAttribute), false); if (tmAttribs.Length > 0) { tm = (TransactionalMethodAttribute)tmAttribs[0]; } WebMethodDef wmd = new WebMethodDef(this, method, (WebMethodAttribute)wmAttribs[0], sm, tm); methods[wmd.MethodName] = wmd; }
private void LoadReflectedMethods(Type[] assemblyTypes) { assemblyTypes .Where(t => t.IsSubclassOf(typeof(ScriptClass)) && t.GetCustomAttributes(typeof(ScriptClassAttribute), false).Any()) .ToList() .ForEach(@class => { ScriptClassAttribute scriptClass = (ScriptClassAttribute)Attribute.GetCustomAttribute(@class, typeof(ScriptClassAttribute)); @class .GetMethods() .Where(m => m.GetCustomAttributes(typeof(ScriptMethodAttribute), false).Any()) .ToList() .ForEach(method => { // throws exception on non-compliant script methods VerifyMethod(method); ScriptMethodAttribute scriptMethod = (ScriptMethodAttribute)Attribute.GetCustomAttribute(method, typeof(ScriptMethodAttribute)); string methodName = $"{new MethodNameExpression(scriptClass.Name, scriptMethod.Name)}"; EnumParameterTypeMapping enumParameterTypes = GetEnumParameterTypes(method); MethodMapping methodMapping = new MethodMapping(@class, method, enumParameterTypes); // Every method should have a unique name for the script language (the registry should ensure this) switch (scriptMethod.Type) { case ScriptEntityType.Condition: if (!this.Conditions.ContainsKey(scriptMethod.Name)) { this.Conditions[methodName] = methodMapping; } else { throw new Exception($"Duplicate Condition Name {scriptMethod.Type}/{scriptMethod.Name}"); } break; case ScriptEntityType.Action: if (!this.Actions.ContainsKey(scriptMethod.Name)) { this.Actions[methodName] = methodMapping; } else { throw new Exception($"Duplicate Action Name {scriptMethod.Type}/{scriptMethod.Name}"); } break; default: throw new Exception($"Unknown {nameof(ScriptEntityType)} - {nameof(LoadReflectedMethods)}"); } }); }); }
public WebMethodDef(WebServiceDef wsDef, MethodInfo method, WebMethodAttribute wmAttribute, ScriptMethodAttribute smAttribute, TransactionalMethodAttribute tmAttribute, ETagMethodAttribute emAttribute) { this.MethodType = method; this.WebMethodAtt = wmAttribute; this.ScriptMethodAtt = smAttribute; this.TransactionAtt = tmAttribute; if (null != emAttribute) { this.IsETagEnabled = emAttribute.Enabled; } if (wmAttribute != null && !string.IsNullOrEmpty(wmAttribute.MessageName)) { this.MethodName = wmAttribute.MessageName; } else { this.MethodName = method.Name; } // HTTP GET method is allowed only when there's a [ScriptMethod] attribute and UseHttpGet is true this.IsGetAllowed = (this.ScriptMethodAtt != null && this.ScriptMethodAtt.UseHttpGet); this.ResponseFormat = (this.ScriptMethodAtt != null ? this.ScriptMethodAtt.ResponseFormat : ResponseFormat.Json); MethodInfo beginMethod = wsDef.WSType.GetMethod("Begin" + method.Name, BINDING_FLAGS); if (null != beginMethod) { // The BeginXXX method must have the [ScriptMethod] attribute object[] scriptMethodAttributes = beginMethod.GetCustomAttributes(typeof(ScriptMethodAttribute), false); if (scriptMethodAttributes.Length > 0) { // Asynchronous methods found for the function this.HasAsyncMethods = true; this.BeginMethod = new WebMethodDef(wsDef, beginMethod, null, null, null, null); MethodInfo endMethod = wsDef.WSType.GetMethod("End" + method.Name, BINDING_FLAGS); this.EndMethod = new WebMethodDef(wsDef, endMethod, null, null, null, null); // get all parameters of begin web method and then leave last two parameters in the input parameters list because // last two parameters are for AsyncCallback and Async State ParameterInfo[] allParameters = beginMethod.GetParameters(); ParameterInfo[] inputParameters = new ParameterInfo[allParameters.Length - 2]; Array.Copy(allParameters, inputParameters, allParameters.Length - 2); this.BeginMethod.InputParameters = new List <ParameterInfo>(inputParameters); this.BeginMethod.InputParametersWithAsyc = new List <ParameterInfo>(allParameters); } } this.InputParameters = new List <ParameterInfo>(method.GetParameters()); }
// Methods internal WebServiceMethodData(WebServiceData owner, MethodInfo methodInfo, WebMethodAttribute webMethodAttribute, ScriptMethodAttribute scriptMethodAttribute) { this._owner = owner; this._methodInfo = methodInfo; this._webMethodAttribute = webMethodAttribute; this._methodName = this._webMethodAttribute.MessageName; this._scriptMethodAttribute = scriptMethodAttribute; if (string.IsNullOrEmpty(this._methodName)) { this._methodName = methodInfo.Name; } }
private void AddMethod(Dictionary <string, WebServiceMethodData> methods, MethodInfo method) { object[] customAttributes = method.GetCustomAttributes(typeof(WebMethodAttribute), true); if (customAttributes.Length != 0) { ScriptMethodAttribute scriptMethodAttribute = null; object[] objArray2 = method.GetCustomAttributes(typeof(ScriptMethodAttribute), true); if (objArray2.Length > 0) { scriptMethodAttribute = (ScriptMethodAttribute)objArray2[0]; } WebServiceMethodData data = new WebServiceMethodData(this, method, (WebMethodAttribute)customAttributes[0], scriptMethodAttribute); methods[data.MethodName] = data; } }