public static doc_task open_index(core c, string folder_path) { doc_task res = null; string i_name = c.config.get_var("lib-vars.index-folder").value , fp = Path.Combine(folder_path, i_name); return(File.Exists(fp) ? new doc_task(fp) : null); }
public static doc_task create_index(core c, string folder_path) { doc_task res = new doc_task() { xml = "<root/>", created = true }; string i_name = c.config.get_var("lib-vars.index-folder").value , fp = Path.Combine(folder_path, i_name); res.save(fp); return(res); }
public task(int synch_folder_id, long?file_id, long?folder_id, string title, string user , string stato, string priorita, string tipo, string stima, DateTime?dt_ins, DateTime?dt_upd, DateTime?dt_lwt, doc_task doc) { this.synch_folder_id = synch_folder_id; this.file_id = file_id; this.folder_id = folder_id; this.title = title; this.user = user; this.dt_upd = dt_upd; this.dt_ins = dt_ins; this.dt_lwt = dt_lwt; this.stato = new task_stato(stato, 0, "", "", ""); this.priorita = new task_priorita(priorita, 0, "", "", ""); this.tipo = new task_tipo(tipo, 0, "", "", ""); this.stima = new task_stima(stima, 0, "", "", ""); this.doc = doc; }
static public task parse_task(core c, int synch_folder_id, string path, DateTime ct, DateTime lwt , List <string> users, List <free_label> labels, long?folder_id = null, long?file_id = null, bool set_index = false) { try { if (!folder_id.HasValue && !file_id.HasValue) { throw new Exception("il task dev'essere un file o un folder"); } string[] parts = Path.GetFileName(path).Split(new char[] { '.' }); if (parts.Length <= 1) { return(null); } // task if (folder_id.HasValue && parts[parts.Length - 1] != "task") { return(null); } else if (file_id.HasValue && parts[parts.Length - 1] != "task" && parts[parts.Length - 2] != "task") { return(null); } // leggo il doc. indice doc_task it = null; if (folder_id.HasValue && set_index) { it = doc_task.exists_index(c, path) ? doc_task.open_index(c, path) : doc_task.create_index(c, path); } // parse nome cartella string title = "", user = it != null ? it.user : "", stato = it != null ? it.stato : "", priorita = it != null ? it.priorita : "" , tipo = it != null ? it.tipo : "", stima = it != null ? it.stima : ""; DateTime?dt = null, dt2 = null; for (int i = 0; i < parts.Length; i++) { string p = parts[i]; if (p == "task") { break; } // date if (dn_lib.tools.strings.is_int(p) && (p.Length == 6 || p.Length == 8)) { if (!dt.HasValue) { parse_date(p, out dt); } else if (!dt2.HasValue) { parse_date(p, out dt2); } if (dt.HasValue && dt2.HasValue && dt2 < dt) { DateTime tmp = dt2.Value; dt = dt2; dt2 = tmp; } if (it != null && it.created && dt.HasValue) { it.dt_create = dt; } if (it != null && it.created && dt2.HasValue) { it.dt_upd = dt2; } continue; } // state free_label lbl = labels.FirstOrDefault(x => !string.IsNullOrEmpty(x.stato) && x.free_txt.ToLower() == p.ToLower()); if (lbl != null) { stato = lbl.stato; if (it != null) { it.stato = stato; } continue; } // priorita lbl = labels.FirstOrDefault(x => !string.IsNullOrEmpty(x.priorita) && x.free_txt.ToLower() == p.ToLower()); if (lbl != null) { priorita = lbl.priorita; if (it != null) { it.priorita = priorita; } continue; } // tipo lbl = labels.FirstOrDefault(x => !string.IsNullOrEmpty(x.tipo) && x.free_txt.ToLower() == p.ToLower()); if (lbl != null) { tipo = lbl.tipo; if (it != null) { it.tipo = tipo; } continue; } // stima lbl = labels.FirstOrDefault(x => !string.IsNullOrEmpty(x.stima) && x.free_txt.ToLower() == p.ToLower()); if (lbl != null) { stima = lbl.stima; if (it != null) { it.stima = stima; } continue; } // user if (user == "" && users.FirstOrDefault(x => x.ToLower() == p.ToLower()) != null) { user = p; if (it != null) { it.user = user; } continue; } // title if (title == "") { title = p; } } return(new task(synch_folder_id, file_id, folder_id, title, user, stato, priorita, tipo, stima , it != null ? it.dt_create : (dt.HasValue ? dt : ct), it != null ? it.dt_upd : (DateTime?)null, lwt, it) { path = path }); } catch (Exception ex) { log.log_err(ex); return(null); } }
public void save_task_notes(int task_id, string notes) { DataTable dt = db_conn.dt_table(core.parse_query("lib-notes.info-task-notes", new string[, ] { { "task_id", task_id.ToString() } })); if (dt.Rows.Count == 0) { throw new Exception("l'attività " + task_id.ToString() + " non è registrata correttamente!"); } DataRow dr = dt.Rows[0]; DateTime ct = sys.without_ms(DateTime.Now); // aggiornamento del file if (db_provider.str_val(dr["file_id_notes"]) != "") { int fid = db_provider.int_val(dr["file_id_notes"]); string file_path = db_provider.str_val(dr["file_path_notes"]) != "" ? db_provider.str_val(dr["file_path_notes"]) : db_provider.str_val(dr["file_path"]); System.Text.Encoding e = encoding_type.GetType(file_path); // file sorgente if (db_provider.str_val(dr["type_content"]) == "source") { string all = File.ReadAllText(file_path, e), oc = db_provider.str_val(dr["open_comment"]) , cc = db_provider.str_val(dr["close_comment"]), key_from = "###FROM_NOTES###", key_to = "###TO_NOTES###"; // cerco i commenti int from = all.IndexOf(key_from), to = all.IndexOf(key_to, from + 1); string src = ""; if (from >= 0 && to > 0) { src = all.Substring(0, from + key_from.Length) + "\r\n" + notes + "\r\n" + all.Substring(to); } else { src = oc + " " + key_from + "\r\n" + notes + "\r\n" + key_to + cc + "\n\n" + all; } File.WriteAllText(file_path, src, e); set_file_content_db(fid, Path.GetExtension(file_path).ToLower(), src, ct, ct); init_task_notes_db(task_id, fid, notes.Trim(new char[] { ' ', '\n', '\r' })); } // file info else { File.WriteAllText(file_path, notes, e); set_file_content_db(fid, Path.GetExtension(file_path).ToLower(), notes.Trim(new char[] { ' ', '\n', '\r' }), ct, ct); init_task_notes_db(task_id, fid, notes.Trim(new char[] { ' ', '\n', '\r' })); } } // nuovo commento else { // file if (db_provider.str_val(dr["file_id"]) != "") { int fid = db_provider.int_val(dr["file_id"]); string file_path = db_provider.str_val(dr["file_path"]); System.Text.Encoding e = encoding_type.GetType(file_path); // sorgente if (db_provider.str_val(dr["type_content"]) == "source") { string all = File.ReadAllText(file_path, e), oc = db_provider.str_val(dr["open_comment"]) , cc = db_provider.str_val(dr["close_comment"]), key_from = "###FROM_NOTES###", key_to = "###TO_NOTES###"; string src = oc + " " + key_from + "\r\n" + notes + "\r\n" + key_to + cc + "\n\n" + all; File.WriteAllText(file_path, src, e); set_file_content_db(fid, Path.GetExtension(file_path).ToLower(), src, ct, ct); init_task_notes_db(task_id, fid, notes.Trim(new char[] { ' ', '\n', '\r' })); } else { // task file -> folder string title = db_provider.str_val(dr["title"]), parent = Path.GetDirectoryName(file_path) , name_folder = Path.GetFileNameWithoutExtension(file_path), new_folder = Path.Combine(parent, name_folder); int sfid = db_provider.int_val(dr["synch_folder_id"]); long?pfid = db_provider.long_val_null(dr["parent_folder_id"]); task_file_to_folder(sfid, task_id, title, file_path, fid, pfid, ct, notes); } } // cartella else { string fp = db_provider.str_val(dr["folder_path"]) + "i.txt"; File.WriteAllText(fp, notes, System.Text.Encoding.UTF8); FileInfo fi = new FileInfo(fp); ct = sys.without_ms(fi.CreationTime); DateTime lwt = sys.without_ms(fi.LastWriteTime); long fid = set_file_db(db_provider.int_val(dr["synch_folder_id"]), db_provider.int_val(dr["folder_id"]), "i.txt", ".txt", ct, lwt, out string tp, out int cc); set_file_content_db((int)fid, ".txt", notes.Trim(new char[] { ' ', '\n', '\r' }), ct, ct); init_task_notes_db(task_id, (int)fid, notes.Trim(new char[] { ' ', '\n', '\r' })); } } // leggo il doc. indice if (doc_task.exists_index(core, db_provider.str_val(dr["folder_path"]))) { doc_task it = doc_task.open_index(core, db_provider.str_val(dr["folder_path"])); it.dt_upd = ct; it.save_into_folder(core, db_provider.str_val(dr["folder_path"])); // aggiorno l'indice db_conn.exec(core.parse_query("lib-notes.set-task-upd" , new string[, ] { { "i_lwt", it.lwt.ToString("yyyy-MM-dd HH:mm:ss") }, { "dt_upd", ct.ToString("yyyy-MM-dd HH:mm:ss") }, { "task_id", task_id.ToString() } })); } }