private static bool IsTrackingEnabled(StoreTrackingOptions trackingOptions, StoreOperationSource source) { bool result = false; switch (source) { case StoreOperationSource.Local: case StoreOperationSource.LocalPurge: result = trackingOptions.HasFlag(StoreTrackingOptions.NotifyLocalOperations); break; case StoreOperationSource.LocalConflictResolution: result = trackingOptions.HasFlag(StoreTrackingOptions.NotifyLocalConflictResolutionOperations); break; case StoreOperationSource.ServerPull: result = (trackingOptions & (StoreTrackingOptions.NotifyServerPullBatch | StoreTrackingOptions.NotifyServerPullOperations)) != StoreTrackingOptions.None; break; case StoreOperationSource.ServerPush: result = (trackingOptions & (StoreTrackingOptions.NotifyServerPushBatch | StoreTrackingOptions.NotifyServerPushOperations)) != StoreTrackingOptions.None; break; default: throw new InvalidOperationException("Unknown store operation source."); } return(result); }
private static bool IsTrackingEnabled(StoreTrackingOptions trackingOptions, StoreOperationSource source) { bool result = false; switch (source) { case StoreOperationSource.Local: case StoreOperationSource.LocalPurge: result = trackingOptions.HasFlag(StoreTrackingOptions.NotifyLocalOperations); break; case StoreOperationSource.LocalConflictResolution: result = trackingOptions.HasFlag(StoreTrackingOptions.NotifyLocalConflictResolutionOperations); break; case StoreOperationSource.ServerPull: result = (trackingOptions & (StoreTrackingOptions.NotifyServerPullBatch | StoreTrackingOptions.NotifyServerPullOperations)) != StoreTrackingOptions.None; break; case StoreOperationSource.ServerPush: result = (trackingOptions & (StoreTrackingOptions.NotifyServerPushBatch | StoreTrackingOptions.NotifyServerPushOperations)) != StoreTrackingOptions.None; break; default: throw new InvalidOperationException("Unknown store operation source."); } return result; }
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); }
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); }
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); } }
/// <summary> /// Creates an instance of <see cref="StoreOperation"/> class. /// </summary> /// <param name="tableName">The name of the table that is the target of this operation.</param> /// <param name="recordId">The target record identifier.</param> /// <param name="kind">The kind of operation.</param> /// <param name="source">The source that triggered this operation.</param> /// <param name="batchId">The id of the batch this operation belongs to.</param> public StoreOperation(string tableName, string recordId, LocalStoreOperationKind kind, StoreOperationSource source, string batchId) { if (tableName == null) { throw new ArgumentNullException("tableName"); } if (recordId == null) { throw new ArgumentNullException("recordId"); } if(batchId == null) { throw new ArgumentNullException("batchId"); } this.TableName = tableName; this.RecordId = recordId; this.Kind = kind; this.Source = source; this.BatchId = batchId; }
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 StoreOperationsBatch(string batchId, StoreOperationSource source) { this.batchId = batchId; this.source = source; this.operationsCountByType = new Dictionary <LocalStoreOperationKind, int>(); }
/// <summary> /// Initializes a new <see cref="StoreTrackingContext"/> with the specified <paramref name="source"/> and /// <paramref name="batchId"/> and <paramref name="trackingOptions"/>. /// </summary> /// <param name="source">The store operation source used by this tracking context.</param> /// <param name="batchId">The batch ID used by this tracking context.</param> /// <param name="trackingOptions">The tracking options used by this tracking context.</param> public StoreTrackingContext(StoreOperationSource source, string batchId, StoreTrackingOptions trackingOptions) { this.BatchId = batchId; this.Source = source; this.TrackingOptions = trackingOptions; }
/// <summary> /// Initializes a new <see cref="StoreTrackingContext"/> with the specified <paramref name="source"/> and /// <paramref name="batchId"/>, enabling the NotifyRecordOperation and NotifyBatch <see cref="TrackingOptions"/>. /// </summary> /// <param name="source">The store operation source used by this tracking context.</param> /// <param name="batchId">The batch ID used by this tracking context.</param> public StoreTrackingContext(StoreOperationSource source, string batchId) : this(source, batchId, StoreTrackingOptions.AllNotificationsAndChangeDetection) { }
public StoreOperationsBatch(string batchId, StoreOperationSource source) { this.batchId = batchId; this.source = source; this.operationsCountByType = new Dictionary<LocalStoreOperationKind, int>(); }
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)); } }
/// <summary> /// Creates an instance of <see cref="StoreOperation"/> class. /// </summary> /// <param name="tableName">The name of the table that is the target of this operation.</param> /// <param name="recordId">The target record identifier.</param> /// <param name="kind">The kind of operation.</param> /// <param name="source">The source that triggered this operation.</param> /// <param name="batchId">The id of the batch this operation belongs to.</param> public StoreOperation(string tableName, string recordId, LocalStoreOperationKind kind, StoreOperationSource source, string batchId) { if (tableName == null) { throw new ArgumentNullException("tableName"); } if (recordId == null) { throw new ArgumentNullException("recordId"); } if (batchId == null) { throw new ArgumentNullException("batchId"); } this.TableName = tableName; this.RecordId = recordId; this.Kind = kind; this.Source = source; this.BatchId = batchId; }
/// <summary> /// Creates an instance of <see cref="StoreOperation"/> class. /// </summary> /// <param name="tableName">The name of the table that is the target of this operation.</param> /// <param name="recordId">The target record identifier.</param> /// <param name="kind">The kind of operation.</param> /// <param name="source">The source that triggered this operation.</param> /// <param name="batchId">The id of the batch this operation belongs to.</param> public StoreOperation(string tableName, string recordId, LocalStoreOperationKind kind, StoreOperationSource source, string batchId) { Arguments.IsNotNull(tableName, nameof(tableName)); Arguments.IsNotNull(recordId, nameof(recordId)); Arguments.IsNotNull(batchId, nameof(batchId)); this.TableName = tableName; this.RecordId = recordId; this.Kind = kind; this.Source = source; this.BatchId = batchId; }