private static VAL WriteVAL(DataTable dt, JsonStyle style) { string[] columns = dt.Columns.Cast <DataColumn>().Select(col => col.ColumnName).ToArray(); VAL L = new VAL(); foreach (DataRow row in dt.Rows) { VAL V = new VAL(); for (int i = 0; i < columns.Length; i++) { object obj; switch (row[i]) { case Guid x: obj = "{" + x.ToString() + "}"; break; case DBNull NULL: obj = null; break; default: obj = row[i]; break; } V.AddMember(columns[i], obj); } L.Add(V); } return(L); }
internal SetJsonOptions(SetJsonOptions options) { ProjectFolder = options.ProjectFolder; Encountered = options.Encountered; Style = options.Style; RepositoryAttributes = options.RepositoryAttributes; LengthDigitCount = options.LengthDigitCount; Version = options.Version; }
internal SetJsonOptions(SetJsonOptions options) { ProjectFolder = options.ProjectFolder; Encountered = options.Encountered; Style = options.Style; RepositoryAttributes = options.RepositoryAttributes; LengthDigitCount = options.LengthDigitCount; Version = options.Version; SerializeAllGlobalIds = options.SerializeAllGlobalIds; SerializeOwnerHistory = options.SerializeOwnerHistory; }
public static string WriteJson(this DataSet ds, JsonStyle style) { VAL val = new VAL(); foreach (DataTable dt in ds.Tables) { var _dt = WriteVAL(dt, style); val.AddMember(dt.TableName, _dt); } return(ToJson(style, val)); }
private static string ToJson(JsonStyle style, VAL val) { switch (style) { case JsonStyle.Coded: return(val.ToString()); case JsonStyle.Extended: return(val.ToExJson()); } return(val.ToJson()); }
public void ExportJson() { DataSet ds = LastOrCurrentDataSet(); if (ds == null) { return; } string ds_name = cmd.GetValue("ds-name"); string[] dt_names = cmd.GetStringArray("dt-names"); if (ds_name != null) { ds.DataSetName = ds_name; } if (dt_names != null) { int min = Math.Min(ds.Tables.Count, dt_names.Length); for (int i = 0; i < min; i++) { ds.Tables[i].TableName = dt_names[i]; } } JsonStyle style = cmd.GetEnum("style", JsonStyle.Normal); if (ds.Tables.Count == 1) { var dt = ds.Tables[0]; string file = FileName($"{dt.TableName}.json"); using (var writer = file.CreateStreamWriter(cmd.Append)) { bool excludeTableName = cmd.Has("exclude-table"); writer.WriteLine(dt.WriteJson(style, excludeTableName)); cout.WriteLine($"completed to generate json on file: \"{file}\""); } } else { string file = FileName($"{ds.DataSetName}.json"); using (var writer = file.CreateStreamWriter(cmd.Append)) { writer.WriteLine(ds.WriteJson(style)); cout.WriteLine($"completed to generate json on file: \"{file}\""); } } }
public static string WriteJson(this DataLake lake, JsonStyle style) { VAL val = new VAL(); foreach (var kvp in lake) { DataSet ds = kvp.Value; VAL _ds = new VAL(); foreach (DataTable dt in ds.Tables) { var _dt = WriteVAL(dt, style); _ds.AddMember(dt.TableName, _dt); } val.AddMember(kvp.Key, _ds); } return(ToJson(style, val)); }
public static string WriteJson(this DataTable dt, JsonStyle style, bool excludeTableName) { if (dt.Columns.Count == 1) { string json = ToJson(style, VAL.Boxing(dt.ToArray(row => row[0]))); return(json); } VAL _dt = WriteVAL(dt, style); if (excludeTableName) { return(ToJson(style, _dt)); } VAL val = new VAL(); val.AddMember(dt.TableName, _dt); return(ToJson(style, val)); }