private static void DefineTable(IMobileServiceLocalStore store)
        {
            var tableLocalStore = store as MobileServiceLocalStore;

            if (tableLocalStore == null)
            {
                return;
            }

            tableLocalStore.DefineTable(FileMetadataTableName, new JObject()
            {
                { MobileServiceSystemColumns.Id, String.Empty },
                { "fileId", string.Empty },
                { "fileName", string.Empty },
                { "length", 0 },
                { "contentMD5", string.Empty },
                { "localPath", string.Empty },
                { "location", FileLocation.Local.ToString() },
                { "lastModified", string.Empty },
                { "parentDataItemType", string.Empty },
                { "parentDataItemId", string.Empty },
                { "pendingDeletion", false },
                { "fileStoreUri", string.Empty },
                { "metadata", string.Empty }
            });
        }
        public LocalStoreChangeTracker(IMobileServiceLocalStore store, StoreTrackingContext trackingContext, IMobileServiceEventManager eventManager, MobileServiceSyncSettingsManager settings)
        {
            if (store == null)
            {
                throw new ArgumentNullException("store");
            }

            if (trackingContext == null)
            {
                throw new ArgumentNullException("trackingContext");
            }

            if (eventManager == null)
            {
                throw new ArgumentNullException("eventManager");
            }

            if (settings == null)
            {
                throw new ArgumentNullException("settings");
            }

            this.objectReader = new MobileServiceObjectReader();

            this.store = store;
            this.trackingContext = trackingContext;
            this.eventManager = eventManager;
            this.settings = settings;

            InitializeTracking();
        }
        private static void DefineTable(IMobileServiceLocalStore store)
        {
            var tableLocalStore = store as MobileServiceLocalStore;

            if (tableLocalStore == null)
            {
                return;
            }

            tableLocalStore.DefineTable(FileMetadataTableName, new JObject()
            {
                { MobileServiceSystemColumns.Id, String.Empty },
                { "fileId", string.Empty },
                { "fileName", string.Empty },
                { "length", 0 },
                { "contentMD5", string.Empty },
                { "localPath", string.Empty },
                { "location", FileLocation.Local.ToString() },
                { "lastModified", DateTimeOffset.Now },
                { "parentDataItemType", string.Empty },
                { "parentDataItemId", string.Empty },
                { "pendingDeletion", false },
                { "fileStoreUri", string.Empty },
                { "metadata", string.Empty }
            });
        }
Exemplo n.º 4
0
        public LocalStoreChangeTracker(IMobileServiceLocalStore store, StoreTrackingContext trackingContext, IMobileServiceEventManager eventManager, MobileServiceSyncSettingsManager settings)
        {
            if (store == null)
            {
                throw new ArgumentNullException("store");
            }

            if (trackingContext == null)
            {
                throw new ArgumentNullException("trackingContext");
            }

            if (eventManager == null)
            {
                throw new ArgumentNullException("eventManager");
            }

            if (settings == null)
            {
                throw new ArgumentNullException("settings");
            }

            this.objectReader = new MobileServiceObjectReader();

            this.store           = store;
            this.trackingContext = trackingContext;
            this.eventManager    = eventManager;
            this.settings        = settings;

            InitializeTracking();
        }
 public OperationBatch(IMobileServiceSyncHandler syncHandler, IMobileServiceLocalStore store, MobileServiceSyncContext context)
 {
     this.OtherErrors = new List <Exception>();
     this.SyncHandler = syncHandler;
     this.Store       = store;
     this.context     = context;
 }
        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);
            }
        }
 public OperationBatch(IMobileServiceSyncHandler syncHandler, IMobileServiceLocalStore store, MobileServiceSyncContext context)
 {
     this.OtherErrors = new List<Exception>();
     this.SyncHandler = syncHandler;
     this.Store = store;
     this.context = context;
 }
        public FileOperationQueue(IMobileServiceLocalStore store)
        {
            this.store = store;

            this.operationsInfo = new Lazy <OperationsInfo>(LoadOperationsInformation, LazyThreadSafetyMode.ExecutionAndPublication);

            DefineTable(store);
        }
Exemplo n.º 9
0
        /// <summary>
        /// Counts all the items returned from the query
        /// </summary>
        /// <param name="store">An instance of <see cref="IMobileServiceLocalStore"/></param>
        /// <param name="query">An instance of <see cref="MobileServiceTableQueryDescription"/></param>
        /// <returns>Task that will complete with count of items.</returns>
        public static async Task <long> CountAsync(this IMobileServiceLocalStore store, MobileServiceTableQueryDescription query)
        {
            query.Top = 0;
            query.IncludeTotalCount = true;
            QueryResult result = await store.QueryAsync(query);

            return(result.TotalCount);
        }
Exemplo n.º 10
0
 public AptkAmaLocalTableService(IAptkAmaLocalStorePluginConfiguration localStoreConfiguration,
                                 IMobileServiceLocalStore store,
                                 IMobileServiceSyncTable <T> syncTable)
 {
     _localStoreConfiguration = localStoreConfiguration;
     _store     = store;
     _syncTable = syncTable;
 }
        public FileOperationQueue(IMobileServiceLocalStore store)
        {
            this.store = store;

            this.operationsInfo = new Lazy<OperationsInfo>(LoadOperationsInformation, LazyThreadSafetyMode.ExecutionAndPublication);

            DefineTable(store);
        }
Exemplo n.º 12
0
 public AzureStoreServiceFixture()
 {
     _client     = Substitute.For <IMobileServiceClient>();
     _connection = Substitute.For <ISqlConnection>();
     _store      = Substitute.For <IMobileServiceLocalStore>();
     _context    = Substitute.For <IMobileServiceSyncContext>();
     _client.SyncContext.Returns(_context);
 }
Exemplo n.º 13
0
        public SyncAction(OperationQueue operationQueue, IMobileServiceLocalStore store, CancellationToken cancellationToken)
        {
            this.OperationQueue    = operationQueue;
            this.Store             = store;
            this.TaskSource        = new TaskCompletionSource <object>();
            this.CancellationToken = cancellationToken;

            cancellationToken.Register(() => TaskSource.TrySetCanceled());
        }
        public override async Task ExecuteLocalAsync(IMobileServiceLocalStore store, JObject item)
        {
            if (await store.LookupAsync(this.TableName, this.ItemId) != null)
            {
                throw new MobileServiceLocalStoreException("An insert operation on the item is already in the queue.", null);
            }

            await store.UpsertAsync(this.TableName, item, fromServer: false);
        }
        public override async Task ExecuteLocalAsync(IMobileServiceLocalStore store, JObject item)
        {
            if (await store.LookupAsync(this.TableName, this.ItemId) != null)
            {
                throw new MobileServiceLocalStoreException(Resources.SyncContext_DuplicateInsert, null);
            }

            await store.UpsertAsync(this.TableName, item, fromServer : false);
        }
        public override async Task ExecuteLocalAsync(IMobileServiceLocalStore store, JObject item)
        {
            if (await store.LookupAsync(this.TableName, this.ItemId) != null)
            {
                throw new MobileServiceLocalStoreException("An insert operation on the item is already in the queue.", null);
            }

            await store.UpsertAsync(this.TableName, item, fromServer : false);
        }
        public static IFileSyncContext InitializeExpressFileSyncContext(this IMobileServiceClient client, IMobileServiceLocalStore store, ILocalStorageProvider localStorage)
        {
            var metadataStore = new FileMetadataStore(store);
            var operationQueue = new FileOperationQueue(store);
            var triggerFactory = new DefaultFileSyncTriggerFactory(client, true);
            var filesClient = client.GetFilesClient();
            var syncHandler = new LocalStorageSyncHandler(localStorage, filesClient);

            return client.InitializeFileSyncContext(new MobileServiceExpressFileSyncContext(client, metadataStore, operationQueue, triggerFactory, syncHandler, filesClient, localStorage));
        }
        private void AssertUntrackedStoreForSourceWithOptions(StoreOperationSource source, StoreTrackingOptions trackingOptions)
        {
            var store           = new MobileServiceLocalStoreMock();
            var trackingContext = new StoreTrackingContext(StoreOperationSource.Local, string.Empty, StoreTrackingOptions.None);
            var eventManager    = new MobileServiceEventManager();
            var settings        = new MobileServiceSyncSettingsManager(store);

            IMobileServiceLocalStore trackedStore = StoreChangeTrackerFactory.CreateTrackedStore(store, source, trackingOptions, eventManager, settings);

            Assert.NotNull(trackedStore);
            Assert.IsType <LocalStoreProxy>(trackedStore);
        }
        public SyncAction(OperationQueue operationQueue, IMobileServiceLocalStore store, CancellationToken cancellationToken)
        {
            this.OperationQueue = operationQueue;
            this.Store = store;
            this.TaskSource = new TaskCompletionSource<object>();
            this.CancellationToken = cancellationToken;

            cancellationToken.Register(() =>
            {
                TaskSource.TrySetCanceled();
            });
        }
Exemplo n.º 20
0
        internal static IMobileServiceLocalStore CreateTrackedStore(IMobileServiceLocalStore targetStore, StoreOperationSource source, StoreTrackingOptions trackingOptions,
                                                                    IMobileServiceEventManager eventManager, MobileServiceSyncSettingsManager settings)
        {
            if (IsTrackingEnabled(trackingOptions, source))
            {
                Guid batchId = source == StoreOperationSource.Local ? Guid.Empty : Guid.NewGuid();

                return(new LocalStoreChangeTracker(targetStore, new StoreTrackingContext(source, batchId.ToString(), trackingOptions), eventManager, settings));
            }
            else
            {
                return(new LocalStoreProxy(targetStore));
            }
        }
        internal static IMobileServiceLocalStore CreateTrackedStore(IMobileServiceLocalStore targetStore, StoreOperationSource source, StoreTrackingOptions trackingOptions, 
            IMobileServiceEventManager eventManager, MobileServiceSyncSettingsManager settings)
        {
            if (IsTrackingEnabled(trackingOptions, source))
            {
                Guid batchId = source == StoreOperationSource.Local ? Guid.Empty : Guid.NewGuid();

                return new LocalStoreChangeTracker(targetStore, new StoreTrackingContext(source, batchId.ToString(), trackingOptions), eventManager, settings);
            }
            else
            {
                return new LocalStoreProxy(targetStore);               
            }
        }
Exemplo n.º 22
0
 public PurgeAction(MobileServiceTable table,
                    MobileServiceTableKind tableKind,
                    string queryId,
                    MobileServiceTableQueryDescription query,
                    bool force,
                    MobileServiceSyncContext context,
                    OperationQueue operationQueue,
                    MobileServiceSyncSettingsManager settings,
                    IMobileServiceLocalStore store,
                    CancellationToken cancellationToken)
     : base(table, tableKind, queryId, query, null, context, operationQueue, settings, store, cancellationToken)
 {
     this.force = force;
 }
 public PurgeAction(MobileServiceTable table,
                    MobileServiceTableKind tableKind,
                    string queryId,
                    MobileServiceTableQueryDescription query,
                    bool force,
                    MobileServiceSyncContext context,
                    OperationQueue operationQueue,
                    MobileServiceSyncSettingsManager settings,
                    IMobileServiceLocalStore store,
                    CancellationToken cancellationToken)
     : base(table, tableKind, queryId, query, null, context, operationQueue, settings, store, cancellationToken)
 {
     this.force = force;
 }
        public static IFileSyncContext InitializeFileSyncContext(this IMobileServiceClient client, IFileSyncHandler syncHandler, IMobileServiceLocalStore store)
        {
            lock (contextsSyncRoot)
            {
                IFileSyncContext context;

                if (!contexts.TryGetValue(client, out context))
                {
                    context = new MobileServiceFileSyncContext(client, new FileMetadataStore(store), new FileOperationQueue(store), syncHandler);
                    contexts.Add(client, context);
                }

                return context;
            }
        }
        public LocalStoreChangeTracker(IMobileServiceLocalStore store, StoreTrackingContext trackingContext, IMobileServiceEventManager eventManager, MobileServiceSyncSettingsManager settings)
        {
            Arguments.IsNotNull(store, nameof(store));
            Arguments.IsNotNull(trackingContext, nameof(trackingContext));
            Arguments.IsNotNull(eventManager, nameof(eventManager));
            Arguments.IsNotNull(settings, nameof(settings));

            this.objectReader    = new MobileServiceObjectReader();
            this.store           = store;
            this.trackingContext = trackingContext;
            this.eventManager    = eventManager;
            this.settings        = settings;

            InitializeTracking();
        }
 public PushAction(OperationQueue operationQueue,
                   IMobileServiceLocalStore store,
                   MobileServiceTableKind tableKind,
                   IEnumerable<string> tableNames,
                   IMobileServiceSyncHandler syncHandler,
                   MobileServiceClient client,
                   MobileServiceSyncContext context,
                   CancellationToken cancellationToken)
     : base(operationQueue, store, cancellationToken)
 {
     this.tableKind = tableKind;
     this.tableNames = tableNames;
     this.client = client;
     this.syncHandler = syncHandler;
     this.context = context;
 }
 public PushAction(OperationQueue operationQueue,
                   IMobileServiceLocalStore store,
                   MobileServiceTableKind tableKind,
                   IEnumerable <string> tableNames,
                   IMobileServiceSyncHandler syncHandler,
                   MobileServiceClient client,
                   MobileServiceSyncContext context,
                   CancellationToken cancellationToken)
     : base(operationQueue, store, cancellationToken)
 {
     this.tableKind   = tableKind;
     this.tableNames  = tableNames;
     this.client      = client;
     this.syncHandler = syncHandler;
     this.context     = context;
 }
Exemplo n.º 28
0
        public async Task InitializeStore()
        {
            if (storeManager == null)
            {
                storeManager = DependencyService.Get <IStoreManager>();
            }
            if (localStore == null)
            {
                localStore = StoreManager.MobileService.SyncContext.Store;
            }

            if (!storeManager.IsInitialized)
            {
                await storeManager.InitializeAsync().ConfigureAwait(false);
            }
        }
Exemplo n.º 29
0
        public static IFileSyncContext InitializeFileSyncContext(this IMobileServiceClient client, IFileSyncHandler syncHandler,
                                                                 IMobileServiceLocalStore store, IFileSyncTriggerFactory fileSyncTriggerFactory)
        {
            lock (contextsSyncRoot)
            {
                IFileSyncContext context;

                if (!contexts.TryGetValue(client, out context))
                {
                    context = new MobileServiceFileSyncContext(client, new FileMetadataStore(store), new FileOperationQueue(store), fileSyncTriggerFactory, syncHandler);
                    contexts.Add(client, context);
                }

                return(context);
            }
        }
        private void DefineTable(IMobileServiceLocalStore store)
        {
            var tableLocalStore = store as MobileServiceLocalStore;

            if (tableLocalStore == null)
            {
                return;
            }

            tableLocalStore.DefineTable(FileOperationTableName, new JObject()
            {
                { MobileServiceSystemColumns.Id, string.Empty },
                { "fileId", string.Empty },
                { "kind", 0 },
                { "sequence", 0 }
            });
        }
        private void DefineTable(IMobileServiceLocalStore store)
        {
            var tableLocalStore = store as MobileServiceLocalStore;

            if (tableLocalStore == null)
            {
                return;
            }

            tableLocalStore.DefineTable(FileOperationTableName, new JObject()
            {
                { MobileServiceSystemColumns.Id, string.Empty },
                { "fileId", string.Empty },
                { "kind", 0 },
                { "sequence", 0 }
            });
        }
 public TableAction(MobileServiceTable table,
                    MobileServiceTableKind tableKind,
                    string queryId,
                    MobileServiceTableQueryDescription query,
                    IEnumerable <string> relatedTables,
                    MobileServiceSyncContext context,
                    OperationQueue operationQueue,
                    MobileServiceSyncSettingsManager settings,
                    IMobileServiceLocalStore store,
                    CancellationToken cancellationToken)
     : base(operationQueue, store, cancellationToken)
 {
     this.Table         = table;
     this.TableKind     = tableKind;
     this.QueryId       = queryId;
     this.Query         = query;
     this.RelatedTables = relatedTables;
     this.Settings      = settings;
     this.Context       = context;
 }
        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);
        }
 public PullAction(MobileServiceTable table,
                   MobileServiceTableKind tableKind,
                   MobileServiceSyncContext context,
                   string queryId,
                   MobileServiceTableQueryDescription query,
                   IDictionary <string, string> parameters,
                   IEnumerable <string> relatedTables,
                   OperationQueue operationQueue,
                   MobileServiceSyncSettingsManager settings,
                   IMobileServiceLocalStore store,
                   MobileServiceRemoteTableOptions options,
                   MobileServiceObjectReader reader,
                   CancellationToken cancellationToken)
     : base(table, tableKind, queryId, query, relatedTables, context, operationQueue, settings, store, cancellationToken)
 {
     this.options    = options;
     this.parameters = parameters;
     this.cursor     = new PullCursor(query);
     this.Reader     = reader ?? new MobileServiceObjectReader();
 }
Exemplo n.º 35
0
 public PullAction(MobileServiceTable table,
                   MobileServiceTableKind tableKind,
                   MobileServiceSyncContext context,
                   string queryId,
                   MobileServiceTableQueryDescription query,
                   IDictionary<string, string> parameters,
                   IEnumerable<string> relatedTables,
                   OperationQueue operationQueue,
                   MobileServiceSyncSettingsManager settings,
                   IMobileServiceLocalStore store,
                   MobileServiceRemoteTableOptions options,
                   MobileServiceObjectReader reader,
                   CancellationToken cancellationToken)
     : base(table, tableKind, queryId, query, relatedTables, context, operationQueue, settings, store, cancellationToken)
 {
     this.options = options;
     this.parameters = parameters;
     this.cursor = new PullCursor(query);
     this.Reader = reader ?? new MobileServiceObjectReader();
 }
 public TableAction(MobileServiceTable table,
                    MobileServiceTableKind tableKind,
                    string queryId,
                    MobileServiceTableQueryDescription query,
                    IEnumerable<string> relatedTables,
                    MobileServiceSyncContext context,
                    OperationQueue operationQueue,
                    MobileServiceSyncSettingsManager settings,
                    IMobileServiceLocalStore store,
                    CancellationToken cancellationToken)
     : base(operationQueue, store, cancellationToken)
 {
     this.Table = table;
     this.TableKind = tableKind;
     this.QueryId = queryId;
     this.Query = query;
     this.RelatedTables = relatedTables;
     this.Settings = settings;
     this.Context = context;
 }
        public async Task InitializeAsync(IMobileServiceLocalStore store, IMobileServiceSyncHandler handler)
        {
            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.syncQueue = new ActionBlock();
                await this.Store.InitializeAsync();
                this.opQueue = await OperationQueue.LoadAsync(store);
                this.settings = new MobileServiceSyncSettingsManager(store);
                this.initializeTask.SetResult(null);
            }
        }
Exemplo n.º 38
0
        public void InitializeFileSyncContext <T>(IMobileServiceClient client, IMobileServiceLocalStore store, IAptkAmaLocalTableService <T> table) where T : ITableData
        {
#if PORTABLE || WINDOWS_PHONE
            throw new ArgumentException("This functionality is not implemented in this version of this assembly. You should reference the NuGet package from your main application project in order to reference the platform-specific implementation.");
#else
            var tInstance = Activator.CreateInstance <T>() as IFileSyncTableData;
            if (tInstance == null)
            {
                return;
            }

            var triggerFactory = tInstance.SpecificFileSyncTriggerFactory ?? _configuration.GlobalFileSyncTriggerFactory;
            if (triggerFactory != null)
            {
                client.InitializeFileSyncContext(new AptkAmaFileSyncHandler <T>(_configuration, table), store, triggerFactory);
            }
            else
            {
                client.InitializeFileSyncContext(new AptkAmaFileSyncHandler <T>(_configuration, table), store);
            }
#endif
        }
        public async Task InitializeAsync(IMobileServiceLocalStore store, IMobileServiceSyncHandler handler)
        {
            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.syncQueue = new ActionBlock();
                await this.Store.InitializeAsync();

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

                this.settings = new MobileServiceSyncSettingsManager(store);
                this.initializeTask.SetResult(null);
            }
        }
        /// <summary>
        /// Counts all the items in a local table
        /// </summary>
        /// <param name="store">Instance of <see cref="IMobileServiceLocalStore"/></param>
        /// <param name="tableName">Name of the table</param>
        /// <returns>Task that will complete with count of items.</returns>
        public async static Task <long> CountAsync(this IMobileServiceLocalStore store, string tableName)
        {
            var query = new MobileServiceTableQueryDescription(MobileServiceLocalSystemTables.OperationQueue);

            return(await CountAsync(store, query));
        }
 /// <summary>
 /// Deletes an item with the specified id in the local table.
 /// </summary>
 /// <param name="store">Instance of <see cref="IMobileServiceLocalStore"/></param>
 /// <param name="tableName">Name of the local table.</param>
 /// <param name="id">Id for the object to be deleted.</param>
 /// <returns>A task that compltes when delete has been executed on local table.</returns>
 public static Task DeleteAsync(this IMobileServiceLocalStore store, string tableName, string id)
 {
     return(store.DeleteAsync(tableName, new[] { id }));
 }
 public static IFileSyncContext InitializeExpressFileSyncContext(this IMobileServiceClient client, IMobileServiceLocalStore store)
 {
     return client.InitializeExpressFileSyncContext(store, ApplicationData.Current.LocalFolder);
 }
 public ReadthruLocalStore(IMobileServiceLocalStore store, IMobileServiceClient client)
 {
     this.store = store;
     this.client = client;
 }
        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);
            }
        }
 public MobileServiceSyncSettingsManager(IMobileServiceLocalStore store)
 {
     this.store = store;
 }
        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;
        }
 public OperationQueue(IMobileServiceLocalStore store)
 {
     this.store = store;
 }
 /// <summary>
 /// Execute the operation on sync store
 /// </summary>
 /// <param name="store">Sync store</param>
 /// <param name="item">The item to use for store operation</param>
 public abstract Task ExecuteLocalAsync(IMobileServiceLocalStore store, JObject item);
 public FileMetadataStore(IMobileServiceLocalStore store)
 {
     this.store = store;
     DefineTable(store);
 }
 public FileMetadataStore(IMobileServiceLocalStore store)
 {
     this.store = store;
     DefineTable(store);
 }
 /// <summary>
 /// Initializes the sync context.
 /// </summary>
 /// <param name="context">An instance of <see cref="IMobileServiceSyncContext"/>.</param>
 /// <param name="store">An instance of <see cref="IMobileServiceLocalStore"/>.</param>
 public static Task InitializeAsync(this IMobileServiceSyncContext context, IMobileServiceLocalStore store)
 {
     return context.InitializeAsync(store, new MobileServiceSyncHandler());
 }
 /// <summary>
 /// Executes the query on local store and returns the parsed result
 /// </summary>
 /// <param name="store">An instance of <see cref="IMobileServiceLocalStore"/></param>
 /// <param name="query">An instance of <see cref="MobileServiceTableQueryDescription"/></param>
 /// <returns>Task that will complete with the parsed result of the query.</returns>
 public static async Task <QueryResult> QueryAsync(this IMobileServiceLocalStore store, MobileServiceTableQueryDescription query)
 {
     return(QueryResult.Parse(await store.ReadAsync(query), null, validate: true));
 }
        /// <summary>
        /// Executes the query on local store and returns the first or default item from parsed result
        /// </summary>
        /// <param name="store">An instance of <see cref="IMobileServiceLocalStore"/></param>
        /// <param name="query">An instance of <see cref="MobileServiceTableQueryDescription"/></param>
        /// <returns>Task that will complete with the first or default item from parsed result of the query.</returns>
        public static async Task <JObject> FirstOrDefault(this IMobileServiceLocalStore store, MobileServiceTableQueryDescription query)
        {
            QueryResult result = await store.QueryAsync(query);

            return(result.Values.FirstOrDefault() as JObject);
        }
 public MobileServiceSyncSettingsManager(IMobileServiceLocalStore store)
 {
     this.store = store;
 }
 public Task InitializeAsync(IMobileServiceLocalStore store, IMobileServiceSyncHandler handler)
 {
     return InitializeAsync(store, handler, StoreTrackingOptions.None);
 }
 public LocalStoreProxy(IMobileServiceLocalStore store)
 {
     this.store = store;
 }
 // not sure if this is useful. trying to make the signature consistent across platforms, but this needs to be async
 public async static Task<IFileSyncContext> InitializeExpressFileSyncContext(this IMobileServiceClient client, IMobileServiceLocalStore store, string basePath)
 {
     var folder = await StorageFolder.GetFolderFromPathAsync(basePath).AsTask();
     return client.InitializeExpressFileSyncContext(store, folder);
 }
 public static IFileSyncContext InitializeExpressFileSyncContext(this IMobileServiceClient client, IMobileServiceLocalStore store, StorageFolder folder)
 {
     return client.InitializeExpressFileSyncContext(store, new FileSystemStorageProvider(new WinAppsFileSystemAccess(folder)));
 }
 /// <summary>
 /// Initializes the file synchronization capabilities of the <see cref="IMobileServiceClient"/>. Offline sync must also be initialized by calling
 /// IMobileServiceClient.SyncContext.InitializeAsync.
 /// </summary>
 /// <param name="client">IMobileServiceClient instance</param>
 /// <param name="syncHandler">An instance of <see cref="IFileSyncHandler"/> that specifies how to handle changes to stored files</param>
 /// <param name="store">The <see cref="IMobileServiceLocalStore"/> for storing file metadata locally</param>
 /// <returns>An instance of <see cref="IFileSyncContext"/></returns>
 public static IFileSyncContext InitializeFileSyncContext(this IMobileServiceClient client, IFileSyncHandler syncHandler, IMobileServiceLocalStore store)
 {
     return InitializeFileSyncContext(client, syncHandler, store, new DefaultFileSyncTriggerFactory(client, true));
 }
 /// <summary>
 /// Initializes the file synchronization capabilities of the <see cref="IMobileServiceClient"/>. Offline sync must also be initialized by calling
 /// IMobileServiceClient.SyncContext.InitializeAsync.
 /// </summary>
 /// <param name="client">IMobileServiceClient instance</param>
 /// <param name="syncHandler">An instance of <see cref="IFileSyncHandler"/> that specifies how to handle changes to stored files</param>
 /// <param name="store">The <see cref="IMobileServiceLocalStore"/> for storing file metadata locally</param>
 /// <param name="fileSyncTriggerFactory">An instance of <see cref="IFileSyncTriggerFactory"/> that generates <see cref="IFileSyncTrigger"/> objects for triggering synchronisation of file metadata and content</param>
 /// <returns>An instance of <see cref="IFileSyncContext"/></returns>
 public static IFileSyncContext InitializeFileSyncContext(this IMobileServiceClient client, IFileSyncHandler syncHandler, IMobileServiceLocalStore store, IFileSyncTriggerFactory fileSyncTriggerFactory)
 {
     return client.InitializeFileSyncContext(new MobileServiceFileSyncContext(client, new FileMetadataStore(store), new FileOperationQueue(store), fileSyncTriggerFactory, syncHandler));
 }