Category: Programming
Posted on 2:57pm 5/22/2008 by Bruno Silva in
Programming
During the last couple of days I’ve been exploring BizTalk 2006 Business Rules Engine for a college assignment.
The objective is calculating the total cost of a travel. The input is the number of days the customer was staying in the destination, and the number of touristic spots he wanted to visit. The business rules defined the price per night of the stay and the price per visit. These values added to the flight cost gives us the total cost of the travel.
There is a nice tutorial about the BizTalk 2004 version of the rule composer which is quite similar to the 2006 version (at least in the UI). After some search I was unable to find an answer to my particular problem (was it that obvious?… read further and tell me).
I wanted to calculate the cost per visit and cost per night within the policy (I wanted to set these values) and I also wanted to calculate the total cost of the travel based on those variables (by getting their values).
(I am using an XML file as input which has the elements I talked about before)
When you create a definition in your vocabulary (which you use do define rules in your policy) you must select the operation you want to do over the element: Get or Set. You can choose only one of them…

So, what’s the trick to perform both actions? Create two definitions of the same element, one as Get and the other as Set.
When a rule uses the Set definition of the element, all the rules that use the Get definition of that XML element read the updated value.
Works great! Just be careful about rules priority. Make sure that rules that read the element value are called after a rule that sets it’s value.
Hoje em dia cada vez temos mais Javascript nos sites que produzimos. Existem “milhentas” bibliotecas giras que usamos para produzir experiências teoricamente mais ricas para os visitantes dos web sites. Vê-se de tudo, desde bibliotecas para efeitos visuais, até frameworks de AJAX incluindo também os nosso próprios ficheiros de script.
O download destes ficheiros corresponde a um overhead considerável, e por isso mesmo enquanto estava, recentemente, a trabalhar num site recorrendo à framework Adobe Spry, pesquisei sobre formas de minimar este peso extra no download. Encontrei uma entrada de um blog bastante interessante. Compara algumas abordagens.
A redução do tamanho de um ficheiro de código Javascript pode ser realizada removendo todos os caracteres dispensáveis: comentários, quebras de linha, espaços, etc. O código continua a ser válido, e correctamente interpretado, perdendo apenas a legibilidade. Encontra-se “na moda” haver versões de debug e release para bibliotecas Javascript por esta razão.
Pode-se ainda aproveitar a capacidade de compressão no protocolo HTTP e reduzir ainda mais o tamanho dos ficheiros, tendo sempre em consideração que vai implicar processamento extra no lado do cliente, pois o que foi comprimido tem de ser descomprimido, de forma a poder ser interpretado.
Deixo a comparação entre 2 métodos distintos de redução de tamanho de ficheiros javascript, que dá bem a ideia do compromisso que está em causa.

Para utilizar ficheiros em Javascript “gzipped” basta utilizar uma ferramenta que comprima neste formato, compactar o ficheiro e colocar o ficheiro gzip no atributo src da tag script.
Exemplo: <script type=”text/javascritpt” src=”mylib.js.gz”/>
I’ve been working in college assignment which goal is to integrate several information systems. One of those is a website where we can see the flight schedules from/to Portuguese airports.
The website URL is http://www.innovata-llc.com/ana/default.asp. Me and a colleague of mine had to write a web service that was used by BizTalk as a wrapper of this web site’s form. It was supposed to send an HTTP request passing some request parameters using POST parameters, and to parse the HTML response in order to extract the flight list for a given destination city and departure date.
First of all lets see the code we used to get the response.
Uri address = new Uri(requestURL);
HttpWebRequest request = WebRequest.Create(address) as HttpWebRequest;
request.Method = “POST”;
request.ContentType = “application/x-www-form-urlencoded”;
StringBuilder data = new StringBuilder();
data.Append(“DPT_Date=” + “17-05-2008″);
data.Append(“&RET_Date=” + “20-05-2008″);
data.Append(“&dpt_station=” + “LIS”);
data.Append(“&arv_station=” + “LHR”);
data.Append(“&non_stops=” + “on”);
// Create a byte array of the data we want to send
byte[] byteData = UTF8Encoding.UTF8.GetBytes(data.ToString());
// Set the content length in the request headers
request.ContentLength = byteData.Length;
// Write data
using (Stream postStream = request.GetRequestStream())
{
postStream.Write(byteData, 0, byteData.Length);
}
// Get response
String htmlResponse;
using (HttpWebResponse response = request.GetResponse() as HttpWebResponse)
{
// Get the response stream
StreamReader reader = new StreamReader(response.GetResponseStream());
// Get the response string
htmlResponse = reader.ReadToEnd();
}
After getting the response content is time to use a nice HTML parser helper library. It is called HTML Agility Pack and it is open-source. You can find it at Codeplex.com/htmlagilitypack.
Now it is time to create an HtmlDocument (a class which ships with HTML Agility Pack) and load the response into this new instance. //Load HTML as XHTML
HtmlDocument htmlDoc = new HtmlDocument();
htmlDoc.LoadHtml(htmlResponse);
After looking to the HTML source code, we got the right Xpath expressions to extract the flight list.
//Get flight lines
HtmlNodeCollection flights = htmlDoc.DocumentNode.SelectNodes(
“//body/div/table[3]/tr[position()>=4 and position()<last()-1]“);
foreach (HtmlNode flight in flights)
{
//Get attributes
string departureTime = flight.ChildNodes[1].FirstChild.InnerText;
string arrivalTime = flight.ChildNodes[3].FirstChild.InnerText;
//Do some stuff …
}
That’s almost it. The next step was adding the extracted information into some data structures, and returning that data. But these details are out of this post scope.
During this week I’ve been experiencing some problems with browser caching.
I’ve a dynamically generated XML file which contents change a lot (it is a photo gallery based on Slide.Show), and I want the people who see this gallery to see newly added photos immediately. Today someone asked me how to prevent the client-side caching (regarding Slide.Show too), so I did some searches and testing in order to enlight us both.
I’ve found reference to a few lines of code which should be used in ASP.NET web pages to prevent caching.
Response.CacheControl = “no-cache”;
Response.AddHeader(”Pragma”, “no-cache”);
Response.Expires = 0;
I tried the first one alone both in IE 7 and Firefox 2 and it seamed to be enough, nevertheless, being care is never enough,so I’ll probably use the 3 lines together!
Just try to be careful and don’t feel tempted to prevent caching in every single web page in your web site, it leads to poor perfomance in both your servers and in the client side. And every one likes to see the content of a previously visited page rendered quickly, right? 

Yesterday I had a nice surprise in my e-mail inbox! I passed in the certification exame I took in January. It is great news, since I just took this exam just as a first time experience with Microsoft Certification Exams.
I took part in the Beta Program of this exam, so I took it for free. And another great thing was the background that the preparation gave me in workflow engines, pretty useful now that I am learning about Microsoft BizTalk.
A great book that I read was Microsoft Windows Workflow Foundation Step by Step.
More details about the certification can be found in the Preparation Guide.