March 2006 - Posts - Raj Kaimal

March 2006 - Posts

Ajax and double buffering..

As I look at the new www.live.com interface, a thought came to my mind. I think it would be cool if the very first time an Ajax application is loaded, the web server would collect all the information from whatever different sources (which can be cached on the webserver) and send it down instead of having different content areas that make individual requests while displaying "Loading...".

This gives the appearance of a page that loads faster. Similar to the concept of double buffering.

The images, Css etc will obviously still be seperate requests the first time and will be pulled from the browser cache on subsequent requests.

Some other things:

  • www.live.com makes ≈ 300-340 requests just to load the homepage with a cleared cache. This is including all css, js, images and the content.
  • Google Personalized Homepage makes ≈ 16 requests
  • my.yahoo.com makes ≈ 84 requests

    These will vary according to how many content areas you have.
  • www.msn.com makes ≈ 45 requests

We know RFC 2068 states that:
Clients that use persistent connections SHOULD limit the number of simultaneous connections that they maintain to a given server. A single-user client SHOULD maintain AT MOST 2 connections with any server or proxy.

So by "double buffering", we might be able to reduce the number of requests and give the appearance of a faster loading page. On the other hand, as connections become faster, this might not be an issue at all.

Thoughts anyone?

 

Posted by rajbk | 3 comment(s)
Filed under:

How to render client report definition files (.rdlc) directly to the Response stream without preview

A ReportViewer control is normally used to open a report definition file, process it and load it into the viewing area.

 

The simple method below allows you to render the report directly to the response stream without using the ReportViewer control. This might be useful in cases where you want to render a non interactive report.

 

The example below renders the report in PDF format. The other report types available when using the LocalReport.Render method are “Excel”and “Image”.

 

 

/// <summary>

/// References:

/// </summary>

private void RenderReport() {

    LocalReport localReport = new LocalReport();

    localReport.ReportPath = Server.MapPath("~/Report.rdlc");
   

    //A method that returns a collection for our report

    //Note: A report can have multiple data sources

    List<Employee> employeeCollection = GetData();

 

    //Give the collection a name (EmployeeCollection) so that we can reference it in our report designer

    ReportDataSource reportDataSource = new ReportDataSource("EmployeeCollection", employeeCollection);

    localReport.DataSources.Add(reportDataSource);

 

    string reportType = "PDF";

    string mimeType;

    string encoding;

    string fileNameExtension;

 

    //The DeviceInfo settings should be changed based on the reportType

    //http://msdn2.microsoft.com/en-us/library/ms155397.aspx

    string deviceInfo =

    "<DeviceInfo>" +

    "  <OutputFormat>PDF</OutputFormat>" +

    "  <PageWidth>8.5in</PageWidth>" +

    "  <PageHeight>11in</PageHeight>" +

    "  <MarginTop>0.5in</MarginTop>" +

    "  <MarginLeft>1in</MarginLeft>" +

    "  <MarginRight>1in</MarginRight>" +

    "  <MarginBottom>0.5in</MarginBottom>" +

    "</DeviceInfo>";

 

    Warning[] warnings;

    string[] streams;

    byte[] renderedBytes;

 

    //Render the report

    renderedBytes = localReport.Render(

        reportType,

        deviceInfo,

        out mimeType,

        out encoding,

        out fileNameExtension,

        out streams,

        out warnings);

 

    //Clear the response stream and write the bytes to the outputstream

    //Set content-disposition to "attachment" so that user is prompted to take an action

    //on the file (open or save)

    Response.Clear();

    Response.ContentType = mimeType;

    Response.AddHeader("content-disposition", "attachment; filename=foo." + fileNameExtension);

    Response.BinaryWrite(renderedBytes);

    Response.End();

 

}

 

Note that if you change the ReportType in the Render method, you will also have to change the DeviceInfo settings.

FAQ


References:

Posted by rajbk | 33 comment(s)
More Posts