public static JObject ConvertToJson(ServerInfo[][] serverinfos) { /* * 구조 * { * "server tab": { * serverinfo, * serverinfo ... * }, * "server tab": { * serverinfo, * serverinfo ... * } * ... * } */ try { JObject jobj_root = new JObject(); JProperty jprop; for (int i = 0; i < ServerPanel.current.Children.Count; i++) { ServerMenuButton smbtn = ServerPanel.current.Children[i] as ServerMenuButton; if (smbtn == null) { continue; } JObject jobj_serverinfos = new JObject(); for (int j = 0; j < serverinfos[i].Length; j++) { jobj_serverinfos.Add(ConvertToJson(serverinfos[i][j])); } jprop = new JProperty(smbtn.Content.ToString(), jobj_serverinfos); jobj_root.Add(jprop); } return(jobj_root); } catch (Exception e) { Console.WriteLine(e.Message); } return(null); }
public static ServerPanel ConvertFromJson(JObject jobj_root) { if (jobj_root == null) { return(null); } ServerPanel servergrid = new ServerPanel(); try { foreach (var v in jobj_root.Properties()) { JObject jobj_server_menu = v.Value as JObject; if (jobj_server_menu == null) { continue; } ServerMenuButton smbtn = new ServerMenuButton(v.Name); servergrid.Children.Add(smbtn); ServerPanel.SubPanel.Children.Add(smbtn.child); foreach (var jprop_server_info in jobj_server_menu.Properties()) { ServerInfo serverinfo = ServerInfo.ConvertFromJson(jprop_server_info); smbtn.child.Items.Add(new ServerInfoTextBlock(serverinfo)); } } return(servergrid); } catch (Exception e) { Console.WriteLine(e.Message); } return(null); }
private void BtnAddServerMenu_Click(object sender, RoutedEventArgs e) { Window_AddServerMenu wms = new Window_AddServerMenu(); Point pt = this.PointToScreen(new Point(0, 0)); wms.Left = pt.X; wms.Top = pt.Y; if (wms.ShowDialog() == true) { string server_menu_name = wms.textBox_name.Text; if (ServerInfo.jobj_root == null) { return; } try { ServerInfo.jobj_root.Add(new JProperty(server_menu_name, new JObject())); if (!ServerInfo.save()) { return; } ServerMenuButton smbtn = new ServerMenuButton(server_menu_name); ServerPanel.current.Children.Add(smbtn); ServerPanel.SubPanel.Children.Add(smbtn.child); } catch (Exception ex) { Log.PrintError(ex.Message, "Add Server Menu"); Log.PrintError("서버 메뉴 이름이 중복됩니다.\r", "Add Server Menu", Status.current.richTextBox_status); } } }