/// <summary> /// The execute. /// </summary> /// <param name="context"> /// The context. /// </param> /// <exception cref="HttpResponseException"> /// There is a matching ETag /// </exception> protected override void Execute(CodeActivityContext context) { if (this.Request.Get(context).Headers.IfMatch.Any(etag => EntityTag.IsMatchingTag(this.ETag.Get(context), etag.Tag))) { throw new HttpResponseException(HttpStatusCode.PreconditionFailed); } }
/// <summary> /// The check conditional update. /// </summary> /// <param name="request"> /// The request. /// </param> /// <param name="resource"> /// The resource. /// </param> /// <exception cref="HttpResponseException"> /// The precondition failed /// </exception> private static void CheckIfMatch(HttpRequestMessage request, Sample resource) { if (request == null) { throw new ArgumentNullException("request"); } if (resource == null) { throw new ArgumentNullException("resource"); } // No etags if (request.Headers.IfMatch.Count == 0) { return; } // If there is no matching etag, the pre-condition fails if (!request.Headers.IfMatch.Any(etag => EntityTag.IsMatchingTag(resource.Tag, etag.Tag))) { throw new HttpResponseException(HttpStatusCode.PreconditionFailed); } }