private void MainForm_FormClosing(object sender, FormClosingEventArgs e) { //SocketInfo si = new SocketInfo(); //si.Name = "服务器端"; //socketList.Add(si); socketInfoList = new List <SocketInfo>(); foreach (TreeNode tn in this.deviceTree.Nodes) { foreach (TreeNode ctn in tn.Nodes) { TabPage tp = (TabPage)ctn.Tag; if (tp != null) { tp.Text = ctn.Text; } foreach (Form f in tp.Controls) { ISocketInfo isi = (ISocketInfo)f; isi.SocketInfo.Name = tp.Text; f.Close(); socketInfoList.Add(isi.SocketInfo); } } } MySerializer.Serialize(socketInfoList, XMLFileName); }
private void ClientConnected(int id, ISocketInfo clientState) { Model.Client c = new Model.Client(id, clientState.LocalIPv4, clientState.LocalIPv6, clientState.RemoteIPv4, clientState.RemoteIPv6); c.Connected = true; Application.Current.Dispatcher.BeginInvoke(System.Windows.Threading.DispatcherPriority.Background, new Action(() => { var count = _clientVM.ClientList.Count; c.ListId = ++count; _clientVM.ClientList.Add(c); })); }
private void MainForm_FormClosing(object sender, FormClosingEventArgs e) { this.socketInfoList = new List <SocketInfo>(); foreach (TreeNode treeNode in this.deviceTree.Nodes) { foreach (TreeNode treeNode2 in treeNode.Nodes) { TabPage tabPage = (TabPage)treeNode2.Tag; if (tabPage != null) { tabPage.Text = treeNode2.Text; } foreach (Form form in tabPage.Controls) { ISocketInfo socketInfo = (ISocketInfo)form; socketInfo.SocketInfo.Names = tabPage.Text; form.Close(); this.socketInfoList.Add(socketInfo.SocketInfo); } } } var doc = new XmlDocument(); doc.Load(this.XMLFileName); doc.DocumentElement.InnerXml = string.Empty; var xmlStringBuild = new System.Text.StringBuilder(""); this.socketInfoList.ForEach(x => { var json = JsonConvert.SerializeObject(x); try { XNode node = JsonConvert.DeserializeXNode(json, "SocketInfo"); var xml = node.ToString(); xmlStringBuild.AppendLine(xml); } catch (Exception ex) { throw; } }); doc.DocumentElement.InnerXml = xmlStringBuild.ToString(); doc.Save(this.XMLFileName); //MySerializer.Serialize<List<SocketInfo>>(this.socketInfoList, this.XMLFileName); }
private void ClientConnected(int id, ISocketInfo clientState) { WriteLine("Client " + id + " with IPv4 " + clientState.RemoteIPv4 + " has connected to the server."); ListViewItem lvi = new ListViewItem { Text = id.ToString() }; lvi.SubItems.Add(clientState.LocalIPv4); lvi.SubItems.Add(clientState.RemoteIPv4); lvi.SubItems.Add(clientState.LocalIPv6); lvi.SubItems.Add(clientState.RemoteIPv6); this.Invoke((MethodInvoker) delegate { lstClients.Items.Add(lvi); }); }
private static void ClientConnected(int id, ISocketInfo clientState) { WriteLine("Client " + id + " with IPv4 " + clientState.RemoteIPv4 + " has connected to the server."); }
protected void ClientConnectedInvoke(int id, ISocketInfo clientInfo) { ClientConnected?.Invoke(id, clientInfo); }