コード例 #1
0
    protected override void OnInit(EventArgs e)
    {
        base.OnInit(e);

        // inizializzazione
        _cmd = master.check_cmd(qry_val("cmd"));

        // elab requests & cmds
        if (this.IsPostBack)
        {
            return;
        }

        try {
            io ob = new io();

            // js request
            if (json_request.there_request(this))
            {
                json_result res = new json_result(json_result.type_result.ok);

                try {
                    json_request jr = new json_request(this);

                    // save_file
                    if (jr.action == "save_file")
                    {
                        synch    s     = ob.get_synch(jr.val_int("user_id"), jr.val_str("user_name"));
                        Encoding enc   = System.Text.Encoding.GetEncoding(jr.val_str("enc"));
                        byte[]   bytes = jr.val_bytes("bin_data", enc);
                        string   path  = ob.file_path(jr.val_int("id"));
                        File.WriteAllBytes(path, bytes);
                        s.set_file_content_db(jr.val_int("id"), Path.GetExtension(path).ToLower(), enc.GetString(bytes), DateTime.Now, DateTime.Now);
                    } // synch folders
                    else if (jr.action == "synch_folders")
                    {
                        synch s = ob.get_synch(jr.val_int("user_id"), jr.val_str("user_name"));
                        s.synch_event += s_synch_event;
                        synch_results rf = s.reload_folders();
                        res.data     = rf;
                        res.contents = _synch_events;
                    }
                } catch (Exception ex) { log.log_err(ex); res = new json_result(json_result.type_result.error, ex.Message); }

                write_response(res);

                return;
            }

            // tasks
            //if(_cmd != null && _cmd.action == "view" && _cmd.obj == "tasks") {
            //  int? fi = qry_val("idt") != "" ? qry_int("idt") : (qry_val("id") != "" ? qry_int("id") : (int?)null)
            //    , sfi = qry_val("sft") != "" ? qry_int("sft") : (qry_val("sf") != "" ? qry_int("sf") : (int?)null);
            //} else throw new Exception("COMANDO NON RICONOSCIUTO!");
        } catch (Exception ex) { log.log_err(ex); if (!json_request.there_request(this))
                                 {
                                     master.err_txt(ex.Message);
                                 }
        }
    }
コード例 #2
0
    protected void add_att(notes ob, int task_id, string file_name, byte[] content = null)
    {
        synch s = ob.get_synch();

        // salvo il file
        DataRow dr = ob.get_task_info(task_id);

        if (db_provider.int_val(dr["file_id"]) > 0)
        {
            throw new Exception("il task non può contenere allegati!");
        }

        string folder = Path.Combine(db_provider.str_val(dr["synch_local_path"]), db_provider.str_val(dr["folder_path"]).Substring(1))
        , file_path   = Path.Combine(folder, file_name);

        if (content != null)
        {
            File.WriteAllBytes(file_path, content);
        }
        else
        {
            File.WriteAllText(file_path, "");
        }

        // aggiorno il db
        string tp; int cc;
        long   nid = s.set_file_db(db_provider.int_val(dr["synch_folder_id"]), db_provider.int_val(dr["folder_id"]), file_name, Path.GetExtension(file_name)
                                   , DateTime.Now, DateTime.Now, out tp, out cc);

        if (s.is_type_file(Path.GetExtension(file_name)) != null)
        {
            s.set_file_content_db((int)nid, Path.GetExtension(file_name).ToLower()
                                  , content != null ? System.Text.Encoding.UTF8.GetString(content) : "", DateTime.Now, DateTime.Now);
        }
        if (s.is_info_file(file_name) != null && db_provider.int_val(dr["file_notes_id"]) <= 0)
        {
            s.init_task_notes_db(task_id, (int)nid, content != null ? System.Text.Encoding.UTF8.GetString(content) : "");
        }
    }