Category: .NET
You probably already know that developing a game that runs both in XBox 360 and Windows is possible and pretty manageable using XNA Game Studio. If you start developing your game for Windows (which is great to compile/debug your code more quickly), you can then duplicate that project as an XBox 360 game. The same files will be used, but during compilation, the assemblies of XNA Framework that are used are chosen based on the target platform.

Developing a game for both platforms isn’t that trivial. There are a lot of functionalities that are exclusive to each platform. For instance, the Gamercard integration that I talked about in an earlier post, only works in XBox 360. In the other hand, since XNA games targeting Windows are pure .NET managed code, you can use whatever .NET libraries you want (such as WiimoteLib
)
If you have a game that you want to compile to both platforms, but which has slight differences, you can use the C# Preprocessor Directives. When you create an XBox 360 project, the XBOX and XBOX360 conditional compilation symbols are used by the preprocessor.

Those symbols can be used to create conditions that make the preprocessor able to choose which lines of code of a file to compile. The example bellow is pretty self-explanatory.

If you compile this game targeting the XBox 360 you’ll get a blue background, otherwise you’ll get a red background.
This is not a XNA or XNA Game Studio feature, but this was the first time I needed to use such feature. More information about C# Preprocessor Directives are available at MSDN.

One nice XNA feature is the ability to manage Xbox 360 users gamer data. This way you can access your gamercard information which include your name, avatar, achievements, played games and list of friend among other things. How can you do that?
In the Initialize method of your game you must add a specific component into the game, in order to prepare the game to access the data.

Since while the Initialize and LoadContent methods are executed, the gamer data is not available yet, you must access it in the Update method. There you can check if a variable is set, and if it is not, you load the gamercard information. Be careful, you must not load the gamer data in every iterations of the game loop. Your Xbox will hang if you do that… It is an expensive operation. Try to load this data only one time or so during the game lifetime.

This example show your gamer picture in the screen, followed by some of your informations such as your gamer tag.

You can download the full source code and deploy it into your Xbox 360 console and give it a try. (I’ve written before about how to get a free XNA Creators Club Membership in order to allow XNA deploying).
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.
A while ago I talked about Slide.Show. Some one asked me how to dynamically look into a folder and create a slide show based on its contents. I suggested using an ASP.NET page that looks into the folder and generates a XML output that can be used by Slide.Show as a data source.
I’ve implemented a simple version that shows how to do it. Download it and change it as you wish.
Take a look at DataProvider.js where I have changed the Data.xml reference to Data.aspx file.
In the Data.aspx file I’ve deleted all the HTML output, and in the Page_Load event handler generated XML output.
Response.ClearContent();
Response.ContentType = “Application/xml”;
Response.Write(”{XML output}”);
Response.End();
I’ve included in the zip file only the required files to let the example work. It has only 1 image. I hope it will be useful to someone. 