Exemplo n.º 1
0
        private void OnClickButtonOpenJsonFile(object sender, RoutedEventArgs e)
        {
            if (JsonInfo.current == null)
            {
                return;
            }

            JsonInfo.current.Clear();
            OpenFileDialog ofd = new OpenFileDialog();

            ofd.InitialDirectory = root_path;

            if (JsonInfo.current.Path != null)
            {
                string        dir_path = JsonInfo.current.Path.Substring(0, JsonInfo.current.Path.LastIndexOf('\\') + 1);
                DirectoryInfo d        = new DirectoryInfo(dir_path);
                if (d.Exists)
                {
                    ofd.InitialDirectory = dir_path;
                }
            }

            // 파일 열기
            ofd.Filter = "JSon Files (.json)|*.json";
            if (ofd.ShowDialog(this) == true)
            {
                Console.WriteLine(ofd.FileName);

                string json = FileContoller.read(ofd.FileName);
                refreshJsonTree(JsonController.parseJson(json));

                JsonInfo.current.Path = ofd.FileName;
            }
        }
Exemplo n.º 2
0
        private void OnClickButtonSaveJsonFile(object sender, RoutedEventArgs e)
        {
            if (JsonInfo.current == null)
            {
                return;
            }

            if (JsonInfo.current.Path == null)
            {
                OnClickButtonOtherSaveJsonFile(sender, e);
                return;
            }

            FileInfo f = new FileInfo(JsonInfo.current.Path);

            if (!f.Exists)
            {
                OnClickButtonOtherSaveJsonFile(sender, e);
                return;
            }

            // root JsonTreeViewItem = TreeView.Items[0]
            JsonTreeViewItem root = json_tree_view.Items[0] as JsonTreeViewItem;

            if (root == null)
            {
                return;
            }

            JToken Jtok_root = JsonTreeViewItem.convertToJToken(root);

            FileContoller.write(JsonInfo.current.Path, Jtok_root.ToString());
        }
Exemplo n.º 3
0
        void InitServerTab()
        {
            // serverinfo.json 파일 로드
            FileInfo fi = new FileInfo(ServerInfo.PATH);

            if (fi.Exists)
            {
                string json = FileContoller.read(ServerInfo.PATH);
                try
                {
                    ServerInfo.jobj_root = JObject.Parse(json);
                    ServerPanel panel_server = ServerInfo.ConvertFromJson(ServerInfo.jobj_root);

                    grid_server.Children.Add(panel_server);
                }
                catch (Exception e)
                {
                    Console.WriteLine(e.Message);
                }
            }
            if (ServerMenuButton.group.Count > 0)
            {
                ServerMenuButton.group[0].IsChecked = true;
            }
        }
Exemplo n.º 4
0
        void UploadJsonFile()
        {
            if (ServerList.selected_serverinfo_textblock.serverinfo == null)
            {
                return;
            }

            string     ip       = ServerList.selected_serverinfo_textblock.serverinfo.ip;
            string     id       = ServerList.selected_serverinfo_textblock.serverinfo.id;
            string     password = ServerList.selected_serverinfo_textblock.serverinfo.password;
            SftpClient sftp     = new SftpClient(ip, id, password);

            sftp.Connect();

            string local_directory  = AppDomain.CurrentDomain.BaseDirectory;
            string remote_directory = "/home/cofile/bin/";

            string[] paths = FileContoller.loadFile(local_directory, "*.json");
            foreach (var path in paths)
            {
                FileInfo fi = new FileInfo(path);
                Console.WriteLine("[ upload ] " + fi);
                FileStream fs = File.Open(path, FileMode.Open, FileAccess.Read);
                sftp.UploadFile(fs, remote_directory + fi.Name);
            }
        }
Exemplo n.º 5
0
        public void refreshJsonFile()
        {
            // 삭제
            listView_json.Items.Clear();
            cur_jsonfile.Clear();

            // 추가
            //string[] files = Directory.GetFiles(@"D:\git\config_manager\ConfigManager_sln\ConfigEditor_proj\bin\Debug", "*.json");
            // 현재 application이 실행되는 경로의 json 파일을 찾아라
            string[] files = Directory.GetFiles(AppDomain.CurrentDomain.BaseDirectory, "*.json");

            for (int i = 0; i < files.Length; i++)
            {
                Label    lb = new Label();
                string[] filename_splited = files[i].Split('\\');
                lb.Content = filename_splited[filename_splited.Length - 1];
                listView_json.Items.Add(lb);
            }
            cur_jsonfile.path     = files[0];
            cur_jsonfile.filename = (listView_json.Items.GetItemAt(0) as Label).Content as string;

            string json = FileContoller.read(cur_jsonfile.path);

            refreshJsonItem(json, cur_jsonfile.filename);

            listView_json.SelectionChanged += ListView_json_SelectionChanged;
        }
Exemplo n.º 6
0
        private void OnTextChanged_value(object sender, TextChangedEventArgs e)
        {
            TextBox tb = sender as TextBox;

            Console.WriteLine(cur_jsonfile.jroot.ToString());
            Console.WriteLine(cur_jsonfile.GetHashCode());

            FileContoller.write(cur_jsonfile.filename, cur_jsonfile.jroot.ToString());
        }
Exemplo n.º 7
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);
                }
            }
        }
Exemplo n.º 8
0
 public static void save()
 {
     if (!FileContoller.write(ServerInfo.PATH, ServerInfo.jobj_root.ToString()))
     {
         string caption = "save error";
         string message = "serverinfo.json 파일을 저장하는데 문제가 생겼습니다.";
         MessageBox.Show(message, caption);
         Console.WriteLine("[" + caption + "] " + message);
     }
 }
Exemplo n.º 9
0
        private void ListView_json_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            Label selected = listView_json.SelectedItem as Label;

            if (selected != null)
            {
                cur_jsonfile.filename = selected.Content as string;
                string json = FileContoller.read(cur_jsonfile.filename);
                refreshJsonItem(json, cur_jsonfile.filename);
            }
        }
Exemplo n.º 10
0
        private void OnClickButtonCancelJsonFile(object sender, RoutedEventArgs e)
        {
            if (JsonInfo.current == null || JsonInfo.current.Path == null)
            {
                return;
            }

            string        dir_path = JsonInfo.current.Path.Substring(0, JsonInfo.current.Path.LastIndexOf('\\') + 1);
            DirectoryInfo d        = new DirectoryInfo(dir_path);

            if (!d.Exists)
            {
                return;
            }

            string json = FileContoller.read(JsonInfo.current.path);

            refreshJsonTree(JsonController.parseJson(json));
        }
Exemplo n.º 11
0
        private void SaveFile(string path)
        {
            if (!CheckJson())
            {
                return;
            }

            JToken Jtok_root = JsonTreeViewItem.convertToJToken(json_tree_view.Items[0] as JsonTreeViewItem);

            if (FileContoller.write(path, Jtok_root.ToString()))
            {
                MessageBox.Show(path + " 파일이 저장되었습니다.", "save");
            }
            else
            {
                string caption = "save error";
                string message = path + " 파일을 저장하는데 문제가 생겼습니다.";
                MessageBox.Show(message, caption);
                Console.WriteLine("[" + caption + "] " + message);
            }
        }
Exemplo n.º 12
0
        void addKeyTextBox(Panel pan, string key, List <string> key_stack)
        {
            string[] arr = new string[key_stack.Count];
            key_stack.CopyTo(arr);

            TextBox tb_key = new TextBox();

            tb_key.Text   = key;
            tb_key.Margin = new Thickness(5);
            tb_key.Width  = 150;
            //tb_key.IsEnabled = false;
            tb_key.TextChanged += delegate(object sender, TextChangedEventArgs e)
            {
                JToken tmp = cur_jsonfile.jtoken;
                for (int i = 0; i < arr.Length; i++)
                {
                    if (tmp is JObject)
                    {
                        tmp = ((JObject)tmp).GetValue(arr[i]);
                    }
                    else if (tmp is JArray)
                    {
                        tmp = ((JArray)tmp)[Convert.ToInt16(arr[i])];
                    }
                    else
                    {
                        break;
                    }
                }
                tmp[tb_key.Text] = tmp[key];
                tmp[key].Parent.Remove();
                //(tmp[key] as JProperty).Remove();

                FileContoller.write(cur_jsonfile.filename, cur_jsonfile.jtoken.ToString());
            };
            pan.Children.Add(tb_key);
            //tb_key.SetValue(Grid.ColumnProperty, 0);
        }
Exemplo n.º 13
0
        private void OnClickButtonOtherSaveJsonFile(object sender, RoutedEventArgs e)
        {
            if (JsonInfo.current == null)
            {
                return;
            }

            SaveFileDialog sfd = new SaveFileDialog();

            sfd.InitialDirectory = root_path;

            if (JsonInfo.current.Path != null)
            {
                string        dir_path = JsonInfo.current.Path.Substring(0, JsonInfo.current.Path.LastIndexOf('\\') + 1);
                DirectoryInfo d        = new DirectoryInfo(dir_path);
                if (d.Exists)
                {
                    sfd.InitialDirectory = dir_path;
                }
            }

            sfd.Filter = "JSon Files (.json)|*.json";
            if (sfd.ShowDialog(this) == true)
            {
                // root JsonTreeViewItem = TreeView.Items[0]
                JsonTreeViewItem root = json_tree_view.Items[0] as JsonTreeViewItem;
                if (root == null)
                {
                    return;
                }

                JToken Jtok_root = JsonTreeViewItem.convertToJToken(root);
                FileContoller.write(sfd.FileName, Jtok_root.ToString());
                JsonInfo.current.Path = sfd.FileName;
            }
        }
Exemplo n.º 14
0
        void addValueTextBox(Panel pan, string key, string data, List <string> key_stack)
        {
            string[] arr = new string[key_stack.Count];
            key_stack.CopyTo(arr);

            TextBox tb_value = new TextBox();

            tb_value.Text         = data;
            tb_value.Margin       = new Thickness(5);
            tb_value.Width        = 150;
            tb_value.TextChanged += delegate(object sender, TextChangedEventArgs e)
            {
                JToken tmp = cur_jsonfile.jtoken;
                for (int i = 0; i < arr.Length; i++)
                {
                    if (tmp is JObject)
                    {
                        tmp = ((JObject)tmp).GetValue(arr[i]);
                    }
                    else if (tmp is JArray)
                    {
                        tmp = ((JArray)tmp)[Convert.ToInt16(arr[i])];
                    }
                    else
                    {
                        break;
                    }
                }
                tmp[key] = tb_value.Text;

                FileContoller.write(cur_jsonfile.filename, cur_jsonfile.jtoken.ToString());
            };
            //tb_value.TextChanged += Tb_value_TextChanged;
            pan.Children.Add(tb_value);
            //tb_value.SetValue(Grid.ColumnProperty, 1);
        }
Exemplo n.º 15
0
 private void Button_Click(object sender, EventArgs e)
 {
     Console.WriteLine(cur_jsonfile.jroot.ToString());
     Console.WriteLine(cur_jsonfile.GetHashCode());
     FileContoller.write(cur_jsonfile.filename, cur_jsonfile.jroot.ToString());
 }
Exemplo n.º 16
0
        void addButtonDeletejson(Panel pan, List <string> key_stack)
        {
            System.Windows.Controls.Button btn = new System.Windows.Controls.Button();
            btn.Content     = '-';
            btn.Background  = Brushes.White;
            btn.BorderBrush = Brushes.Black;
            btn.Width       = 20;
            btn.Height      = 20;
            btn.VerticalContentAlignment   = VerticalAlignment.Center;
            btn.HorizontalContentAlignment = HorizontalAlignment.Center;

            string[] arr_key_stack = new string[key_stack.Count];
            key_stack.CopyTo(arr_key_stack);
            btn.Click += delegate(object sender, RoutedEventArgs e)
            {
                TreeViewItem parent = pan.Parent as TreeViewItem;
                if (parent != null)
                {
                    if (parent.Header == pan)
                    {
                        TreeViewItem grandparent = parent.Parent as TreeViewItem;
                        if (grandparent != null)
                        {
                            grandparent.Items.Remove(parent);
                        }
                    }
                    else
                    {
                        parent.Items.Remove(pan);
                    }
                }

                JToken tmp = cur_jsonfile.jtoken;
                for (int i = 0; i < arr_key_stack.Length; i++)
                {
                    if (tmp is JObject)
                    {
                        tmp = ((JObject)tmp).GetValue(arr_key_stack[i]);
                    }
                    else if (tmp is JArray)
                    {
                        tmp = ((JArray)tmp)[Convert.ToInt16(arr_key_stack[i])];
                    }
                    else
                    {
                        break;
                    }
                }
                string  key;
                TextBox tb = pan.Children[0] as TextBox;
                if (tb != null)
                {
                    key = tb.Text;
                    JToken jt = tmp[key];
                    if (jt != null)
                    {
                        tmp[key].Parent.Remove();
                    }
                }

                FileContoller.write(cur_jsonfile.filename, cur_jsonfile.jtoken.ToString());
            };
            pan.Children.Add(btn);
            //btn.SetValue(Grid.ColumnProperty, 2);
        }
Exemplo n.º 17
0
 public static void save()
 {
     FileContoller.write(ServerInfo.PATH, ServerInfo.jobj_root.ToString());
 }