示例#1
0
        /// <summary>
        /// Adds the given value to the collection
        /// </summary>
        /// <param name="targetResource">target object which defines the property</param>
        /// <param name="propertyName">name of the property whose value needs to be updated</param>
        /// <param name="resourceToBeAdded">value of the property which needs to be added</param>
        public virtual void AddReferenceToCollection(object targetResource, string propertyName, object resourceToBeAdded)
        {
            ExceptionUtilities.CheckArgumentNotNull(targetResource, "targetResource");
            ExceptionUtilities.CheckArgumentNotNull(propertyName, "propertyName");
            ExceptionUtilities.CheckArgumentNotNull(resourceToBeAdded, "resourceToBeAdded");

            // resolve the target token
            var targetToken = UpdatableToken.AssertIsToken(targetResource, "targetResource");

            targetResource = targetToken.Resource;

            // resolve the added token
            resourceToBeAdded = UpdatableToken.AssertIsTokenAndResolve(resourceToBeAdded, "resourceToBeAdded");

            // All resource set reference properties must be of type IList<T> where T is the type of an entitySet
            // Note that we don't support bi-directional relationships so we only handle the one resource set reference property in isolation.
            IList list = this.GetValue(targetToken, propertyName) as IList;

            ExceptionUtilities.CheckObjectNotNull(list, "Property '{0}' on type '{1}' was not a list", propertyName, targetResource.GetType().Name);

            this.pendingChanges.Add(() =>
            {
                list.Add(resourceToBeAdded);
            });
        }
示例#2
0
 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]);
     }
 }
示例#3
0
        public virtual void RemoveReferenceFromCollection(object targetResource, string propertyName, object resourceToBeRemoved)
        {
            ExceptionUtilities.CheckArgumentNotNull(targetResource, "targetResource");
            ExceptionUtilities.CheckArgumentNotNull(propertyName, "propertyName");
            ExceptionUtilities.CheckArgumentNotNull(resourceToBeRemoved, "resourceToBeRemoved");
            UpdatableToken.AssertIsToken(targetResource, "targetResource");
            resourceToBeRemoved = UpdatableToken.AssertIsTokenAndResolve(resourceToBeRemoved, "resourceToBeRemoved");
            IList list = this.GetValue(targetResource, propertyName) as IList;

            ExceptionUtilities.CheckObjectNotNull(list, "Property '{0}' on type '{1}' was not a list", new object[] { propertyName, targetResource.GetType().Name });
            this.pendingChanges.Add(delegate {
                list.Remove(resourceToBeRemoved);
            });
        }
示例#4
0
        public virtual void DeleteResource(object targetResource)
        {
            ExceptionUtilities.CheckArgumentNotNull(targetResource, "targetResource");
            targetResource = UpdatableToken.AssertIsTokenAndResolve(targetResource, "targetResource");
            string resourceSetName = this.GetResourceSetOfTargetResource(targetResource);

            ExceptionUtilities.CheckObjectNotNull(resourceSetName, "Unable to find set of the resource to delete", new object[0]);
            this.deletedObjects.Add(targetResource);
            IList resourceSetList = this.GetResourceSetEntities(resourceSetName);

            this.DeleteAllReferences(targetResource);
            this.pendingChanges.Add(delegate {
                resourceSetList.Remove(targetResource);
            });
        }
示例#5
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");
        }
示例#6
0
        /// <summary>
        /// Delete the given resource
        /// </summary>
        /// <param name="targetResource">resource that needs to be deleted</param>
        public virtual void DeleteResource(object targetResource)
        {
            ExceptionUtilities.CheckArgumentNotNull(targetResource, "targetResource");

            targetResource = UpdatableToken.AssertIsTokenAndResolve(targetResource, "targetResource");

            string resourceSetName = this.GetResourceSetOfTargetResource(targetResource);

            ExceptionUtilities.CheckObjectNotNull(resourceSetName, "Unable to find set of the resource to delete");

            this.deletedObjects.Add(targetResource);

            IList resourceSetList = this.GetResourceSetEntities(resourceSetName);

            // Remove any any references this target resource has
            this.DeleteAllReferences(targetResource);

            // Add a pending change to remove the resource from the resource set
            this.pendingChanges.Add(() =>
            {
                resourceSetList.Remove(targetResource);
            });
        }
示例#7
0
 public virtual object ResolveResource(object resource)
 {
     ExceptionUtilities.CheckArgumentNotNull(resource, "resource");
     return(UpdatableToken.AssertIsTokenAndResolve(resource, "resource"));
 }