internal object GetJson(Base parentColumn, Column column)
 {
     if (parentColumn is ESDataSourceConnection)
     {
         parentColumn = (parentColumn as ESDataSourceConnection).GetParentJTDSByName(column.Name);
     }
     if (parentColumn is JsonDataSourceConnection)
     {
         // return zero level json
         return((parentColumn as JsonDataSourceConnection).Json);
     }
     else if (parentColumn is JsonTableDataSource)
     {
         if (parentColumn.Parent is ESDataSourceConnection)
         {
             parentColumn.Parent = (parentColumn.Parent as ESDataSourceConnection).GetParentJTDSByName(parentColumn.Name);
         }
         JsonTableDataSource source = parentColumn as JsonTableDataSource;
         return(source.Json[source.CurrentRowNo] as object);
     }
     else if (parentColumn is Column)
     {
         object parentJson = GetJson(parentColumn.Parent, parentColumn as Column);
         if (parentJson is JsonBase && !String.IsNullOrEmpty(column.PropName))
         {
             return((parentJson as JsonBase)[column.PropName]);
         }
     }
     return(null);
 }
        /// <inheritdoc/>
        public override void CreateAllTables(bool initSchema)
        {
            bool found = false;

            foreach (Base b in Tables)
            {
                if (b is JsonTableDataSource)
                {
                    (b as JsonTableDataSource).UpdateSchema = true;
                    (b as JsonTableDataSource).InitSchema();
                    found = true;
                    break;
                }
            }

            if (!found)
            {
                JsonTableDataSource jsonDataSource = new JsonTableDataSource();

                string fixedTableName = TABLE_NAME;
                jsonDataSource.TableName = fixedTableName;

                if (Report != null)
                {
                    jsonDataSource.Name  = Report.Dictionary.CreateUniqueName(fixedTableName);
                    jsonDataSource.Alias = Report.Dictionary.CreateUniqueAlias(jsonDataSource.Alias);
                }
                else
                {
                    jsonDataSource.Name = fixedTableName;
                }

                jsonDataSource.Parent = this;
                jsonDataSource.InitSchema();
                jsonDataSource.Enabled = true;
            }

            // init table schema
            if (initSchema)
            {
                foreach (TableDataSource table in Tables)
                {
                    table.InitSchema();
                }
            }
        }
Beispiel #3
0
        internal static object GetJsonBaseByColumn(Base parentColumn, Column column)
        {
            if (parentColumn is JsonTableDataSource)
            {
                switch (column.PropName)
                {
                case "item":
                    return((parentColumn as JsonTableDataSource).Json[(parentColumn as JsonTableDataSource).CurrentIndex]);
                }
                JsonTableDataSource source = column as JsonTableDataSource;
                return(source.Json);
            }
            if (parentColumn is Column && !String.IsNullOrEmpty(column.PropName))
            {
                object json = GetJsonBaseByColumn(parentColumn.Parent, parentColumn as Column);
                if (json is JsonBase)
                {
                    return((json as JsonBase)[column.PropName]);
                }
            }

            return(null);
        }
Beispiel #4
0
        internal static void InitSchema(Column table, JsonSchema schema)
        {
            List <Column> saveColumns = new List <Column>();

            switch (schema.Type)
            {
            case "object":
                foreach (KeyValuePair <string, JsonSchema> kv in schema.Properties)
                {
                    if (kv.Value.Type == "object")
                    {
                        Column c = new Column();
                        c.Name     = kv.Key;
                        c.Alias    = kv.Key;
                        c.PropName = kv.Key;
                        c.DataType = kv.Value.DataType;
                        c          = UpdateColumn(table, c, saveColumns);
                        InitSchema(c, kv.Value);
                    }
                    else if (kv.Value.Type == "array")
                    {
                        Column c = new JsonTableDataSource();
                        c.Name     = kv.Key;
                        c.Alias    = kv.Key;
                        c.PropName = kv.Key;
                        c.DataType = kv.Value.DataType;
                        c          = UpdateColumn(table, c, saveColumns);
                        InitSchema(c, kv.Value);
                    }
                    else
                    {
                        Column c = new Column();
                        c.Name     = kv.Key;
                        c.Alias    = kv.Key;
                        c.PropName = kv.Key;
                        c.DataType = kv.Value.DataType;
                        c.SetBindableControlType(c.DataType);
                        UpdateColumn(table, c, saveColumns);
                    }
                }
                break;

            case "array":
                JsonSchema items = schema.Items;
                {
                    Column c = new Column();
                    c.Name     = "index";
                    c.Alias    = "index";
                    c.PropName = "index";
                    c.DataType = typeof(int);
                    UpdateColumn(table, c, saveColumns);
                }

                {
                    Column c;
                    bool   iSchema = false;

                    if (items.Type == "object")
                    {
                        c       = new Column();
                        iSchema = true;
                    }
                    else if (items.Type == "array")
                    {
                        c       = new JsonTableDataSource();
                        iSchema = true;
                    }
                    else
                    {
                        c = new Column();
                    }

                    c.Name     = "item";
                    c.Alias    = "item";
                    c.PropName = "item";
                    c.DataType = items.DataType;
                    c          = UpdateColumn(table, c, saveColumns);

                    if (iSchema)
                    {
                        InitSchema(c, items);
                    }
                }

                {
                    Column c = new Column();
                    c.Name     = "array";
                    c.Alias    = "array";
                    c.PropName = "array";
                    c.DataType = typeof(JsonBase);
                    UpdateColumn(table, c, saveColumns);
                }
                break;
            }

            for (int i = 0; i < table.Columns.Count; i++)
            {
                if (!(table.Columns[i].Calculated || saveColumns.Contains(table.Columns[i])))
                {
                    table.Columns.RemoveAt(i);
                    i--;
                }
            }
        }