Ejemplo n.º 1
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;
        }
        public static ItemQuery QueryForKey(ItemKey key)
        {
            if (key == null)
            {
                throw new ArgumentNullException("key");
            }

            var query = new ItemQuery();

            query.Keys = new[] { key };

            return(query);
        }
        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)
                );
        }
        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)
                );
        }
 public IAsyncAction RemoveItemAsync(ItemKey key)
 {
     return m_record.RemoveAsync(key);
 }
        internal async Task<IItemDataTyped> RefreshAndGetAsyncImpl(ItemKey key)
        {
            RecordItem item = await RefreshAndGetItemAsyncImpl(key);
            if (item == null || !item.HasTypedData)
            {
                return null;
            }

            return item.TypedData;
        }
        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> EnsureItemAvailableAndGetByKeyAsync(ItemKey key)
 {
     if (key == null)
     {
         throw new ArgumentNullException("key");
     }
     return AsyncInfo.Run(async cancelToken =>
     {
         return await this.GetItemByKeyAsync(key, true, cancelToken);
     });
 }
 // Returns null if no lock acquired (somebody else owns it)
 internal RecordItemLock AcquireItemLock(ItemKey key)
 {
     return this.Data.Locks.AcquireItemLock(key.ID);
 }
        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 IAsyncOperation<IItemDataTyped> GetLocalItemByKeyAsync(ItemKey key)
 {
     return AsyncInfo.Run(async cancelToken =>
     {
         using (await CrossThreadLockScope.Enter(m_lock))
         {
             return await m_items.GetLocalItemByKeyAsync(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();
                    }
                }
            });            
        }
        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;
            }));
        }
Ejemplo n.º 14
0
 public IAsyncOperation<RecordItem> GetItemAsync(ItemKey key, ItemSectionType sections)
 {
     return GetItemAsync(key, null, sections);
 }
        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);
                }
            });
        }
        public IAsyncAction RemoveItemAsync(ItemKey key)
        {
            key.ValidateRequired("key");

            return AsyncInfo.Run(async cancelToken =>
            {                          
                using (await CrossThreadLockScope.Enter(m_lock))
                {
                    await m_objectStore.DeleteAsync(key.ID);
                }
             });
        }
        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);
        }
        /// <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 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;    
        }
Ejemplo n.º 20
0
 public IAsyncAction RemoveAsync(ItemKey key)
 {
     return RemoveMultipleAsync(new[] {key});
 }
        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;
            }
        }
Ejemplo n.º 22
0
        public IAsyncOperation<RecordItem> GetItemAsync(
            ItemKey key,
            string versionType,
            ItemSectionType sections)
        {
            if (key == null)
            {
                throw new ArgumentNullException("key");
            }

            ItemQuery query = ItemQuery.QueryForKey(key);
            query.View.SetSections(sections);

            if (!String.IsNullOrEmpty(versionType))
            {
                query.View.TypeVersions.Add(versionType);
            }

            return AsyncInfo.Run(
                async cancelToken =>
                {
                    ItemQueryResult result = await GetItemsAsync(query).AsTask(cancelToken);
                    return result.FirstItem;
                }
                );
        }
        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;
            }
        }
 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<IItemDataTyped> GetAsync(ItemKey key)
        {
            key.ValidateRequired("key");

            return GetAsyncImpl(key).AsAsyncOperation();
        }
 /// <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<RecordItem> RefreshAndGetItemAsync(ItemKey key)
        {
            key.ValidateRequired("key");

            return RefreshAndGetItemAsyncImpl(key).AsAsyncOperation();
        }
        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);
        }
 // SynchronizedStore calls this to track "Removes"
 internal async Task TrackRemoveAsync(string typeID, ItemKey key)
 {
     await m_changeTable.TrackChangeAsync(typeID, key, RecordItemChangeType.Remove);
 }
 async Task RemoveKeyAsync(ItemKey key)
 {
     using (await CrossThreadLockScope.Enter(m_lock))
     {
         m_items.Keys.RemoveByItemKey(key);
         await this.SaveView();
     }
 }
 public IAsyncOperation<RecordItem> GetItemAsync(ItemKey key, ItemSectionType sections)
 {
     this.ProduceError();
     return m_innerStore.GetItemAsync(key, sections);
 }
Ejemplo n.º 32
0
        public static ItemQuery QueryForKey(ItemKey key)
        {
            if (key == null)
            {
                throw new ArgumentNullException("key");
            }

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

            return query;
        }
 public IAsyncAction RemoveItemAsync(ItemKey key)
 {
     this.ProduceError();
     return m_innerStore.RemoveItemAsync(key);
 }