public void open_att(int file_id, int user_id, string user_name) { Task.Factory.StartNew(() => { // download file... string fp = ""; try { string folder = Program._c.config.get_var("client.client-tmp-path").value; if (!Directory.Exists(folder)) { Directory.CreateDirectory(folder); } fi i = fi.load_fi(file_id); lbl_message(log.log_info($"download file {i.http_path}")); fp = Path.Combine(folder, i.file_name_local); using (WebClient webClient = new WebClient()) { webClient.DownloadFile(i.http_path, fp); } xml_att idoc = xml_att.open(); idoc.set_file(i, DateTime.Now, user_id, user_name); idoc.save(); lbl_message(log.log_info($"downloaded file {i.http_path}")); } catch (Exception ex) { log.log_err(ex); lbl_message($"download file error: {ex.Message}"); } // apri il file try { lbl_message(log.log_info($"open file {fp}")); System.Diagnostics.Process.Start(new System.Diagnostics.ProcessStartInfo("explorer", "\"" + fp + "\"") { RedirectStandardOutput = true, UseShellExecute = false, CreateNoWindow = true }); lbl_message(); } catch (Exception ex) { log.log_err(ex); lbl_message($"open file error: {ex.Message}"); } }); }
protected void check_upload_att() { string folder = Program._c.config.get_var("client.client-tmp-path").value , iname = Program._c.config.get_var("client.index-att").value; if (!Directory.Exists(folder)) { Directory.CreateDirectory(folder); } xml_att idoc = xml_att.open(); // enum files & check to upload bool savei = false; foreach (FileInfo i in Directory.EnumerateFiles(folder).Select(x => new FileInfo(x))) { if (i.Name.ToLower() == iname) { continue; } try { string fn = i.Name.ToLower(); int id_file = int.Parse(fn.Split(new char[] { '_' })[0]); // add file if (!idoc.exists_file(id_file, out xml_node n)) { n = idoc.add_file(fi.load_fi(id_file), i.LastWriteTime, n.get_int("user_id"), n.get_val("user_name")); savei = true; continue; } // check upload DateTime lwt = DateTime.Parse(n.get_attr("lwt")); if (lwt.ToString("yyyy-MM-dd HH:mm:ss") != i.LastWriteTime.ToString("yyyy-MM-dd HH:mm:ss")) { savei = true; upload_file(i.FullName, id_file, n); n.set_attr("lwt", i.LastWriteTime.ToString("yyyy-MM-dd HH:mm:ss")); continue; } // check delete if ((DateTime.Now - lwt).TotalHours > 12) { n.remove(); i.Delete(); savei = true; continue; } } catch (Exception ex) { log.log_err(ex); } } // del file foreach (fi f in idoc.files()) { if (!File.Exists(Path.Combine(folder, f.file_name_local))) { idoc.del_file(f.id_file); savei = true; } } if (savei) { idoc.save(); } }