Пример #1
0
        public static bool IsModifiedOrNoneMatch(string ifNoneMatch, string ifModifiedSince, string resourceVersionNumber, DateTimeOffset?lastModified)
        {
            if (!string.IsNullOrWhiteSpace(ifNoneMatch))
            {
                if (resourceVersionNumber != HttpHeaderSupport.GetETagValueFromETagString(ifNoneMatch.Trim()))
                {
                    return(true);
                }
            }

            if (!string.IsNullOrWhiteSpace(ifModifiedSince))
            {
                DateTimeOffset?ifModifiedSinceDateTimeOffset = HttpHeaderSupport.ParseHttpDate(ifModifiedSince);
                if (!ifModifiedSinceDateTimeOffset.HasValue)
                {
                    string ErrorMessage     = "if-Modified-Since value could not be converted to a DateTime. The value found was: " + ifModifiedSince;
                    var    Operationoutcome = Common.Tools.FhirOperationOutcomeSupport.Create(OperationOutcome.IssueSeverity.Fatal, OperationOutcome.IssueType.Exception, ErrorMessage);
                    throw new PyroException(System.Net.HttpStatusCode.InternalServerError, Operationoutcome, ErrorMessage);
                }
                //Remove the milliseconds
                lastModified = new DateTimeOffset(lastModified.Value.Year, lastModified.Value.Month, lastModified.Value.Day, lastModified.Value.Hour, lastModified.Value.Minute, lastModified.Value.Second, 0, lastModified.Value.Offset);
                ifModifiedSinceDateTimeOffset = new DateTimeOffset(ifModifiedSinceDateTimeOffset.Value.Year, ifModifiedSinceDateTimeOffset.Value.Month, ifModifiedSinceDateTimeOffset.Value.Day, ifModifiedSinceDateTimeOffset.Value.Hour, ifModifiedSinceDateTimeOffset.Value.Minute, ifModifiedSinceDateTimeOffset.Value.Second, 0, ifModifiedSinceDateTimeOffset.Value.Offset);
                if (lastModified > ifModifiedSinceDateTimeOffset)
                {
                    return(true);
                }
            }
            return(false);
        }
Пример #2
0
        /// <summary>
        /// Expects a Etag string e.g(W/"3141") and returns 3214 as a string
        /// </summary>
        /// <param name="ETag"></param>
        /// <returns>EntityTagHeaderValue</returns>
        public static string GetETagValueFromETagString(string ETag)
        {
            EntityTagHeaderValue TempEtag = HttpHeaderSupport.GetETagEntityTagHeaderValueFromETagString(ETag);

            return(TempEtag.Tag.Trim(new Char[] { '\"' }));
        }