Microsoft.WindowsAzure.MobileServices.Sync.OperationQueue.LoadAsync C# (CSharp) Method

LoadAsync() public static method

public static LoadAsync ( IMobileServiceLocalStore store ) : Task
store IMobileServiceLocalStore
return Task
        public static async Task<OperationQueue> LoadAsync(IMobileServiceLocalStore store)
        {
            var opQueue = new OperationQueue(store);

            var query = CreateQuery();
            // to know how many pending operations are there
            query.IncludeTotalCount = true;
            // to get the max sequence id, order by sequence desc
            query.Ordering.Add(new OrderByNode(new MemberAccessNode(null, "sequence"), OrderByDirection.Descending));
            // we just need the highest value, not all the operations
            query.Top = 1;

            QueryResult result = await store.QueryAsync(query);
            opQueue.pendingOperations = result.TotalCount;
            opQueue.sequenceId = result.Values == null ? 0 : result.Values.Select(v => v.Value<long>("sequence")).FirstOrDefault();

            return opQueue;
        }

Usage Example

        public async Task InitializeAsync(IMobileServiceLocalStore store, IMobileServiceSyncHandler handler, StoreTrackingOptions trackingOptions)
        {
            if (store == null)
            {
                throw new ArgumentNullException("store");
            }
            handler = handler ?? new MobileServiceSyncHandler();

            this.initializeTask = new TaskCompletionSource <object>();

            using (await this.storeQueueLock.WriterLockAsync())
            {
                this.Handler = handler;
                this.Store   = store;
                this.storeTrackingOptions = trackingOptions;

                this.syncQueue = new ActionBlock();
                await this.Store.InitializeAsync();

                this.opQueue = await OperationQueue.LoadAsync(store);

                this.settings             = new MobileServiceSyncSettingsManager(store);
                this.localOperationsStore = StoreChangeTrackerFactory.CreateTrackedStore(store, StoreOperationSource.Local, trackingOptions, this.client.EventManager, this.settings);

                this.initializeTask.SetResult(null);
            }
        }
All Usage Examples Of Microsoft.WindowsAzure.MobileServices.Sync.OperationQueue::LoadAsync