async Task <bool> CollectNextUpdateBatchAsync()
        {
            m_keyBatch.Clear();
            try
            {
                while (m_updateCandidates.MoveNext())
                {
                    UpdateCandidate candidate = m_updateCandidates.Current;
                    IItemDataTyped  item      = await candidate.Chunk.View.GetLocalItemByKeyAsync(candidate.ViewKey.Key);

                    if (item == null)
                    {
                        m_keyBatch.Add(candidate.ViewKey);
                    }
                    else
                    {
                        candidate.ViewKey.IsLoadPending = false;
                    }

                    if (m_keyBatch.Count >= m_maxBatchSize)
                    {
                        break;
                    }
                }

                return(m_keyBatch.Count > 0);
            }
            catch
            {
                this.ClearUpdateStatusForBatch();
                throw;
            }
        }
Ejemplo n.º 2
0
        async Task <bool> CommitPutAsync(RecordItemChange change, long itemLockID)
        {
            IItemDataTyped item = await m_store.Local.GetByIDAsync(change.ItemID);

            if (item == null)
            {
                return(false);
            }

            change.LocalData = item;
            if (item.Key.IsLocal)
            {
                await this.CommitNewAsync(change);
            }
            else
            {
                await this.CommitUpdateAsync(change);
            }
            //
            // Refetch the item from HealthVault, to get updated dates etc...
            //
            await this.RefreshItemAsync(change, itemLockID);

            return(true);
        }
Ejemplo n.º 3
0
 /// <summary>
 /// Puts a new item into the synchronized store. The new item will be comitted to the remote store in the background
 /// </summary>
 /// <param name="item"></param>
 /// <returns></returns>
 public IAsyncAction NewAsync(IItemDataTyped item)
 {
     if (item == null)
     {
         throw new ArgumentNullException("item");
     }
     return(this.NewItemAsync(item.Item));
 }
Ejemplo n.º 4
0
 /// <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));
 }
Ejemplo n.º 5
0
        public IAsyncOperation <ItemKey> PutAsync(IItemDataTyped data)
        {
            if (data == null)
            {
                throw new ArgumentNullException("data");
            }

            return(PutItemAsync(data.Item));
        }
Ejemplo n.º 6
0
        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);
            }));
        }
Ejemplo n.º 7
0
 public ItemData(IItemDataTyped typedData, ItemDataCommon commonData)
 {
     if (typedData == null)
     {
         throw new ArgumentNullException("typedData");
     }
     Typed = typedData;
     Common = commonData;
 }
 public ItemData(IItemDataTyped typedData, ItemDataCommon commonData)
 {
     if (typedData == null)
     {
         throw new ArgumentNullException("typedData");
     }
     Typed  = typedData;
     Common = commonData;
 }
        public static ViewKey FromTypedData(IItemDataTyped item)
        {
            if (item == null)
            {
                throw new ArgumentNullException("item");
            }

            return(FromItem(item.Item));
        }
Ejemplo n.º 10
0
        public IAsyncOperation <ItemKey> NewAsync(IItemDataTyped data)
        {
            if (data == null)
            {
                throw new ArgumentNullException("data");
            }

            data.Item.PrepareForNew();
            return(PutAsync(data));
        }
Ejemplo n.º 11
0
        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));
        }
        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.º 13
0
 void ValidateItem(IItemDataTyped item)
 {
     if (item == null)
     {
         throw new ArgumentNullException("item");
     }
     item.Type.ValidateRequired("Type");
     if (item.Type.ID != m_typeID)
     {
         throw new ArgumentException("TypeID mismatch");
     }
 }
        internal async Task <IItemDataTyped> GetItemAsync(int index, bool shouldAwaitRefresh, CancellationToken cancelToken)
        {
            if (!m_data.HasKeys)
            {
                return(null);
            }

            m_data.ValidateIndex(index);

            ViewKey viewKey = m_data.Keys[index];
            //
            // Try to load the item from the local store
            //
            IItemDataTyped item = await this.LoadLocalItemAsync(viewKey.Key);

            if (item != null)
            {
                return(item);
            }

            //
            // Don't have the item locally available. Will need to fetch it.
            // While we do this, might as well read ahead
            //
            int startAt;

            if (this.ReadAheadMode == SynchronizedViewReadAheadMode.Page)
            {
                startAt = this.GetStartAtPositionForPage(index, this.ReadAheadChunkSize);
            }
            else
            {
                startAt = index;
            }

            await BeginRefreshAsync(startAt, shouldAwaitRefresh, cancelToken);

            if (!shouldAwaitRefresh)
            {
                return(null);
            }
            //
            // Reload the item
            //
            return(await Store.Local.GetAsyncImpl(viewKey.Key));
        }
        internal async Task <IList <ItemKey> > SelectKeysAsync(PredicateDelegate predicate, CancellationToken cancelToken)
        {
            if (predicate == null)
            {
                throw new ArgumentNullException("predicate");
            }
            List <ItemKey> matches = new List <ItemKey>();

            for (int i = 0, max = this.KeyCount; i < max; ++i)
            {
                IItemDataTyped item = await this.GetItemAsync(i, true, cancelToken);

                if (item != null && predicate(item))
                {
                    matches.Add(item.Key);
                }
            }

            return(matches);
        }
        internal async Task <IList <IItemDataTyped> > EnsureItemsAvailableAndGetAsync(int startAt, int count, CancellationToken cancelToken)
        {
            if (!m_data.HasKeys)
            {
                return(null);
            }

            m_data.ValidateIndex(startAt);
            count = m_data.Keys.GetCorrectedCount(startAt, count);

            var items = new LazyList <IItemDataTyped>();

            for (int i = startAt, max = startAt + count; i < max; ++i)
            {
                IItemDataTyped item = await EnsureItemAvailableAndGetAsync(i).AsTask(cancelToken);

                items.Add(item);
            }

            return(items.HasValue ? items.Value : null);
        }
        internal async Task <IList <IItemDataTyped> > GetItemsAsync(int startAt, int count, bool shouldAwaitRefresh, CancellationToken cancelToken)
        {
            if (!m_data.HasKeys)
            {
                return(null);
            }

            m_data.ValidateIndex(startAt);
            count = m_data.Keys.GetCorrectedCount(startAt, count);

            var items = new LazyList <IItemDataTyped>();

            for (int i = startAt, max = startAt + count; i < max; ++i)
            {
                IItemDataTyped item = await GetItemAsync(i, shouldAwaitRefresh, cancelToken);

                items.Add(item);
            }

            return(items.HasValue ? items.Value : null);
        }
        internal async Task <IList <IItemDataTyped> > GetMultipleAsyncImpl(
            IEnumerable <ItemKey> keys, bool includeNullItems)
        {
            var items = new LazyList <IItemDataTyped>();

            foreach (ItemKey key in keys)
            {
                key.Validate();

                IItemDataTyped item = await GetAsyncImpl(key);

                if (includeNullItems)
                {
                    items.Add(item);
                }
                else if (item != null)
                {
                    items.Add(item);
                }
            }

            return((items.Count > 0) ? items.Value : null);
        }
Ejemplo n.º 19
0
        /// <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();
            }));
        }
 public IAsyncOperation <ItemKey> PutAsync(IItemDataTyped item)
 {
     this.ProduceError();
     return(m_innerStore.PutAsync(item));
 }
Ejemplo n.º 21
0
 public ItemData(IItemDataTyped typedData)
     : this(typedData, null)
 {
 }
Ejemplo n.º 22
0
 public IAsyncOperation<ItemKey> PutAsync(IItemDataTyped item)
 {
     return m_record.UpdateAsync(item);
 }
Ejemplo n.º 23
0
 public RecordItem(string typeID, IItemDataTyped typedData)
     : this()
 {
     Type = new ItemType(typeID);
     Data = new ItemData(typedData);
 }
Ejemplo n.º 24
0
        public IAsyncOperation<ItemKey> PutAsync(IItemDataTyped data)
        {
            if (data == null)
            {
                throw new ArgumentNullException("data");
            }

            return PutItemAsync(data.Item);
        }
Ejemplo n.º 25
0
        public IAsyncAction PutAsync(IItemDataTyped item)
        {
            if (item == null)
            {
                throw new ArgumentNullException("item");
            }

            return PutItemAsync(item.Item);
        }
Ejemplo n.º 26
0
 internal RecordItemEditOperation(SynchronizedType sType, IItemDataTyped data, RecordItemLock rLock)
 {
     m_sType = sType;
     m_rLock = rLock;
     m_data  = data.Item.DeepClone().TypedData;
 }
Ejemplo n.º 27
0
 public RecordItem(string typeID, IItemDataTyped typedData) : this()
 {
     Type = new ItemType(typeID);
     Data = new ItemData(typedData);
 }
Ejemplo n.º 28
0
 public IAsyncOperation<ItemKey> PutAsync(IItemDataTyped item)
 {
     this.ProduceError();
     return m_innerStore.PutAsync(item);
 }
        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 RecordItemEditOperation(SynchronizedType sType, IItemDataTyped data, RecordItemLock rLock)
 {
     m_sType = sType;
     m_rLock = rLock;
     m_data = data.Item.DeepClone().TypedData;
 }
 public IAsyncOperation <ItemKey> NewAsync(IItemDataTyped item)
 {
     return(m_record.NewAsync(item));
 }
 internal ItemProxy(string typeID, IItemDataTyped typedData)
 {
     m_typeID = typeID;
     m_typedData = typedData;
     m_itemData = null;
 }
 public IAsyncOperation <ItemKey> PutAsync(IItemDataTyped item)
 {
     return(m_record.UpdateAsync(item));
 }
 internal ItemProxy(string typeID, IItemDataTyped typedData)
 {
     m_typeID    = typeID;
     m_typedData = typedData;
     m_itemData  = null;
 }
Ejemplo n.º 35
0
        public IAsyncOperation<ItemKey> NewAsync(IItemDataTyped data)
        {
            if (data == null)
            {
                throw new ArgumentNullException("data");
            }

            data.Item.PrepareForNew();
            return PutAsync(data);
        }
 /// <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);
 }
        /// <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();
            });
        }
Ejemplo n.º 38
0
 public IAsyncOperation<ItemKey> NewAsync(IItemDataTyped item)
 {
     return m_record.NewAsync(item);
 }
 void ValidateItem(IItemDataTyped item)
 {
     if (item == null)
     {
         throw new ArgumentNullException("item");
     }
     item.Type.ValidateRequired("Type");
     if (item.Type.ID != m_typeID)
     {
         throw new ArgumentException("TypeID mismatch");
     }
 }
 public ItemData(IItemDataTyped typedData)
     : this(typedData, null)
 {
 }