internal void Tick() { long curTime = TimeUtility.GetLocalMilliseconds(); if (m_LastTickTime + c_TickInterval <= curTime || UserServer.Instance.WaitQuit) { m_LastTickTime = curTime; foreach (var pair in m_Datas) { if (pair.Value.Modified) { TableGlobalData record = pair.Value.ToProto(); UserServer.Instance.DataCacheThread.SaveGlobalData(record); pair.Value.Modified = false; } if (pair.Value.Deleted) { UserServer.Instance.DataCacheThread.DeleteGlobalData(pair.Key); m_WaitDeletedDatas.Add(pair.Key); } } foreach (var key in m_WaitDeletedDatas) { m_Datas.Remove(key); } m_WaitDeletedDatas.Clear(); } }
private void InitGlobalData() { if (m_GlobalInitStatus == DataInitStatus.Unload) { if (m_DataStoreAvailable) { m_GlobalInitStatus = DataInitStatus.Loading; Msg_LD_Load msg = new Msg_LD_Load(); msg.MsgId = (int)DataEnum.TableGlobalData; GameFrameworkMessage.Msg_LD_SingleLoadRequest slr = new GameFrameworkMessage.Msg_LD_SingleLoadRequest(); slr.MsgId = (int)GameFrameworkData.DataEnum.TableGlobalData; slr.LoadType = GameFrameworkMessage.Msg_LD_SingleLoadRequest.LoadTypeEnum.LoadAll; slr.Keys.Clear(); msg.LoadRequests.Add(slr); RequestLoad(msg, ((ret) => { if (ret.ErrorNo == Msg_DL_LoadResult.ErrorNoEnum.Success) { List <TableGlobalData> datas = new List <TableGlobalData>(); foreach (var singlerow in ret.Results) { object _msg; if (DbDataSerializer.Decode(singlerow.Data, DataEnum2Type.Query(slr.MsgId), out _msg)) { TableGlobalData data = _msg as TableGlobalData; if (null != data) { datas.Add(data); } } } GlobalData.Instance.Init(datas); m_GlobalInitStatus = DataInitStatus.Done; LogSys.Log(LOG_TYPE.INFO, ConsoleColor.Green, "Load DataCache global data success. Table:TableGlobalData"); } else if (ret.ErrorNo == Msg_DL_LoadResult.ErrorNoEnum.NotFound) { GlobalData.Instance.Clear(); m_GlobalInitStatus = DataInitStatus.Done; LogSys.Log(LOG_TYPE.INFO, ConsoleColor.Green, "Load DataCache global data success. Table:TableGlobalData (empty)"); } else { m_GlobalInitStatus = DataInitStatus.Unload; LogSys.Log(LOG_TYPE.ERROR, ConsoleColor.Red, "Load DataCache global data failed. Table: {0}", "TableGlobalData"); } } )); } else { List <TableNicknameInfo> nicknameList = new List <TableNicknameInfo>(); UserServer.Instance.UserProcessScheduler.InitNicknameData(nicknameList); m_GlobalInitStatus = DataInitStatus.Done; LogSys.Log(LOG_TYPE.INFO, "load GlobalData done!"); } } }
internal int SaveGlobalData(TableGlobalData data) { try { Msg_LD_Save msg = new Msg_LD_Save(); msg.MsgId = (int)DataEnum.TableGlobalData; msg.PrimaryKeys.Add(data.Key); msg.ForeignKeys.Clear(); msg.Data = DbDataSerializer.Encode(data); RequestSave(msg); return(0); } catch (Exception e) { LogSys.Log(LOG_TYPE.ERROR, "DataCache Save ERROR:{0}, Stacktrace:{1}", e.Message, e.StackTrace); return(0); } }
public void FromProto(TableGlobalData proto) { m_TableGlobalData = proto; UpdatePrimaryKeys(); UpdateForeignKeys(); }