当前位置: 首页>>代码示例>>C#>>正文


C# Headers.EntityTagHeaderValue类代码示例

本文整理汇总了C#中System.Net.Http.Headers.EntityTagHeaderValue的典型用法代码示例。如果您正苦于以下问题:C# EntityTagHeaderValue类的具体用法?C# EntityTagHeaderValue怎么用?C# EntityTagHeaderValue使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


EntityTagHeaderValue类属于System.Net.Http.Headers命名空间,在下文中一共展示了EntityTagHeaderValue类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: RangeConditionHeaderValue

		public RangeConditionHeaderValue (EntityTagHeaderValue entityTag)
		{
			if (entityTag == null)
				throw new ArgumentNullException ("entityTag");

			EntityTag = entityTag;
		}
开发者ID:nlhepler,项目名称:mono,代码行数:7,代码来源:RangeConditionHeaderValue.cs

示例2: EntityTagHeaderValue

        private EntityTagHeaderValue(EntityTagHeaderValue source)
        {
            Contract.Requires(source != null);

            _tag = source._tag;
            _isWeak = source._isWeak;
        }
开发者ID:ChuangYang,项目名称:corefx,代码行数:7,代码来源:EntityTagHeaderValue.cs

示例3: EntityTagHeaderValue

        private EntityTagHeaderValue(EntityTagHeaderValue source)
        {
            Contract.Requires(source != null);

            this.tag = source.tag;
            this.isWeak = source.isWeak;
        }
开发者ID:nuxleus,项目名称:WCFWeb,代码行数:7,代码来源:EntityTagHeaderValue.cs

示例4: OnActionExecuted

        /// <summary>
        /// The on action executed.
        /// </summary>
        /// <param name="context">
        /// The context.
        /// </param>
        public override void OnActionExecuted(HttpActionExecutedContext context)
        {
            var request = context.Request;
            var key = GetKey(request);

            EntityTagHeaderValue etag = null;

            bool isGet = request.Method == HttpMethod.Get;
            bool isPutOrPost = request.Method == HttpMethod.Put || request.Method == HttpMethod.Post;

            if (isPutOrPost)
            {
                ////empty the dictionary because the resource has been changed.So now all tags will be cleared and data
                //// will be fetched from server. It would be good to implement a logic in which only change the ETags
                //// of that urls which are affected by this post or put method rather than clearing entire dictionary
                     etags.Clear();
                //// generate new ETag for Put or Post because the resource is changed.
                    etag = new EntityTagHeaderValue("\"" + Guid.NewGuid().ToString() + "\"");
                    etags.AddOrUpdate(key, etag, (k, val) => etag);

            }
            //if ((isGet && !etags.TryGetValue(key, out etag)) || isPutOrPost)
            //{
            //    //// generate new ETag for Put or Post because the resource is changed.
            //    etag = new EntityTagHeaderValue("\"" + Guid.NewGuid().ToString() + "\"");
            //    etags.AddOrUpdate(key, etag, (k, val) => etag);
            //}

            if (isGet)
            {
                context.Response.Headers.ETag = etag;
            }
        }
开发者ID:sandipuchdadiya,项目名称:QTecApp,代码行数:39,代码来源:ETagAttribute.cs

示例5: GetInternal

	    protected HttpResponseMessage GetInternal(string path)
	    {
	        var pathInfo = PathInfo.Create(path);

	        var filePath = _fileSystem.Path.Combine(this.FilePath, pathInfo);
            if (!_fileSystem.FileExists(filePath))
                return new HttpResponseMessage(HttpStatusCode.NotFound);

	        var eTag = new EntityTagHeaderValue(string.Concat("\"", _fileSystem.GetFileInfo(filePath).Etag, "\""));
	        if (Request.Headers.IfNoneMatch != null)
	        {
	            foreach (var noneMatch in Request.Headers.IfNoneMatch)
	            {
	                if (eTag.Equals(noneMatch))
	                    return new HttpResponseMessage(HttpStatusCode.NotModified);
	            }
	        }

            var stream = _fileSystem.OpenRead(filePath);
            var message = new HttpResponseMessage(HttpStatusCode.OK) { Content = new StreamContent(stream) };
            message.Content.Headers.ContentType = new MediaTypeHeaderValue(GetMimeType(_fileSystem.Path.GetExtension(pathInfo).ToLower()));
	        message.Headers.ETag = eTag;

			// remove Pragma
		    message.Headers.Remove("Pragma");

		    message.Headers.CacheControl = new CacheControlHeaderValue {Private = true, MaxAge = TimeSpan.Zero};
			message.Content.Headers.Expires = DateTimeOffset.Now.Subtract(TimeSpan.FromSeconds(1));
		    //message.Content.Headers.LastModified

			return message;
	    }
开发者ID:namics,项目名称:TerrificNet,代码行数:32,代码来源:StaticFileController.cs

示例6: ParseETag

        public IDictionary<string, object> ParseETag(EntityTagHeaderValue etagHeaderValue)
        {
            if (etagHeaderValue == null)
            {
                throw Error.ArgumentNull("etagHeaderValue");
            }

            string tag = etagHeaderValue.Tag.Trim('\"');

            // split etag
            string[] rawValues = tag.Split(Separator);
            IDictionary<string, object> properties = new Dictionary<string, object>();
            for (int index = 0; index < rawValues.Length; index++)
            {
                string rawValue = rawValues[index];

                // base64 decode
                byte[] bytes = Convert.FromBase64String(rawValue);
                string valueString = Encoding.UTF8.GetString(bytes);
                object obj = ODataUriUtils.ConvertFromUriLiteral(valueString, ODataVersion.V3);
                if (obj is ODataUriNullValue)
                {
                    obj = null;
                }
                properties.Add(index.ToString(CultureInfo.InvariantCulture), obj);
            }

            return properties;
        }
开发者ID:ZhaoYngTest01,项目名称:WebApi,代码行数:29,代码来源:DefaultODataETagHandler.cs

示例7: EntityTagHeaderValue

        private EntityTagHeaderValue(EntityTagHeaderValue source)
        {
            Debug.Assert(source != null);

            _tag = source._tag;
            _isWeak = source._isWeak;
        }
开发者ID:Corillian,项目名称:corefx,代码行数:7,代码来源:EntityTagHeaderValue.cs

示例8: Equals

 public void Equals()
 {
     var tfhv = new EntityTagHeaderValue ("\"abc\"");
     Assert.AreEqual (tfhv, new EntityTagHeaderValue ("\"abc\""), "#1");
     Assert.AreNotEqual (tfhv, new EntityTagHeaderValue ("\"AbC\""), "#2");
     Assert.AreNotEqual (tfhv, new EntityTagHeaderValue ("\"AA\""), "#3");
 }
开发者ID:RainsSoft,项目名称:dotnet-httpclient35,代码行数:7,代码来源:EntityTagHeaderValueTest.cs

示例9: NotModifiedResponse

        public NotModifiedResponse(HttpRequestMessage request, EntityTagHeaderValue etag)
            : base(HttpStatusCode.NotModified)
        {
            if(etag!=null)
                this.Headers.ETag = etag;

            this.RequestMessage = request;
        }
开发者ID:erpframework,项目名称:CacheCow,代码行数:8,代码来源:NotModifiedResponse.cs

示例10: RangeConditionHeaderValue

        public RangeConditionHeaderValue(EntityTagHeaderValue entityTag)
        {
            if (entityTag == null)
            {
                throw new ArgumentNullException(nameof(entityTag));
            }

            _entityTag = entityTag;
        }
开发者ID:shiftkey-tester,项目名称:corefx,代码行数:9,代码来源:RangeConditionHeaderValue.cs

示例11: SendAsync

        protected override Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
        {
            if (request.Method == HttpMethod.Get)
            {
                // should we ignore trailing slash
                var resource = request.RequestUri.ToString();

                ICollection<EntityTagHeaderValue> etags = request.Headers.IfNoneMatch;
                // compare the Etag with the one in the cache
                // do conditional get.
                EntityTagHeaderValue actualEtag = null;
                if (etags.Count > 0 && ETagHandler.ETagCache.TryGetValue(resource, out actualEtag))
                {
                    if (etags.Any(etag => etag.Tag == actualEtag.Tag))
                    {
                        return Task.Factory.StartNew<HttpResponseMessage>(task => new NotModifiedResponse(), cancellationToken);
                    }
                }
            }
            else if (request.Method == HttpMethod.Put)
            {
                // should we ignore trailing slash
                var resource = request.RequestUri.ToString();

                ICollection<EntityTagHeaderValue> etags = request.Headers.IfMatch;
                // compare the Etag with the one in the cache
                // do conditional get.

                EntityTagHeaderValue actualEtag = null;
                if (etags.Count > 0 && ETagHandler.ETagCache.TryGetValue(resource, out actualEtag))
                {
                    var matchFound = etags.Any(etag => etag.Tag == actualEtag.Tag);

                    if (!matchFound)
                    {
                        return Task.Factory.StartNew<HttpResponseMessage>(task => new ConflictResponse(), cancellationToken);
                    }
                }
            }
            return base.SendAsync(request, cancellationToken).ContinueWith(task =>
            {
                var httpResponse = task.Result;
                var eTagKey = request.RequestUri.ToString();
                EntityTagHeaderValue eTagValue;

                // Post would invalidate the collection, put should invalidate the individual item
                if (!ETagCache.TryGetValue(eTagKey, out eTagValue) || request.Method == HttpMethod.Put || request.Method == HttpMethod.Post)
                {
                    eTagValue = new EntityTagHeaderValue("\"" + Guid.NewGuid().ToString() + "\"");
                    ETagCache.AddOrUpdate(eTagKey, eTagValue, (key, existingVal) => eTagValue);
                }
                httpResponse.Headers.ETag = eTagValue;

                return httpResponse;
            });
        }
开发者ID:BiaoLiu,项目名称:osharp,代码行数:56,代码来源:ETagHandler.cs

示例12: SetEntityTagHeader

        public static void SetEntityTagHeader(this HttpResponseMessage httpResponseMessage, EntityTagHeaderValue etag, DateTime lastModified)
        {
            if (httpResponseMessage.Content == null)
            {
                httpResponseMessage.Content = new NullContent();
            }

            httpResponseMessage.Headers.ETag = etag;
            httpResponseMessage.Content.Headers.LastModified = lastModified;
        }
开发者ID:NorimaConsulting,项目名称:kudu,代码行数:10,代码来源:HttpResponseMessageExtensions.cs

示例13: ToString_UseDifferentETags_AllSerializedCorrectly

        public void ToString_UseDifferentETags_AllSerializedCorrectly()
        {
            EntityTagHeaderValue etag = new EntityTagHeaderValue("\"e tag\"");
            Assert.Equal("\"e tag\"", etag.ToString());

            etag = new EntityTagHeaderValue("\"e tag\"", true);
            Assert.Equal("W/\"e tag\"", etag.ToString());

            etag = new EntityTagHeaderValue("\"\"", false);
            Assert.Equal("\"\"", etag.ToString());
        }
开发者ID:ChuangYang,项目名称:corefx,代码行数:11,代码来源:EntityTagHeaderValueTest.cs

示例14: Should_return_Conflict_for_Put_if_key_is_in_header_but_match_not_found_in_cache

        public void Should_return_Conflict_for_Put_if_key_is_in_header_but_match_not_found_in_cache()
        {
            var eTagHandler = GetHandler();

            var requestMessage = new HttpRequestMessage(HttpMethod.Put, etag.Key);
            requestMessage.Headers.Add("If-Match", etag.Value.Tag);

            var newRandomValue = new EntityTagHeaderValue("\"" + Guid.NewGuid() + "\"");
            AddETagValue(new KeyValuePair<string, EntityTagHeaderValue>(etag.Key, newRandomValue));

            var response = ExecuteRequest(eTagHandler, requestMessage);

            response.StatusCode.ShouldEqual(HttpStatusCode.Conflict);
        }
开发者ID:aehyok,项目名称:WebAPIContrib,代码行数:14,代码来源:ETagHandlerTests.cs

示例15: GetHashCode_UseSameAndDifferentETags_SameOrDifferentHashCodes

        public void GetHashCode_UseSameAndDifferentETags_SameOrDifferentHashCodes()
        {
            EntityTagHeaderValue etag1 = new EntityTagHeaderValue("\"tag\"");
            EntityTagHeaderValue etag2 = new EntityTagHeaderValue("\"TAG\"");
            EntityTagHeaderValue etag3 = new EntityTagHeaderValue("\"tag\"", true);
            EntityTagHeaderValue etag4 = new EntityTagHeaderValue("\"tag1\"");
            EntityTagHeaderValue etag5 = new EntityTagHeaderValue("\"tag\"");
            EntityTagHeaderValue etag6 = EntityTagHeaderValue.Any;

            Assert.NotEqual(etag1.GetHashCode(), etag2.GetHashCode());
            Assert.NotEqual(etag1.GetHashCode(), etag3.GetHashCode());
            Assert.NotEqual(etag1.GetHashCode(), etag4.GetHashCode());
            Assert.NotEqual(etag1.GetHashCode(), etag6.GetHashCode());
            Assert.Equal(etag1.GetHashCode(), etag5.GetHashCode());
        }
开发者ID:ChuangYang,项目名称:corefx,代码行数:15,代码来源:EntityTagHeaderValueTest.cs


注:本文中的System.Net.Http.Headers.EntityTagHeaderValue类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。