public virtual void SetConcurrencyValues(object resourceCookie, bool?checkForEquality, IEnumerable <KeyValuePair <string, object> > concurrencyValues) { ExceptionUtilities.CheckArgumentNotNull(resourceCookie, "resourceCookie"); ExceptionUtilities.ThrowDataServiceExceptionIfFalse(checkForEquality.HasValue, 0x1a1, "Missing concurrency token for update operation", new object[0]); ExceptionUtilities.Assert(checkForEquality.Value, "Should not be called with check for equality parameter equal to false", new object[0]); ExceptionUtilities.CheckArgumentNotNull(concurrencyValues, "concurrencyValues"); if (concurrencyValues.Any <KeyValuePair <string, object> >()) { resourceCookie = UpdatableToken.AssertIsTokenAndResolve(resourceCookie, "resourceCookie"); ExceptionUtilities.ThrowDataServiceExceptionIfFalse(CompareETagValues(this.GetConcurrencyValues(resourceCookie), concurrencyValues), 0x19c, "Concurrency tokens do not match", new object[0]); } }
/// <summary> /// Sets the concurrencyValues /// </summary> /// <param name="resourceCookie">The resource to be evaluated</param> /// <param name="checkForEquality">Determines whether to apply the equality check or not</param> /// <param name="concurrencyValues">The concurrency values to compare against</param> public virtual void SetConcurrencyValues(object resourceCookie, bool?checkForEquality, IEnumerable <KeyValuePair <string, object> > concurrencyValues) { ExceptionUtilities.CheckArgumentNotNull(resourceCookie, "resourceCookie"); ExceptionUtilities.ThrowDataServiceExceptionIfFalse(checkForEquality.HasValue, 417, "Missing concurrency token for update operation"); ExceptionUtilities.Assert(checkForEquality.Value, "Should not be called with check for equality parameter equal to false"); ExceptionUtilities.CheckArgumentNotNull(concurrencyValues, "concurrencyValues"); // If-Match: * if (!concurrencyValues.Any()) { return; } resourceCookie = UpdatableToken.AssertIsTokenAndResolve(resourceCookie, "resourceCookie"); Dictionary <string, object> etags = this.GetConcurrencyValues(resourceCookie); bool matches = CompareETagValues(etags, concurrencyValues); ExceptionUtilities.ThrowDataServiceExceptionIfFalse(matches, 412, "Concurrency tokens do not match"); }
private UpdatableToken InstantiateResourceType(string fullTypeName) { Type t = this.ReflectionMetadataHelper.FindClrTypeByFullName(fullTypeName); ExceptionUtilities.ThrowDataServiceExceptionIfFalse(!t.IsAbstract, 400, "Cannot create resource because type \"{0}\" is abstract", t.FullName); var instance = Activator.CreateInstance(t); var token = new UpdatableToken(instance); foreach (var p in t.GetProperties().Where(p => p.CanWrite)) { // make local variable so that lambdas below work var property = p; if (this.IsCollectionProperty(property)) { Type collectionType = this.GetCollectionPropertyType(GetResourceTypeFullName(t), property.Name); if (collectionType != null) { var newCollection = Activator.CreateInstance(collectionType); token.PendingPropertyUpdates[property.Name] = newCollection; this.pendingChanges.Add(() => property.SetValue(instance, newCollection, null)); } } string entitySetName = this.ReflectionMetadataHelper.FindSetNameForType(t); object generatedValue; if (this.TryGetStoreGeneratedValue(entitySetName, fullTypeName, property.Name, out generatedValue)) { token.PendingPropertyUpdates[property.Name] = generatedValue; this.pendingChanges.Add(() => property.SetValue(instance, generatedValue, null)); } } return(token); }