Exemple #1
0
        private void LoadDrRecursive(List <RowParsed> childs, DataTable dt)
        {
            foreach (var oItem in childs)
            {
                var dr = dt.Rows.Add();

                RowParsed currentItem = oItem;

                foreach (var cv in currentItem.Values)
                {
                    if (!dt.Columns.Contains(cv.ColumnName))
                    {
                        continue;
                    }

                    dr[cv.ColumnName] = cv.Value;
                }

                while (currentItem.Parent != null)
                {
                    currentItem = currentItem.Parent;

                    foreach (var cv in currentItem.Values)
                    {
                        if (!dt.Columns.Contains(cv.ColumnName))
                        {
                            continue;
                        }

                        dr[cv.ColumnName] = cv.Value;
                    }
                }
            }
        }
Exemple #2
0
 private void FindChildRowRecursive(RowParsed startRow, List <RowParsed> output)
 {
     if (startRow.SubRow.Any())
     {
         foreach (var sr in startRow.SubRow)
         {
             FindChildRowRecursive(sr, output);
         }
     }
     else
     {
         output.Add(startRow);
     }
 }
Exemple #3
0
        private List <RowParsed> ParseValues(string json)
        {
            var result = new List <RowParsed>();

            var jt = JToken.Parse(json);

            if (jt.Type == JTokenType.Array)
            {
                foreach (JToken c in jt.Children())
                {
                    var row = new RowParsed(null);
                    result.Add(row);

                    ParseValues(row, c);
                }
            }
            else if (jt.Type == JTokenType.Object)
            {
                var row = new RowParsed(null);
                result.Add(row);

                ParseValues(row, jt);
            }
            else
            {
                var row = new RowParsed(null);
                result.Add(row);

                var colName = EpureKey(jt.Path);
                if (string.IsNullOrEmpty(colName))
                {
                    colName = "result";
                }
                row.Values.Add(new ValueParsed {
                    Path = jt.Path, Value = jt.ToString(), ColumnName = colName
                });
            }

            return(result);
        }
Exemple #4
0
 public RowParsed(RowParsed parent)
 {
     Values = new List <ValueParsed>();
     SubRow = new List <RowParsed>();
     Parent = parent;
 }
Exemple #5
0
        private void ParseValues(RowParsed row, JToken jt)
        {
            var colName = EpureKey(jt.Path);

            switch (jt.Type)
            {
            case JTokenType.Object:
                foreach (var p in ((JObject)jt).Properties())
                {
                    ParseValues(row, p);
                }
                break;

            case JTokenType.Array:
                foreach (JToken c in jt.Children())
                {
                    RowParsed sr = new RowParsed(row);
                    row.SubRow.Add(sr);

                    ParseValues(sr, c);
                }
                break;

            case JTokenType.Property:
                var jp = (JProperty)jt;
                foreach (var c in jp.Children())
                {
                    ParseValues(row, c);
                }
                break;

            case JTokenType.None:
            case JTokenType.Constructor:
            case JTokenType.Comment:
            case JTokenType.Null:
            case JTokenType.Undefined:
            case JTokenType.Raw:
            case JTokenType.Bytes:
                break;

            case JTokenType.Integer:
            case JTokenType.Float:
                row.Values.Add(new ValueParsed {
                    Value = jt.ToString(), Path = jt.Path, ColumnName = colName, ValueJsonType = JsonTypeValue.Decimal
                });
                break;

            case JTokenType.Boolean:
                row.Values.Add(new ValueParsed {
                    Value = jt.ToString(), Path = jt.Path, ColumnName = colName, ValueJsonType = JsonTypeValue.Boolean
                });
                break;

            case JTokenType.Date:
                row.Values.Add(new ValueParsed {
                    Value = jt.ToString(), Path = jt.Path, ColumnName = colName, ValueJsonType = JsonTypeValue.DateTime
                });
                break;

            case JTokenType.String:
            case JTokenType.Guid:
            case JTokenType.Uri:
            case JTokenType.TimeSpan:
                row.Values.Add(new ValueParsed {
                    Value = jt.ToString(), Path = jt.Path, ColumnName = colName, ValueJsonType = JsonTypeValue.String
                });
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }
        }