Ejemplo n.º 1
0
        void ReadData(XElement x, TableData td, string orderBy, string parentId)
        {
            TableContent d = td.Data;

            string type = ReadAttr(x, "type");

            if (type == "json")
            {
                ReadDataJson(x.Value, d);
            }
            else if (type == "csv")
            {
                ReadDataCsv(x.Value, d);
            }
            else
            {
                throw new Exception($"Inknown data type {type} in {_file}");
            }

            Sort(td, orderBy);
            if (!string.IsNullOrEmpty(td.Group))
            {
                if (string.IsNullOrEmpty(td.Key))
                {
                    throw new Exception("'key' element not set inside 'table'");
                }
                Group(td, parentId);
            }
        }
Ejemplo n.º 2
0
        void ReadDataCsv(string content, TableContent d)
        {
            CsvManager.TextTrim = true;
            var td = CsvManager.ReadCsvString(content);

            d.Schema.AddRange(td.Header);
            foreach (var r in td.Content)
            {
                var tr = new TableRow();
                tr.AddRange(r);
                d.Rows.Add(tr);
            }
        }
Ejemplo n.º 3
0
        void Sort(TableData td, string orderBy)
        {
            TableContent d = td.Data;

            if (d.Rows.Count == 0)
            {
                return;
            }

            int oCol = -1;

            string[] orderByList = { };
            if (!string.IsNullOrEmpty(orderBy))
            {
                orderBy     = orderBy.ToLower();
                orderByList = orderBy.Split(' ', StringSplitOptions.RemoveEmptyEntries);
                for (int i = 0; i < d.Schema.Count; i++)
                {
                    if (d.Schema[i].ToLower() == orderByList[0])
                    {
                        oCol = i;
                        break;
                    }
                }
            }

            if (oCol != -1)
            {
                if (orderByList.Length > 1 && orderByList[1] == "desc")
                {
                    d.Rows.Sort((i1, i2) => - ((IComparable)i1[oCol]).CompareTo(i2[oCol]));
                }
                else
                {
                    d.Rows.Sort((i1, i2) => ((IComparable)i1[oCol]).CompareTo(i2[oCol]));
                }
//                    d.Rows.OrderBy(r => r[oCol]);
                td.OrderByColumn = orderBy;
            }
        }
Ejemplo n.º 4
0
        void ReadDataJson(string content, TableContent d)
        {
            var td = JsonManager.ReadJsonString(content);

            var names = new Dictionary <string, bool>();

            foreach (var r in td)
            {
                foreach (var n in r.Keys)
                {
                    var n1 = n.ToLower();
                    if (names.ContainsKey(n1))
                    {
                        continue;
                    }
                    names.Add(n1, true);
                }
            }
            d.Schema.AddRange(names.Keys);

            foreach (var r in td)
            {
                var tr = new TableRow();

                var comparer = StringComparer.OrdinalIgnoreCase;
                var r1       = new Dictionary <string, object>(r, comparer);
                foreach (var n in names.Keys)
                {
                    if (r1.ContainsKey(n))
                    {
                        tr.Add(r1[n]);
                    }
                }

                d.Rows.Add(tr);
            }
        }