public CacheChangeData(Guid cacheId, CacheChange change, ICoreItem oldItem, ICoreItem newItem) { CacheId = cacheId; Change = change; OldItem = oldItem; NewItem = newItem; }
protected override void OnUpdate(CacheChange change, string userKey, string oldValue, string newValue, object userParam) { switch (change) { case CacheChange.CacheCleared: ClearedCount += 1; break; case CacheChange.ItemCreated: CreatedCount += 1; break; case CacheChange.ItemUpdated: UpdatedCount += 1; break; case CacheChange.ItemRemoved: RemovedCount += 1; break; case CacheChange.ItemExpired: ExpiredCount += 1; break; default: throw new NotSupportedException("CacheChange=" + change); } }
protected override void OnUpdate(CacheChange change, string userKey, ICoreItem oldValue, ICoreItem newValue, CoreItemCacheParams userParam) { switch (change) { case CacheChange.CacheCleared: if (oldValue != null) { throw new ArgumentException("oldValue"); } if (newValue != null) { throw new ArgumentException("newValue"); } _updates.Add(new CacheChangeData(_cacheId, change, null, null)); break; case CacheChange.ItemCreated: if (oldValue != null) { throw new ArgumentException("oldValue"); } if (newValue == null) { throw new ArgumentException("newValue"); } _updates.Add(new CacheChangeData(_cacheId, change, null, newValue)); Interlocked.Increment(ref _itemsCreated); break; case CacheChange.ItemExpired: case CacheChange.ItemRemoved: if (oldValue == null) { throw new ArgumentException("oldValue"); } if (newValue != null) { throw new ArgumentException("newValue"); } _updates.Add(new CacheChangeData(_cacheId, change, oldValue, null)); Interlocked.Increment(ref _itemsDeleted); break; case CacheChange.ItemUpdated: if (oldValue == null) { throw new ArgumentException("oldValue"); } if (newValue == null) { throw new ArgumentException("newValue"); } if (newValue.Id != oldValue.Id) { _updates.Add(new CacheChangeData(_cacheId, change, oldValue, newValue)); Interlocked.Increment(ref _itemsUpdated); } break; } }
private void ProgressCallback(ISubscription subscription, ICoreItem item) { try { ProgressObj oldProgress = null; ProgressObj newProgress = null; if (item != null) { // get old request view object Guid requestId = item.AppProps.GetValue <Guid>(RequestBase.Prop.RequestId, true); oldProgress = _ProgressCache.Remove(requestId); // build the new request view object if (item.IsCurrent()) { if (item.DataType.IsSubclassOf(typeof(RequestBase))) { RequestBase request = item.Data as RequestBase; if (request != null) { newProgress = new ProgressObj(requestId, item.Created, oldProgress, request); } } else if (item.DataType.IsSubclassOf(typeof(ResponseBase))) { ResponseBase response = item.Data as ResponseBase; if (response != null) { newProgress = new ProgressObj(requestId, item.Created, oldProgress, response); } } else { throw new NotSupportedException(String.Format("Type: '{0}'", item.DataType.Name)); } } if (newProgress != null) { _ProgressCache.Set(requestId, newProgress); } } else { throw new ArgumentNullException("item"); } // determine the change type CacheChange change = CacheChange.Undefined; if (oldProgress != null) { // updated or deleted if (newProgress != null) { change = CacheChange.ItemUpdated; } else { change = CacheChange.ItemRemoved; } } else { // created or ??? if (newProgress != null) { change = CacheChange.ItemCreated; } } if (change != CacheChange.Undefined) { _ProgressView.UpdateData(new ViewChangeNotification <ProgressObj>() { Change = change, OldData = oldProgress, NewData = newProgress }); } } catch (Exception excp) { _MainLog.Log(excp); } }