/// <summary> /// Returns null if: /// 1. Could not take a lock on the item /// 2. Item was not available locally /// /// When you are done editing, call CommitAsync() on the RecordItemEditOperation /// To abort, call RecordItemEditOperation::Cancel() /// /// </summary> public IAsyncOperation <RecordItemEditOperation> OpenForEditAsync(ItemKey key) { if (key == null) { throw new ArgumentNullException("key"); } return(AsyncInfo.Run <RecordItemEditOperation>(async cancelToken => { RecordItemLock rLock = this.AcquireItemLock(key); if (rLock == null) { return null; } RecordItemEditOperation editOp = null; try { editOp = await this.OpenForEditAsync(key, rLock); return editOp; } finally { if (editOp == null) { rLock.Release(); } } })); }
void ReleaseLock() { if (m_rLock != null) { m_rLock.Release(); m_rLock = null; } }
/// <summary> /// Updates an existing item. To update, you must first acquire a lock on it, and prove that you own the lock. /// Note: if you use higher level objects like SynchronizedStore, you won't have to acquire locks yourself. /// </summary> public IAsyncAction PutAsync(IItemDataTyped item, RecordItemLock itemLock) { if (item == null) { throw new ArgumentNullException("item"); } return(this.PutItemAsync(item.Item, itemLock)); }
internal IAsyncAction PutAsync(IItemDataTyped item, RecordItemLock itemLock) { this.ValidateItem(item); return(AsyncInfo.Run(async cancelToken => { await this.Data.PutAsync(item, itemLock); await this.UpdateKeyAsync(item.Item); })); }
internal IAsyncAction RemoveAsync(ItemKey key, RecordItemLock itemLock) { key.ValidateRequired("key"); return(AsyncInfo.Run(async cancelToken => { await this.Data.RemoveItemAsync(m_typeID, key, itemLock); await this.RemoveKeyAsync(key); })); }
void Dispose(bool fromDispose) { if (fromDispose) { this.ReleaseLock(); GC.SuppressFinalize(this); } m_rLock = null; }
internal async Task <RecordItemEditOperation> OpenForEditAsync(ItemKey key, RecordItemLock itemLock) { IItemDataTyped data = await this.EnsureItemAvailableAndGetByKeyAsync(key); if (data == null) { return(null); } return(new RecordItemEditOperation(this, data, itemLock)); }
/// <summary> /// Remove an item. To remove, you must first acquire a lock on the item, and prove that you own the lock. /// If you use the higher level SychronizedType object, you won't have to acquire the lock yourself /// </summary> public IAsyncAction RemoveItemAsync(string typeID, ItemKey itemKey, RecordItemLock itemLock) { itemKey.ValidateRequired("key"); if (itemLock == null) { throw new ArgumentNullException("itemLock"); } m_itemLocks.ValidateLock(itemKey.ID, itemLock.LockID); return(AsyncInfo.Run(async cancelToken => { await m_localStore.RemoveItemAsync(itemKey); await m_changeManager.TrackRemoveAsync(typeID, itemKey); })); }
public IAsyncAction NewItemAsync(RecordItem item) { if (item == null) { throw new ArgumentNullException("item"); } SynchronizedStore.PrepareForNew(item); return(AsyncInfo.Run(async cancelToken => { RecordItemLock rlock = m_itemLocks.AcquireItemLock(item.ID); if (rlock != null) { using (rlock) { await this.PutItemAsync(item, rlock); } } })); }
public IAsyncAction PutItemAsync(RecordItem item, RecordItemLock itemLock) { if (item == null) { throw new ArgumentNullException("item"); } if (itemLock == null) { throw new ArgumentNullException("itemLock"); } m_itemLocks.ValidateLock(item.ID, itemLock.LockID); item.UpdateEffectiveDate(); return(AsyncInfo.Run(async cancelToken => { await m_localStore.PutItemAsync(item); await m_changeManager.TrackPutAsync(item); })); }
/// <summary> /// Before removing the item, will try to take a lock on the item in question. /// If it can't, it will return FALSE /// </summary> public IAsyncOperation <bool> RemoveAsync(ItemKey key) { if (key == null) { throw new ArgumentNullException("key"); } return(AsyncInfo.Run(async cancelToken => { RecordItemLock rLock = this.AcquireItemLock(key); if (rLock == null) { return false; } using (rLock) { await this.RemoveAsync(key, rLock); } this.StartCommitChanges(); return true; })); }
internal RecordItemLock AcquireItemLock(string itemID) { long lockID = 0; try { lockID = this.AcquireLock(itemID); if (!IsValidLockID(lockID)) { return(null); } RecordItemLock itemLock = new RecordItemLock(this, itemID, lockID); lockID = 0; return(itemLock); } finally { if (IsValidLockID(lockID)) { this.ReleaseLock(itemID, lockID); } } }
/// <summary> /// Add a new item. The item is saved in the local store immediately, and a pending commit to the remote store is put in /// the synchronized store's change queue /// </summary> public IAsyncAction AddNewAsync(IItemDataTyped item) { this.ValidateItem(item); RecordItem recordItem = item.Item; SynchronizedStore.PrepareForNew(recordItem); return(AsyncInfo.Run(async cancelToken => { RecordItemLock rlock = this.AcquireItemLock(recordItem.Key); if (rlock == null) { return; } using (rlock) { await this.Data.PutItemAsync(recordItem, rlock); await this.AddKeyAsync(recordItem); } this.StartCommitChanges(); })); }
internal RecordItemEditOperation(SynchronizedType sType, IItemDataTyped data, RecordItemLock rLock) { m_sType = sType; m_rLock = rLock; m_data = data.Item.DeepClone().TypedData; }
/// <summary> /// Remove an item. To remove, you must first acquire a lock on the item, and prove that you own the lock. /// If you use the higher level SychronizedType object, you won't have to acquire the lock yourself /// </summary> public IAsyncAction RemoveItemAsync(string typeID, ItemKey itemKey, RecordItemLock itemLock) { itemKey.ValidateRequired("key"); if (itemLock == null) { throw new ArgumentNullException("itemLock"); } m_itemLocks.ValidateLock(itemKey.ID, itemLock.LockID); return AsyncInfo.Run(async cancelToken => { await m_localStore.RemoveItemAsync(itemKey); await m_changeManager.TrackRemoveAsync(typeID, itemKey); }); }
internal IAsyncAction PutAsync(IItemDataTyped item, RecordItemLock itemLock) { this.ValidateItem(item); return AsyncInfo.Run(async cancelToken => { await this.Data.PutAsync(item, itemLock); await this.UpdateKeyAsync(item.Item); }); }
internal RecordItemLock AcquireItemLock(string itemID) { long lockID = 0; try { lockID = this.AcquireLock(itemID); if (!IsValidLockID(lockID)) { return null; } RecordItemLock itemLock = new RecordItemLock(this, itemID, lockID); lockID = 0; return itemLock; } finally { if (IsValidLockID(lockID)) { this.ReleaseLock(itemID, lockID); } } }
internal async Task<RecordItemEditOperation> OpenForEditAsync(ItemKey key, RecordItemLock itemLock) { IItemDataTyped data = await this.EnsureItemAvailableAndGetByKeyAsync(key); if (data == null) { return null; } return new RecordItemEditOperation(this, data, itemLock); }
/// <summary> /// Updates an existing item. To update, you must first acquire a lock on it, and prove that you own the lock. /// Note: if you use higher level objects like SynchronizedStore, you won't have to acquire locks yourself. /// </summary> public IAsyncAction PutAsync(IItemDataTyped item, RecordItemLock itemLock) { if (item == null) { throw new ArgumentNullException("item"); } return this.PutItemAsync(item.Item, itemLock); }
internal IAsyncAction RemoveAsync(ItemKey key, RecordItemLock itemLock) { key.ValidateRequired("key"); return AsyncInfo.Run(async cancelToken => { await this.Data.RemoveItemAsync(m_typeID, key, itemLock); await this.RemoveKeyAsync(key); }); }
public IAsyncAction PutItemAsync(RecordItem item, RecordItemLock itemLock) { if (item == null) { throw new ArgumentNullException("item"); } if (itemLock == null) { throw new ArgumentNullException("itemLock"); } m_itemLocks.ValidateLock(item.ID, itemLock.LockID); item.UpdateEffectiveDate(); return AsyncInfo.Run(async cancelToken => { await m_localStore.PutItemAsync(item); await m_changeManager.TrackPutAsync(item); }); }