The CruiseControl.NET Monitor for Vista Sidebar is the first "real" Vista Sidebar gadget I developed, so I want to share 2 of the problems I encountered during the development.

The first problem was that the XmlHttpRequest always returned "undefined" (which is the null in javascript) for its responseXML property. I was reading an xml file, why did I receive a null instead of the XML Document contained into the response?

The XmlStatusReport.aspx file that contains the report for the build server doesn't have an xml content-type (not text/xml, application/xml or with a .xml extension) but has, as any other html page, a text/html content-type. So I had to work around that CCNET bug (now fixed and available in the next version of CC.NET 1.3):

var xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
xmlDoc.async="false";
xmlDoc.loadXML(xmlHttp.responseText);

I read the responseText property and I create a new xml document from scratch using the XMLDOM object.

Then I encountered another problem: the XmlHttpRequest always returned the same data, even if the data had changed.

I think it has something to do with some kind of caching implemented by the javascript engine of the Vista Sidebar. In this case the fix was easy: instead of asking for the XmlStatusReport.aspx file I append a timestamp to the filename, in order bypass the cache and always get a fresh copy of the file.

function buildUrl(url)
{
var now = new Date();
if(url.charAt(url.length-1)!='/')
url = url+'/';
var finalUrl=url + "XmlStatusReport.aspx?sid=" + now.getTime();
return finalUrl;
}

This is not the best solution, since it uses both bandwidth and server processing time, but that seems to be an issue with the way IE implement caching, so not of easy solution.

 

Technorati tags: , , , ,