public long task_file_to_folder(int synch_id, int task_id, string title, string file_path, int file_id, long?parent_folder_id, DateTime c_time, out string new_folder_path, string notes = "") { fire_synch_event($"trasformazione task file in task folder: {file_path}"); file_type ftp = is_type_file(Path.GetExtension(file_path)); bool ifile = ftp.type_content == file_type.ft_type_content.info; // creo una cartella con questo nome di task e aggiungo le note string parent = Path.GetDirectoryName(file_path) , name_folder = Path.GetFileNameWithoutExtension(file_path); new_folder_path = Path.Combine(parent, name_folder); int sfid = synch_id; long?pfid = parent_folder_id; DirectoryInfo di = Directory.CreateDirectory(new_folder_path); DateTime ct = sys.without_ms(di.CreationTime), lwt = sys.without_ms(di.LastWriteTime); string tp; int cc; long folder_id = set_folder_db(sfid, pfid, name_folder, ct, lwt, out tp, out cc); fire_synch_event("creato folder: " + new_folder_path); // sposto il task file string name_file = (ifile ? "i" : "content"), ext = Path.GetExtension(file_path); if (File.Exists(Path.Combine(new_folder_path, name_file + ext))) { File.Delete(Path.Combine(new_folder_path, name_file + ext)); } File.Move(file_path, Path.Combine(new_folder_path, name_file + ext)); db_conn.exec(core.parse_query("lib-notes.move-file", new string[, ] { { "synch_folder_id", synch_id.ToString() } , { "name_file", name_file + ext }, { "folder_id", folder_id.ToString() }, { "file_id", file_id.ToString() } })); set_folder_task(task_id, (int)folder_id); fire_synch_event("spostato file da: " + file_path + ", a:" + Path.Combine(new_folder_path, name_file + ext)); if (ifile) { init_task_notes_db(task_id, file_id, notes.Trim(new char[] { ' ', '\n', '\r' }), false); fire_synch_event("salvate le note del task: " + new_folder_path); } // setto le note if (notes != "" && !ifile) { string fp = Path.Combine(new_folder_path, "i.txt"); File.WriteAllText(fp, notes, System.Text.Encoding.UTF8); FileInfo fi = new FileInfo(fp); ct = sys.without_ms(fi.CreationTime); lwt = sys.without_ms(fi.LastWriteTime); long nid = set_file_db(sfid, folder_id, "i.txt", ".txt", ct, lwt, out tp, out cc); set_file_content_db((int)nid, ".txt", notes.Trim(new char[] { ' ', '\n', '\r' }), c_time, c_time); init_task_notes_db(task_id, (int)nid, notes.Trim(new char[] { ' ', '\n', '\r' }), false); fire_synch_event("salvate le note nel file: " + Path.Combine(new_folder_path, "i.txt")); } return(folder_id); }
protected synch_results init_synch_folder(int synch_folder_id, string path , long?parent_id = null, task parent_task = null, synch_results res = null, bool check = false) { if (res == null) { res = new synch_results(); } try { // folders foreach (string fp in Directory.EnumerateDirectories(path)) { DirectoryInfo di = new DirectoryInfo(fp); DateTime ct = sys.without_ms(di.CreationTime), lwt = sys.without_ms(di.LastWriteTime); string folder_name = di.Name; long folder_id = 0; task t = null; if (!check) { // folder string tp; int cc = 0; folder_id = set_folder_db(synch_folder_id, parent_id, folder_name, ct, lwt, out tp, out cc); if (tp == "insert") { fire_synch_event("aggiunto folder al database: " + fp); } else if (tp == "update" && cc > 0) { fire_synch_event("aggiornato folder nel database: " + fp); } // task folder if (parent_task == null) { t = elab_task_folder(res, synch_folder_id, fp, ct, lwt, folder_id); if (t != null) { di = new DirectoryInfo(t.path); folder_name = di.Name; } } } res.folders++; if (parent_task != null) { parent_task.level_folder++; } res = init_synch_folder(synch_folder_id, Path.Combine(path, folder_name), folder_id, t != null ? t : parent_task, res, check); } // files string i_task = core.config.get_var("lib-vars.index-folder").value; foreach (string fn in Directory.EnumerateFiles(path)) { FileInfo fi = new FileInfo(fn); DateTime ct = sys.without_ms(fi.CreationTime), lwt = sys.without_ms(fi.LastWriteTime); if (lwt > res.lwt) { res.lwt = lwt; } // web.config if (fi.Name.ToLower() == "web.config" && !parent_id.HasValue) { continue; } // __i.xml if (parent_task != null && fi.Name == i_task) { continue; } if (!check) { // file long file_id = set_file_db(synch_folder_id, parent_id, fi.Name, fi.Extension, ct, lwt, out string tp, out int cc); if (tp == "insert") { fire_synch_event("aggiunto file al database: " + fn); } else if (tp == "update" && cc > 0) { fire_synch_event("aggiornato file nel database: " + fn); } // file content string new_content = ""; file_info info = is_info_file(fi.Name); file_type ftp = is_type_file(fi.Extension); if (info != null || ftp != null) { if (tp == "insert" || (tp == "update" && cc > 0)) { new_content = File.ReadAllText(fn); if (new_content.Replace(" ", "").Replace("\r", "").Replace("\n", "") != "") { set_file_content_db((int)file_id, Path.GetExtension(fn).ToLower(), new_content, ct, lwt); fire_synch_event("salvato contenuto file nel database: " + fn); if (parent_task != null && info != null) { if (set_task_notes_db(parent_task.id, file_id, new_content, file_type.ft_type_content.info, ct, lwt)) { fire_synch_event($"salvate le note del task nel database: {fn}"); } } } } } // task file if (parent_task == null) { task t = task.parse_task(core, synch_folder_id, fn, ct, lwt, _users, _labels, file_id: file_id); if (t != null) { long task_id = set_task_db(t, out tp, out cc); if (tp == "insert") { fire_synch_event("inserito task nel database: " + Path.Combine(path, t.title)); } else if (tp == "update" && cc > 0) { fire_synch_event("aggiornato il task nel database: " + Path.Combine(path, t.title)); } // task notes string notes = ""; if (ftp != null && (tp == "insert" || (tp == "update" && cc > 0))) { if (set_task_notes_db(task_id, file_id, new_content, ftp.type_content, ct, lwt, out notes)) { fire_synch_event($"salvate le note del task nel database: {fn}"); } } // file -> folder long folder_id = task_file_to_folder(synch_folder_id, (int)task_id, t.title, fn, (int)file_id, parent_id, ct, out string new_folder_path, notes); // reparse folder task elab_task_folder(res, synch_folder_id, new_folder_path, ct, lwt, folder_id); } } } res.files++; } // task folder - dt_upd if (parent_task != null && !check) { string cc = db_conn.exec(core.parse_query("lib-notes.upd-task-date", new string[, ] { { "task_id", parent_task.id.ToString() } })); if (cc != "0") { fire_synch_event("aggiornato task date nel database: " + Path.Combine(Path.GetDirectoryName(path), parent_task.title)); } } } catch (Exception ex) { log.log_err(ex.Message); res.err = ex.Message; } return(res); }