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);
        }
        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);
            }
        }
        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.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);               
            }
        }
        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);
            }
        }
Ejemplo n.º 7
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));
            }
        }
        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 void CreateTrackedStore_ReturnsUntrackedProxyForLocalConflictResolutionSource_WhenNoNotificationsAreEnabledForSource()
        {
            StoreTrackingOptions trackingOptions = StoreTrackingOptions.AllNotificationsAndChangeDetection & ~StoreTrackingOptions.NotifyLocalConflictResolutionOperations;

            AssertUntrackedStoreForSourceWithOptions(StoreOperationSource.LocalConflictResolution, trackingOptions);
        }
        public void CreateTrackedStore_ReturnsUntrackedProxyForServerPushSource_WhenNoNotificationsAreEnabledForSource()
        {
            StoreTrackingOptions trackingOptions = StoreTrackingOptions.AllNotificationsAndChangeDetection & ~(StoreTrackingOptions.NotifyServerPushBatch | StoreTrackingOptions.NotifyServerPushOperations);

            AssertUntrackedStoreForSourceWithOptions(StoreOperationSource.ServerPush, trackingOptions);
        }
 /// <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 the sync context.
 /// </summary>
 /// <param name="context">An instance of <see cref="IMobileServiceSyncContext"/>.</param>
 /// <param name="store">An instance of <see cref="IMobileServiceLocalStore"/>.</param>
 /// <param name="trackingOptions">The traking options that should be enabled on this instance of <see cref="IMobileServiceSyncContext"/>.</param>
 /// <returns>A task that completes when the initialization when initialization has finished.</returns>
 public static Task InitializeAsync(this IMobileServiceSyncContext context, IMobileServiceLocalStore store, StoreTrackingOptions trackingOptions)
 => context.InitializeAsync(store, new MobileServiceSyncHandler(), trackingOptions);
 /// <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 the sync context.
 /// </summary>
 /// <param name="context">An instance of <see cref="IMobileServiceSyncContext"/>.</param>
 /// <param name="store">An instance of <see cref="IMobileServiceLocalStore"/>.</param>
 /// <param name="trackingOptions">The traking options that should be enabled on this instance of <see cref="IMobileServiceSyncContext"/>.</param>
 /// <returns>A task that completes when the initialization when initialization has finished.</returns>
 public static Task InitializeAsync(this IMobileServiceSyncContext context, IMobileServiceLocalStore store, StoreTrackingOptions trackingOptions)
 {
     return context.InitializeAsync(store, new MobileServiceSyncHandler(), trackingOptions);
 }