/// <summary> /// Removes system properties from the passed in item /// </summary> /// <param name="item"> /// The item returned from the server /// </param> /// <param name="parameters"> /// A dictionary of user-defined parameters and values to include in /// the request URI query string. /// </param> /// <param name="version"> /// Set to the value of the version system property before it is removed. /// </param> /// <returns> /// An item that only contains normal fields and the requested system properties /// </returns> private JToken RemoveUnrequestedSystemProperties(JToken item, IDictionary <string, string> parameters, string version) { object id = null; if (item == null) { return(null); } MobileServiceSerializer.TryGetId(item as JObject, true, out id); if (id == null || MobileServiceSerializer.IsIntegerId(id)) { return(item); } var actualSystemProperties = GetRequestedSystemProperties(parameters); if (actualSystemProperties == MobileServiceSystemProperties.All) { return(item); } string ignoredVersion = null; var cleanedItem = MobileServiceSerializer.RemoveSystemProperties(item as JObject, out ignoredVersion, actualSystemProperties); if (version != null) { cleanedItem[MobileServiceSerializer.VersionSystemPropertyString] = GetValueFromEtag(version); } return(cleanedItem); }
/// <summary> /// if id is of type string then it strips the system properties and adds version header. /// </summary> /// <returns>The header collection with if-match header.</returns> private Dictionary <string, string> StripSystemPropertiesAndAddVersionHeader(ref JObject instance, ref IDictionary <string, string> parameters, object id) { string version = null; instance = MobileServiceSerializer.RemoveSystemProperties(instance, out version); Dictionary <string, string> headers = AddIfMatchHeader(version); return(headers); }
/// <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> /// 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; string unused; value = MobileServiceSerializer.RemoveSystemProperties(value, out unused); JToken insertedValue = await TransformHttpException(serializer, () => this.InsertAsync(value, parameters, MobileServiceFeatures.TypedTable)); serializer.Deserialize <T>(insertedValue, instance); }