public override void KeyMovement(Vector3 moveDirection, MovementState movementState) { if (!CacheEntity.CanMove()) { return; } switch (CacheEntity.MovementSecure) { case MovementSecure.ServerAuthoritative: // Multiply with 100 and cast to sbyte to reduce packet size // then it will be devided with 100 later on server side CallNetFunction(NetFuncKeyMovement, DeliveryMethod.Sequenced, FunctionReceivers.Server, new DirectionVector3(moveDirection), movementState); break; case MovementSecure.NotSecure: tempInputDirection = moveDirection; tempMovementState = movementState; if (tempInputDirection.sqrMagnitude > 0) { navPaths = null; } if (canFly && !CacheOpenCharacterController.isGrounded && !isUnderWater && tempMovementState.HasFlag(MovementState.IsJump)) { isFlying = true; isJumping = false; applyingJumpForce = false; } if (!isJumping && !applyingJumpForce) { isJumping = (isUnderWater || CacheOpenCharacterController.isGrounded) && tempMovementState.HasFlag(MovementState.IsJump); } break; } }
public void UpdateCache <TDbEntity>(List <TDbEntity> entities) { try { CacheEntity type = CacheEntityMap.GetEntityTypeForDBEntity <TDbEntity>(); CacheStatus cacheStatus = Uow.CacheStatusesRepository.GetCacheStatus(type); cacheStatus.Status = CacheEntryStatus.UpdateInProgress; cacheStatus.LastUpdated = DateTime.UtcNow; // try to get DB lock; if (Uow.CacheStatusesRepository.TryUpdate(cacheStatus)) { ICachedEntitiesRepository <TDbEntity> entityRepository = Uow.GetRepository <ICachedEntitiesRepository <TDbEntity> >(); Task task = entityRepository.UpdateCacheAsync(entities); task.ContinueWith(task1 => { using (IOptionsPlayUow uow = ObjectFactory.GetInstance <IOptionsPlayUow>()) { cacheStatus = uow.CacheStatusesRepository.GetCacheStatus(type); cacheStatus.Status = CacheEntryStatus.Active; cacheStatus.LastUpdated = DateTime.UtcNow; uow.CacheStatusesRepository.Update(cacheStatus); uow.Commit(); } }); } } catch (Exception ex) { Logging.Logger.Debug("thread ID:" + System.Threading.Thread.CurrentThread.ManagedThreadId.ToString() + ", UpdateCache Exception is:" + ex.StackTrace.ToString() + ", class is DatabaseCacheService"); } }
public void GetDataFromCacheTest() { var list = TableCacheHelper.GetDataFromCache <Workflow>(typeof(WorkflowDao)); if (list.Count == 0) { return; } WorkflowDao dao = new WorkflowDao(); string key = typeof(Workflow).FullName; var item = cache.GetItem(key); CacheEntity <Workflow> cacheentity = item.Value as CacheEntity <Workflow>; Assert.IsNotNull(item); Assert.AreEqual(list, cacheentity.List); DateTime dt = DateTime.Now; dao.Update(new WorkflowUpdateForm { Entity = new Workflow { LastUpdateTime = dt }, WorkflowQueryForm = new WorkflowQueryForm { ID = list[0].ID } }); list = TableCacheHelper.GetDataFromCache <Workflow>(typeof(WorkflowDao)); item = cache.GetItem(key); cacheentity = item.Value as CacheEntity <Workflow>; Assert.AreEqual(dt.ToString("yyyyMMddHHmmss"), cacheentity.LastUpdateTime.Value.ToString("yyyyMMddHHmmss")); }
/// <summary> /// 增加/变更缓存 /// </summary> /// <param name="inputKey"></param> /// <param name="inputValue"></param> public static void SetCache(string inputKey, object inputValue) { if (string.IsNullOrWhiteSpace(inputKey)) { return; } var tempCacheRepository = GetCacheRespository(); if (null == tempCacheRepository) { return; } var tempValue = tempCacheRepository.Get(k => k.KeyName.Equals(inputKey)).FirstOrDefault(); if (null != tempValue) { tempValue.Value = inputValue; tempCacheRepository.Update(tempValue); } else { tempValue = new CacheEntity(); tempValue.KeyName = inputKey; tempValue.Value = inputValue; tempCacheRepository.Add(tempValue); } }
public void Write(CacheEntity entity) { using (var client = _manager.GetClient()) { var redisValue = JsonConvert.SerializeObject(entity); //client.RemoveItemFromSortedSet() } }
private static TimeSpan GetExpirationForEntity(CacheEntity entityType) { if (!ExpirationMap.ContainsKey(entityType)) { throw new InvalidOperationException(string.Format("Expiration is not found for type {0}", entityType)); } return(ExpirationMap[entityType]); }
protected void NetFuncPointClickMovement(Vector3 position) { if (!CacheEntity.CanMove()) { return; } tempMovementState = MovementState.Forward; SetMovePaths(position, true); }
public bool Contains(T entity) { ICacheEntity <T> cacheEntity = new CacheEntity <T>() { Target = entity, ExpirtTime = DateTime.UtcNow.AddSeconds(1) }; return(Pool.Values.Contains(cacheEntity)); }
public void Constructor_Should_Initialize_Properties_Correctly() { var cacheItem = new object(); var expiry = DateTime.UtcNow.AddMinutes(10); var ce = new CacheEntity("/webform.aspxac", cacheItem, expiry); Assert.Equal("_webform.aspxac", ce.RowKey); Assert.Equal(cacheItem, ce.CacheItem); Assert.Equal("5", ce.PartitionKey); Assert.Equal(expiry, ce.UtcExpiry); }
protected void NetFuncUpdateYRotation(short yRotation) { if (!CacheEntity.CanMove()) { return; } if (!HasNavPaths) { this.yRotation = yRotation; UpdateRotation(); } }
public static CacheEntity GetEntityTypeForDBEntity <T>() { Type type = typeof(T); if (!TypeMap.ContainsKey(type)) { throw new InvalidOperationException(string.Format("Type {0} is not registered to be DB cached", type.Name)); } CacheEntity result = TypeMap[type]; return(result); }
public void SanitizeKey_Should_Replace_Invalid_Chars_In_Key() { // invalid chars: '/', '\\', '?', '#' var sanitizedKey = CacheEntity.SanitizeKey("/k\\e?y#"); Assert.Equal("_k_e_y_", sanitizedKey); sanitizedKey = CacheEntity.SanitizeKey("_key_/\\?#"); Assert.Equal("_key_____", sanitizedKey); sanitizedKey = CacheEntity.SanitizeKey("#\\k?#e/\\y?/"); Assert.Equal("__k__e__y__", sanitizedKey); }
public void Set(string Key, T target, TimeSpan duration) { lock (this) { CheckCache(); ICacheEntity <T> cacheEntity = new CacheEntity <T>() { Target = target, ExpirtTime = DateTime.UtcNow.Add(duration) }; Pool[Key] = cacheEntity; } }
/// <summary> /// 缓存数据。 /// 数据名已存在但值类型不同时,如果ForceSave为true时,直接覆盖,否则抛出异常。 /// 数据名不存在则创建。 /// </summary> /// <param name="key">数据名</param> /// <param name="value">数据值</param> /// <param name="ForceSave">数据值类型不同时是否强制覆盖</param> /// <param name="EffectiveDuration">增加有效时长,单位为秒</param> /// <exception cref="数据类型不同异常。当数据名已存在,数据值类型不同,且ForceSave为False时触发"></exception> public void Set(string key, object value, bool ForceSave = true, int EffectiveDuration = 0) { var vs = JsonConvert.SerializeObject(value); var JsonTarget = JsonContent.Find(j => j.Key == key); if (JsonTarget == null) { JsonTarget = new CacheEntity(); JsonTarget.Key = key; JsonTarget.Value = vs; JsonTarget.Type = value.GetType(); if (EffectiveDuration != 0) { if (JsonTarget.ExpireDate == default(DateTime) || JsonTarget.ExpireDate != default(DateTime) && DateTime.Now > JsonTarget.ExpireDate) { JsonTarget.ExpireDate = DateTime.Now.AddSeconds(EffectiveDuration); } else { JsonTarget.ExpireDate = JsonTarget.ExpireDate.AddSeconds(EffectiveDuration); } } JsonContent.Add(JsonTarget); } else { var a = JsonTarget.Type == value.GetType(); if (JsonTarget.Type == value.GetType() || ForceSave) { JsonTarget.Value = vs; JsonTarget.Type = value.GetType(); if (EffectiveDuration != 0) { if (JsonTarget.ExpireDate == default(DateTime) || JsonTarget.ExpireDate != default(DateTime) && DateTime.Now > JsonTarget.ExpireDate) { JsonTarget.ExpireDate = DateTime.Now.AddSeconds(EffectiveDuration); } else { JsonTarget.ExpireDate = JsonTarget.ExpireDate.AddSeconds(EffectiveDuration); } } } else { throw new Exception($"[数类型据]名为{key}数据的值类型为{JsonTarget.Type},而当前值类型为{value.GetType()},请考虑在使用Set()方法时将ForceSave设置为true"); } } }
public void Refresh(CacheEntity localCache) { try { _localCache = localCache; tbxDeviceResult.Text = string.Empty; BindInstructionCombo(); BindDashboardLogs(localCache); } catch (Exception ex) { errorLog.SaveLog(ex); throw ex; } }
public DashContent(int deviceID, CacheEntity localCache) { try { Logs = new List <DashboardLogEntityUI>(); this.InitializeComponent(); _deviceID = deviceID; _localCache = localCache; errorLog = new ErrorLog(localCache.Setting.SQLServerIP); } catch (Exception ex) { errorLog.SaveLog(ex); throw ex; } }
public static void SetCachedDataset(string dbkey, string spName, int timeOut, DataSet data, params object[] parameterValues) { string key = GetKeyFromSpCommand(dbkey, spName, parameterValues); CacheEntity ce = _datasetHash[key] as CacheEntity; if (ce == null) { ce = new CacheEntity(data); _datasetHash.Add(key, ce); } else { ce.Data = data; _datasetHash[key] = ce; } }
public void GeneratePartitionKey_Should_Generate_PartitionKey_Based_On_Key_Length() { var pkey = CacheEntity.GeneratePartitionKey(""); Assert.Equal("0", pkey); pkey = CacheEntity.GeneratePartitionKey("a"); Assert.Equal("1", pkey); pkey = CacheEntity.GeneratePartitionKey("123456789"); Assert.Equal("9", pkey); pkey = CacheEntity.GeneratePartitionKey("1234567890"); Assert.Equal("0", pkey); pkey = CacheEntity.GeneratePartitionKey("123456789012"); Assert.Equal("2", pkey); }
public void InsertOrUpdate(Cargo entity) { var cacheEntity = Get(entity.Id); if (cacheEntity == null) { var cargo = new CacheEntity <Cargo>(entity) { PendingAction = PendingAction.Insert }; _cargoes.TryAdd(entity.Id, cargo); } else { cacheEntity.Entity = entity; cacheEntity.PendingAction = PendingAction.Update; } }
public override void PointClickMovement(Vector3 position) { if (!CacheEntity.CanMove()) { return; } switch (CacheEntity.MovementSecure) { case MovementSecure.ServerAuthoritative: CallNetFunction(NetFuncPointClickMovement, FunctionReceivers.Server, position); break; case MovementSecure.NotSecure: tempMovementState = MovementState.Forward; SetMovePaths(position, true); break; } }
private void BindDashboardLogs(CacheEntity localCache) { try { var cache = localCache.DashboardLogs; var result = new List <DashboardLogEntity>(); var currentdevins = _localCache.Instructions.Where(l => l.DeviceType == _localCache.Devices.FirstOrDefault(j => j.ID == _deviceID).DeviceType).Select(p => p.ID).ToList(); foreach (var ll in cache.Where(l => l.DashboardItemID > 0)) { if (currentdevins.Contains(_localCache.DashboardItems.FirstOrDefault(d => d.ID == ll.DashboardItemID).InstructionID)) { ll.InstructionID = _localCache.DashboardItems.FirstOrDefault(d => d.ID == ll.DashboardItemID).InstructionID; result.Add(ll); } } foreach (var ll in cache.Where(l => l.InstructionID > 0)) { if (currentdevins.Contains(ll.InstructionID.Value)) { result.Add(ll); } } var logs = new List <DashboardLogEntityUI>(); foreach (var item in result) { logs.Add(new DashboardLogEntityUI(item)); } if (logs != null && logs.Count > 0) { logs.ForEach(l => l.ResultName = ((l.ResultID.HasValue && l.ResultID > 0) ? _localCache.Results.FirstOrDefault(j => j.ID == l.ResultID).Memo : string.Empty)); logs.ForEach(l => l.InstructionName = ((l.InstructionID.HasValue && l.InstructionID > 0) ? _localCache.Instructions.FirstOrDefault(j => j.ID == l.InstructionID).Memo : string.Empty)); } Logs = logs; var Logss = Logs.OrderByDescending(p => p.SaveTime).DistinctBy(l => new { l.InstructionID, l.DashboardItemID }).ToList(); dgvLogs.ItemsSource = Logss.OrderBy(l => l.DashboardItemID);//.DistinctBy(l => new { l.SaveTime, l.Value, l.InstructionID, l.DashboardItemID }); } catch (Exception ex) { errorLog.SaveLog(ex); throw; } }
public T Get(string Key, Func <T> func, TimeSpan duration) { T entity = default(T); entity = Get(Key); if (entity == default(T)) { entity = func(); lock (this) { ICacheEntity <T> cacheEntity = new CacheEntity <T>() { Target = entity, ExpirtTime = DateTime.UtcNow.Add(duration) }; Pool[Key] = cacheEntity; } } return(entity); }
public override void EntityUpdate() { if ((CacheEntity.MovementSecure == MovementSecure.ServerAuthoritative && !IsServer) || (CacheEntity.MovementSecure == MovementSecure.NotSecure && !IsOwnerClient)) { return; } UpdateMovement(Time.deltaTime); tempMovementState = tempMoveDirection.sqrMagnitude > 0f ? tempMovementState : MovementState.None; if (isUnderWater) { tempMovementState |= MovementState.IsUnderWater; } if (CacheOpenCharacterController.isGrounded || airborneElapsed < airborneDelay) { tempMovementState |= MovementState.IsGrounded; } CacheEntity.SetMovement(tempMovementState); }
internal Row(CacheEntity <SPSite> site) { Url = site.CachedObject.Url; Id = site.CachedObject.ID; User = site.User.IsAuthenticated ? site.User.Name : "SHAREPOINT\\system"; LastUsed = (int)(DateTime.Now - site.LastUsed).TotalSeconds; bool entered = false; try { entered = Monitor.TryEnter(site.CachedObject); Locked = !entered; } finally { if (entered) { Monitor.Exit(site.CachedObject); } } }
internal Row(CacheEntity <SPWeb> web) { Url = web.CachedObject.Url; Id = web.CachedObject.ID; User = web.CachedObject.CurrentUser.LoginName; LastUsed = (int)(DateTime.Now - web.LastUsed).TotalSeconds; bool entered = false; try { entered = Monitor.TryEnter(web.CachedObject); Locked = !entered; } finally { if (entered) { Monitor.Exit(web.CachedObject); } } }
public override void SetLookRotation(Quaternion rotation) { if (!CacheEntity.CanMove()) { return; } switch (CacheEntity.MovementSecure) { case MovementSecure.ServerAuthoritative: // Cast to short to reduce packet size CallNetFunction(NetFuncUpdateYRotation, DeliveryMethod.Sequenced, FunctionReceivers.Server, (short)rotation.eulerAngles.y); break; case MovementSecure.NotSecure: if (!HasNavPaths) { yRotation = rotation.eulerAngles.y; } break; } }
//public static IQueryable<OptionBasicInformation> Get(out DBCacheStatus status) //{ // if (LastUpdated.Value.Add(TimeSpan.FromMinutes(60)) <= DateTime.UtcNow) // { // status = DBCacheStatus.Ok; // } // else // { // status = DBCacheStatus.Expired; // } // return OptionBasicInformationCache; //} public IQueryable <TEntity> Get <TEntity>(out DBCacheStatus status) { CacheEntity type = CacheEntityMap.GetEntityTypeForDBEntity <TEntity>(); CacheStatus cacheStatus = Uow.CacheStatusesRepository.GetCacheStatus(type); if (cacheStatus.Status == CacheEntryStatus.Empty || cacheStatus.Status == CacheEntryStatus.UpdateInProgress) { status = DBCacheStatus.Empty; return(null); } TimeSpan expiration = GetExpirationForEntity(type); ICachedEntitiesRepository <TEntity> entityRepository = Uow.GetRepository <ICachedEntitiesRepository <TEntity> >(); if (!cacheStatus.LastUpdated.HasValue || cacheStatus.LastUpdated.Value.Add(expiration) <= DateTime.UtcNow) { status = DBCacheStatus.Expired; return(entityRepository.GetAll()); } if (type == CacheEntity.OptionBasicInformation) { if (OptionBasicInformationCache == null) { var repository = (IList <OptionBasicInformationCache>)entityRepository.GetAll().ToList(); OptionBasicInformationCache = (List <OptionBasicInformationCache>)repository; } } else { if (SecurityInformationCache == null) { var repository = (IList <SecurityInformationCache>)entityRepository.GetAll().ToList(); SecurityInformationCache = (List <SecurityInformationCache>)entityRepository.GetAll(); } } status = DBCacheStatus.Ok; return(entityRepository.GetAll()); }
protected void NetFuncKeyMovement(DirectionVector3 inputDirection, MovementState movementState) { if (!CacheEntity.CanMove()) { return; } tempInputDirection = inputDirection; tempMovementState = movementState; if (tempInputDirection.sqrMagnitude > 0) { navPaths = null; } if (canFly && !CacheOpenCharacterController.isGrounded && !isUnderWater && tempMovementState.HasFlag(MovementState.IsJump)) { isFlying = true; isJumping = false; applyingJumpForce = false; } if (!isJumping && !applyingJumpForce) { isJumping = (CacheOpenCharacterController.isGrounded || isUnderWater) && tempMovementState.HasFlag(MovementState.IsJump); } }
public IQueryable <TDbEntity> Get <TDbEntity>(out DBCacheStatus status) { CacheEntity type = CacheEntityMap.GetEntityTypeForDBEntity <TDbEntity>(); CacheStatus cacheStatus = Uow.CacheStatusesRepository.GetCacheStatus(type); ICachedEntitiesRepository <TDbEntity> entityRepository = Uow.GetRepository <ICachedEntitiesRepository <TDbEntity> >(); if (cacheStatus.Status == CacheEntryStatus.Empty || cacheStatus.Status == CacheEntryStatus.UpdateInProgress) { status = DBCacheStatus.Empty; return(null); } TimeSpan expiration = GetExpirationForEntity(type); if (!cacheStatus.LastUpdated.HasValue || cacheStatus.LastUpdated.Value.Add(expiration) <= DateTime.UtcNow) { status = DBCacheStatus.Expired; return(entityRepository.GetAll()); } status = DBCacheStatus.Ok; return(entityRepository.GetAll()); }
public static DataSet GetCashedDataset(string dbkey, string spName, int timeOut, params object[] parameterValues) { dbkey = dbkey.ToLower(); string key = GetKeyFromSpCommand(dbkey, spName, parameterValues); CacheEntity ce = _datasetHash[key] as CacheEntity; if (ce == null) { return(null); } if (timeOut <= 0) { return(ce.Data); } if (System.DateTime.Now.AddSeconds(0 - timeOut).CompareTo(ce.TimeStamp) < 0) { return(ce.Data); } else { return(null); } }
public async void Must_not_throw_exception_if_same_entity_is_added_more_than_once() { var observer = MockRepository.GenerateMock<ISessionObserver<CacheKey, object>>(); using (INonTransactionalCacheKeySession session = await SessionManager.Enroll(observer)) { var cacheEntity = new CacheEntity<object>(new Entity1(), Guid.NewGuid()); session.EntityWasPersisted(cacheEntity); Assert.DoesNotThrow(() => session.EntityWasPersisted(cacheEntity)); observer.AssertWasCalled(arg => arg.EntityPersisted(session, new Entity1().GetType(), cacheEntity.Id), options => options.Repeat.Twice()); } }
public async void Must_throw_exception_if_same_entity_is_added_with_different_id() { using (INonTransactionalCacheKeySession session = await SessionManager.Enroll()) { var entity = new Entity1(); var cacheEntity1 = new CacheEntity<object>(entity, Guid.NewGuid()); var cacheEntity2 = new CacheEntity<object>(entity, Guid.NewGuid()); session.EntityWasPersisted(cacheEntity1); Assert.Throws<SessionException>(() => session.EntityWasPersisted(cacheEntity2)); } }
public async void Must_remove_cache_keys_and_all_their_entities_for_cache_keys_referencing_a_removed_entity() { var observer = MockRepository.GenerateMock<ISessionObserver<CacheKey, object>>(); using (INonTransactionalCacheKeySession session = await SessionManager.Enroll(observer)) { var cacheKey = new CacheKey("test"); Guid entityId = Guid.NewGuid(); var cacheEntities = new[] { new CacheEntity<object>(new Entity1(), Guid.NewGuid()), new CacheEntity<object>(new Entity1(), entityId), new CacheEntity<object>(new Entity1(), Guid.NewGuid()), new CacheEntity<object>(new Entity1(), Guid.NewGuid()), new CacheEntity<object>(new Entity1(), Guid.NewGuid()) }; var addedCacheEntity = new CacheEntity<object>(new Entity1(), Guid.NewGuid()); foreach (CacheEntity<object> cacheEntity in cacheEntities) { CacheEntity<object> tempCacheEntity = cacheEntity; observer.Expect(arg => arg.EntityFound(session, tempCacheEntity.Entity.GetType(), tempCacheEntity.Id)).Repeat.Once(); } observer.Expect(arg => arg.EntityPersisted(session, addedCacheEntity.Entity.GetType(), addedCacheEntity.Id)).Repeat.Once(); observer.Expect(arg => arg.EntityRemoved(session, addedCacheEntity.Entity.GetType(), addedCacheEntity.Id)).Repeat.Once(); foreach (CacheEntity<object> cacheEntity in cacheEntities) { CacheEntity<object> tempCacheEntity = cacheEntity; observer.Expect(arg => arg.EntityRemoved(session, tempCacheEntity.Entity.GetType(), tempCacheEntity.Id)).Repeat.Once(); } session.EntitiesWereFound(cacheKey, cacheEntities); session.EntityWasPersisted(addedCacheEntity); session.RemoveEntity(entityId); } observer.VerifyAllExpectations(); }
public async void Must_replace_cached_entities_with_new_entity_instances() { var observer = MockRepository.GenerateMock<ISessionObserver<CacheKey, object>>(); using (INonTransactionalCacheKeySession session = await SessionManager.Enroll(observer)) { var cacheKey = new CacheKey("test"); var cacheEntityA1 = new CacheEntity<object>(new Entity1(), Guid.NewGuid()); var cacheEntityA2 = new CacheEntity<object>(new Entity1(), Guid.NewGuid()); var cacheEntityB1 = new CacheEntity<object>(new Entity1(), cacheEntityA1.Id); var cacheEntityB2 = new CacheEntity<object>(new Entity1(), cacheEntityA2.Id); observer.Expect(arg => arg.EntityFound(session, cacheEntityA1.GetType(), cacheEntityA1.Id)).Repeat.Once(); observer.Expect(arg => arg.EntityFound(session, cacheEntityA2.GetType(), cacheEntityA2.Id)).Repeat.Once(); observer.Expect(arg => arg.EntityFound(session, cacheEntityB1.GetType(), cacheEntityB1.Id)).Repeat.Once(); observer.Expect(arg => arg.EntityFound(session, cacheEntityB2.GetType(), cacheEntityB2.Id)).Repeat.Once(); session.EntitiesWereFound(cacheKey, new[] { cacheEntityA1, cacheEntityA2 }); session.EntitiesWereFound(cacheKey, new[] { cacheEntityB1, cacheEntityB2 }); } }
// 主线程中回调 private static void TranslateAsyncEnd(object arg) { HttpRequest req = arg as HttpRequest; if (req.IsFront) { // 通知关闭网络提示 Notifier.Notify(NetState.Succeed); mFrontRequest = null; } // 通知数据被修改 if (DataManager.UpdatesCache != null) { Dictionary<BaseData, CacheEntity> dic = new Dictionary<BaseData, CacheEntity>(); for (int i = 0; i != DataManager.UpdatesCache.Count; i++) { object[] arr = DataManager.UpdatesCache[i] as object[]; if (arr == null || arr.Length != 4) continue; BaseData data = (BaseData)arr[0]; string fieldName = arr[1].ToString(); object newValue = arr[2]; object oldValue = arr[3]; // 检测是否为同一个对象 CacheEntity entity = null; if (!dic.TryGetValue(data, out entity)) { entity = new CacheEntity(); dic.Add(data, entity); } entity.names.Add(fieldName); entity.newValues.Add(newValue); entity.oldValues.Add(oldValue); data.OnDataUpdate(fieldName, newValue, oldValue); } // 遍历dic using (Dictionary<BaseData, CacheEntity>.Enumerator erator = dic.GetEnumerator()) { while (erator.MoveNext()) { CacheEntity entity = erator.Current.Value; erator.Current.Key.OnDataUpdate(entity.names, entity.newValues, entity.oldValues); } } DataManager.UpdatesCache.Clear(); } if (DataManager.DeletesCache.Count > 0) { foreach (BaseData data in DataManager.DeletesCache) { data.OnDataDelete(); } DataManager.DeletesCache.Clear(); } if (DataManager.AddsCache.Count > 0) { foreach (BaseData data in DataManager.AddsCache) { data.OnDataAdd(); } DataManager.AddsCache.Clear(); } // 回调 req.Callback(); req.Dispose(); }