コード例 #1
0
        /// <summary>
        /// 开始计数
        /// </summary>
        /// <returns></returns>
        public void End(RouteData data)
        {
            data.End = DateTime.Now;
            try
            {
                var tm = (DateTime.Now - Start).TotalMilliseconds;
                if (tm > 200)
                {
                    LogRecorder.Warning($"{data.HostName}/{data.ApiName}:执行时间异常({tm:F2}ms):");
                }

                if (tm > AppConfig.Config.SystemConfig.WaringTime)
                {
                    RuntimeWaring.Waring(data.HostName, data.ApiName, $"执行时间异常({tm:F0}ms)");
                }

                long unit = DateTime.Today.Year * 1000000 + DateTime.Today.Month * 10000 + DateTime.Today.Day * 100 + DateTime.Now.Hour;
                if (unit != Unit)
                {
                    Unit = unit;
                    Save();
                    Station = new CountItem();
                }

                Station.SetValue(tm, data);
                if (string.IsNullOrWhiteSpace(data.HostName))
                {
                    return;
                }
                CountItem host;
                lock (Station)
                {
                    if (!Station.Items.TryGetValue(data.HostName, out host))
                    {
                        Station.Items.Add(data.HostName, host = new CountItem());
                    }
                }
                host.SetValue(tm, data);

                if (string.IsNullOrWhiteSpace(data.ApiName))
                {
                    return;
                }
                CountItem api;
                lock (host)
                {
                    if (!host.Items.TryGetValue(data.ApiName, out api))
                    {
                        host.Items.Add(data.ApiName, api = new CountItem());
                    }
                }
                api.SetValue(tm, data);
            }
            catch (Exception e)
            {
                LogRecorder.Exception(e);
            }
        }
コード例 #2
0
        /// <summary>
        /// 有命令请求时调用
        /// </summary>
        /// <param name="arg"></param>
        protected void OnClientCall(object arg)
        {
            CallArgument argument = (CallArgument)arg;
            string       result   = OnCall(argument);

            if (RpcEnvironment.NetState != ZmqNetStatus.Runing)
            {
                LogRecorder.Warning($"来自{argument.client}的请求操作已完成,但网络连接已关闭,无法返回。参数为{argument.callArg}");
                return;
            }
            argument.socket.TrySendFrame(timeOut, argument.client, true);
            argument.socket.TrySendFrameEmpty(timeOut, true);
            argument.socket.TrySendFrame(timeOut, result);
        }