public synch_results reload_folders(bool check = false, bool force = false) { reload_settings(); synch_results res = new synch_results(); try { // check cache synch_results rc = null; if (!check) { res.scan = true; // seconds if (!force) { string prev_last = get_cache_var("synch-last", -1); DateTime last = prev_last != "" ? DateTime.Parse(prev_last) : DateTime.MinValue; setting s = settings.get_setting(core, db_conn, "synch-seconds"); if (s != null && last != DateTime.MinValue && (DateTime.Now - last).TotalSeconds < int.Parse(s.value)) { res.scan = false; return(res); } } // files, folders, lwt int prev_files = int.Parse(get_cache_var("synch-files", -1, "-1")) , prev_folders = int.Parse(get_cache_var("synch-folders", -1, "-1")); string prev_lwt = get_cache_var("synch-lwt", -1); DateTime lwt = prev_lwt != "" ? DateTime.Parse(prev_lwt) : DateTime.MinValue; rc = reload_folders(true); if (!force && ((prev_files > 0 && prev_files == rc.files) && (prev_folders > 0 && prev_folders == rc.folders) && (lwt != DateTime.MinValue && lwt == rc.lwt))) { set_cache_var("synch-last", DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss"), -1); res.scan = false; return(res); } } DateTime start = DateTime.Now; if (!check) { fire_synch_event("elenco cartelle da sincronizzare", true); } // folders to synch this.synch_folders = list_synch_folders(Environment.MachineName); if (!check) { foreach (synch_folder f in this.synch_folders) { fire_synch_event(string.Format(" - cartella di sincronizzazione '{0}' - {1}, path: {2}" , f.title, f.des, f.local_path), true); } } // leggo le cartelle if (!check) { clean_readed(); } foreach (synch_folder f in this.synch_folders) { if (!check) { fire_synch_event($"elaboro la cartella {f.local_path}...", true); } res = init_synch_folder(f.id, f.local_path, res: res, check: check); } if (!check) { del_unreaded(out int cc_files, out int cc_folders); res.deleted = cc_files + cc_folders; if (res.deleted > 0) { if (cc_files > 0) { fire_synch_event($"cancellati dal database: {cc_files} files"); } if (cc_folders > 0) { fire_synch_event($"cancellati dal database: {cc_folders} folders"); } } } res.seconds = (int)(DateTime.Now - start).TotalSeconds; // check cache if (!check) { set_cache_var("synch-files", rc.files.ToString(), -1); set_cache_var("synch-folders", rc.folders.ToString(), -1); set_cache_var("synch-lwt", rc.lwt.ToString("yyyy/MM/dd HH:mm:ss"), -1); set_cache_var("synch-last", DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss"), -1); } } catch (Exception ex) { res.err = ex.Message; log.log_err(ex.Message); } finally { } return(res); }
public string get_value(string setting_name) { setting s = this.list.FirstOrDefault(x => x.name == setting_name && x.machine_name == sys.machine_name()); return(s != null ? s.value : this.list.FirstOrDefault(x => x.name == setting_name).value); }