コード例 #1
0
        public void Push(CallTimeout callTimeout)
        {
            var ar = box2.BeginInvoke(new Action(() =>
            {
                if (box2.Items.Count >= rowCount)
                {
                    box2.Items.RemoveAt(box2.Items.Count - 1);
                }

                var msgType = ParseMessageType.None;
                if (callTimeout.ElapsedTime >= timeout)
                    msgType = ParseMessageType.Error;
                else if (callTimeout.ElapsedTime >= warningTimeout)
                    msgType = ParseMessageType.Warning;
                else if (callTimeout.Count >= outCount)
                    msgType = ParseMessageType.Question;

                box2.Items.Insert(0,
                    new ParseMessageEventArgs
                    {
                        MessageType = msgType,
                        LineHeader = string.Format("【{0}】 [{3}] Timeout => ({1} rows):{2} ms.", callTimeout.Caller.CallTime, callTimeout.Count, callTimeout.ElapsedTime, callTimeout.Caller.AppName),
                        MessageText = string.Format("{0},{1}", callTimeout.Caller.ServiceName, callTimeout.Caller.MethodName),
                        // + "\r\n" + callTimeout.Caller.Parameters
                        Source = callTimeout
                    });

                box2.Invalidate();
                control.TabPages[2].Text = "警告信息(" + box2.Items.Count + ")";

                if (writeLog && (msgType == ParseMessageType.Error || callTimeout.Count >= outCount))
                {
                    var item = box2.Items[0];
                    var message = string.Format("{0}\r\n{1}\r\n{2}", item.LineHeader, item.MessageText,
                        (item.Source as CallTimeout).Caller.Parameters);

                    if (callTimeout.Count >= outCount)
                        SimpleLog.Instance.WriteLogForDir("CallCount", message);

                    if (msgType == ParseMessageType.Error)
                        SimpleLog.Instance.WriteLogForDir("CallTimeout", message);
                }
            }));

            box2.EndInvoke(ar);
        }
コード例 #2
0
 /// <summary>
 /// 超时信息
 /// </summary>
 /// <param name="callTimeout"></param>
 public void Notify(CallTimeout callTimeout)
 {
     _innerListener.Push(callTimeout);
 }
コード例 #3
0
        /// <summary>
        /// 调用事件信息
        /// </summary>
        /// <param name="callArgs"></param>
        public void Notify(CallEventArgs callArgs)
        {
            if (_listeners.Count == 0) return;

            MessageListener[] listeners = _listeners.ToArray();
            foreach (MessageListener lstn in listeners)
            {
                try
                {
                    if ((lstn.Apps.Count == 0 || lstn.Apps.Any(p => string.Compare(p, callArgs.Caller.AppName, true) == 0)) &&
                        (lstn.Types.Count == 0 || lstn.Types.Any(p => string.Compare(p, callArgs.Caller.ServiceName, true) == 0)))
                    {
                        var options = lstn.Options;
                        if (options.PushCallError && callArgs.IsError)
                        {
                            var callError = new CallError
                            {
                                Caller = callArgs.Caller,
                                Message = callArgs.Error.Message,
                                Error = ErrorHelper.GetErrorWithoutHtml(callArgs.Error),
                                HtmlError = ErrorHelper.GetHtmlError(callArgs.Error)
                            };

                            lstn.Notify(callError);
                        }

                        if (options.PushCallTimeout && !callArgs.IsError)
                        {
                            //如果设定的时间不正确,不进行推送
                            if (options.CallTimeout <= 0
                                && options.CallRowCount <= 0) continue;

                            if (callArgs.ElapsedTime > options.CallTimeout * 1000
                                || callArgs.Count > options.CallRowCount)
                            {
                                var callTimeout = new CallTimeout
                                {
                                    Caller = callArgs.Caller,
                                    Count = callArgs.Count,
                                    ElapsedTime = callArgs.ElapsedTime
                                };

                                lstn.Notify(callTimeout);
                            }
                        }
                    }
                }
                catch (SocketException ex)
                {
                    RemoveListener(lstn);
                }
                catch (Exception ex)
                {
                    if (OnError != null) OnError(ex);
                }
            }
        }