Beispiel #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);
                                 }
        }
    }