Пример #1
0
        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()));
                    ServerInfo.save();

                    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", Home.m_wnd.richTextBox_status);
                    Log.PrintError("서버 메뉴 이름이 중복됩니다.\r", "Add Server Menu", Home.m_wnd.richTextBox_status);
                }
            }
        }
Пример #2
0
        void initServerTab()
        {
            // UI 초기화
            ServerGrid servergrid = new ServerGrid();

            grid_server.Children.Add(servergrid);
            ServerMenuButton[] smbtn = new ServerMenuButton[ServerInfo.CATEGORIES.Length];
            for (int i = 0; i < ServerInfo.CATEGORIES.Length; i++)
            {
                ServerInfo.jobj_root.Add(new JProperty(ServerInfo.CATEGORIES[i], new JObject()));
                smbtn[i] = new ServerMenuButton(ServerInfo.CATEGORIES[i]);
                servergrid.Children.Add(smbtn[i]);
                ServerGrid.current.submenu.Children.Add(smbtn[i].child);
            }
            smbtn[0].IsChecked = true;

            CommandView commandView;

            commandView = new CommandView();
            grid_second.Children.Add(commandView);


            // serverinfo.json 파일 로드
            FileInfo fi = new FileInfo(ServerInfo.PATH);

            if (fi.Exists)
            {
                string json = FileContoller.read(ServerInfo.PATH);
                try
                {
                    ServerInfo.jobj_root = JObject.Parse(json);
                    List <ServerInfo>[] serverinfos = ServerInfo.ConvertFromJson(ServerInfo.jobj_root);
                    for (int i = 0; i < ServerInfo.CATEGORIES.Length; i++)
                    {
                        for (int j = 0; j < serverinfos[i].Count; j++)
                        {
                            smbtn[i].child.Items.Add(new ServerInfoTextBlock(serverinfos[i][j]));
                        }
                    }
                    //for(int i = 0; i < ServerInfo.CATEGORIES.Length; i++)
                    //{
                    //	JObject jobj = ServerInfo.jobj_root[ServerInfo.CATEGORIES[i]] as JObject;
                    //	ServerInfo si;
                    //	foreach(var v in jobj.Properties())
                    //	{
                    //		si = ServerInfo.ConvertFromJson(v);
                    //		smbtn[i].child.Items.Add(new ServerInfoTextBlock(si));
                    //	}
                    //}
                }
                catch (Exception e)
                {
                    Console.WriteLine(e.Message);
                }
            }
        }
Пример #3
0
        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);
        }
Пример #4
0
        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);
        }