Exemplo n.º 1
0
        public void Push(CallError callError)
        {
            var ar = box3.BeginInvoke(new Action(() =>
            {
                if (box3.Items.Count >= rowCount)
                {
                    box3.Items.RemoveAt(box3.Items.Count - 1);
                }

                box3.Items.Insert(0,
                    new ParseMessageEventArgs
                    {
                        MessageType = ParseMessageType.Error,
                        LineHeader = string.Format("【{0}】 [{2}] Error => {1}", callError.Caller.CallTime, callError.Message, callError.Caller.AppName),
                        MessageText = string.Format("{0},{1}", callError.Caller.ServiceName, callError.Caller.MethodName),
                        //+ "\r\n" + callError.Caller.Parameters
                        Source = callError
                    });

                box3.Invalidate();
                control.TabPages[3].Text = "异常信息(" + box3.Items.Count + ")";

                if (writeLog)
                {
                    var item = box3.Items[0];
                    var message = string.Format("{0}\r\n{1}\r\n{2}\r\n{3}", item.LineHeader, item.MessageText,
                        (item.Source as CallError).Caller.Parameters, (item.Source as CallError).Error);
                    SimpleLog.Instance.WriteLogForDir("CallError", message);
                }
            }));

            box3.EndInvoke(ar);
        }
 /// <summary>
 /// 错误信息
 /// </summary>
 /// <param name="callError"></param>
 public void Notify(CallError callError)
 {
     _innerListener.Push(callError);
 }
Exemplo n.º 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);
                }
            }
        }