Пример #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 { }
        }
Пример #2
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;
        }
Пример #3
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 { }
        }
    }