/// <summary> /// 发送错误邮件 /// </summary> /// <param name="message"></param> /// <param name="inner"></param> private void SendErrorMail(string message, Exception inner) { var appClient = new AppClient { AppName = "监控客户端", HostName = DnsHelper.GetHostName(), IPAddress = DnsHelper.GetIPAddress() }; var ex = new IoCException(message, inner) { ApplicationName = appClient.AppName, ServiceName = "Shumi.Framework.Monitor", ErrorHeader = string.Format("Application【{0}】occurs error. ==> Comes from {1}({2}).", appClient.AppName, appClient.HostName, appClient.IPAddress) }; SimpleLog.Instance.WriteLogWithSendMail(ex, emails); }
/// <summary> /// 连接服务器 /// </summary> private void ConnectServer(RequestMessage reqMsg) { //如果连接断开,直接抛出异常 if (!IsConnected) { try { //连接到服务器 client.Connect(); //发送客户端信息到服务端 var clientInfo = new AppClient { AppPath = AppDomain.CurrentDomain.BaseDirectory, AppName = reqMsg.AppName, IPAddress = reqMsg.IPAddress, HostName = reqMsg.HostName }; client.SendMessage(new ScsClientMessage(clientInfo)); } catch (Exception e) { throw new WarningException(string.Format("Can't connect to server ({0}:{1})!Server node : {2} -> {3}", ip, port, node, e.Message)); } } }
/// <summary> /// 通知消息 /// </summary> /// <param name="ipAddress"></param> /// <param name="port"></param> /// <param name="appClient"></param> public void Notify(string ipAddress, int port, AppClient appClient) { _innerListener.Change(ipAddress, port, appClient); }
public void Change(string ipAddress, int port, AppClient appClient) { var ar = box1.BeginInvoke(new Action(() => { for (int i = 0; i < box1.Items.Count; i++) { var args = box1.Items[i]; var connect = args.Source as ConnectInfo; if (connect.AppName == null && connect.IPAddress == ipAddress && connect.Port == port) { connect.IPAddress = appClient.IPAddress; connect.AppName = appClient.AppName; connect.HostName = appClient.HostName; args.LineHeader += string.Format(" 【{0} <=> {1}】", appClient.AppName, appClient.HostName); break; } } box1.Invalidate(); })); box1.EndInvoke(ar); }
/// <summary> /// 客户端信息 /// </summary> /// <param name="client"></param> public ScsClientMessage(AppClient client) { this.client = client; }
/// <summary> /// 改变客户端信息 /// </summary> /// <param name="ipAddress"></param> /// <param name="port"></param> /// <param name="appClient"></param> public void Notify(string ipAddress, int port, AppClient appClient) { if (_listeners.Count == 0) return; MessageListener[] listeners = _listeners.ToArray(); foreach (MessageListener lstn in listeners) { try { var options = lstn.Options; if (options.PushClientConnect) { lstn.Notify(ipAddress, port, appClient); } } catch (SocketException ex) { RemoveListener(lstn); } catch (Exception ex) { if (OnError != null) OnError(ex); } } }