Exemple #1
0
 public table(string doc_key, string name, xml_node tbl, bool for_pg = false)
     : base(doc_key, for_pg)
 {
     _name = name; _rows = new List <table_row>();
     _cols = tbl.get_attr("cols").Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries).ToList();
     foreach (xml_node row in tbl.nodes("rows/row"))
     {
         _rows.Add(new table_row(this, _cols.Select(c => row.get_attr(c)).ToList()));
     }
 }
Exemple #2
0
        Camera(pugi::xml_node &camera)
        {
            cfa = newiPoint2D(0, 0);
            pugi::xml_attribute key = camera.attribute("make");
            if (!key)

                ThrowCME("Camera XML Parser: \"make\" attribute not found.");
            make = canonical_make = key.as_string();

            key = camera.attribute("model");
            if (!key)

                ThrowCME("Camera XML Parser: \"model\" attribute not found.");
            model = canonical_model = canonical_alias = key.as_string();

            canonical_id = make + " " + model;

            supported = true;
            key = camera.attribute("supported");
            if (key)
            {
                string s = string(key.as_string());
                if (s.compare("no") == 0)
                    supported = false;
            }

            key = camera.attribute("mode");
            if (key)
            {
                mode = key.as_string();
            }
            else
            {
                mode = string("");
            }

            key = camera.attribute("decoder_version");
            if (key)
            {
                decoderVersion = key.as_int(0);
            }
            else
            {
                decoderVersion = 0;
            }

            for (xml_node node = camera.first_child(); node; node = node.next_sibling())
            {

                parseCameraChild(node);
            }
        }
Exemple #3
0
 protected void upload_file(string path, int id_file, xml_node n)
 {
     try {
         lbl_message(log.log_info($"upload file {n.get_attr("http_path")}"));
         System.Text.Encoding e = encoding_type.GetType(path);
         var file = new {
             action    = "save_file", id = id_file, bin_data = e.GetString(File.ReadAllBytes(path)), enc = e.HeaderName
             , user_id = n.get_int("user_id"), user_name = n.get_val("user_name")
         };
         json_request.post(_c.base_url + _c.config.get_var("client.io-page").value, file);
         lbl_message(log.log_info($"uploaded file {n.get_attr("http_path")}!"), 2);
     } catch (Exception ex) {
         log.log_err(ex);
         lbl_message($"uploaded error {ex.Message}!", 5, true);
         n.set_attr("upload_err", $"error at {DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")}: {ex.Message}"); throw ex;
     }
 }
Exemple #4
0
        public xml_node parse_node(xml_node n, Dictionary <string, object> keys, DataRow dr = null)
        {
            // text
            if (!string.IsNullOrEmpty(n.text))
            {
                n.text = parse(n.text, keys, dr);
            }

            // attributes
            foreach (string a in n.get_attrs())
            {
                n.set_attr(a, parse(n.get_attr(a), keys, dr));
            }

            // childs
            foreach (xml_node nc in n.childs)
            {
                parse_node(nc, keys, dr);
            }

            return(n);
        }
Exemple #5
0
void parseBlackAreas(xml_node &cur)
{
    if (isTag(cur.name(), "Vertical"))
    {

        int x = cur.attribute("x").as_int(-1);
        if (x < 0)
        {
            ThrowCME("Invalid x coordinate in vertical BlackArea of in camera %s %s", make.c_str(), model.c_str());
        }

        int w = cur.attribute("width").as_int(-1);
        if (w < 0)
        {
            ThrowCME("Invalid width in vertical BlackArea of in camera %s %s", make.c_str(), model.c_str());
        }

        blackAreas.push_back(BlackArea(x, w, true));

    }
    else if (isTag(cur.name(), "Horizontal"))
    {

        int y = cur.attribute("y").as_int(-1);
        if (y < 0)
        {
            ThrowCME("Invalid y coordinate in horizontal BlackArea of in camera %s %s", make.c_str(), model.c_str());
        }

        int h = cur.attribute("height").as_int(-1);
        if (h < 0)
        {
            ThrowCME("Invalid width in horizontal BlackArea of in camera %s %s", make.c_str(), model.c_str());
        }
        blackAreas.push_back(BlackArea(y, h, false));
    }
}
Exemple #6
0
 public bool exists_file(int id_file, out xml_node n)
 {
     n = this.node($"/root/file[@id='{id_file}']"); return(n.node != null);
 }
Exemple #7
0
        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); }
        }
Exemple #8
0
void parseCFA(xml_node &cur)
{
    if (isTag(cur.name(), "ColorRow"))
    {
        int y = cur.attribute("y").as_int(-1);
        if (y < 0 || y >= cfa.size.y)
        {
            ThrowCME("Invalid y coordinate in CFA array of in camera %s %s", make.c_str(), model.c_str());
        }
        stringkey = cur.first_child().value();
        if ((int)strlen(key) != cfa.size.x)
        {
            ThrowCME("Invalid number of colors in definition for row %d in camera %s %s. Expected %d, found %zu.", y, make.c_str(), model.c_str(), cfa.size.x, strlen(key));
        }
        for (int x = 0; x < cfa.size.x; x++)
        {
            char v = (char)tolower((int)key[x]);
            if (v == 'g')
                cfa.setColorAt(iPoint2D(x, y), CFA_GREEN);
            else if (v == 'r')
                cfa.setColorAt(iPoint2D(x, y), CFA_RED);
            else if (v == 'b')
                cfa.setColorAt(iPoint2D(x, y), CFA_BLUE);
            else if (v == 'f')
                cfa.setColorAt(iPoint2D(x, y), CFA_FUJI_GREEN);
            else if (v == 'c')
                cfa.setColorAt(iPoint2D(x, y), CFA_CYAN);
            else if (v == 'm')
                cfa.setColorAt(iPoint2D(x, y), CFA_MAGENTA);
            else if (v == 'y')
                cfa.setColorAt(iPoint2D(x, y), CFA_YELLOW);
            else
                supported = false;
        }
    }
    if (isTag(cur.name(), "Color"))
    {
        int x = cur.attribute("x").as_int(-1);
        if (x < 0 || x >= cfa.size.x)
        {
            ThrowCME("Invalid x coordinate in CFA array of in camera %s %s", make.c_str(), model.c_str());
        }

        int y = cur.attribute("y").as_int(-1);
        if (y < 0 || y >= cfa.size.y)
        {
            ThrowCME("Invalid y coordinate in CFA array of in camera %s %s", make.c_str(), model.c_str());
        }

        stringkey = cur.first_child().value();
        if (isTag(key, "GREEN"))
            cfa.setColorAt(iPoint2D(x, y), CFA_GREEN);
        else if (isTag(key, "RED"))
            cfa.setColorAt(iPoint2D(x, y), CFA_RED);
        else if (isTag(key, "BLUE"))
            cfa.setColorAt(iPoint2D(x, y), CFA_BLUE);
        else if (isTag(key, "FUJIGREEN"))
            cfa.setColorAt(iPoint2D(x, y), CFA_FUJI_GREEN);
        else if (isTag(key, "CYAN"))
            cfa.setColorAt(iPoint2D(x, y), CFA_CYAN);
        else if (isTag(key, "MAGENTA"))
            cfa.setColorAt(iPoint2D(x, y), CFA_MAGENTA);
        else if (isTag(key, "YELLOW"))
            cfa.setColorAt(iPoint2D(x, y), CFA_YELLOW);
    }
}
Exemple #9
0
void parseCameraChild(xml_node &cur)
{
    if (isTag(cur.name(), "CFA"))
    {
        if (2 != cur.attribute("width").as_int(0) || 2 != cur.attribute("height").as_int(0))
        {
            supported = false;
        }
        else
        {
            cfa.setSize(iPoint2D(2, 2));
            xml_node c = cur.child("Color");
            while (c != null)
            {
                parseCFA(c);
                c = c.next_sibling("Color");
            }
        }
        return;
    }

    if (isTag(cur.name(), "CFA2"))
    {
        cfa.setSize(iPoint2D(cur.attribute("width").as_int(0), cur.attribute("height").as_int(0)));
        xml_node c = cur.child("Color");
        while (c != null)
        {
            parseCFA(c);
            c = c.next_sibling("Color");
        }
        c = cur.child("ColorRow");
        while (c != null)
        {
            parseCFA(c);
            c = c.next_sibling("ColorRow");
        }
        return;
    }

    if (isTag(cur.name(), "Crop"))
    {
        cropPos.x = cur.attribute("x").as_int(0);
        cropPos.y = cur.attribute("y").as_int(0);

        if (cropPos.x < 0)
            ThrowCME("Negative X axis crop specified in camera %s %s", make.c_str(), model.c_str());
        if (cropPos.y < 0)
            ThrowCME("Negative Y axis crop specified in camera %s %s", make.c_str(), model.c_str());

        cropSize.x = cur.attribute("width").as_int(0);
        cropSize.y = cur.attribute("height").as_int(0);
        return;
    }

    if (isTag(cur.name(), "Sensor"))
    {
        parseSensorInfo(cur);
        return;
    }

    if (isTag(cur.name(), "BlackAreas"))
    {
        xml_node c = cur.first_child();
        while (c != null)
        {
            parseBlackAreas(c);
            c = c.next_sibling();
        }
        return;
    }

    if (isTag(cur.name(), "Aliases"))
    {
        xml_node c = cur.child("Alias");
        while (c != null)
        {
            parseAlias(c);
            c = c.next_sibling();
        }
        return;
    }

    if (isTag(cur.name(), "Hints"))
    {
        xml_node c = cur.child("Hint");
        while (c != null)
        {
            parseHint(c);
            c = c.next_sibling();
        }
        return;
    }

    if (isTag(cur.name(), "ID"))
    {
        parseID(cur);
        return;
    }
}