December 2003 - Posts
Rob introduced us recently to the provider model being implemented in V2; the similaraties of this description really reminded of the proxy design pattern.

Obviusly the asp.net implementation includes some special code to deal with configuration files, but other than that - is the “Provider Model” just a new name on the proxy pattern...?
Is it just me or does the resemblence scare anyone else??? Dr Phil is really Steve Ballmer and the
whole Dr. Phil phenomenon is some kind psycho-subversive ploy from Microsoft take over the world!
[UPDATE]
Scott pointed out the the fact that you can force file names in a download using content-disposition. This is probably the easiest way but the solution listed below will allow you to call to files that do not exists; ie KentuckyThirdDistrict.xls?querystringcrap and the file will download as KentuckyThirdDistrict. Oh well, I did it the hard way :)
Sometimes a little feature can give quite a bit of effort to your site in style points. Take for instance data grids and excel documents. This is a common thing now, to take a data grid and give it to the user as an excel document. Some people are even trying to sell products doing this but by and large it is simple enough that most people will just roll their own.
It is quite simple…
Create instances of a DataGrid, StringWrtier and HtmlWriter
Set the response content type to "application/vnd.ms-excel"
Render the grid to the HtmlTextWriter
Reponse.Write the StringWriter data to the client.
This is all well and good except for the fact that of your user chooses to save to disk, they have an ASPX file. For the purposes of this lesson we will go ahead and assume the obvious and state that all users are stupid and will not pay attention to the file extension wonder why their excel document will not open in excel when they double click it!
HttpHandlers to the rescue!
After one to many stupid users double clicking the aspx file with great confusion I conjoured up the idea of using an HttpHander to give the file the proper extension when the user saved it to disk.
It is also quite simple…
Create a class that implements System.Web.IHttpHandler
Code up the ProcessRequest method with your data grid rendering code (see above)
Create entries in your web.config and IIS metabase to support your new handler for .xls files
The really cool part about this scenario is that you can code the call just like a call to an aspx file, using querystring parameters and all!
Here is an example…
public void ProcessRequest(System.Web.HttpContext context)
{
DataGrid Grid = new DataGrid();
StringWriter oStringWriter = new StringWriter();
HtmlTextWriter oHtmlTextWriter = new HtmlTextWriter(oStringWriter);
context.Response.Clear();
context.Response.Buffer = true;
context.Response.ContentType = "application/vnd.ms-excel";
context.Response.ContentEncoding = System.Text.Encoding.Default;
//Little diddy I do to get a data table instance
Grid.DataSource = EmployerData.Get(context);
Grid.DataBind();
Grid.RenderControl(oHtmlTextWriter);
context.Response.Write(oStringWriter.ToString());
context.Response.End();
}
So once again boys and girls, give your users what they want! If they want excel; go the extra mile and give it to em!
Usually I dont care about traffic stats and such but I was reading some of the news generated by my latest project and noticed that for a time we were one of the 300 busiest sites on the net! Since May we have seen over 120 million hits and Win2K3 is loving it!
The best part, the sites runs off a single dual proc web server. We have a hot standby ready in case that box dies but racking up that traffic on a single box is pretty impressive to me :)
Robert McLaws wants to why so many people are making O/R Mapping tools?
Certainly not for the money because nobody is charging all that much and getting into a business to sell a product that Microsoft is going to be giving away for free in the future would not be financially fruitful lest one could target themselves for acquisition. Seems the only company who might execute on such a strategy successfully is SourceGear (HINT TO MICROSOFT, Eric will not retire if you give him millions of dollars, he will just by a fancy car and take one of those famous “sabbaticals” to get rejuvenated!”)
Age old problem...Writing code is part art, therefore there is no "right" way to do many things. In most real world business apps a very large portion of the code deals with database IO thus this is also the place where there tends to be the most problems.
OOP lends to reuse and the natural progressions of things would dictate the redundant nature of DBIO calls would lend toward a reusable subset specifically tailored to the project needs. Since the refinement of this subset can raise overall quality by abstracting the common problematic code, and increase speed to market (common argument of reuse) this is a high value target for re-factoring.
Back to the art aspect; many people see other peoples code (written or generated) and cringe. They look and say, "too cluttered, I can make it prettier" or "why did they do X, I can do it using Y". Since the O/R mapping concept is relatively easy to understand, many devs embark on the creation of their own mapping tool because in their own mind, they can write "better" code; even though such a distinction is in many cases a subjective one at best.
My belief is that most people build code generators or O/R mapping tools for a specific project and refine it over time, since most OOP devs hate the idea of target specific coding (step-sister of hard coding), they tend to write their code as “generically” as their allotted time will permit them.
I have a tool I wrote that looks at a table and generates code to reflect against that table. Not really a O/R mapping tool and not really a great generator (even though I use the Code DOM and can generate in many different languages J ) but I can see where this type of tool can be the genesis of a mapping tool. I would be interested to hear from the likes of Frans and others who make commercial tools to know how they came to build them.
Dave Wanta of ASP.NET Email fame told me at the KyDotNET users group last month that he heard the ObjectSpaces team had been researching and developing for over 5 years; if this be true I think we can expect some truly innovative things when this hits true fruition.
In SQL2K, the system stores a revision history for DTS packages. Every change you make is stored and versioned using a date/time stamp. Please do this same thing for other objects as well. Stored procedures would be best but if a change history was available for any table, view, proc, function yada yada yada, that would be superb!
More Posts