コード例 #1
0
        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);
        }
コード例 #2
0
        private static void CreateMethod(CodeNamespace name, CodeTypeDeclaration proxy, MethodInfo item, Type typeInterface)
        {
            string strMethod = @"        public void {0}({1}, RpcResult2<{2}> callback)
        {{
            RpcClientProxy<{3}> clientProxy =
                RpcProxyFactory.GetProxy<{3}>(_ip);
            {4} temp_args = new {4}({5});
            clientProxy.BeginInvoke(""{0}"", temp_args,
                delegate(RpcClientContext context)
                {{                    
                    try
                    {{
                        {2} ret = context.EndInvoke<{2}>();
                        callback.Callback(ret);
                    }}
                    catch (Exception ex)
                    {{
                        Action<Exception> temp = callback.ExceptionHandler;
                        if (temp != null)
                            temp(ex);
                    }}
                }});
        }}";

            ParameterInfo[] pis = item.GetParameters();

            string strArgType    = RpcGetArgsHelper.GetTypeStr2(pis);
            string strParams     = RpcGetArgsHelper.GetParams(pis);
            string strParams2    = RpcGetArgsHelper.GetParams2(pis);
            Type   returnType    = pis[pis.Length - 1].ParameterType;
            string strReturnType = returnType.GetGenericArguments()[0].FullName;

            strMethod = string.Format(strMethod, item.Name, strParams, strReturnType,
                                      typeInterface.FullName, strArgType, strParams2);
            proxy.Members.Add(new CodeSnippetTypeMember(strMethod));
        }