public class ReportHandler : IHttpHandler
{
public void ProcessRequest(HttpContext context)
{
Warning[] warningArray;
HttpResponse response = context.Response;
response.StatusCode = 200;
MemoryStream lastMemoryStream = null;
context.Response.BufferOutput = false;
context.Response.ContentType = null;
context.Response.Expires = -1;
var ds = new DataSet();
LocalReport localReport = new LocalReport();
localReport.ReportEmbeddedResource = string.Format("{0}.rdlc", context.Request.QueryString["name"]);
localReport.DataSources.Add(new Microsoft.Reporting.WebForms.ReportDataSource("ds", ds));
StringBuilder builder = new StringBuilder("<DeviceInfo>");
NameValueCollection requestParameters = context.Request.QueryString ;
for (int i = 0; i < requestParameters.Count; i++)
{
if (requestParameters.Keys[i] != null)
{
if (requestParameters.Keys[i].StartsWith("rc:", StringComparison.OrdinalIgnoreCase))
{
builder.AppendFormat("<{0}>{1}</{0}>", XmlConvert.EncodeName(requestParameters.Keys[i].Substring(3)), HttpUtility.HtmlEncode(requestParameters[i]));
}
}
}
builder.Append("</DeviceInfo>");
localReport.Render("IMAGE", builder.ToString(), delegate(string name, string extension, Encoding encoding, string mimeType, bool willSeek)
{
if (!HttpContext.Current.Response.IsClientConnected)
{
throw new HttpException("Client disconnected");
}
if (lastMemoryStream != null)
{
this.SendPrintStream(lastMemoryStream, response);
lastMemoryStream.Dispose();
lastMemoryStream = null;
}
lastMemoryStream = new MemoryStream();
return lastMemoryStream;
}, out warningArray);
this.SendPrintStream(lastMemoryStream, response);
lastMemoryStream.Dispose();
this.SendPrintStream(null, response);
if (!response.BufferOutput)
{
string a = context.Request.ServerVariables["SERVER_PROTOCOL"];
if (string.Equals(a, "HTTP/1.0", StringComparison.OrdinalIgnoreCase))
{
context.Response.Close();
}
}
}
private void SendPrintStream(Stream stream, HttpResponse response)
{
int length = 0;
if (stream != null)
{
length = (int)stream.Length;
}
foreach (byte num2 in BitConverter.GetBytes(length))
{
response.OutputStream.WriteByte(num2);
}
if (stream != null)
{
stream.Position = 0L;
StreamToResponse(stream, response);
response.Flush();
}
}
internal static void StreamToResponse(Stream data, HttpResponse response)
{
int count = 0;
byte[] buffer = new byte[0x14000];
while ((count = data.Read(buffer, 0, 0x14000)) > 0)
{
response.OutputStream.Write(buffer, 0, count);
}
}
public bool IsReusable
{
get
{
return true;
}
}
}