示例#1
0
 void InitChange(ItemKey key, RecordItemChangeType changeType)
 {
     this.Key        = key;
     this.ChangeType = changeType;
     this.SetChangeID();
     this.SetTimestamp();
 }
        //
        // In practice, RecordChangeToItem is accessed by SynchronizedStore, which prevents simultaneous changes to
        // an item by taking an item lock
        //
        public void TrackChangeToItem(RecordItem item, RecordItemChangeType changeType)
        {
            if (item == null)
            {
                throw new ArgumentNullException("item");
            }

            item.Key.ValidateRequired("item.Key");
            item.Type.ValidateRequired("item.Type");

            this.TrackChange(item.Type.ID, item.Key, changeType);
        }
        public void TrackChange(string typeID, ItemKey key, RecordItemChangeType changeType)
        {
            if (string.IsNullOrEmpty(typeID))
            {
                throw new ArgumentException("typeID");
            }
            if (key == null)
            {
                throw new ArgumentException("key");
            }

            m_changes[key.ID] = RecordItemChange.UpdateChange(typeID, key, changeType, this.GetChange(key.ID));
        }
示例#4
0
        public static RecordItemChange UpdateChange(string typeID, ItemKey key, RecordItemChangeType changeType, RecordItemChange existingChange)
        {
            if (existingChange == null)
            {
                return(new RecordItemChange(typeID, key, changeType));
            }

            if (existingChange.ChangeType == RecordItemChangeType.Remove && changeType == RecordItemChangeType.Put)
            {
                // Can't put an item already marked for deletion
                throw new StoreException(StoreErrorNumber.ItemAlreadyDeleted);
            }

            if (existingChange.TypeID != typeID)
            {
                // Defensive code. Should never happen
                throw new StoreException(StoreErrorNumber.TypeIDMismatch);
            }

            existingChange.InitChange(key, changeType);

            return(existingChange);
        }
示例#5
0
        // TRACK CHANGES for the given typeID & key
        public IAsyncAction TrackChangeAsync(string typeID, ItemKey key, RecordItemChangeType changeType)
        {
            if (string.IsNullOrEmpty(typeID))
            {
                throw new ArgumentException("typeID");
            }
            if (key == null)
            {
                throw new ArgumentException("key");
            }

            return(AsyncInfo.Run(async cancelToken =>
            {
                using (await CrossThreadLockScope.Enter(m_lock))
                {
                    RecordItemChange change = await this.GetChangeAsync(key.ID);
                    change = RecordItemChange.UpdateChange(typeID, key, changeType, change);

                    await this.SaveChangeAsync(change);

                    this.UpdateIndex(key.ID);
                }
            }));
        }
示例#6
0
 internal RecordItemChange(string typeID, ItemKey key, RecordItemChangeType changeType)
 {
     this.TypeID = typeID;
     this.InitChange(key, changeType);
 }
 internal RecordItemChange(string typeID, ItemKey key, RecordItemChangeType changeType)
 {
     this.TypeID = typeID;
     this.InitChange(key, changeType);
 }
 void InitChange(ItemKey key, RecordItemChangeType changeType)
 {
     this.Key = key;
     this.ChangeType = changeType;
     this.SetChangeID();
     this.SetTimestamp();
 }
        public static RecordItemChange UpdateChange(string typeID, ItemKey key, RecordItemChangeType changeType, RecordItemChange existingChange)
        {
            if (existingChange == null)
            {
                return new RecordItemChange(typeID, key, changeType);
            }

            if (existingChange.ChangeType == RecordItemChangeType.Remove && changeType == RecordItemChangeType.Put)
            {
                // Can't put an item already marked for deletion
                throw new StoreException(StoreErrorNumber.ItemAlreadyDeleted);
            }

            if (existingChange.TypeID != typeID)
            {
                // Defensive code. Should never happen
                throw new StoreException(StoreErrorNumber.TypeIDMismatch);
            }

            existingChange.InitChange(key, changeType);

            return existingChange;
        }
        // TRACK CHANGES for the given typeID & key
        public IAsyncAction TrackChangeAsync(string typeID, ItemKey key, RecordItemChangeType changeType)
        {
            if (string.IsNullOrEmpty(typeID))
            {
                throw new ArgumentException("typeID");
            }
            if (key == null)
            {
                throw new ArgumentException("key");
            }

            return AsyncInfo.Run(async cancelToken =>
            {
                using (await CrossThreadLockScope.Enter(m_lock))
                {
                    RecordItemChange change = await this.GetChangeAsync(key.ID);
                    change = RecordItemChange.UpdateChange(typeID, key, changeType, change);

                    await this.SaveChangeAsync(change);

                    this.UpdateIndex(key.ID);                    
                }
            });
        }