Esempio n. 1
0
        /// <summary>
        /// Creates a Csv database schema from a json file
        /// </summary>
        /// <param name="jsonfilepath">json file path</param>
        /// <param name="flags">creation schema flags</param>
        /// <returns></returns>
        public static CsvDb CreateFromJson(string jsonfilepath, DbSchemaConfigType flags = DbSchemaConfigType.None)
        {
            //generate the __schema.bin file and create normal database
            var text = io.File.ReadAllText(jsonfilepath);

            ////Newtonsoft.Json.JsonConvert.DeserializeObject<CsvDbStructure>(text);
            ////fastJSON is 4X+ faster than Newtonsoft.Json parser
            ////https://github.com/mgholam/fastJSON

            var schema = fastJSON.JSON.ToObject <DbSchemaConfig>(text);

            //define paths
            var rootPath = io.Path.GetDirectoryName(jsonfilepath);
            var sysPath  = io.Path.Combine(rootPath, $"{SchemaSystemFilename}");

            //set flags
            schema.Flags = flags;

            //save
            var writer = new io.BinaryWriter(io.File.Create(sysPath));

            schema.Save(writer);
            writer.Dispose();

            //remove the ending \bin\
            return(new CsvDb(io.Path.GetDirectoryName(rootPath)));
        }
Esempio n. 2
0
        static void GenerateInitialDbData(
            Config.ConfigSettings appConfig,
            string dbname,
            DbSchemaConfigType dbConfig,
            string zipfile
            )
        {
            var basePath = appConfig.Database.BasePath;

            var jsonfilepath = $"{basePath}\\{dbname}\\bin\\__tables.init.json";

            var db = CsvDb.CsvDb.CreateFromJson(jsonfilepath, dbConfig);

            var gen = new DbGenerator(db, $@"{basePath}{zipfile}", removeAll: false);

            gen.Generate();
        }