private void frm_main_Load(object sender, EventArgs e) { try { tmr_state.Interval = _interval_ss * 1000; db_provider conn = Program.open_conn(); client_opened(conn, true); _settings = settings.read_settings(_c, conn); this.WindowState = FormWindowState.Minimized; this.ShowInTaskbar = false; // log this._cache_log = new RichTextBox(); this._cache_log.BackColor = Color.Black; this._cache_log.BorderStyle = BorderStyle.None; this._cache_log.Font = new Font("Courier New", 9.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); this._cache_log.ForeColor = Color.FromArgb(((int)(((byte)(255)))), ((int)(((byte)(255)))), ((int)(((byte)(192))))); // tray ntf_main.ContextMenuStrip = new System.Windows.Forms.ContextMenuStrip(); ntf_main.ContextMenuStrip.Items.Add("Apri...", null, this.MenuApri_Click); ntf_main.ContextMenuStrip.Items.Add("Pannello...", null, this.MenuPannello_Click); ntf_main.ContextMenuStrip.Items.Add("Esci", null, this.MenuExit_Click); ntf_main.ContextMenuStrip.BackColor = Color.Gray; ntf_main.ContextMenuStrip.ForeColor = Color.White; ntf_main.ContextMenuStrip.Font = new Font("segoe ui light", 9, FontStyle.Regular); } catch (Exception ex) { log_err(ex.Message); } }
protected void client_opened(db_provider conn = null, bool first = false) { try { bool close = false; if (conn == null) { conn = Program.open_conn(); close = true; } if (_client_key == "") { _client_key = strings.random_hex(20); } conn.exec(_c.parse_query("lib-base.client-refresh", new string[, ] { { "client_key", _client_key }, { "ip_machine", sys.machine_ip() } , { "first", first ? "1" : "0" }, { "machine_name", sys.machine_name() }, { "interval_ss", _interval_ss.ToString() } })); if (first) { log_txt($"connected client key '{_client_key}'", Color.Azure); } if (close) { conn.close_conn(); conn = null; } } catch { } }
public static settings read_settings(core c, db_provider conn) { return(new settings(conn.dt_table(c.config.get_query("lib-base.get-settings").text) .Rows.Cast <DataRow>().Select(r => new setting((int)r["setting_id"] , (string)r["setting_name"], db_provider.str_val(r["setting_var"]) , db_provider.str_val(r["machine_name"]))).ToList())); }
public static setting get_setting(core c, db_provider conn, string setting_name) { DataRow r = conn.first_row(c.parse_query("lib-base.get-setting", new string[, ] { { "setting-name", setting_name } })); return(r == null ? null : new setting((int)r["setting_id"], (string)r["setting_name"] , db_provider.str_val(r["setting_var"]), db_provider.str_val(r["machine_name"]))); }
public void load_config(xml_doc doc, string doc_key, db_provider conn, Dictionary <string, object> keys = null, string vars_key = "", bool page = false) { try { if (!_cfg_keys.Keys.Contains(doc_key)) { _cfg_keys.Add(doc_key, "doc_path"); } _config.load_doc(doc_key, vars_key, doc, conn, keys, page); } catch (Exception ex) { _cfg_keys.Clear(); throw new Exception("caricamento documento '" + doc.path + "': " + ex.Message); } }
public static DataTable dt_query(string name, string[,] fields = null) { db_provider conn = null; try { conn = Program.open_conn(); return(conn.dt_table(_c.parse_query(name, fields))); } catch { return(null); } finally { if (conn != null) { conn.close_conn(); } } }
public bool close_conn() { bool res = false; try { db_provider db = db_conn; if (db.is_opened()) { db.close_conn(); res = true; } _db_connected = false; } catch (Exception ex) { log.log_err(ex); _db_connected = false; } return(res); }
public bool db_reconn(bool throw_err = false) { try { db_provider db = db_conn; if (db.is_opened()) { db.close_conn(); } _db_connected = db.open_conn(); } catch (Exception ex) { log.log_err(ex); _db_connected = false; if (throw_err) { throw ex; } } return(_db_connected); }
private void tmr_cmds_Tick(object sender, EventArgs e) { if (_cmd) { return; } _cmd = true; db_provider conn = null; try { conn = Program.open_conn(); DataRow r = conn.first_row(_c.parse_query("lib-base.client-cmd-to-elab", new string[, ] { { "client_key", _client_key } })); if (r != null) { int id_cmd = db_provider.int_val(r["id_client_cmd"]); string cmd = db_provider.str_val(r["cmd"]); log_txt($"elab command '{cmd}'"); conn.exec(_c.parse_query("lib-base.client-remove-cmd", new string[, ] { { "id_cmd", id_cmd.ToString() } })); client_cmd cc = new client_cmd(cmd); if (cc.function == "open_att") { open_att(cc.par_int("file_id"), cc.par_int("user_id"), cc.par("user_name")); } } } catch (Exception ex) { log_err(ex.Message); } finally { if (conn != null) { conn.close_conn(); } } _cmd = false; }
public bool canLogin(string user, string pwd, out int id, out string type, out string conn, out string type_des, out int n_users) { id = -1; n_users = 0; type_des = type = conn = ""; db_provider db = cfg_exist("/root/login[@conn]") ? conn_db(cfg_value("/root/login", "conn")) : conn_db_base(); if (!isRcvUser(user, pwd)) { Dictionary <string, string> fields = new Dictionary <string, string>(); string[] inFields = cfg_value("/root/login/infields").Split(','); fields.Add(inFields[0], user); fields.Add(inFields[1], pwd); System.Data.DataTable dt = classPage.dt_from_id(cfg_value("/root/login", "selid"), "", "", fields); if (dt == null || dt.Rows.Count <= 0) { return(false); } string[] outFields = cfg_value("/root/login/outfields").Split(','); id = int.Parse(dt.Rows[0][outFields[0]].ToString()); type = dt.Rows[0][outFields[1]].ToString(); type_des = dt.Rows[0][outFields[2]].ToString(); conn = dt.Rows[0][outFields[3]].ToString(); string users = ""; try { users = classPage.user_ids(id, true); } catch { } n_users = users.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries).Length; } else { id = -1; type = "admin"; type_des = "recovery user"; conn = ""; } return(true); }
public void load_page_config(xml_doc doc, string doc_key, db_provider conn, Dictionary <string, object> keys) { load_config(doc, doc_key, conn, keys, page: true); }
public void load_doc(string doc_key, string vars_key, xml_doc doc, db_provider conn, Dictionary <string, object> keys = null, bool for_pg = false) { string var_key = !string.IsNullOrEmpty(vars_key) ? vars_key + "." : ""; // sql-select if (doc.exists("//sql-select")) { foreach (xml_node s in doc.nodes("//sql-select")) { xml_node ref_node = s; foreach (DataRow r in conn.dt_table(_core.parse(s.get_attr("qry"), keys)).Rows) { foreach (xml_node n in _core.parse_nodes(s.clone_childs(s), keys, r)) { ref_node = ref_node.add_after(n); } } } while (true) { xml_node s = doc.node("//sql-select"); if (!s.remove()) { break; } } } // aggiungo string nkey = ""; try { foreach (xml_node var in doc.nodes("/config//folders/folder")) { nkey = var_key + var.get_attr("name"); _folders.Add(nkey, new folder(doc_key, nkey, _core.parse(var.get_val()), for_pg)); } } catch (Exception ex) { throw new Exception("chiave folders.'" + nkey + "' - " + ex.Message); } nkey = ""; try { foreach (xml_node tbl in doc.nodes("/config//tables/table")) { nkey = var_key + tbl.get_attr("name"); _tables.Add(nkey, new table(doc_key, nkey, tbl, for_pg)); } } catch (Exception ex) { throw new Exception("chiave tables.'" + nkey + "' - " + ex.Message); } nkey = ""; try { foreach (xml_node tbl in doc.nodes("/config/html-blocks/html-block")) { nkey = var_key + tbl.get_attr("name"); html_block b = new html_block(doc_key, nkey, tbl.text, for_pg); foreach (xml_node f in tbl.nodes("cond")) { b.add_cond(f.get_attr("name"), f.text); } _html_blocks.Add(nkey, b); } } catch (Exception ex) { throw new Exception("chiave html-blocks.'" + nkey + "' - " + ex.Message); } nkey = ""; try { foreach (xml_node qry in doc.nodes("/config//queries/*")) { if (qry.name == "query") { nkey = var_key + qry.get_attr("name"); query q = new query(doc_key, nkey, qry.text, qry.get_attr("des"), for_pg); foreach (xml_node f in qry.nodes("cond")) { q.add_cond(f.get_attr("name"), f.text); } _queries.Add(nkey, q); } else if (qry.name == "query_do") { nkey = var_key + qry.get_attr("name"); _queries.Add(nkey, new query(doc_key, nkey, qry.get_attr("des"), for_pg) { tp = query.tp_query.do_while, text_do = qry.sub_node("do").text, text_while = qry.sub_node("while").text }); } else if (qry.name == "queries") { nkey = var_key + qry.get_attr("name"); query q = new query(doc_key, nkey, qry.get_attr("des"), for_pg); _queries.Add(nkey, q); foreach (xml_node q2 in qry.nodes("*")) { if (q2.name == "query") { q.add_query(q2.text); } else if (q2.name == "exec_query") { foreach (string q3 in _queries[q2.get_attr("name")].queries) { q.add_query(q3); } } } } } } catch (Exception ex) { throw new Exception("chiave queries.'" + nkey + "' - " + ex.Message); } }
static void Main() { db_provider conn = null; try { // init _c = new core(AppDomain.CurrentDomain.BaseDirectory); // configs // docs Dictionary <string, xml_doc> docs = new Dictionary <string, xml_doc>(); Directory.EnumerateFiles(_c.app_setting("settings-folder")).ToList().ForEach(f => { string doc_key = strings.rel_path(_c.base_path, f), vars_key = Path.GetFileNameWithoutExtension(f).ToLower(); log.log_info("load xml config doc: " + doc_key + " - " + f); docs.Add(string.Format("{0};{1};{2}", doc_key, vars_key, f), new xml_doc(f)); }); // vars foreach (KeyValuePair <string, xml_doc> d in docs) { string[] keys = d.Key.Split(new char[] { ';' }); string doc_key = keys[0], vars_key = keys[1], f = keys[2]; log.log_info("load vars doc: " + doc_key + " - " + f); _c.load_base_config(d.Value, doc_key, vars_key); } // conn conn = open_conn(); // docs foreach (KeyValuePair <string, xml_doc> d in docs) { string[] keys = d.Key.Split(new char[] { ';' }); string doc_key = keys[0], vars_key = keys[1], f = keys[2]; log.log_info("load config doc: " + doc_key + " - " + f); _c.load_config(d.Value, doc_key, conn, vars_key: vars_key); } // opened client conn.close_conn(); conn = null; // data providers //string l = ""; //foreach (DataRow dr in DbProviderFactories.GetFactoryClasses().Rows) // l += "\n - " + string.Join(", ", dr.Table.Columns.Cast<DataColumn>().Select( // col => dr[col.ColumnName] != DBNull.Value ? col.ColumnName + ": " + dr[col.ColumnName].ToString() : "")); // test //try { // string cmd = @"C:\_todd\git\dn\dn_client\bin\Debug\att\1340_queries.sql.sql"; // Process.Start(new System.Diagnostics.ProcessStartInfo("cmd", "/c \"" + cmd + "\"") { // RedirectStandardOutput = true, UseShellExecute = false, CreateNoWindow = true // }); // Process.Start(new System.Diagnostics.ProcessStartInfo("explorer", "\"" + cmd + "\"") { // RedirectStandardOutput = true, UseShellExecute = false, CreateNoWindow = true // }); // return; //} catch (Exception ex) { MessageBox.Show(ex.Message); } Application.SetCompatibleTextRenderingDefault(false); Application.Run(new frm_main(_c)); } catch (Exception ex) { MessageBox.Show(ex.Message, "Attenzione!", MessageBoxButtons.OK, MessageBoxIcon.Error); if (conn != null) { conn.close_conn(); } } }
protected void res_backup(object sender, EventArgs e) { bool del_tmp = false, del_folder = false; string tmp_file = "", tmp_folder = ""; try { cmd c = master.check_cmd(qry_val("cmd")); string fn = c.sub_obj(); if (res_val_type.Value == "") { throw new Exception("il backup automatico non è stato configurato correttamente!"); } // fs if (res_val_type.Value == "fs") { // sposto il file nella cartella di destinazione remota tmp_file = Path.Combine(_core.config.get_var("vars.tmp-folder").value, fn); if (res_val_net_user.Value != "") { using (unc_access unc = new unc_access()) { if (unc.NetUseWithCredentials(res_val_net_folder.Value, res_val_net_user.Value, "", res_val_net_pwd.Value)) { string src_file = Path.Combine(res_val_net_folder.Value, fn); if (File.Exists(tmp_file)) { File.Delete(tmp_file); } File.Copy(src_file, tmp_file); del_tmp = true; unc.NetUseDelete(); } else { throw new Exception(unc.DesLastError); } } } // sposto il file nella cartella di destinazione locale else { string src_file = Path.Combine(val_net_folder.Value, fn); if (File.Exists(tmp_file)) { File.Delete(tmp_file); } File.Copy(src_file, tmp_file); del_tmp = true; } // restore del database tmp_folder = Path.Combine(_core.config.get_var("vars.tmp-folder").value, Path.GetRandomFileName()); using (ZipFile zf = new ZipFile(tmp_file)) { zf.ExtractSelectedEntries("*.*", "__backup", tmp_folder); del_folder = true; } string bak = Directory.EnumerateFiles(Path.Combine(tmp_folder, "__backup")).ElementAt(0); close_conn(); db_provider db = conn_to(_core.config.get_var("vars.bck.conn-restore").value); db.exec(res_sql_command.InnerText.Replace("##RESTORE-FILE##", bak)); db.close_conn(); } else { throw new Exception("il backup di tipo '" + res_val_type.Value + "' non è gestito!"); } master.status_txt("Ripristino effettuato con successo!"); } catch (Exception ex) { master.err_txt(ex.Message); } finally { try { if (del_tmp) { File.Delete(tmp_file); } if (del_folder) { (new DirectoryInfo(tmp_folder)).Delete(true); } } catch { } } }
public bo(db_provider conn, core c, config cfg, int user_id = 0, string user_name = "") { this.db_conn = conn; this.core = c; this.config = cfg; this.user_id = user_id; this.user_name = user_name; }
public synch(db_provider conn, core c, config cfg, int user_id = 0, string user_name = "") : base(conn, c, cfg, user_id, user_name) { }