Esempio n. 1
0
 /// <summary>
 ///
 /// </summary>
 public void Dispose()
 {
     mLoginId        = string.Empty;
     mHisDataClient  = null;
     mRealDataClient = null;
     mSecurityClient = null;
     grpcChannel.Dispose();
 }
        /// <summary>
        /// 执行回调业务
        /// </summary>
        /// <param name="address">地址</param>
        /// <param name="options">自定义配置</param>
        /// <param name="channel">已经创建的渠道</param>
        /// <param name="headers">头</param>
        /// <param name="eventId">事件ID</param>
        /// <param name="action">回调业务动作</param>
        /// <param name="exAction">发生异常回调,如果为null,则不会捕获异常</param>
        private static void ExecCallBusiness(string address, ChannelCustomerOptions options, GrpcChannel channel, Metadata headers,
                                             string eventId, Action <GrpcChannel, Metadata> action, Action <RpcException> exAction)
        {
            RpcException rpcEx = null;
            Exception    exce  = null;
            Stopwatch    watch = new Stopwatch();

            try
            {
                watch.Start();
                action(channel, headers);
                watch.Stop();
            }
            catch (RpcException ex)
            {
                watch.Stop();
                exce = rpcEx = ex;
            }
            catch (Exception ex)
            {
                watch.Stop();
                exce = ex;
            }
            finally
            {
                channel.Dispose();
            }

            if (App.InfoEvent != null)
            {
                App.InfoEvent.RecordAsync($"grpc发起请求地址:{address}.接口:{options.Api}.耗时:{watch.ElapsedMilliseconds}ms",
                                          exce, "CreateChannel", eventId, address, options.Api);
            }
            if (rpcEx != null && exAction != null)
            {
                exAction(rpcEx);
            }
            else if (exce != null)
            {
                throw new Exception(exce.Message, exce);
            }
        }