Esempio n. 1
0
        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);
        }
Esempio n. 2
0
 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;
 }
Esempio n. 4
0
        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));
        }
Esempio n. 5
0
        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());
        }
Esempio n. 6
0
        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}\"");
                }
            }
        }
Esempio n. 7
0
        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));
        }
Esempio n. 8
0
        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));
        }