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 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 async Task BatchNotification_ReportsOperationCount() { var store = new MobileServiceLocalStoreMock(); var trackingContext = new StoreTrackingContext(StoreOperationSource.ServerPull, string.Empty); var eventManager = new MobileServiceEventManagerMock<IMobileServiceEvent>(); var settings = new MobileServiceSyncSettingsManager(store); var changeTracker = new LocalStoreChangeTracker(store, trackingContext, eventManager, settings); EnqueueSimpleObjectResponse(store, "123", "XXX", "789"); await changeTracker.UpsertAsync("test", new JObject() { { "id", "123" }, { "version", "2" } }, true); // Update await changeTracker.UpsertAsync("test", new JObject() { { "id", "456" }, { "version", "2" } }, true); // Insert await changeTracker.DeleteAsync("test", "789"); // Delete StoreOperationsBatchCompletedEvent batchEvent = null; eventManager.PublishAsyncFunc = e => { batchEvent = e as StoreOperationsBatchCompletedEvent; return Task.FromResult(0); }; changeTracker.Dispose(); Assert.IsNotNull(batchEvent); Assert.AreEqual(batchEvent.Batch.OperationCount, 3); Assert.AreEqual(batchEvent.Batch.GetOperationCountByKind(LocalStoreOperationKind.Update), 1); Assert.AreEqual(batchEvent.Batch.GetOperationCountByKind(LocalStoreOperationKind.Insert), 1); Assert.AreEqual(batchEvent.Batch.GetOperationCountByKind(LocalStoreOperationKind.Delete), 1); }
public void Constructor_Throws_WhenTrackingOptionsAreInvalid() { var store = new MobileServiceLocalStoreMock(); var trackingContext = new StoreTrackingContext(StoreOperationSource.Local, string.Empty, StoreTrackingOptions.None); var eventManager = new MobileServiceEventManager(); var settings = new MobileServiceSyncSettingsManager(store); AssertEx.Throws<InvalidOperationException>(() => new LocalStoreChangeTracker(store, trackingContext, eventManager, settings)); }
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.IsNotNull(trackedStore); Assert.IsTrue(trackedStore is LocalStoreProxy); }
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; }
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); } }
public IncrementalPullStrategy(MobileServiceTable table, MobileServiceTableQueryDescription query, string queryId, MobileServiceSyncSettingsManager settings, PullCursor cursor, MobileServiceRemoteTableOptions options) : base(query, cursor, options) { this.table = table; this.originalFilter = query.Filter; this.queryId = queryId; this.settings = settings; this.ordered = options.HasFlag(MobileServiceRemoteTableOptions.OrderBy); }
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 void Disposing_CompletesBatch() { var store = new MobileServiceLocalStoreMock(); var trackingContext = new StoreTrackingContext(StoreOperationSource.ServerPull, string.Empty); var eventManager = new MobileServiceEventManagerMock<IMobileServiceEvent>(); var settings = new MobileServiceSyncSettingsManager(store); StoreOperationsBatchCompletedEvent batchEvent = null; eventManager.PublishAsyncFunc = e => { batchEvent = e as StoreOperationsBatchCompletedEvent; return Task.FromResult(0); }; var changeTracker = new LocalStoreChangeTracker(store, trackingContext, eventManager, settings); changeTracker.Dispose(); Assert.IsNotNull(batchEvent); }
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 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 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 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); } }
private static async Task TestPullAsyncIncrementalWithOptions(MobileServiceRemoteTableOptions options, params string[] uris) { var store = new MobileServiceLocalStoreMock(); var settings = new MobileServiceSyncSettingsManager(store); await settings.SetDeltaTokenAsync("stringId_test_table", "incquery", new DateTime(2001, 02, 01, 0, 0, 0, DateTimeKind.Utc)); await TestIncrementalPull(store, options, uris); }
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)); } }
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); } }
public async Task DeleteAsync_WithQuery_SendsNotification() { var store = new MobileServiceLocalStoreMock(); var trackingContext = new StoreTrackingContext(StoreOperationSource.Local, string.Empty); var eventManager = new MobileServiceEventManagerMock<IMobileServiceEvent>(); var settings = new MobileServiceSyncSettingsManager(store); var changeTracker = new LocalStoreChangeTracker(store, trackingContext, eventManager, settings); JObject item = EnqueueSimpleObjectResponse(store); StoreOperationCompletedEvent operationEvent = null; eventManager.PublishAsyncFunc = t => { operationEvent = t as StoreOperationCompletedEvent; return Task.FromResult(0); }; MobileServiceTableQueryDescription query = new MobileServiceTableQueryDescription("test"); query.Filter = new BinaryOperatorNode(BinaryOperatorKind.Equal, new MemberAccessNode(null, MobileServiceSystemColumns.Id), new ConstantNode("123")); await changeTracker.DeleteAsync(query); Assert.IsNotNull(operationEvent); Assert.AreEqual(operationEvent.Operation.Kind, LocalStoreOperationKind.Delete); Assert.AreEqual(operationEvent.Operation.RecordId, "123"); Assert.AreEqual(operationEvent.Operation.TableName, "test"); }
private async Task AssertNotificationResultWithMatchingLocalRecordVersion(StoreOperationSource[] operationSources, bool shouldNotify) { foreach (var operationSource in operationSources) { var store = new MobileServiceLocalStoreMock(); var trackingContext = new StoreTrackingContext(operationSource, string.Empty); var eventManager = new MobileServiceEventManagerMock<IMobileServiceEvent>(); var settings = new MobileServiceSyncSettingsManager(store); var changeTracker = new LocalStoreChangeTracker(store, trackingContext, eventManager, settings); JObject item = EnqueueSimpleObjectResponse(store); bool notificationSent = false; eventManager.PublishAsyncFunc = t => { notificationSent = true; return Task.FromResult(0); }; await changeTracker.UpsertAsync("test", item, true); Assert.AreEqual(notificationSent, shouldNotify, string.Format("Incorrect notification result with source {0}", operationSource)); } }
public async Task DeleteAsync_WithTableNameAndRecordIds_SendsNotification() { var store = new MobileServiceLocalStoreMock(); var trackingContext = new StoreTrackingContext(StoreOperationSource.Local, string.Empty); var eventManager = new MobileServiceEventManagerMock<IMobileServiceEvent>(); var settings = new MobileServiceSyncSettingsManager(store); var changeTracker = new LocalStoreChangeTracker(store, trackingContext, eventManager, settings); JObject item = EnqueueSimpleObjectResponse(store); StoreOperationCompletedEvent operationEvent = null; eventManager.PublishAsyncFunc = t => { operationEvent = t as StoreOperationCompletedEvent; return Task.FromResult(0); }; await changeTracker.DeleteAsync("test", "123"); Assert.IsNotNull(operationEvent); Assert.AreEqual(operationEvent.Operation.Kind, LocalStoreOperationKind.Delete); Assert.AreEqual(operationEvent.Operation.RecordId, "123"); Assert.AreEqual(operationEvent.Operation.TableName, "test"); }
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); } }
/// <summary> /// Defines all the system tables on the store /// </summary> /// <param name="store">An instance of <see cref="IMobileServiceLocalStore"/></param> public static void DefineAll(MobileServiceLocalStore store) { MobileServiceTableOperation.DefineTable(store); MobileServiceTableOperationError.DefineTable(store); MobileServiceSyncSettingsManager.DefineTable(store); }
private static async Task<MobileServiceSyncSettingsManager> GetSettingManager(bool resetDb = true) { if (resetDb) { TestUtilities.ResetDatabase(TestDbName); } var store = new MobileServiceSQLiteStore(TestDbName); await store.InitializeAsync(); var settings = new MobileServiceSyncSettingsManager(store); return settings; }