本文整理汇总了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
{
//.........这里部分代码省略.........
示例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 ();
}
}