Beispiel #1
0
        //
        // Returns 0 if lock was not acquired because somebody else already holds it
        // Else returns > 0
        // Does NOT BLOCK
        //
        public long AcquireLock(string itemID)
        {
            if (string.IsNullOrEmpty(itemID))
            {
                throw new ArgumentException("itemID");
            }

            lock (m_locks)
            {
                if (this.GetLock(itemID) != null)
                {
                    return(LockNotAcquired);
                }

                long lockID = this.NextLockID();
                Debug.Assert(RecordItemLockTable.IsValidLockID(lockID));

                m_locks[itemID] = LockData.Create(lockID);
                return(lockID);
            }
        }
Beispiel #2
0
        //
        // Will only write the item to the local store IF:
        //  - Can take the write lock on the item (no pending edits in progress)
        //  - There are no pending changes on the item
        //
        async Task SafePutItemInLocalStoreAsync(RecordItem item)
        {
            long lockID = m_itemLocks.AcquireLock(item.ID);

            if (!RecordItemLockTable.IsValidLockID(lockID))
            {
                return;  // Item is locked for editing. Don't overrwrite yet
            }

            try
            {
                // Make sure there are no pending updates
                if (!await m_changeManager.HasChangesForItemAsync(item.ID))
                {
                    await m_localStore.PutItemAsync(item);
                }
            }
            finally
            {
                m_itemLocks.SafeReleaseLock(item.ID, lockID);
            }
        }
        internal SynchronizedStore(IRecord record, LocalItemStore localStore, RecordItemChangeTable changeTable)
        {
            if (record == null)
            {
                throw new ArgumentNullException("record");
            }
            if (localStore == null)
            {
                throw new ArgumentNullException("itemStore");
            }
            if (changeTable == null)
            {
                throw new ArgumentNullException("changeTable");
            }

            //m_record = record;
            SectionsToFetch = ItemSectionType.Standard;

            m_localStore = localStore;
            m_remoteStore = new RemoteItemStore(record);
            m_changeManager = new RecordItemChangeManager(this, changeTable);
            m_itemLocks = new RecordItemLockTable();
        }
Beispiel #4
0
        internal SynchronizedStore(IRecord record, LocalItemStore localStore, RecordItemChangeTable changeTable)
        {
            if (record == null)
            {
                throw new ArgumentNullException("record");
            }
            if (localStore == null)
            {
                throw new ArgumentNullException("itemStore");
            }
            if (changeTable == null)
            {
                throw new ArgumentNullException("changeTable");
            }

            //m_record = record;
            SectionsToFetch = ItemSectionType.Standard;

            m_localStore    = localStore;
            m_remoteStore   = new RemoteItemStore(record);
            m_changeManager = new RecordItemChangeManager(this, changeTable);
            m_itemLocks     = new RecordItemLockTable();
        }
Beispiel #5
0
 internal RecordItemLock(RecordItemLockTable lockTable, string itemID, long lockID)
 {
     m_lockTable = lockTable;
     m_lockID    = lockID;
     m_itemID    = itemID;
 }
 internal RecordItemLock(RecordItemLockTable lockTable, string itemID, long lockID)
 {
     m_lockTable = lockTable;
     m_lockID = lockID;
     m_itemID = itemID;
 }