/// <summary> /// Updates an instance in the table. /// </summary> /// <param name="instance"> /// The instance to update. /// </param> /// <param name="parameters"> /// A dictionary of user-defined parameters and values to include in /// the request URI query string. /// </param> /// <returns> /// A task that will complete when the update has finished. /// </returns> public async Task UpdateAsync(T instance, IDictionary <string, string> parameters) { if (instance == null) { throw new ArgumentNullException("instance"); } MobileServiceSerializer serializer = this.MobileServiceClient.Serializer; JObject value = serializer.Serialize(instance) as JObject; JToken updatedValue = null; try { updatedValue = await this.UpdateAsync(value, parameters); } catch (MobileServicePreconditionFailedException ex) { T item = default(T); try { item = serializer.Deserialize <T>(ex.Value); } catch { } throw new MobileServicePreconditionFailedException <T>(ex, item); } serializer.Deserialize <T>(updatedValue, instance); }
/// <summary> /// Undeletes an <paramref name="instance"/> from the table. /// </summary> /// <param name="instance">The instance to undelete from the table.</param> /// <param name="parameters"> /// A dictionary of user-defined parameters and values to include in /// the request URI query string. /// </param> /// <returns>A task that will complete when the undelete finishes.</returns> public async Task UndeleteAsync(T instance, IDictionary <string, string> parameters) { Arguments.IsNotNull(instance, nameof(instance)); MobileServiceSerializer serializer = this.MobileServiceClient.Serializer; JObject value = serializer.Serialize(instance) as JObject; JToken updatedValue = await TransformHttpException(serializer, () => UndeleteAsync(value, parameters, MobileServiceFeatures.TypedTable)); serializer.Deserialize(updatedValue, instance); }
/// <summary> /// Inserts a new instance into the table. /// </summary> /// <param name="instance"> /// The instance to insert. /// </param> /// <param name="parameters"> /// A dictionary of user-defined parameters and values to include in /// the request URI query string. /// </param> /// <returns> /// A task that will complete when the insertion has finished. /// </returns> public async Task InsertAsync(T instance, IDictionary <string, string> parameters) { Arguments.IsNotNull(instance, nameof(instance)); MobileServiceSerializer serializer = this.MobileServiceClient.Serializer; JObject value = serializer.Serialize(instance) as JObject; value = MobileServiceSerializer.RemoveSystemProperties(value, out string unused); JToken insertedValue = await TransformHttpException(serializer, () => InsertAsync(value, parameters, MobileServiceFeatures.TypedTable)); serializer.Deserialize(insertedValue, instance); }
/// <summary> /// Deletes an instance from the table. /// </summary> /// <param name="instance"> /// The instance to delete. /// </param> /// <param name="parameters"> /// A dictionary of user-defined parameters and values to include in /// the request URI query string. /// </param> /// <returns> /// A task that will complete when the delete has finished. /// </returns> public async Task DeleteAsync(T instance, IDictionary <string, string> parameters) { Arguments.IsNotNull(instance, nameof(instance)); MobileServiceSerializer serializer = this.MobileServiceClient.Serializer; JObject value = serializer.Serialize(instance) as JObject; await TransformHttpException(serializer, () => DeleteAsync(value, parameters, MobileServiceFeatures.TypedTable)); // Clear the instance id since it's no longer associated with that // id on the server (note that reflection is goodly enough to turn // null into the correct value for us). serializer.SetIdToDefault(instance); }
/// <summary> /// Deletes an instance from the table. /// </summary> /// <param name="instance"> /// The instance to delete. /// </param> /// <param name="parameters"> /// A dictionary of user-defined parameters and values to include in /// the request URI query string. /// </param> /// <returns> /// A task that will complete when the delete has finished. /// </returns> public async Task DeleteAsync(T instance, IDictionary <string, string> parameters) { if (instance == null) { throw new ArgumentNullException("instance"); } MobileServiceSerializer serializer = this.MobileServiceClient.Serializer; JObject value = serializer.Serialize(instance) as JObject; await this.DeleteAsync(value, parameters); // Clear the instance id since it's no longer associated with that // id on the server (note that reflection is goodly enough to turn // null into the correct value for us). serializer.SetIdToDefault(instance); }
public async Task <U> InvokeApiAsync <T, U>(string apiName, T body, HttpMethod method, IDictionary <string, string> parameters, CancellationToken cancellationToken = default) { Arguments.IsNotNullOrWhiteSpace(apiName, nameof(apiName)); MobileServiceSerializer serializer = this.Serializer; string content = null; if (body != null) { content = serializer.Serialize(body).ToString(); } string response = await this.InternalInvokeApiAsync(apiName, content, method, parameters, MobileServiceFeatures.TypedApiCall, cancellationToken); if (string.IsNullOrEmpty(response)) { return(default);
/// <summary> /// Inserts a new instance into the table. /// </summary> /// <param name="instance"> /// The instance to insert. /// </param> /// <param name="parameters"> /// A dictionary of user-defined parameters and values to include in /// the request URI query string. /// </param> /// <returns> /// A task that will complete when the insertion has finished. /// </returns> public async Task InsertAsync(T instance, IDictionary <string, string> parameters) { if (instance == null) { throw new ArgumentNullException("instance"); } MobileServiceSerializer serializer = this.MobileServiceClient.Serializer; JObject value = serializer.Serialize(instance) as JObject; if (!this.hasIntegerId) { string unused; value = RemoveSystemProperties(value, out unused); } JToken insertedValue = await this.InsertAsync(value, parameters); serializer.Deserialize <T>(insertedValue, instance); }
/// <summary> /// Invokes a user-defined custom API of a Windows Azure Mobile Service using the specified HTTP Method. /// Additional data can be sent though the HTTP content or the query string. /// </summary> /// <typeparam name="T">The type of instance sent to the Windows Azure Mobile Service.</typeparam> /// <typeparam name="U">The type of instance returned from the Windows Azure Mobile Service.</typeparam> /// <param name="apiName">The name of the custom API.</param> /// <param name="body">The value to be sent as the HTTP body.</param> /// <param name="method">The HTTP method.</param> /// <param name="parameters"> /// A dictionary of user-defined parameters and values to include in the request URI query string. /// </param> /// <returns>The response content from the custom api invocation.</returns> public async Task <U> InvokeApiAsync <T, U>(string apiName, T body, HttpMethod method, IDictionary <string, string> parameters) { if (string.IsNullOrWhiteSpace(apiName)) { throw new ArgumentNullException("apiName"); } MobileServiceSerializer serializer = this.Serializer; string content = null; if (body != null) { content = serializer.Serialize(body); } string response = await this.InternalInvokeApiAsync(apiName, content, method, parameters); return(serializer.Deserialize <U>(response)); }