コード例 #1
0
        //---------------------------------------------------------------------
        // 运行在"ThreadSerializer"线程中
        public override void handleLoad()
        {
            EbFileStream file_stream = mEntityMgr._getFileStream();

            bool result = file_stream.load(mFileName);

            if (result)
            {
                string buf = file_stream.getDataAsString();
                mEntityData = JsonConvert.DeserializeObject <EntityData>(buf);
            }
            else
            {
                // log error
            }
        }
コード例 #2
0
        //---------------------------------------------------------------------
        public void setup(string db_name, string db_filename, string dbinfo_dir, string dbforeignkeyinfo_filename)
        {
            // 加载Table描述文件
            mDbInfo.ListTable = new List <EbTableInfo>();
            string[] list_tableinfofile = Directory.GetFiles(dbinfo_dir, "*.json");
            foreach (var i in list_tableinfofile)
            {
                bool result = mFileStream.load(i);
                if (!result)
                {
                    EbLog.Note("EbDataMgr.setup() failed! tableinfo_filename=" + dbforeignkeyinfo_filename);
                    return;
                }
                string      buf        = mFileStream.getDataAsString();
                EbTableInfo table_info = JsonConvert.DeserializeObject <EbTableInfo>(buf);
                mDbInfo.ListTable.Add(table_info);
            }

            // 加载ForeignKey描述文件
            {
                bool result = mFileStream.load(dbforeignkeyinfo_filename);
                if (!result)
                {
                    EbLog.Note("EbDataMgr.setup() failed! dbforeignkeyinfo_filename=" + dbforeignkeyinfo_filename);
                    return;
                }
                string buf = mFileStream.getDataAsString();
                List <EbForeignKeyInfo> list_foreignkeyinfo = JsonConvert.DeserializeObject <List <EbForeignKeyInfo> >(buf);
                mDbInfo.ListForeignKeyInfo = list_foreignkeyinfo;
            }

            // 加载所有Db数据
            if (!mFileStream.load(db_filename))
            {
                EbLog.Note("EbDataMgr.setup() failed! db_filename=" + db_filename);
                return;
            }

            mSqliteDb = new SQLiteDB();

            try
            {
                byte[] bytes = mFileStream.getData();
                using (var mem_stream = new MemoryStream(bytes, 0, bytes.Length))
                {
                    mSqliteDb.OpenStream(db_name, mem_stream);

                    // 加载所有Table数据
                    foreach (var i in mDbInfo.ListTable)
                    {
                        _loadTable(i.TableName, i.ListFieldInfo);
                    }

                    mSqliteDb.Close();
                }
            }
            catch (Exception e)
            {
                EbLog.Note(e.ToString());
            }
        }