Ejemplo n.º 1
0
        private void CalcelJsonFile()
        {
            string json = FileContoller.Read(ConfigOptionManager.Path);

            Refresh(JsonController.ParseJsonUI(json));
            WindowMain.current.ShowMessageDialog("Cancel", "변경사항을 되돌렸습니다.", MessageDialogStyle.Affirmative);
        }
Ejemplo n.º 2
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;
            }
        }
Ejemplo n.º 3
0
        public void Refresh()
        {
            if (WindowMain.current?.EnableConnect?.SshManager == null)
            {
                return;
            }

            string local_dir = MainSettings.Path.PathDirConfigFile + "\\" + WindowMain.current.EnableConnect.Name + "\\" + WindowMain.current.EnableConnect.Id;

            WindowMain.current.EnableConnect.SshManager.GetConfig(local_dir);

            string file_json = FileContoller.Read(local_dir + "\\" + "file.json");
            string sam_json  = FileContoller.Read(local_dir + "\\" + "sam.json");
            string tail_json = FileContoller.Read(local_dir + "\\" + "tail.json");

            jobjFileRoot = JObject.Parse(file_json);
            jobjSamRoot  = JObject.Parse(sam_json);
            jobjTailRoot = JObject.Parse(tail_json);

            //JObject jobj_work_group_root = jobjFileRoot["work_group"] as JObject;
            //if(jobj_work_group_root != null)
            //{
            //	foreach(JProperty jprop_work_group in jobj_work_group_root.Properties())
            //	{
            //		this.FileConfig.Add(new ConfigMenuModel(jobjFileRoot, jprop_work_group.Name));
            //	}
            //}
        }
Ejemplo n.º 4
0
        private void SaveFile(string path)
        {
            if (!CheckJson())
            {
                return;
            }

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

            if (Jtok_root != null && FileContoller.Write(path, Jtok_root.ToString()))
            {
                if (SSHController.SetConfig(path, cur_root_path) == null)
                {
                    WindowMain.current.ShowMessageDialog("Save", "서버 연결 에러");
                }
                else
                {
                    WindowMain.current.ShowMessageDialog("Save", path + " 파일이 저장되었습니다.");
                }
            }
            else
            {
                string caption = "Save Error";
                string message = path + " 파일을 저장하는데 문제가 생겼습니다.";
                WindowMain.current.ShowMessageDialog(caption, message);
                Console.WriteLine("[" + caption + "] " + message);
            }
        }
Ejemplo n.º 5
0
        void UploadJsonFile()
        {
            if (ServerList.selected_serverinfo_textblock.serverinfo == null)
            {
                return;
            }

            string ip       = ServerList.selected_serverinfo_textblock.serverinfo.ip;
            string id       = "root";
            string password = "******";
            //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);
            }
        }
Ejemplo n.º 6
0
        private void CalcelJsonFile()
        {
            string json = FileContoller.Read(JsonTreeViewItem.Path);

            refreshJsonTree(JsonController.parseJson(json));
            WindowMain.current.ShowMessageDialog("Cancel", "변경사항을 되돌렸습니다.", MessageDialogStyle.Affirmative);
        }
Ejemplo n.º 7
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;
            }
        }
Ejemplo n.º 8
0
        void checkServerInfoJsonFile()
        {
            FileInfo fi = new FileInfo(ServerInfo.PATH);

            if (!fi.Exists)
            {
                FileContoller.write(ServerInfo.PATH, new JObject(new JProperty("Server", new JObject())).ToString());
            }
        }
Ejemplo n.º 9
0
 void InitJsonFileView()
 {
     try
     {
         FileContoller.CreateDirectory(cur_root_path);
     }
     catch (Exception e)
     {
         Log.PrintError(e.Message, "CreateDirectory", Status.current.richTextBox_status);
     }
 }
Ejemplo n.º 10
0
 public static bool save()
 {
     if (!FileContoller.Write(ServerInfo.PATH, ServerInfo.jobj_root.ToString()))
     {
         string caption = "save error";
         string message = "serverinfo.json 파일을 저장하는데 문제가 생겼습니다.";
         Log.PrintConsole(message, caption);
         WindowMain.current.ShowMessageDialog(caption, message, MahApps.Metro.Controls.Dialogs.MessageDialogStyle.Affirmative);
         return(false);
     }
     return(true);
 }
Ejemplo n.º 11
0
 public bool Save()
 {
     if (!FileContoller.Write(ServerViewModel.PATH, this.JobjRoot.ToString()))
     {
         string caption = "save error";
         string message = "serverinfo.json 파일을 저장하는데 문제가 생겼습니다.";
         Log.PrintLog(message, "UserControls.ServerViewModel.Save");
         WindowMain.current.ShowMessageDialog(caption, message, MahApps.Metro.Controls.Dialogs.MessageDialogStyle.Affirmative);
         return(false);
     }
     return(true);
 }
Ejemplo n.º 12
0
        public int Refresh()
        {
            if (WindowMain.current?.EnableConnect?.Name == null ||
                WindowMain.current?.EnableConnect?.Id == null)
            {
                return(-1);
            }

            string local_dir = MainSettings.Path.PathDirConfigFile + WindowMain.current.EnableConnect.Name + "\\" + WindowMain.current.EnableConnect.Id;

            if (WindowMain.current?.EnableConnect?.SshManager?.GetConfig(local_dir) != 0)
            {
                FileContoller.Write(local_dir + "/file.json", Properties.Resources.file_config_default);
                FileContoller.Write(local_dir + "/sam.json", Properties.Resources.file_config_default);
                FileContoller.Write(local_dir + "/tail.json", Properties.Resources.file_config_default);
            }
            string file_json = FileContoller.Read(local_dir + "/file.json");
            string sam_json  = FileContoller.Read(local_dir + "/sam.json");
            string tail_json = FileContoller.Read(local_dir + "/tail.json");

            if (file_json == null || file_json.Length == 0 ||
                sam_json == null || sam_json.Length == 0 ||
                tail_json == null || tail_json.Length == 0)
            {
                return(-3);
            }

            try
            {
                if (file_json != null && file_json.Length > 0)
                {
                    panFileConfig.Root = JObject.Parse(file_json);
                }
                if (sam_json != null && sam_json.Length > 0)
                {
                    panSamConfig.Root = JObject.Parse(sam_json);
                }
                if (tail_json != null && tail_json.Length > 0)
                {
                    panTailConfig.Root = JObject.Parse(tail_json);
                }
            }
            catch (Exception e)
            {
                Console.WriteLine("JHLIM_DEBUG : ConfigMenu JObject.Parse " + e.Message);
                return(-2);
            }
            return(0);
        }
Ejemplo n.º 13
0
        private void OnClickButtonViewJsonFile(object sender, RoutedEventArgs e)
        {
            if (ConfigOptionManager.Path == null)
            {
                return;
            }

            Window_EditFile w = new Window_EditFile(FileContoller.Read(ConfigOptionManager.Path), ConfigOptionManager.Path);

            if (w.ShowDialog() == true)
            {
                Refresh(JsonController.ParseJsonUI(w.tb_file.Text));
                ConfigOptionManager.bChanged = true;
            }
        }
Ejemplo n.º 14
0
        public JToken GetSelectedConfigFile()
        {
            string path = SelectedConfigLocalPath;

            if (path == null)
            {
                return(null);
            }

            JToken jtok = JsonController.ParseJson(FileContoller.Read(path));

            if (jtok == null)
            {
                PrintCheckConfigFile();
            }
            return(jtok);
        }
Ejemplo n.º 15
0
        public static void RefreshUi(string db_name = "")
        {
            FileContoller.DeleteFilesInDirectory(path_root);
            db_name = db_name + (Idx_db_name++) + ".db";
            Path    = WindowMain.current?.EnableConnect?.SshManager?.GetDataBase(path_root, db_name);

            if (Sqlite_LogTable.current != null)
            {
                Sqlite_LogTable.current.Refresh();
            }
            if (Sqlite_StatusTable.current != null)
            {
                Sqlite_StatusTable.current.Refresh();
            }
            //FileContoller.DeleteFile(path_root + prev_db_name);
            prev_db_name = db_name;
            bUpdated     = true;
        }
Ejemplo n.º 16
0
        private void OnClickButtonOpenJsonFile(object sender, RoutedEventArgs e)
        {
            //SftpFile[] files = SSHController.GetListConfigFile();
            //if(files != null)
            //{
            //	LinuxDirectoryViewer l = new LinuxDirectoryViewer(files);
            //	l.ShowDialog();
            //}
            if (InitOpenFile() != 0)
            {
                return;
            }

            OpenFileDialog ofd = new OpenFileDialog();

            ofd.InitialDirectory = CurRootPathLocal;

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

            // 파일 열기
            ofd.Filter = "JSon Files (.json)|*.json|All Files (*.*)|*.*";
            if (ofd.ShowDialog() == true)
            {
                Log.PrintConsole(ofd.FileName, "UserControls.ConfigJsonTree.OnClickButtonOpenJsonFile");
                string json = FileContoller.Read(ofd.FileName);
                JToken jtok = JsonController.ParseJsonUI(json);
                if (jtok != null)
                {
                    Refresh(jtok);
                }
                JsonTreeViewItem.Path = ofd.FileName;
                //refreshJsonTree(JsonController.parseJson(json));
                //JsonTreeViewItem.Path = ofd.FileName;
            }
        }
Ejemplo n.º 17
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));
        }
Ejemplo n.º 18
0
        private void OnClickButtonOpenJsonFile(object sender, RoutedEventArgs e)
        {
            //SftpFile[] files = SSHController.GetListConfigFile();
            //if(files != null)
            //{
            //	LinuxDirectoryViewer l = new LinuxDirectoryViewer(files);
            //	l.ShowDialog();
            //}
            Refresh();


            OpenFileDialog ofd = new OpenFileDialog();

            ofd.InitialDirectory = cur_root_path;

            if (JsonTreeViewItem.Path != null)
            {
                string        dir_path = JsonTreeViewItem.Path.Substring(0, JsonTreeViewItem.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() == true)
            {
                Console.WriteLine(ofd.FileName);

                string json = FileContoller.Read(ofd.FileName);
                JToken jtok = JsonController.parseJson(json);
                if (jtok != null)
                {
                    refreshJsonTree(jtok);
                }
                JsonTreeViewItem.Path = ofd.FileName;
                //refreshJsonTree(JsonController.parseJson(json));
                //JsonTreeViewItem.Path = ofd.FileName;
            }
        }
Ejemplo n.º 19
0
        private int SaveFile(string path_local)
        {
            if (!CheckJson())
            {
                return(-1);
            }

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

            if (Jtok_root != null && FileContoller.Write(path_local, Jtok_root.ToString()))
            {
                string path_remote;
                if ((path_remote = SSHController.SetConfig(path_local, CurRootPathLocal)) == null)
                {
                    //FileContoller.FileDelete(path_local);

                    string caption = "Save Error";
                    string message = "서버 연결 에러";
                    WindowMain.current.ShowMessageDialog(caption, message);
                    Log.PrintError(message, "UserControls.ConfigJsonTree.SaveFile");
                    return(-3);
                }
                else
                {
                    string message = path_remote + " 파일이 저장되었습니다.";
                    WindowMain.current.ShowMessageDialog("Save", message);
                    Log.PrintLog(message, "UserControls.ConfigJsonTree.SaveFile");

                    ConfigOptions.ConfigOptionManager.bChanged = false;
                    return(0);
                }
            }
            else
            {
                string caption = "Save Error";
                string message = path_local + " 파일을 저장하는데 문제가 생겼습니다.";
                WindowMain.current.ShowMessageDialog(caption, message);
                Log.PrintError(message, "UserControls.ConfigJsonTree.SaveFile");
                return(-2);
            }
        }
Ejemplo n.º 20
0
        private void OnClickButtonViewJsonFile(object sender, RoutedEventArgs e)
        {
            if (JsonTreeViewItem.Path == null)
            {
                return;
            }

            //if(json_tree_view.Items.Count <= 0)
            //	return;
            //JsonTreeViewItem root = json_tree_view.Items[0] as JsonTreeViewItem;
            //if(root == null)
            //	return;

            //Window_EditFile w = new Window_EditFile(JsonTreeViewItem.convertToJToken(root).ToString(), JsonTreeViewItem.Path);
            Window_EditFile w = new Window_EditFile(FileContoller.Read(JsonTreeViewItem.Path), JsonTreeViewItem.Path);

            if (w.ShowDialog() == true)
            {
                refreshJsonTree(JsonController.parseJson(w.tb_file.Text));
            }
        }
Ejemplo n.º 21
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);
                    panel_server         = ServerInfo.ConvertFromJson(ServerInfo.jobj_root);

                    grid_server.Children.Add(panel_server);
                }
                catch (Exception e)
                {
                    Log.PrintError(e.Message, "UserControls.ServerMenu.InitServertab");
                }
            }
            else
            {
                try
                {
                    ServerInfo.jobj_root = new JObject(new JProperty("Server", new JObject()));
                    ServerPanel panel_server = ServerInfo.ConvertFromJson(ServerInfo.jobj_root);

                    grid_server.Children.Add(panel_server);
                }
                catch (Exception e)
                {
                    Log.PrintError(e.Message, "UserControls.ServerMenu.InitServertab");
                }
            }

            if (ServerMenuButton.group.Count > 0)
            {
                ServerMenuButton.group[0].IsChecked = true;
            }
        }
Ejemplo n.º 22
0
        public ServerViewModel()
        {
            // serverinfo.json 파일 로드
            FileInfo fi = new FileInfo(ServerViewModel.PATH);

            try
            {
                if (fi.Exists)
                {
                    string json = FileContoller.Read(ServerViewModel.PATH);
                    this.JobjRoot = JObject.Parse(json);
                }
                else
                {
                    this.JobjRoot = new JObject(new JProperty("Server", new JObject()));
                }
            }
            catch (Exception e)
            {
                Log.PrintError(e.Message, "UserControls.ServerViewModel.ServerViewModel");
            }
        }
Ejemplo n.º 23
0
        public void Refresh()
        {
            //string file_json = Properties.Resources.file_config_default;
            //string sam_json = Properties.Resources.sam_config_default;
            //string tail_json = Properties.Resources.tail_config_default;
            //btnFileConfig.Root = JObject.Parse(file_json);
            //btnSamConfig.Root = JObject.Parse(sam_json);
            //btnTailConfig.Root = JObject.Parse(tail_json);

            if (WindowMain.current?.enableConnect?.sshManager?.NewGetConfig(MainSettings.Path.PathDirConfigFile) == 0)
            {
                string file_json = FileContoller.Read(MainSettings.Path.PathDirConfigFile + "/file.json");
                if (file_json == null || file_json.Length == 0)
                {
                    file_json = Properties.Resources.file_config_default;
                }
                string sam_json = FileContoller.Read(MainSettings.Path.PathDirConfigFile + "/sam.json");
                if (file_json == null || file_json.Length == 0)
                {
                    file_json = Properties.Resources.sam_config_default;
                }
                string tail_json = FileContoller.Read(MainSettings.Path.PathDirConfigFile + "/tail.json");
                if (file_json == null || file_json.Length == 0)
                {
                    file_json = Properties.Resources.tail_config_default;
                }

                try
                {
                    btnFileConfig.Root = JObject.Parse(file_json);
                    btnSamConfig.Root  = JObject.Parse(sam_json);
                    btnTailConfig.Root = JObject.Parse(tail_json);
                }
                catch (Exception e)
                {
                    Console.WriteLine("JHLIM_DEBUG : ConfigMenu JObject.Parse " + e.Message);
                }
            }
        }
Ejemplo n.º 24
0
        private int ExportCSV(string path, DataTable table)
        {
            if (table == null)
            {
                return(-1);
            }

            try
            {
                string        delimiter = ",";
                string        newLine   = Environment.NewLine;
                StringBuilder sb        = new StringBuilder();

                for (int i = 0; i < table.Rows.Count; i++)
                {
                    sb.Append(table.Rows[i].ItemArray[0].ToString());
                    for (int j = 1; j < table.Columns.Count; j++)
                    {
                        sb.Append(delimiter);
                        sb.Append(table.Rows[i].ItemArray[j].ToString());
                    }
                    sb.Append(newLine);
                }
                if (FileContoller.Write(path, sb.ToString()))
                {
                    return(0);
                }
                else
                {
                    return(-3);
                }
            }
            catch (Exception e)
            {
                Log.PrintError(e.Message, "UserControls.Sqlite_LogTable.ExportCSV");
                return(-2);
            }
        }
Ejemplo n.º 25
0
        private void OpenJsonFile()
        {
            if (InitOpenFile() != 0)
            {
                return;
            }

            OpenFileDialog ofd = new OpenFileDialog();

            ofd.InitialDirectory = CurRootPathLocal;

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

            // 파일 열기
            ofd.Filter = "JSon Files (.json)|*.json|All Files (*.*)|*.*";
            if (ofd.ShowDialog() == true)
            {
                Log.PrintConsole(ofd.FileName, "UserControls.ConfigJsonTree.OnClickButtonOpenJsonFile");
                string json = FileContoller.Read(ofd.FileName);
                JToken jtok = JsonController.ParseJsonUI(json);
                if (jtok != null)
                {
                    Refresh(jtok);
                }
                ConfigOptionManager.Path = ofd.FileName;
                //refreshJsonTree(JsonController.parseJson(json));
                //ConfigOptionManager.Path = ofd.FileName;
            }
        }
Ejemplo n.º 26
0
        private void SaveFile(string path)
        {
            // root JsonTreeViewItem = TreeView.Items[0]
            JsonTreeViewItem root = json_tree_view.Items[0] as JsonTreeViewItem;

            if (root == null)
            {
                return;
            }

            JToken Jtok_root = JsonTreeViewItem.convertToJToken(root);

            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);
            }
        }
Ejemplo n.º 27
0
 int RemoveConfigFile(string path)
 {
     return(FileContoller.DeleteDirectory(path));
 }
Ejemplo n.º 28
0
        void EncryptFileOpen()
        {
            if (listView_linux_files.SelectedItems.Count < 1)
            {
                return;
            }

            LinuxListViewItem llvi = listView_linux_files.SelectedItems[0] as LinuxListViewItem;

            if (llvi == null)
            {
                return;
            }

            if (SSHController.SendNRecvCofileCommand(listView_linux_files.SelectedItems.Cast <Object>(), false))
            {
                string remote_path = llvi.LinuxTVI.Path;
                JToken jtok        = JsonController.parseJson(FileContoller.Read(current.Selected_config_file_path));
                if (jtok == null)
                {
                    return;
                }

                JValue jval_input_extansion  = jtok["dec_option"]["input_extension"] as JValue;
                JValue jval_output_extension = jtok["dec_option"]["output_extension"] as JValue;

                if (remote_path.Length > jval_input_extansion.Value.ToString().Length + 1 &&
                    remote_path.Substring(remote_path.Length - jval_input_extansion.Value.ToString().Length) == jval_input_extansion.Value.ToString())
                {
                    remote_path = remote_path.Substring(0, remote_path.Length - jval_input_extansion.Value.ToString().Length - 1);
                }

                string   remote_dec_path   = remote_path + "." + jval_output_extension.Value.ToString();
                string[] split_remote_path = remote_path.Split('/');
                string   local_filename    = split_remote_path[split_remote_path.Length - 1] + Idx_Encrypt_File_Open++;

                if (SSHController.moveFileToLocal(root_path, remote_dec_path, local_filename))
                {
                    llvi.LinuxTVI.RefreshChildFromParent();
                    Cofile.current.RefreshListView(Cofile.cur_LinuxTreeViewItem);

                    string   url_localfile = root_path + local_filename;
                    string[] split         = remote_path.Split('.');
                    if (split[split.Length - 1] == "gif" ||
                        split[split.Length - 1] == "bmp" ||
                        split[split.Length - 1] == "jpg" ||
                        split[split.Length - 1] == "png"
                        )
                    {
                        Window_ViewImage wvi = new Window_ViewImage(LoadImage(url_localfile), llvi.LinuxTVI.FileInfo.Name);
                        File.Delete(url_localfile);

                        wvi.ShowDialog();
                    }
                    else
                    {
                        string str = FileContoller.Read(url_localfile);
                        File.Delete(url_localfile);

                        Window_ViewFile wvf = new Window_ViewFile(str, llvi.LinuxTVI.FileInfo.Name);
                        wvf.ShowDialog();
                    }
                }
                else
                {
                    Log.PrintError("Decryption Failed\r\tCheck the config file", "ListView_linux_files_MouseDoubleClick", Status.current.richTextBox_status);
                }
            }
        }
Ejemplo n.º 29
0
        private int OpenEncryptFile()
        {
            if (listView_linux_files.SelectedItems.Count < 1)
            {
                return(-1);
            }

            LinuxListViewItem llvi = listView_linux_files.SelectedItems[0] as LinuxListViewItem;

            if (llvi == null)
            {
                return(-2);
            }

            string remote_path = llvi.LinuxTVI.Path;

            string local_filename       = "temp" + Idx_Encrypt_File_Open++;
            string remote_path_dec_file = FindDecryptFile(remote_path);

            if (remote_path_dec_file == null)
            {
                return(-3);
            }

            if (SSHController.SendNRecvCofileCommandPreview(listView_linux_files.SelectedItems.Cast <Object>(), false))
            {
                StartCoRoutine(10000,
                               delegate
                {
                    if (SSHController.MoveFileToLocal(root_path, remote_path_dec_file, local_filename, 0))
                    {
                        llvi.LinuxTVI.RefreshChildFromParent();
                        Cofile.current.RefreshListView(Cofile.cur_LinuxTreeViewItem);

                        string url_localfile = root_path + local_filename;
                        string[] split       = remote_path.Split('.');
                        string expansion     = split[split.Length - 2];
                        if (expansion == "png" ||
                            expansion == "dib" ||
                            expansion == "bmp" ||
                            expansion == "jpg" ||
                            expansion == "jpeg" ||
                            expansion == "jpe" ||
                            expansion == "jfif" ||
                            expansion == "gif" ||
                            expansion == "tif" ||
                            expansion == "tiff"
                            )
                        {
                            Window_ViewImage wvi = new Window_ViewImage(LoadImage(url_localfile), llvi.LinuxTVI.FileInfo.Name);
                            FileContoller.DeleteFile(url_localfile);

                            Point pt = this.PointToScreen(new Point(0, 0));
                            wvi.Left = pt.X;
                            wvi.Top  = pt.Y;
                            wvi.ShowDialog();
                        }
                        else
                        {
                            string str = FileContoller.Read(url_localfile);
                            FileContoller.DeleteFile(url_localfile);

                            Window_ViewFile wvf = new Window_ViewFile(str, llvi.LinuxTVI.FileInfo.Name);

                            Point pt = this.PointToScreen(new Point(0, 0));
                            wvf.Left = pt.X;
                            wvf.Top  = pt.Y;
                            wvf.ShowDialog();
                        }
                        return(0);
                    }
                    else
                    {
                        //Log.ErrorIntoUI("Check the Cofile Config File or Check File To Decrypt", "Decrypt Failed", Status.current.richTextBox_status);
                        //Log.PrintError("Cant Download Decrypt File", "UserControls.Cofile.OpenEncryptFile");
                        return(-1);
                    }
                }, "Check the Cofile Config File or Check File To Decrypt", "Decrypt Failed");
            }
            return(-4);
        }
Ejemplo n.º 30
0
        public static int SaveOption(JObject root = null)
        {
            if (root == null)
            {
                if (ConfigOptionManager.root == null ||
                    curRoot == null)
                {
                    return(-1);
                }
                JObject jobj_cur_data = null;
                JObject jobj_par_data = null;

                if (workName != null && index == null)
                {
                    jobj_cur_data = ((ConfigOptionManager.root as JObject)?.GetValue("work_group") as JObject)?.GetValue(workName) as JObject;
                    jobj_par_data = ConfigOptionManager.root.DeepClone() as JObject;
                }
                else if (workName != null && index != null)
                {
                    jobj_cur_data = ((((ConfigOptionManager.root as JObject)?.GetValue("work_group") as JObject)?.GetValue(workName) as JObject)?.GetValue("processes") as JArray)?[int.Parse(index)] as JObject;
                    jobj_par_data = ConfigOptionManager.root.DeepClone() as JObject;
                    JObject jobj_work = ((ConfigOptionManager.root as JObject)?.GetValue("work_group") as JObject)?.GetValue(workName) as JObject;
                    foreach (var v in jobj_work.Properties())
                    {
                        if (v.Value as JArray == null)
                        {
                            JObject jobj_cur = jobj_par_data.GetValue(v.Name) as JObject;
                            if (jobj_cur == null)
                            {
                                continue;
                            }
                            foreach (var prop in (v.Value as JObject)?.Properties())
                            {
                                jobj_cur[prop.Name] = prop.Value;
                            }
                        }
                        else
                        {
                            JArray jarr_cur = jobj_par_data.GetValue(v.Name) as JArray;
                            if (jarr_cur == null)
                            {
                                jobj_par_data.Add(v.Name, new JArray());
                                int i = 0;
                                foreach (var jobj in (v.Value as JArray))
                                {
                                    (jobj_par_data[v.Name] as JArray)?.Add(new JObject());
                                    foreach (var prop in (jobj as JObject)?.Properties())
                                    {
                                        (jobj_par_data[v.Name]?[i] as JObject)?.Add(prop.Name, prop.Value);
                                    }
                                    i++;
                                }
                                continue;
                            }
                            int idx = 0;
                            foreach (var jobj in (v.Value as JArray))
                            {
                                foreach (var prop in (jobj as JObject)?.Properties())
                                {
                                    jarr_cur[idx][prop.Name] = prop.Value;
                                }
                                idx++;
                            }
                        }
                    }
                }
                else if (workName == null && index == null)
                {
                    jobj_cur_data = ConfigOptionManager.root as JObject;
                }

                if (jobj_cur_data == null)
                {
                    return(-1);
                }

                foreach (var jprop_section in (curRoot as JObject)?.Properties())
                {
                    int idx_keyword;
                    for (idx_keyword = 0; idx_keyword < arrJsonKeyword.Length; idx_keyword++)
                    {
                        if (arrJsonKeyword[idx_keyword] == jprop_section.Name)
                        {
                            break;
                        }
                    }
                    if (idx_keyword == arrJsonKeyword.Length)
                    {
                        continue;
                    }

                    if (jprop_section.Value as JArray == null)
                    {
                        foreach (var jprop_changed in (jprop_section.Value as JObject)?.Properties())
                        {
                            if (jobj_par_data != null &&
                                (jobj_par_data[jprop_section.Name]?[jprop_changed.Name] as JValue)?.Value != null &&
                                (jobj_par_data[jprop_section.Name]?[jprop_changed.Name] as JValue)?.Value.Equals((jprop_changed.Value as JValue)?.Value) == true)
                            {
                                jobj_cur_data[jprop_section.Name]?[jprop_changed.Name]?.Parent.Remove();
                                if (jprop_changed.Name[0] == ConfigOptionManager.StartDisableProperty)
                                {
                                    jobj_cur_data[jprop_section.Name]?[jprop_changed.Name.Substring(1)]?.Parent?.Remove();
                                }
                                else
                                {
                                    jobj_cur_data[jprop_section.Name]?[ConfigOptionManager.StartDisableProperty + jprop_changed.Name]?.Parent?.Remove();
                                }

                                if (jobj_cur_data[jprop_section.Name]?.LongCount() == 0)
                                {
                                    jobj_cur_data[jprop_section.Name]?.Parent.Remove();
                                }
                            }
                            else if (jobj_cur_data[jprop_section.Name] == null)
                            {
                                if (jobj_cur_data["processes"] != null)
                                {
                                    jobj_cur_data["processes"]?.Parent?.AddBeforeSelf(new JProperty(jprop_section.Name, new JObject()));
                                }
                                else
                                {
                                    (jobj_cur_data as JObject)?.Add(jprop_section.Name, new JObject());
                                }
                                (jobj_cur_data[jprop_section.Name] as JObject)?.Add(jprop_changed.Name, jprop_changed.Value);
                            }
                            else if (jobj_cur_data[jprop_section.Name][jprop_changed.Name] == null)
                            {
                                (jobj_cur_data[jprop_section.Name] as JObject)?.Add(jprop_changed.Name, jprop_changed.Value);
                                if (jprop_changed.Name[0] == ConfigOptionManager.StartDisableProperty)
                                {
                                    jobj_cur_data[jprop_section.Name][jprop_changed.Name.Substring(1)]?.Parent?.Remove();
                                }
                                else
                                {
                                    jobj_cur_data[jprop_section.Name][ConfigOptionManager.StartDisableProperty + jprop_changed.Name]?.Parent?.Remove();
                                }
                            }
                            else
                            {
                                jobj_cur_data[jprop_section.Name][jprop_changed.Name] = jprop_changed.Value;
                            }
                        }
                    }
                    else
                    {
                        int idx = 0;
                        foreach (var jarr_changed in jprop_section.Value as JArray)
                        {
                            foreach (var jprop_changed in (jarr_changed as JObject)?.Properties())
                            {
                                if (jobj_par_data != null &&
                                    (jobj_par_data[jprop_section.Name]?[idx]?[jprop_changed.Name] as JValue)?.Value != null &&
                                    (jobj_par_data[jprop_section.Name]?[idx]?[jprop_changed.Name] as JValue)?.Value.Equals((jprop_changed.Value as JValue)?.Value) == true)
                                {
                                    jobj_cur_data[jprop_section.Name]?[idx]?[jprop_changed.Name]?.Parent.Remove();
                                    if (jprop_changed.Name[0] == ConfigOptionManager.StartDisableProperty)
                                    {
                                        jobj_cur_data[jprop_section.Name]?[idx]?[jprop_changed.Name.Substring(1)]?.Parent?.Remove();
                                    }
                                    else
                                    {
                                        jobj_cur_data[jprop_section.Name]?[idx]?[ConfigOptionManager.StartDisableProperty + jprop_changed.Name]?.Parent?.Remove();
                                    }
                                    int i;
                                    if (jobj_cur_data[jprop_section.Name]?.LongCount() != null)
                                    {
                                        for (i = 0; i < jobj_cur_data[jprop_section.Name].LongCount(); i++)
                                        {
                                            if (jobj_cur_data[jprop_section.Name]?[idx]?.LongCount() > 0)
                                            {
                                                break;
                                            }
                                        }
                                        if (jobj_cur_data[jprop_section.Name].LongCount() == i)
                                        {
                                            jobj_cur_data[jprop_section.Name]?.Parent.Remove();
                                        }
                                    }
                                }
                                else if (jobj_cur_data[jprop_section.Name] == null)
                                {
                                    if (jobj_cur_data["processes"] != null)
                                    {
                                        jobj_cur_data["processes"]?.Parent?.AddBeforeSelf(new JProperty(jprop_section.Name, new JArray()));
                                    }
                                    else
                                    {
                                        (jobj_cur_data as JObject)?.Add(jprop_section.Name, new JArray());
                                    }
                                    while ((jobj_cur_data[jprop_section.Name] as JArray)?.Count < idx + 1)
                                    {
                                        (jobj_cur_data[jprop_section.Name] as JArray)?.Add(new JObject());
                                    }
                                    (jobj_cur_data[jprop_section.Name]?[idx] as JObject)?.Add(jprop_changed.Name, jprop_changed.Value);
                                }
                                else if ((jobj_cur_data[jprop_section.Name] as JArray)?.Count < idx + 1)
                                {
                                    while ((jobj_cur_data[jprop_section.Name] as JArray)?.Count < idx + 1)
                                    {
                                        (jobj_cur_data[jprop_section.Name] as JArray)?.Add(new JObject());
                                    }
                                    (jobj_cur_data[jprop_section.Name]?[idx] as JObject)?.Add(jprop_changed.Name, jprop_changed.Value);
                                }
                                else if (jobj_cur_data[jprop_section.Name][idx][jprop_changed.Name] == null)
                                {
                                    (jobj_cur_data[jprop_section.Name]?[idx] as JObject)?.Add(jprop_changed.Name, jprop_changed.Value);
                                    if (jprop_changed.Name[0] == ConfigOptionManager.StartDisableProperty)
                                    {
                                        jobj_cur_data[jprop_section.Name][idx][jprop_changed.Name.Substring(1)]?.Parent?.Remove();
                                    }
                                    else
                                    {
                                        jobj_cur_data[jprop_section.Name][idx][ConfigOptionManager.StartDisableProperty + jprop_changed.Name]?.Parent?.Remove();
                                    }
                                }
                                else
                                {
                                    jobj_cur_data[jprop_section.Name][idx][jprop_changed.Name] = jprop_changed.Value;
                                }
                            }
                            idx++;
                        }
                    }
                }
                //WindowMain.current?.enableConnect?.sshManager?.UploadString(Root.ToString(), WindowMain.current.enableConnect.sshManager.EnvCoHome + "/var/conf/" + WindowMain.current.enableConnect.sshManager.id + "/" + Root["type"].ToString() + ".json");
                if (WindowMain.current?.EnableConnect?.Name == null ||
                    WindowMain.current?.EnableConnect?.Id == null)
                {
                    return(-1);
                }

                string local_dir = MainSettings.Path.PathDirConfigFile + WindowMain.current.EnableConnect.Name + "\\" + WindowMain.current.EnableConnect.Id;

                FileContoller.Write(local_dir + "\\" + ConfigOptionManager.root["type"].ToString() + ".json", ConfigOptionManager.root.ToString());
                if (WindowMain.current?.EnableConnect?.SshManager?.SetConfig(local_dir) != 0)
                {
                    return(-5);
                }
            }
            else
            {
                if (root == null ||
                    root["type"] == null ||
                    WindowMain.current?.EnableConnect?.Id == null ||
                    WindowMain.current?.EnableConnect?.SshManager?.EnvCoHome == null)
                {
                    return(-2);
                }

                //WindowMain.current?.enableConnect?.sshManager?.UploadString(root.ToString(), WindowMain.current.enableConnect.sshManager.EnvCoHome + "/var/conf/" + WindowMain.current.enableConnect.sshManager.id + "/" + root["type"].ToString() + ".json");
                if (WindowMain.current?.EnableConnect?.Name == null ||
                    WindowMain.current?.EnableConnect?.Id == null)
                {
                    return(-1);
                }

                string local_dir = MainSettings.Path.PathDirConfigFile + WindowMain.current.EnableConnect.Name + "\\" + WindowMain.current.EnableConnect.Id;

                FileContoller.Write(local_dir + "\\" + root["type"].ToString() + ".json", root.ToString());
                if (WindowMain.current?.EnableConnect?.SshManager?.SetConfig(local_dir) != 0)
                {
                    return(-5);
                }
            }
            return(0);
        }