void SetInitialCache() { //open default database and subscribe for table update events (update, delete and insert) by setting flag ClientSide.CAsyncDBHandler.ENABLE_TABLE_UPDATE_MESSAGES bool ok = m_hander.GetCachedTables(DefaultDBName, (res, errMsg) => { uint port; string ip = m_hander.Socket.GetPeerName(out port); ip += ":"; ip += port; m_cache.Set(ip, m_hander.DBManagementSystem); m_cache.DBServerName = m_hander.Socket.ConnectionContext.Host; if (res == 0) { m_MasterCache.Swap(m_cache); //exchange between master Cache and this m_cache m_cache.Set(ip, m_hander.DBManagementSystem); } }, (vData) => { m_cache.AddRows(m_meta[0].DBPath, m_meta[0].TablePath, vData); }, (meta) => { m_cache.AddEmptyRowset(meta); m_meta = meta; }, UDB.DB_CONSTS.ENABLE_TABLE_UPDATE_MESSAGES); }
public bool SendMeta(UDB.CDBColumnInfoArray meta, ulong index) { //A client expects a rowset meta data and call index uint ret = SendResult(UDB.DB_CONSTS.idRowsetHeader, meta, index); return(ret != REQUEST_CANCELED && ret != SOCKET_NOT_FOUND); }
void SetInitialCache() { //open default database and subscribe for table update events (update, delete and insert) by setting flag ClientSide.CAsyncDBHandler.ENABLE_TABLE_UPDATE_MESSAGES bool ok = m_hander.Open(DefaultDBName, (h, res, errMsg) => { m_cache.Updater = ""; m_cache.Empty(); uint port; string ip = h.Socket.GetPeerName(out port); ip += ":"; ip += port; m_cache.DBServerName = h.Socket.ConnectionContext.Host; m_cache.Set(ip, h.DBManagementSystem); }, UDB.DB_CONSTS.ENABLE_TABLE_UPDATE_MESSAGES); //bring all cached table data into m_cache first for initial cache, and exchange it with Cache if there is no error ok = m_hander.Execute("", (h, res, errMsg, affected, fail_ok, id) => { if (res == 0) { m_MasterCache.Swap(m_cache); //exchange between master Cache and this m_cache } }, (h, vData) => { UDB.CDBColumnInfoArray meta = h.ColumnInfo; try { m_cache.AddRows(meta[0].DBPath, meta[0].TablePath, vData); } catch (Exception err) { Console.WriteLine(err.Message); } }, (h) => { try { m_cache.AddEmptyRowset(h.ColumnInfo); } catch (Exception err) { Console.WriteLine(err.Message); } }); }
/// <summary> /// Add an empty rowset from a given column meta data for cache /// </summary> /// <param name="meta">A meta data for a rowset</param> /// <remarks>Track the event that a new rowset is added into a cache by overriding this method</remarks> public virtual void AddEmptyRowset(UDB.CDBColumnInfoArray meta) { if (meta == null || meta.Count == 0) { return; } if (meta[0].DBPath == null || meta[0].DBPath.Length == 0 || meta[0].TablePath == null || meta[0].TablePath.Length == 0) { throw new Exception("The first column meta must contain database name and table name"); } System.Data.DataTable tbl = ClientSide.CAsyncDBHandler.MakeDataTable(meta, meta[0].TablePath); if (tbl.PrimaryKey == null || tbl.PrimaryKey.Length == 0) { throw new Exception("Column meta must contain at least one key"); } lock (m_cs) { tbl.CaseSensitive = m_bDataCaseSensitive; m_ds.Add(new KeyValuePair <string, System.Data.DataTable>(meta[0].DBPath, tbl)); } }