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


C# HttpServerResponse.WriteBinary方法代码示例

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


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

示例1: HttpGetHistoryGraph

		private static void HttpGetHistoryGraph (HttpServerResponse resp, HttpServerRequest req)
		{
			networkLed.High ();
			try
			{
				string SessionId = req.Header.GetCookie ("SessionId");
				if (!CheckSession (SessionId))
					throw new HttpException (HttpStatusCode.ClientError_Forbidden);

				string ValueAxis;
				string ParameterName;
				string s;
				int Width, Height;

				if (!req.Query.TryGetValue ("w", out s) || !int.TryParse (s, out Width) || Width <= 0 || Width > 2048)
					throw new HttpException (HttpStatusCode.ClientError_BadRequest);

				if (!req.Query.TryGetValue ("h", out s) || !int.TryParse (s, out Height) || Height <= 0 || Height > 2048)
					throw new HttpException (HttpStatusCode.ClientError_BadRequest);

				if (!req.Query.TryGetValue ("p", out s))
					throw new HttpException (HttpStatusCode.ClientError_BadRequest);

				switch (s)
				{
					case "temp":
						ParameterName = "TemperatureC";
						ValueAxis = "Temperature (C)";
						break;

					case "light":
						ParameterName = "LightPercent";
						ValueAxis = "Light (%)";
						break;

					case "motion":
						ParameterName = "Motion";
						ValueAxis = "Motion";
						break;

					default:
						throw new HttpException (HttpStatusCode.ClientError_BadRequest);
				}

				if (!req.Query.TryGetValue ("base", out s))
					throw new HttpException (HttpStatusCode.ClientError_BadRequest);

				Variables v = new Variables ();
				DateTime Now = DateTime.Now;

				lock (synchObject)
				{
					switch (s)
					{
						case "sec":
							v ["Records"] = perSecond.ToArray ();
							resp.Expires = Now;
							break;

						case "min":
							v ["Records"] = perMinute.ToArray ();
							resp.Expires = new DateTime (Now.Year, Now.Month, Now.Day, Now.Hour, Now.Minute, 0).AddMinutes (1);
							break;

						case "h":
							v ["Records"] = perHour.ToArray ();
							resp.Expires = new DateTime (Now.Year, Now.Month, Now.Day, Now.Hour, 0, 0).AddHours (1);
							break;

						case "day":
							v ["Records"] = perDay.ToArray ();
							resp.Expires = new DateTime (Now.Year, Now.Month, Now.Day, 0, 0, 0).AddDays (1);
							break;

						case "month":
							v ["Records"] = perMonth.ToArray ();
							resp.Expires = new DateTime (Now.Year, Now.Month, 1, 0, 0, 0).AddMonths (1);
							break;

						default:
							throw new HttpException (HttpStatusCode.ClientError_BadRequest);
					}
				}
				Graph Result;

				if (ParameterName == "Motion")
					Result = Expression.ParseCached ("scatter2d(Records.Timestamp,if (Values:=Records.Motion) then 1 else 0,5,if Values then 'Red' else 'Blue','','Motion')").Evaluate (v) as Graph;
				else
					Result = Expression.ParseCached ("line2d(Records.Timestamp,Records." + ParameterName + ",'','" + ValueAxis + "')").Evaluate (v)as Graph;

				Image Img = Result.GetImage (Width, Height);
				byte[] Data = MimeUtilities.Encode (Img, out s);

				resp.ContentType = s;
				resp.ReturnCode = HttpStatusCode.Successful_OK;

				resp.WriteBinary (Data);

			} finally
			{
//.........这里部分代码省略.........
开发者ID:mukira,项目名称:Learning-IoT-HTTP,代码行数:101,代码来源:Program.cs

示例2: HttpGetImg

		private static void HttpGetImg (HttpServerResponse resp, HttpServerRequest req, bool Protected)
		{
			networkLed.High ();
			try
			{
				if (Protected)
				{
					string SessionId = req.Header.GetCookie ("SessionId");
					if (!CheckSession (SessionId))
						throw new HttpException (HttpStatusCode.ClientError_Forbidden);
				}

				LinkSpriteJpegColorCamera.ImageSize Resolution;
				string Encoding;
				byte Compression;
				ushort Size;
				byte[] Data;

				GetImageProperties (req, out Encoding, out Compression, out Resolution);

				lock (cameraLed)
				{
					try
					{
						cameraLed.High ();

						if (Resolution != currentResolution)
						{
							try
							{
								camera.SetImageSize (Resolution);
								currentResolution = Resolution;
								camera.Reset ();
							} catch (Exception)
							{
								camera.Dispose ();
								camera = new LinkSpriteJpegColorCamera (LinkSpriteJpegColorCamera.BaudRate.Baud__38400);
								camera.SetBaudRate (LinkSpriteJpegColorCamera.BaudRate.Baud_115200);
								camera.Dispose ();
								camera = new LinkSpriteJpegColorCamera (LinkSpriteJpegColorCamera.BaudRate.Baud_115200);
							}
						}

						if (Compression != currentCompressionRatio)
						{
							camera.SetCompressionRatio (Compression);
							currentCompressionRatio = Compression;
						}

						camera.TakePicture ();
						Size = camera.GetJpegFileSize ();
						Data = camera.ReadJpegData (Size);

						errorLed.Low ();

					} catch (Exception ex)
					{
						errorLed.High ();
						Log.Exception (ex);
						throw new HttpException (HttpStatusCode.ServerError_ServiceUnavailable);
					} finally
					{
						cameraLed.Low ();
						camera.StopTakingPictures ();
					}
				}

				resp.ContentType = Encoding;
				resp.Expires = DateTime.Now;
				resp.ReturnCode = HttpStatusCode.Successful_OK;

				if (Encoding != "imgage/jpeg")
				{
					MemoryStream ms = new MemoryStream (Data);
					Bitmap Bmp = new Bitmap (ms);
					Data = MimeUtilities.EncodeSpecificType (Bmp, Encoding);
				}

				resp.WriteBinary (Data);

			} finally
			{
				networkLed.Low ();
			}
		}
开发者ID:wrtcoder,项目名称:Learning-IoT-MQTT,代码行数:85,代码来源:Program.cs


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