internal static void RegisterMethod(string service, RpcServiceMethod method) { if (dict.ContainsKey(service + method.Method.Name)) { throw new ApplicationException("已经注册过"); } ParameterInfo[] pis = method.Method.GetParameters(); string strArgType = GetTypeStr(pis); Type returnType = pis[pis.Length - 1].ParameterType; string strReturnType = returnType.GetGenericArguments()[0].FullName; string strObjs = getStrObjs(pis); string strMethod = @" public static object[] {0}{1}(RpcServerContext context) {{ Action<{2}> action = delegate({2} ret) {{ context.Return(ret); }}; RpcResult2<{2}> result = new RpcResult2<{2}>(action); result.Context = context; {3} arg = context.GetArgs<{3}>(); return new object[] {{ {4} }}; }}"; strMethod = string.Format(strMethod, service, method.Method.Name, strReturnType, strArgType, strObjs); Methodhelper.Members.Add(new CodeSnippetTypeMember(strMethod)); dict[service + method.Method.Name] = method; }
public RpcServiceDecorator(T serviceObj, string serviceName) : base(string.Empty) { Type intf = typeof(T); if (!intf.IsInterface) { throw new NotSupportedException(); } RpcServiceAttribute serviceAttr = AttributeHelper.GetAttribute <RpcServiceAttribute>(intf); if (!string.IsNullOrEmpty(serviceName)) { p_serviceName = serviceName; } else { p_serviceName = serviceAttr.ServiceName; } _serviceObj = serviceObj; _methods = new HybridDictionary <string, RpcServiceMethod>(); bool enableCounter = serviceAttr.EnableCounters == RpcPerformanceCounterMode.Both || serviceAttr.EnableCounters == RpcPerformanceCounterMode.Server; IICPerformanceCounterCategory category = new IICPerformanceCounterCategory("rpc:" + p_serviceName, PerformanceCounterCategoryType.MultiInstance); foreach (MethodInfo method in intf.GetMethods()) { string methodName = method.Name; RpcServiceMethod m; RpcServiceBatchMethodAttribute battr = AttributeHelper.TryGetAttribute <RpcServiceBatchMethodAttribute>(method); if (battr != null) { if (!string.IsNullOrEmpty(battr.MethodName)) { methodName = battr.MethodName; } m = new RpcServiceBatchMethod(serviceObj, category, methodName, method, enableCounter); } else { RpcServiceMethodAttribute attr = AttributeHelper.GetAttribute <RpcServiceMethodAttribute>(method); if (!string.IsNullOrEmpty(attr.MethodName)) { methodName = attr.MethodName; } m = new RpcServiceMethod(serviceObj, category, methodName, method, enableCounter); } _methods.Add(methodName, m); } IICPerformanceCounterFactory.GetCounters(category); }
internal RpcTransparentService(T serviceObj, string serviceUrl) : base(string.Empty) { Type intf = typeof(T); if (!intf.IsInterface) { throw new NotSupportedException(); } RpcServiceAttribute serviceAttr = AttributeHelper.GetAttribute <RpcServiceAttribute>(intf); p_serviceName = serviceAttr.ServiceName; _serviceObj = serviceObj; _serviceUrl = serviceUrl; IICPerformanceCounterCategory category = new IICPerformanceCounterCategory("rpc:" + p_serviceName, PerformanceCounterCategoryType.MultiInstance); foreach (MethodInfo method in intf.GetMethods()) { string methodName = method.Name; DynamicMethod dm = new DynamicMethod("fun", typeof(object[]), new[] { typeof(RpcServerContext) }); RpcServiceMethod m = new RpcServiceMethod(); m.RatePerSecond = category.CreateCounter(methodName + " /sec.", PerformanceCounterType.RateOfCountsPerSecond32); m.TotalCount = category.CreateCounter(methodName + " Total.", PerformanceCounterType.NumberOfItems32); m.TotalFailed = category.CreateCounter(methodName + " Failed.", PerformanceCounterType.NumberOfItems32); m.Concurrent = category.CreateCounter(methodName + " Concurrent.", PerformanceCounterType.NumberOfItems32); m.Method = method; RpcGetArgsHelper.RegisterMethod(p_serviceName, m); _methods.Add(methodName, m); } IICPerformanceCounterFactory.GetCounters(category); }