Ejemplo n.º 1
0
        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 { }
        }
Ejemplo n.º 2
0
        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();
                                                }
            }
        }
Ejemplo n.º 3
0
    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);
    }
Ejemplo n.º 4
0
 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);
 }
Ejemplo n.º 5
0
        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;
        }
Ejemplo n.º 6
0
        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();
                }
            }
        }
Ejemplo n.º 7
0
    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 { }
        }
    }