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


C# IRequest.StreamResponse方法代码示例

本文整理汇总了C#中IRequest.StreamResponse方法的典型用法代码示例。如果您正苦于以下问题:C# IRequest.StreamResponse方法的具体用法?C# IRequest.StreamResponse怎么用?C# IRequest.StreamResponse使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在IRequest的用法示例。


在下文中一共展示了IRequest.StreamResponse方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Handle

		/// <summary>
		/// Tries to handle an incoming request.
		/// </summary>
		/// <param name="api">The current api</param>
		/// <param name="request">The incoming route request</param>
		/// <returns>The result</returns>
		public IResponse Handle(Api api, IRequest request) {
			var slug = request.Segments.Length > 1 ? request.Segments[1] : "";
			int? width = null, height = null;

			if (!String.IsNullOrWhiteSpace(slug)) {
				var index = slug.LastIndexOf('.');

				if (index != -1) {
					var name = slug.Substring(0, index);
					var ending = slug.Substring(index);

					var segments = name.Split(new char[] { '_' });

					if (segments.Length > 2) {
						height = Convert.ToInt32(segments[2]);
					}
					if (segments.Length > 1) {
						width = Convert.ToInt32(segments[1]);
					}
					slug = segments[0] + ending;
				}

				var media = api.Media.GetSingle(slug);

				if (media != null) {
					var response = request.StreamResponse();
					var data = App.Media.Get(media);

					if (data != null) {
						response.ContentType = media.ContentType;

						if (width.HasValue) {
							using (var mem = new MemoryStream(data)) {
								// Get the image
								var image = Image.FromStream(mem);								

								// Scale & resize
								image = height.HasValue ? 
									Drawing.ImageUtils.Resize(image, width.Value, height.Value) :
									Drawing.ImageUtils.Resize(image, width.Value);

								// Save to output stream
								image.Save(response.OutputStream, image.RawFormat);
							}
						} else {
							using (var writer = new BinaryWriter(response.OutputStream)) {
								writer.Write(data);
							}
						}
						return response;
					}
				}
			}
			return null;
		}
开发者ID:cdie,项目名称:Piranha.vNext,代码行数:61,代码来源:MediaHandler.cs

示例2: Handle

		/// <summary>
		/// Tries to handle an incoming request.
		/// </summary>
		/// <param name="api">The current api</param>
		/// <param name="request">The incoming route request</param>
		/// <returns>The result</returns>
		public IResponse Handle(Api api, IRequest request) {
			var now = DateTime.Now;

			if (request.Segments.Length == 1 || String.IsNullOrWhiteSpace(request.Segments[1])) {
				// Post feed for the entire site
				var posts = api.Posts.Get(where: p => p.Published <= now, limit: Config.Site.ArchivePageSize);

				var feed = new Syndication.PostRssFeed(posts);
				var response = request.StreamResponse();

				feed.Write(response);

				return response;
			} else if (request.Segments[1] == "comments") {
				// Comment feed for the entire site
				var comments = api.Comments.Get(where: c => c.IsApproved, 
					order: q => q.OrderByDescending(c => c.Created),
					limit: Config.Site.ArchivePageSize);

				var feed = new Syndication.CommentRssFeed(comments);
				var response = request.StreamResponse();

				feed.Write(response);

				return response;
			} else {
				var type = api.PostTypes.GetSingle(request.Segments[1]);

				if (type != null) {
					// Comment feed for an individual post
					if (request.Segments.Length > 2 && !String.IsNullOrWhiteSpace(request.Segments[2])) {
						var post = PostModel.GetBySlug(request.Segments[2], type.Id).WithComments();

						if (post != null) {
							var comments = api.Comments.Get(where: c => c.IsApproved && c.PostId == post.Id,
								order: q => q.OrderByDescending(c => c.Created),
								limit: Config.Site.ArchivePageSize);

							var feed = new Syndication.CommentRssFeed(comments);
							var response = request.StreamResponse();

							feed.Write(response);

							return response;
						}
					} else {
						// Post feed for an individual post type
						var posts = api.Posts.Get(where: p => p.Published <= now && p.TypeId == type.Id, 
							limit: Config.Site.ArchivePageSize);

						var feed = new Syndication.PostRssFeed(posts);
						var response = request.StreamResponse();

						feed.Write(response);

						return response;
					}
				}
			}
			return null;
		}
开发者ID:cdie,项目名称:Piranha.vNext,代码行数:67,代码来源:FeedHandler.cs


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