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();
        }
Example #2
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 void GetId_ReturnsSystemProperty_ByDefault()
        {
            string value = "abc";

            string actualValue = new MobileServiceObjectReader().GetId(new JObject() { { "id", new JValue(value) } });

            Assert.AreEqual(value, actualValue);
        }
        public void GetCreatedAt_ReturnsSystemProperty_ByDefault()
        {
            DateTimeOffset value = DateTimeOffset.Parse("2001-02-03T00:00:00.0000000+00:00");

            DateTimeOffset? actualValue = new MobileServiceObjectReader().GetCreatedAt(new JObject() { { "createdAt", new JValue(value) } });

            Assert.AreEqual(value, actualValue);
        }
        public void GetId_ReturnsCustomProperty_WhenSet()
        {
            string value = "abc";
            var reader = new MobileServiceObjectReader() { IdPropertyName = "Name" };

            string actualValue = reader.GetId(new JObject() { { "Name", new JValue(value) } });

            Assert.AreEqual(value, actualValue);
        }
        public void GetCreatedAt_ReturnsCustomProperty_WhenSet()
        {
            DateTimeOffset value = DateTimeOffset.Parse("2001-02-03T00:00:00.0000000+00:00");
            var reader = new MobileServiceObjectReader() { CreatedAtPropertyName = "Timestamp" };

            DateTimeOffset? actualValue = reader.GetCreatedAt(new JObject() { { "Timestamp", new JValue(value) } });

            Assert.AreEqual(value, actualValue);
        }
Example #7
0
        public void GetCreatedAt_ReturnsSystemProperty_ByDefault()
        {
            DateTimeOffset value = DateTimeOffset.Parse("2001-02-03T00:00:00.0000000+00:00");

            DateTimeOffset?actualValue = new MobileServiceObjectReader().GetCreatedAt(new JObject()
            {
                { "__createdAt", new JValue(value) }
            });

            Assert.AreEqual(value, actualValue);
        }
Example #8
0
        public void GetId_ReturnsSystemProperty_ByDefault()
        {
            string value = "abc";

            string actualValue = new MobileServiceObjectReader().GetId(new JObject()
            {
                { "id", new JValue(value) }
            });

            Assert.AreEqual(value, actualValue);
        }
Example #9
0
        public void IsDeleted_ReturnsSystemProperty_ByDefault()
        {
            bool value = true;

            bool actualValue = new MobileServiceObjectReader().IsDeleted(new JObject()
            {
                { "__deleted", new JValue(value) }
            });

            Assert.AreEqual(value, actualValue);
        }
Example #10
0
        public void GetVersion_ReturnsCustomProperty_WhenSet()
        {
            string value  = "abc";
            var    reader = new MobileServiceObjectReader()
            {
                VersionPropertyName = "ETag"
            };

            string actualValue = reader.GetVersion(new JObject()
            {
                { "ETag", new JValue(value) }
            });

            Assert.AreEqual(value, actualValue);
        }
Example #11
0
        public void IsDeleted_ReturnsCustomProperty_WhenSet()
        {
            bool value  = true;
            var  reader = new MobileServiceObjectReader()
            {
                DeletedPropertyName = "Deleted"
            };

            bool actualValue = reader.IsDeleted(new JObject()
            {
                { "Deleted", new JValue(value) }
            });

            Assert.AreEqual(value, actualValue);
        }
Example #12
0
        public void GetCreatedAt_ReturnsCustomProperty_WhenSet()
        {
            DateTimeOffset value  = DateTimeOffset.Parse("2001-02-03T00:00:00.0000000+00:00");
            var            reader = new MobileServiceObjectReader()
            {
                CreatedAtPropertyName = "Timestamp"
            };

            DateTimeOffset?actualValue = reader.GetCreatedAt(new JObject()
            {
                { "Timestamp", new JValue(value) }
            });

            Assert.AreEqual(value, actualValue);
        }
        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 GetId_ReturnsCustomProperty_WhenSet()
        {
            string value  = "abc";
            var    reader = new MobileServiceObjectReader()
            {
                IdPropertyName = "Name"
            };

            string actualValue = reader.GetId(new JObject()
            {
                { "Name", new JValue(value) }
            });

            Assert.Equal(value, actualValue);
        }
 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 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 Task PullAsync(string queryId, string query, IDictionary<string, string> parameters, MobileServiceObjectReader reader, CancellationToken cancellationToken, PullOptions pullOptions, params string[] relatedTables)
        {
            ValidateQueryId(queryId);

            return this.syncContext.PullAsync(this.TableName, this.Kind, queryId, query, this.SupportedOptions, parameters, relatedTables, reader, cancellationToken, pullOptions);
        }
        /// <summary>
        /// Pulls all items that match the given query from the associated remote table.
        /// </summary>
        /// <param name="tableName">The name of table to pull</param>
        /// <param name="tableKind">The kind of table</param>
        /// <param name="queryId">A string that uniquely identifies this query and is used to keep track of its sync state.</param>
        /// <param name="query">An OData query that determines which items to 
        /// pull from the remote table.</param>
        /// <param name="options">An instance of <see cref="MobileServiceRemoteTableOptions"/></param>
        /// <param name="parameters">A dictionary of user-defined parameters and values to include in 
        /// the request URI query string.</param>
        /// <param name="relatedTables">
        /// List of tables that may have related records that need to be push before this table is pulled down.
        /// When no table is specified, all tables are considered related.
        /// </param>
        /// <param name="reader">An instance of <see cref="MobileServiceObjectReader"/></param>
        /// <param name="cancellationToken">The <see cref="System.Threading.CancellationToken"/> token to observe
        /// </param>
        /// <param name="pullOptions">
        /// PullOptions that determine how to pull data from the remote table
        /// </param>
        /// <returns>
        /// A task that completes when pull operation has finished.
        /// </returns>
        public async Task PullAsync(string tableName, MobileServiceTableKind tableKind, string queryId, string query, MobileServiceRemoteTableOptions options, IDictionary<string, string> parameters, IEnumerable<string> relatedTables, MobileServiceObjectReader reader, CancellationToken cancellationToken, PullOptions pullOptions)
        {
            await this.EnsureInitializedAsync();

            if (parameters != null)
            {
                if (parameters.Keys.Any(k => k.Equals(MobileServiceTable.IncludeDeletedParameterName, StringComparison.OrdinalIgnoreCase)))
                {
                    throw new ArgumentException("The key '{0}' is reserved and cannot be specified as a query parameter.".FormatInvariant(MobileServiceTable.IncludeDeletedParameterName));
                }
            }

            var table = await this.GetTable(tableName);
            var queryDescription = MobileServiceTableQueryDescription.Parse(this.client.MobileAppUri, tableName, query);

            // local schema should be same as remote schema otherwise push can't function
            if (queryDescription.Selection.Any() || queryDescription.Projections.Any())
            {
                throw new ArgumentException("Pull query with select clause is not supported.", "query");
            }

            bool isIncrementalSync = !String.IsNullOrEmpty(queryId);
            if (isIncrementalSync)
            {
                if (queryDescription.Ordering.Any())
                {
                    throw new ArgumentException("Incremental pull query must not have orderby clause.", "query");
                }
                if (queryDescription.Top.HasValue || queryDescription.Skip.HasValue)
                {
                    throw new ArgumentException("Incremental pull query must not have skip or top specified.", "query");
                }
            }

            if (!options.HasFlag(MobileServiceRemoteTableOptions.OrderBy) && queryDescription.Ordering.Any())
            {
                throw new ArgumentException("The supported table options does not include orderby.", "query");
            }

            if (!options.HasFlag(MobileServiceRemoteTableOptions.Skip) && queryDescription.Skip.HasValue)
            {
                throw new ArgumentException("The supported table options does not include skip.", "query");
            }

            if (!options.HasFlag(MobileServiceRemoteTableOptions.Top) && queryDescription.Top.HasValue)
            {
                throw new ArgumentException("The supported table options does not include top.", "query");
            }

            // let us not burden the server to calculate the count when we don't need it for pull
            queryDescription.IncludeTotalCount = false;

            using (var store = StoreChangeTrackerFactory.CreateTrackedStore(this.Store, StoreOperationSource.ServerPull, this.storeTrackingOptions, this.client.EventManager, this.settings))
            {
                var action = new PullAction(table, tableKind, this, queryId, queryDescription, parameters, relatedTables,
                    this.opQueue, this.settings, store, options, pullOptions, reader, cancellationToken);
                await this.ExecuteSyncAction(action);
            }
        }
        /// <summary>
        /// Pulls all items that match the given query from the associated remote table.
        /// </summary>
        /// <param name="tableName">The name of table to pull</param>
        /// <param name="tableKind">The kind of table</param>
        /// <param name="queryId">A string that uniquely identifies this query and is used to keep track of its sync state.</param>
        /// <param name="query">An OData query that determines which items to
        /// pull from the remote table.</param>
        /// <param name="options">An instance of <see cref="MobileServiceRemoteTableOptions"/></param>
        /// <param name="parameters">A dictionary of user-defined parameters and values to include in
        /// the request URI query string.</param>
        /// <param name="relatedTables">
        /// List of tables that may have related records that need to be push before this table is pulled down.
        /// When no table is specified, all tables are considered related.
        /// </param>
        /// <param name="reader">An instance of <see cref="MobileServiceObjectReader"/></param>
        /// <param name="cancellationToken">The <see cref="System.Threading.CancellationToken"/> token to observe
        /// </param>
        /// <param name="pullOptions">
        /// PullOptions that determine how to pull data from the remote table
        /// </param>
        /// <returns>
        /// A task that completes when pull operation has finished.
        /// </returns>
        public async Task PullAsync(string tableName, MobileServiceTableKind tableKind, string queryId, string query, MobileServiceRemoteTableOptions options, IDictionary <string, string> parameters, IEnumerable <string> relatedTables, MobileServiceObjectReader reader, CancellationToken cancellationToken, PullOptions pullOptions)
        {
            await this.EnsureInitializedAsync();

            if (parameters != null)
            {
                if (parameters.Keys.Any(k => k.Equals(MobileServiceTable.IncludeDeletedParameterName, StringComparison.OrdinalIgnoreCase)))
                {
                    throw new ArgumentException("The key '{0}' is reserved and cannot be specified as a query parameter.".FormatInvariant(MobileServiceTable.IncludeDeletedParameterName));
                }
            }

            var table = await this.GetTable(tableName);

            var queryDescription = MobileServiceTableQueryDescription.Parse(this.client.MobileAppUri, tableName, query);

            // local schema should be same as remote schema otherwise push can't function
            if (queryDescription.Selection.Any() || queryDescription.Projections.Any())
            {
                throw new ArgumentException("Pull query with select clause is not supported.", "query");
            }

            bool isIncrementalSync = !String.IsNullOrEmpty(queryId);

            if (isIncrementalSync)
            {
                if (queryDescription.Ordering.Any())
                {
                    throw new ArgumentException("Incremental pull query must not have orderby clause.", "query");
                }
                if (queryDescription.Top.HasValue || queryDescription.Skip.HasValue)
                {
                    throw new ArgumentException("Incremental pull query must not have skip or top specified.", "query");
                }
            }

            if (!options.HasFlag(MobileServiceRemoteTableOptions.OrderBy) && queryDescription.Ordering.Any())
            {
                throw new ArgumentException("The supported table options does not include orderby.", "query");
            }

            if (!options.HasFlag(MobileServiceRemoteTableOptions.Skip) && queryDescription.Skip.HasValue)
            {
                throw new ArgumentException("The supported table options does not include skip.", "query");
            }

            if (!options.HasFlag(MobileServiceRemoteTableOptions.Top) && queryDescription.Top.HasValue)
            {
                throw new ArgumentException("The supported table options does not include top.", "query");
            }

            // let us not burden the server to calculate the count when we don't need it for pull
            queryDescription.IncludeTotalCount = false;

            using (var store = StoreChangeTrackerFactory.CreateTrackedStore(this.Store, StoreOperationSource.ServerPull, this.storeTrackingOptions, this.client.EventManager, this.settings))
            {
                var action = new PullAction(table, tableKind, this, queryId, queryDescription, parameters, relatedTables,
                                            this.opQueue, this.settings, store, options, pullOptions, reader, cancellationToken);
                await this.ExecuteSyncAction(action);
            }
        }
        public void IsDeleted_ReturnsSystemProperty_ByDefault()
        {
            bool value = true;

            bool actualValue = new MobileServiceObjectReader().IsDeleted(new JObject() { { "deleted", new JValue(value) } });

            Assert.AreEqual(value, actualValue);
        }
        public void IsDeleted_ReturnsCustomProperty_WhenSet()
        {
            bool value = true;
            var reader = new MobileServiceObjectReader() { DeletedPropertyName = "Deleted" };

            bool actualValue = reader.IsDeleted(new JObject() { { "Deleted", new JValue(value) } });

            Assert.AreEqual(value, actualValue);
        }
        /// <summary>
        /// Pulls all items that match the given query from the associated remote table.
        /// </summary>
        /// <param name="tableName">The name of table to pull</param>
        /// <param name="tableKind">The kind of table</param>
        /// <param name="queryId">A string that uniquely identifies this query and is used to keep track of its sync state.</param>
        /// <param name="query">An OData query that determines which items to
        /// pull from the remote table.</param>
        /// <param name="options">An instance of <see cref="MobileServiceRemoteTableOptions"/></param>
        /// <param name="parameters">A dictionary of user-defined parameters and values to include in
        /// the request URI query string.</param>
        /// <param name="relatedTables">
        /// List of tables that may have related records that need to be push before this table is pulled down.
        /// When no table is specified, all tables are considered related.
        /// </param>
        /// <param name="reader">An instance of <see cref="MobileServiceObjectReader"/></param>
        /// <param name="cancellationToken">The <see cref="System.Threading.CancellationToken"/> token to observe
        /// </param>
        /// <returns>
        /// A task that completes when pull operation has finished.
        /// </returns>
        public async Task PullAsync(string tableName, MobileServiceTableKind tableKind, string queryId, string query, MobileServiceRemoteTableOptions options, IDictionary <string, string> parameters, IEnumerable <string> relatedTables, MobileServiceObjectReader reader, CancellationToken cancellationToken)
        {
            await this.EnsureInitializedAsync();

            if (parameters != null)
            {
                if (parameters.Keys.Any(k => k.Equals(MobileServiceTable.IncludeDeletedParameterName, StringComparison.OrdinalIgnoreCase)))
                {
                    throw new ArgumentException(Resources.Pull_Cannot_Use_Reserved_Key.FormatInvariant(MobileServiceTable.IncludeDeletedParameterName));
                }

                if (parameters.Keys.Any(k => k.Equals(MobileServiceTable.SystemPropertiesQueryParameterName, StringComparison.OrdinalIgnoreCase)))
                {
                    throw new ArgumentException(Resources.Pull_Cannot_Use_Reserved_Key.FormatInvariant(MobileServiceTable.SystemPropertiesQueryParameterName));
                }
            }

            var table = await this.GetTable(tableName);

            var queryDescription = MobileServiceTableQueryDescription.Parse(this.client.ApplicationUri, tableName, query);


            // local schema should be same as remote schema otherwise push can't function
            if (queryDescription.Selection.Any() || queryDescription.Projections.Any())
            {
                throw new ArgumentException(Resources.MobileServiceSyncTable_PullWithSelectNotSupported, "query");
            }

            bool isIncrementalSync = !String.IsNullOrEmpty(queryId);

            if (isIncrementalSync)
            {
                if (queryDescription.Ordering.Any())
                {
                    throw new ArgumentException(Resources.MobileServiceSyncTable_IncrementalPullWithOrderNotAllowed, "query");
                }
                if (queryDescription.Top.HasValue || queryDescription.Skip.HasValue)
                {
                    throw new ArgumentException(Resources.MobileServiceSyncTable_IncrementalPullWithSkipTopNotSupported, "query");
                }
            }

            if (!options.HasFlag(MobileServiceRemoteTableOptions.OrderBy) && queryDescription.Ordering.Any())
            {
                throw new ArgumentException(Resources.MobileServiceSyncTable_OrderByNotAllowed, "query");
            }

            if (!options.HasFlag(MobileServiceRemoteTableOptions.Skip) && queryDescription.Skip.HasValue)
            {
                throw new ArgumentException(Resources.MobileServiceSyncTable_SkipNotAllowed, "query");
            }

            if (!options.HasFlag(MobileServiceRemoteTableOptions.Top) && queryDescription.Top.HasValue)
            {
                throw new ArgumentException(Resources.MobileServiceSyncTable_TopNotAllowed, "query");
            }

            // let us not burden the server to calculate the count when we don't need it for pull
            queryDescription.IncludeTotalCount = false;

            var action = new PullAction(table, tableKind, this, queryId, queryDescription, parameters, relatedTables, this.opQueue, this.settings, this.Store, options, reader, cancellationToken);

            await this.ExecuteSyncAction(action);
        }
        public Task PullAsync(string queryId, string query, IDictionary <string, string> parameters, MobileServiceObjectReader reader, CancellationToken cancellationToken, params string[] relatedTables)
        {
            ValidateQueryId(queryId);

            return(this.syncContext.PullAsync(this.TableName, this.Kind, queryId, query, this.SupportedOptions, parameters, relatedTables, reader, cancellationToken));
        }