Beispiel #1
0
        public bool EqualsKey(ItemKey key)
        {
            if (key == null)
            {
                return false;
            }

            if (ReferenceEquals(this, key))
            {
                return true;
            }

            return (
                ID.SafeEquals(key.ID, StringComparison.Ordinal) &&
                    Version.SafeEquals(key.Version, StringComparison.Ordinal)
                );
        }
        internal async Task<IItemDataTyped> RefreshAndGetAsyncImpl(ItemKey key)
        {
            RecordItem item = await RefreshAndGetItemAsyncImpl(key);
            if (item == null || !item.HasTypedData)
            {
                return null;
            }

            return item.TypedData;
        }
        internal async Task<IItemDataTyped> GetItemByKeyAsync(ItemKey key, bool shouldAwaitRefresh, CancellationToken cancelToken)
        {
            if (key == null)
            {
                throw new ArgumentNullException("key");
            }
            int index = m_data.Keys.IndexOfItemKey(key);
            if (index < 0)
            {
                return null;
            }

            return await this.GetItemAsync(index, shouldAwaitRefresh, cancelToken);
        }
 public IAsyncOperation<IItemDataTyped> GetLocalItemByKeyAsync(ItemKey key)
 {
     if (key == null)
     {
         throw new ArgumentNullException("key");
     }
     return AsyncInfo.Run(async cancelToken =>
     {
         return await this.LoadLocalItemAsync(key);
     }); 
 }
 async Task RemoveKeyAsync(ItemKey key)
 {
     using (await CrossThreadLockScope.Enter(m_lock))
     {
         m_items.Keys.RemoveByItemKey(key);
         await this.SaveView();
     }
 }
        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>
 /// 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;
     });
 }
 public IAsyncOperation<IItemDataTyped> EnsureItemAvailableAndGetByKeyAsync(ItemKey key)
 {
     if (key == null)
     {
         throw new ArgumentNullException("key");
     }
     return AsyncInfo.Run(async cancelToken =>
     {
         using (await CrossThreadLockScope.Enter(m_lock))
         {
             return await m_items.GetItemByKeyAsync(key, true, cancelToken);
         }
     });
 }
 public IAsyncOperation<RecordItem> GetItemAsync(ItemKey key, ItemSectionType sections)
 {
     return m_record.GetItemAsync(key, sections);
 }
 public IAsyncAction RemoveItemAsync(ItemKey key)
 {
     this.ProduceError();
     return m_innerStore.RemoveItemAsync(key);
 }
 public IAsyncOperation<RecordItem> GetItemAsync(ItemKey key, ItemSectionType sections)
 {
     this.ProduceError();
     return m_innerStore.GetItemAsync(key, sections);
 }
        public IAsyncOperation<RecordItem> RefreshAndGetItemAsync(ItemKey key)
        {
            key.ValidateRequired("key");

            return RefreshAndGetItemAsyncImpl(key).AsAsyncOperation();
        }
        public IAsyncOperation<IItemDataTyped> GetAsync(ItemKey key)
        {
            key.ValidateRequired("key");

            return GetAsyncImpl(key).AsAsyncOperation();
        }
        internal async Task<RecordItem> RefreshAndGetItemAsyncImpl(ItemKey key)
        {
            using (await CrossThreadLockScope.Enter(m_lock))
            {
                var item = (RecordItem)await m_objectStore.RefreshAndGetAsync(key.ID, typeof(RecordItem));
                if (item == null)
                {
                    return null;
                }
                //
                // Verify the version stamp
                //
                if (!item.Key.IsVersion(key.Version))
                {
                    return null;
                }

                return item;
            }
        }
        internal async Task<RecordItem> GetItemAsyncImpl(ItemKey key)
        {
            using (await CrossThreadLockScope.Enter(m_lock))
            {
                RecordItem item = await this.GetItemFromStore(key.ID);
                if (item == null)
                {
                    return null;
                }
                //
                // Verify the version stamp
                //
                if (!item.Key.IsVersion(key.Version))
                {
                    return null;
                }

                return item;
            }
        }
        public static IAsyncOperation<ItemDataBlob> GetBlobDataAsync(IRecord record, ItemKey key)
        {
            if (record == null)
            {
                throw new ArgumentNullException("record");
            }

            return AsyncInfo.Run(
                async cancelToken =>
                      {
                          RecordItem item = await record.GetItemAsync(key, ItemSectionType.Blobs).AsTask(cancelToken);
                          return (item != null) ? item.BlobData : null;
                      });
        }
 public IAsyncOperation<IItemDataTyped> GetLocalItemByKeyAsync(ItemKey key)
 {
     return AsyncInfo.Run(async cancelToken =>
     {
         using (await CrossThreadLockScope.Enter(m_lock))
         {
             return await m_items.GetLocalItemByKeyAsync(key);
         }
     });
 }
 public IAsyncAction RemoveItemAsync(ItemKey key)
 {
     return m_record.RemoveAsync(key);
 }
        /// <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();
                    }
                }
            });            
        }
Beispiel #20
0
        public static int Compare(ItemKey key1, ItemKey key2)
        {
            if (key1 == null)
            {
                if (key2 == null)
                {
                    return 0;
                }

                return -1;
            }

            if (key2 == null)
            {
                return 1;
            }

            int cmp = string.CompareOrdinal(key1.ID, key2.ID);
            if (cmp == 0)
            {
                cmp = string.CompareOrdinal(key1.Version, key2.Version);
            }

            return cmp;
        }
 // Returns null if no lock acquired (somebody else owns it)
 internal RecordItemLock AcquireItemLock(ItemKey key)
 {
     return this.Data.Locks.AcquireItemLock(key.ID);
 }
        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;
        }
        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 InitChange(ItemKey key, RecordItemChangeType changeType)
 {
     this.Key = key;
     this.ChangeType = changeType;
     this.SetChangeID();
     this.SetTimestamp();
 }
 public int IndexOfItemKey(ItemKey key)
 {
     return m_data.Keys.IndexOfItemKey(key);
 }
 internal RecordItemChange(string typeID, ItemKey key, RecordItemChangeType changeType)
 {
     this.TypeID = typeID;
     this.InitChange(key, changeType);
 }
 public IAsyncOperation<IItemDataTyped> EnsureItemAvailableAndGetByKeyAsync(ItemKey key)
 {
     if (key == null)
     {
         throw new ArgumentNullException("key");
     }
     return AsyncInfo.Run(async cancelToken =>
     {
         return await this.GetItemByKeyAsync(key, true, cancelToken);
     });
 }
Beispiel #28
0
        public static ItemQuery QueryForKey(ItemKey key)
        {
            if (key == null)
            {
                throw new ArgumentNullException("key");
            }

            var query = new ItemQuery();
            query.Keys = new[] {key};

            return query;
        }
        internal async Task<IItemDataTyped> LoadLocalItemAsync(ItemKey key)
        {
            IItemDataTyped item = await m_store.Local.GetAsyncImpl(key);
            if (item != null && m_data.TypeVersions.Contains(item.Type.ID))
            {
                return item;
            }

            return null;    
        }
        public IAsyncOperation<DateTimeOffset> UpdateDateForAsync(ItemKey key)
        {
            if (key == null)
            {
                throw new ArgumentNullException("key");
            }

            return AsyncInfo.Run(async cancelToken =>
            {
                using (await CrossThreadLockScope.Enter(m_lock))
                {
                    return await m_objectStore.GetUpdateDateAsync(key.ID);
                }
            });
        }