Monday, July 14, 2008

Cool solution for posting source code in your blog

Ok, so I have been looking for a tool or a way of posting source code in my blog without breaking the whole page or making the source code lines a whole mess. There are some possible solutions tweaking the blog HTML and adding CSS, but the solution I liked the most comes from this link. Check it out and hope it solves your source coding blogging problems at least while somebody comes up with a better way or until blogger puts some effort in making the blogging tool better.

Cheers!

WindowsCE works out iPhone sales

It's kind of ironic, but it makes sense. Apple stores needed a robust Point of Sales(POS) solution for their massive sales, including the iPhone sales volume with the new released version. It turns out that the POS machines Apple stores use, which are made by Symbol, use WindowsCE. Funny thast after all, is Microsoft who is running the iPhone sales !!!

From: JKOnTheRun

Read the comments of that post, they are quite interesting !!!

-arbbot

Gamers, be prepared !!!

Microsoft will unveil the new mayor update for DirectX, which is DirectX 11 at the annual XNA Gamefest 2008 conference (which unfourtunately I won't be able to attend). The conference will take place on July 22 and July 23 in Seattle. Check out the XNA conference site and stay tuned with the XNA development!!!

-arbbot

New XBox 360 Editon

I just found out in the Microsoft XBox Site that a new edition of the XBox 360 is going to be available in early August. The Premium XBox 360 Elite will have a 60Gb hard drive for the same price of $449(U.S.).

Now I'm considering to buy it, since with more Gigabytes for storage it makes more sense, although I might wait to see if Microsoft resolves to include a Blue ray DVD on the console. Chek it out !!!

Happy Gamming!!!

-arbbot

Saturday, July 12, 2008

Silverlight 2.0 Controls Bubbling Issues

Recently I was working on some Silverlight 2.0 code examples following the “Controls” tutorial from the silverlight site. First of all, the tutorial was really messy, finding a lot of copy-paste code and a lot of differences between the text and the code that what was actually showed on the tutorial. However those are minor mistakes and the tutorial was easy to follow. The tutorial was about Silverlight 2.0 controls. I was coding using Visual Studio 2008 with the Silverlight 2.0 Beta 2 tools.

Silverlight 2.0 extends the CLR event handling mechanism with RoutedEvents. The defining characteristic of Routed Events is that each event is passed up the Interface Tree in a process known as bubbling (the events are like tiny bubbles rising up from the bottom). However when using Silverlight 2.0 controls, the event is "handled" at the control level and then the bubbling stops. This presents a problem when you have complex UI elements for a control (for example a custom control with different visual behavior, meaning that you have canvas, borders and other UI elements and a Silverlight 2.0 button inside) and you want to capture the “MouseLeftButtonDown” event at the higher level to implement different behaviors, since this event will always be trapped by the button control itself. Let me show you an example (Note: I’m not going to enter into details on the code structure of the example since you can follow the tutorial by yourself and do all the steps and understand how to implement each peace).

Let’s say that we want to have a dragable button on our application. We are going to use a Silverlight 2.0 common button inside a canvas:





In order to attach the event handlers we need to make that button dragable, we need to create and attach the event handlers for the “MouseLeftButtonDown”, “MouseLeftButtonUp” and “MouseMove” in the code behind of our XAML, as follows:


compositeButton.MouseLeftButtonDown += new MouseButtonEventHandler(CompositeButton_MouseLeftButtonDown);
compositeButton.MouseLeftButtonUp += new MouseButtonEventHandler(CompositeButton_MouseLeftButtonUp);
compositeButton.MouseMove += new MouseEventHandler(CompositeButton_MouseMove);

Now that we have our events attached to the canvas UI element (“CompositeButton”), we can implement the drag and drop functionality on those event handlers as follows:


void CompositeButton_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
{
beginX = e.GetPosition(null).X;
beginY = e.GetPosition(null).Y;
trackingMouseMove = true;
FrameworkElement fe = sender as FrameworkElement;
if (fe != null)
fe.CaptureMouse();
}

void CompositeButton_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
{
FrameworkElement fe = sender as FrameworkElement;
if (fe != null)
{
fe.ReleaseMouseCapture();
trackingMouseMove = false;
}
}

void CompositeButton_MouseMove(object sender, MouseEventArgs e)
{
if (trackingMouseMove)
{
double currentX = e.GetPosition(null).X;
double currentY = e.GetPosition(null).Y;
FrameworkElement fe = sender as FrameworkElement;
if (fe != null)
{
double canvLeft = Convert.ToDouble(fe.GetValue(Canvas.LeftProperty));
double canvTop = Convert.ToDouble(fe.GetValue(Canvas.TopProperty));

double newLeft = canvLeft + currentX - beginX;
double newTop = canvTop + currentY - beginY;

fe.SetValue(Canvas.LeftProperty, newLeft);
fe.SetValue(Canvas.TopProperty, newTop);

beginX = currentX;
beginY = currentY;
}
}
}

If you run this example, you will notice that the button is not dragable. In fact you will see the button “MouseOver” state and the “MousePressed” state, but it won’t be dragable. The problem is not on the code behind, the issue is that the button is capturing the mouse events and handling them by itself stopping the mouse events to bubble to the canvas element that contains it (the “CompositeButton” canvas element). The solution I was able to find is to place a transparent canvas on top of the button, with the same size, so that when you click the button you are actually clicking the canvas that is on top. Let me show you how the XAML looks like:




As you can see I have declared a canvas after the button with the same width and height and same position as the button itself, but with a transparent background so is not noticeable. When you click on the button, you are actually clicking the canvas, and that’s why now the mouse events are bubbled to the containing canvas (“CompositeButton”). Now the button is dragable!!

This might seem very simple, but the technique can be applied to complex code and UI elements to make sure you are capturing the events and being able to do whatever you need to do without having issues because of the controls blocking or hiding the events from you, even if you are using the Silverlight 2.0 controls.

Happy Silver-coding!!!

-arbbot

Friday, July 11, 2008

PDF is Now ISO Standard

I just found out that the International Organization of Standarization (ISO) has approved the PDF as a standard format for electronic files. PDF stands for Portable Document Format. Adobe submitted the format to ISO for standarization in February 2007. You can read more from the article on the Redmond Developer News web site (article here).

The important thing about this is that from now on there will be more development of PDF readers and more integration with different tools. Adobe Acrobat Reader has been one of the most used PDF readers, which is totally normal since Adobe created the PDF digital document format back in 1993. If you want to learn a little about the ADOBE PDF format check out Wikipedia (article hre).

There are many PDF tools out there that allow you to create, convert or simply view PDF files. Some of them are Sumatra (Windows), Zamzar (Web Based), Skim (MAC) and Foxit Reader (Multi-Platform). If you want to have more references to this tools, check out this wiki page.
I’m sure we will see a lot of improvements and new tools coming out soon, so stay tune !!!

-arbbot

Wednesday, July 9, 2008

Make your ASP.NET web site to serve .MCML pages

When you are working in Windows Media Center Web Hosted application projects you are going to have the need to generate dynamic MCML pages to serve your MCE client applications. MCE web hosted applications retrieve all the MCML pages and the data from the server, rendering all the markup code before displaying it to the user. When you need to serve dynamic generated data, you need to dynamicaly create .mcml pages in the server with the data and make the web site serve those pages to the client.

The problem is that an ASP.NET web server does not serve MCML (.mcml) pages by default. In order to deliver the .mcml pages to the client you need to make the ASP.NET web server to serve the .mcml pages as XML pages (.mcml pages are xml based markup code). The cool thing is that you can extend this approach to make the web server to serve any kind of files you want. For example, for a project we worked on we also needed to serve our custom dynamic data xml pages (.dax) which are xml pages containing dynamicly generated xml data.

To make the ASP.NET web site to serve this new file types, you have to include those file extensions in the web site MIME types.

To add new MIME types on IIS 7 (Vista Machine) follow this steps:

1. Click on the start button, type IIS in the search box. The first result should be the Internet Information Services (IIS) Manager, open it, and the IIS 7 Manager console will appear. Note: if it doesn’t you might need to install the IIS windows features from the control panel (I’ll post how to do it separately).

2. Expand the server tree to web sites and click on your web site from the tree view of the websites, and its options will appear in the center of the window. From the Home options select MIME Types.

3. In the actions pane right click on add.

4. In the File Name Extension field type the name of the file extension (i.e.: “.mcml”) and in the MIME Type field type “text/xml”. This will make the web server to serve the new types as if they were xml files.

5. Done.

To add new MIME types on IIS 6 (Windows Server 2003 Machine) follow this steps:

1. First, to enable Framework Extensions, go to IIS Manager, you can find it in the Start menu, under the Administrative Tools menu, and open it. The IIS 6 manager console will appear. Note: if it doesn’t you might need to install the IIS windows features from the control panel(I’ll post how to do it separately).

2. Browse in the tree view to find the Web Service Extensions.

3. Select .Net Framework 2.0 Extensions and allow those.

4. Now, you need to add the new MIME types to your web site. Expand the contents of your website in the IIS Manager. Find the web folder from where the pages will be served, right click it and go to options.

5. In the Directory tab under Application Settings press the create button that will enable all the files inside to serve as application files, and change the Execute permissions drop down to Scripts Only.

6. After that the configuration button will enable, click it and the application configuration window will appear.

7. Add a new application extension for .mcml using the following values.
• In executable use the following address: \%windir%\Microsoft.NET\Framework\v2.0.50727\aspnet_isapi.dll
• For Extension: .mcml
• Verbs - use limit to: GET,HEAD,POST,DEBUG
• Script Engine: Checked
• Verify that file exists: Unchecked

8. Press ok to create the Extension then OK again to exit the Application Settings, and finally OK to the UI properties.

9. Add a new application extension for .dax using the following values:
• In executable use the following address: \%windir%\Microsoft.NET\Framework\v2.0.50727\aspnet_isapi.dll
• For Extension: .dax
• Verbs - use limit to: GET,HEAD,POST,DEBUG
• Script Engine: Checked
• Verify that file exists: Unchecked

10. Press ok to create the Extension then OK again to exit the Application Settings, and finally OK to the UI properties.

11. Open the web.config file of your web site and make sure you specify the handlers for the new MIME types. The “httpHandlers” should be included in the section of the web.config file. Here is an example of the handler for .mcml files: .

12. Done.

-arbbot

Tuesday, July 8, 2008

ASP.NET Simple Cache Implementation

I was working on a Windows Media Center Web Hosted project a few days ago. For this project we were working on, we had the need to save some objects on the server side cache for retrieving them later from the client (Windows Media Center application). Since we needed to save only a couple of objects on the server side cache it didn’t make much sense to implement the whole server side caching structure for caching several pages and information. We needed a quick way to save a couple of objects with the information retrieved from the xml services in the server, avoiding the need to parse the whole xml again each time the client requested the information. The solution was to implement the out of the box ASP.NET native server side cache.

To implement the native ASP.NET cache is really simple (at least for what we needed). We use the Cache.Insert() method to insert the object in the ASP.NET Cache instance. We implemented it using this constructor:

Cache.Insert(String key, object value, CacheDependency dependencies, DateTime absoluteExpiration, TimeSpan slidingExpiration);

As follows:

Cache.Insert("mykeyName", object, null,DateTime.Now.AddMinutes(Double.Parse(System.Configuration.ConfigurationManager.AppSettings["cacheExpirationTime"])), TimeSpan.Zero);

Our object is a list of MyClass instances containing the information we needed to save. Doing this inserts our object in the server side ASP.NET cache for the time we configured in the web.config file.
Now for retrieving the cache object when we needed we followed this implementation:

// Verifying if the object is on cache
List cacheItem = Cache[("mykeyName"] as List;
if (cacheItem != null)
{
this.myObjectList = cacheItem;
}


Notice that we are doing a cast to List when we are retrieving the object, so we have the desirable object with the corresponding type it is supposed to be. After that we can check if it is null and perform the tasks we want to.
This is a very out of the box basic implementation, but it solved our needs and might help you on your projects too.

The very cool thing about it is that you can save any object in the ASP.NET cache instance, set the expiration time from the web.config file and retrieved any time you want. The Cache ASP.NET instance has other methods and properties so be sure to check them out.

-arbbot

Thursday, July 3, 2008

I'm Back

Long time without writing!!! I know, this shouldn't be happening, but lately I have been very busy with my projects at Schematic and at other personal projects. I moved in to a new place, I'm working very hard with my music project (expect more news on this) and I have been working in some really cool projects.

I'm currently working on migrating my Silverlight 2.0 projects from Beta 1 to Beta 2. Also researching and working a lot on interactive multi-tier applications improving my skills and knowledge about .NET Architecture and how to optimize integration points with other platforms and technologies.

I have also been playing with LINQ, which I really like and makes my life easier. Windows Media Center and MCML have been on my agenda too, getting to know the technology and markup better and improving my skills with some nice and cool MCML advance coding practices.

I hope I'll be able to post some interesting stuff, articles and code about what I have been working on.

Stay tuned!!!
-arbbot