private void MergeData() { CacheKeyInfo keyInfo = CacheKeyContants.CHAR_DATA_SNAPSHOT_KEY.BuildCacheInfo(PlayerManager.Instance.GetCharBaseData().CharId); CharacterDataSnapshot data = CacheManager.GetInsance().Get(keyInfo) as CharacterDataSnapshot; if (null != data) { foreach (var elem in data.DataList) { if (elem is CharBaseInfo) { m_CharInfo.CharBaseInfo = (CharBaseInfo)elem; } else if (elem is CharCounterInfo) { m_CharInfo.CharCounterInfo = (CharCounterInfo)elem; } else if (elem is CharBagInfo) { m_CharInfo.CharBagInfo = (CharBagInfo)elem; } else if (elem is CharMissionInfo) { m_CharInfo.CharMissionInfo = (CharMissionInfo)elem; } } } }
public override bool Equals(object obj) { if (!(obj is CacheKeyInfo)) { return(false); } CacheKeyInfo other = obj as CacheKeyInfo; if (!GetRealKey().Equals(other.GetRealKey())) { return(false); } return(true); }
public void GetDefaultLoginRequest(ref string username, ref string password) { try { //encode pkg CacheKeyInfo keyInfo = CacheKeyContants.STRING_KEY.BuildCacheInfo(""); string content = CacheManager.GetInsance().Get(keyInfo) as string; Dictionary <string, object> root = Json.Deserialize(content) as Dictionary <string, object>; username = root[m_strUsernameKey] as string; password = root[m_strpasswordKey] as string; } catch (Exception) { Debuger.LogWarning("error on decode username"); } }
protected override void AfterRequest(SyncCharDataResponse resp) { CacheKeyInfo keyInfo = CacheKeyContants.CHAR_DATA_SNAPSHOT_KEY.BuildCacheInfo(PlayerManager.Instance.GetCharBaseData().CharId); CharacterDataSnapshot data = CacheManager.GetInsance().Get(keyInfo) as CharacterDataSnapshot; if (data == null) { return; } if (data.Version != SyncVersion) { return; } CacheManager.GetInsance().Del(keyInfo); }
private void SaveDefaultLoginRequest(string username, string password) { try { Dictionary <string, object> contentInstance = new Dictionary <string, object>(); contentInstance.Add(m_strUsernameKey, username); contentInstance.Add(m_strpasswordKey, password); string content = Json.Serialize(contentInstance); //decode pkg CacheKeyInfo keyInfo = CacheKeyContants.STRING_KEY.BuildCacheInfo(""); CacheManager.GetInsance().Set(keyInfo, content); } catch (Exception) { Debuger.LogWarning("error on encode username"); } }
protected override void Beat() { if (!m_bIsActive || (syncRequest != null && syncRequest.Running)) { return; } CacheKeyInfo keyInfo = CacheKeyContants.CHAR_DATA_SNAPSHOT_KEY.BuildCacheInfo(PlayerManager.Instance.GetCharBaseData().CharId); CharacterDataSnapshot data = CacheManager.GetInsance().Get(keyInfo) as CharacterDataSnapshot; if (data == null) { return; } SyncCharDataRequest request = new SyncCharDataRequest(); foreach (TBase tbase in data.DataList) { if (tbase is CharBaseInfo) { request.CharBaseInfo = tbase as CharBaseInfo; continue; } if (tbase is CharCounterInfo) { request.CharCounterInfo = tbase as CharCounterInfo; continue; } if (tbase is CharBagInfo) { request.CharBagInfo = tbase as CharBagInfo; continue; } if (tbase is CharMissionInfo) { request.CharMissionInfo = tbase as CharMissionInfo; continue; } } syncRequest = new AsyncSyncCharDataRequest(request); syncRequest.SyncVersion = data.Version; syncRequest.TryRequest(); }
public CacheKeyInfo BuildCacheInfo(object param) { CacheKeyInfo cacheInfo = new CacheKeyInfo(this, param); return cacheInfo; }
protected override void Beat() { List <TBase> updateList = null; while (true) { AbstractBusinessObject obj = UpdateManager.Instance.Poll(); if (obj == null) { break; } ICharDataConverter converter = ConverterManager.Instance.FindConverter(obj.GetType()); if (converter == null) { Debuger.LogError(string.Format("not found converter. type:{0}", obj.GetType())); continue; } TBase info = converter.Convert(obj); obj.ResetModify(); if (info == null) { Debuger.LogError(string.Format("convert result is null. type:{0}", obj.GetType())); continue; } if (updateList == null) { updateList = new List <TBase>(); } updateList.Add(info); } if (updateList != null) { CacheKeyInfo keyInfo = CacheKeyContants.CHAR_DATA_SNAPSHOT_KEY.BuildCacheInfo(PlayerManager.Instance.GetCharBaseData().CharId); CharacterDataSnapshot data = CacheManager.GetInsance().Get(keyInfo) as CharacterDataSnapshot; if (data == null) { data = new CharacterDataSnapshot(); data.Version = 0L; data.DataList = updateList; } else { data.Version += 1; List <TBase> delList = new List <TBase>(); for (int i = 0; i < updateList.Count; i++) { TBase newTbase = updateList[i]; for (int j = 0; j < data.DataList.Count; j++) { if (newTbase.GetType() == data.DataList[j].GetType()) { data.DataList[j] = newTbase; delList.Add(newTbase); break; } } } foreach (TBase delTbase in delList) { updateList.Remove(delTbase); } if (updateList.Count > 0) { data.DataList.AddRange(updateList); } } CacheManager.GetInsance().Set(keyInfo, data); } }
public CacheKeyInfo BuildCacheInfo(object param) { CacheKeyInfo cacheInfo = new CacheKeyInfo(this, param); return(cacheInfo); }