IT Blog NOW

An Information Technology View by Sam Moreira

Free Microsoft E-Learning Courses to Sharpen your IT Skills

If you’re short on money to spend on training or if you’re just looking for a good deal, check out Microsoft Learning. There you can find close to 50 free e-learning courses available on several categories. The majority of them are, of course, introductions and overviews of specific technologies, but there are also a few that could be used to sharpen your skills.

Below you can find a short list with some of the courses that are available for free through Microsoft Learning. For the complete list, click here:

  • Clinic 3402: ASP.NET for PHP Developers: Introduction to ASP.NET
  • Collection 5134: Developing Rich Experiences with Microsoft .NET Framework 3.0 and Visual Studio 2005
  • Clinic 5230: Developing Enhanced Web Experiences with Microsoft ASP.NET AJAX Extensions
  • Clinic 5939: Introducing Server Management in Windows Server 2008
  • Clinic 6189: What’s New in Microsoft SQL Server 2008 for Business Intelligence
  • Clinic 6190: What’s New in Microsoft SQL Server 2008 for Database Development
  • Course 6258: New Features Of Microsoft SQL Server 2008 Reporting Services
  • Collection 6261: Developing Rich Experiences using Microsoft .Net Framework 3.5 & Visual Studio 2008
  • Collection 6262: Introducing Windows Workflow Foundation using .Net Framework & Visual Studio 2008
  • Clinic 6263: Introducing Windows Presentation Foundation using .Net Framework 3.5 & Visual Studio 2008
  • Clinic 6264: Introducing Windows Communication Foundation using .Net Framework 3.5 & Visual Studio 2008
  • Clinic 6335: Exploring Microsoft Application Virtualization
  • Course 6339: Database Fundamentals in Microsoft SQL Server 2008
  • Collection 6340: Introducing Microsoft SQL Server Data Services for Developers
  • Clinic 6341: Overview of Microsoft SQL Server Data Services
  • Clinic 6342: Developing an Application for Microsoft SQL Server Data Services

Happy Learning!

How to Respond and Raise Events in .NET

I was talking to a friend over the weekend and the “Events in .NET” subject came up. Basically, over the years working with .NET, he had created several applications that responded to .NET events, but he had never worked on the other side of the fence: raising the event itself. During the conversation, I’ve realized there’s a possibility that creating classes that raise events is not a common trait among most developers as .NET Framework is extensive enough to address most common issues. So, I’ve decided to create this post to address how to raise and respond to events in .NET.

Let’s start with raising the event on the class side. There are three main steps you need to take when raising an event for a specific situation:

  1. Define a delegate to hold the reference to the method that will respond to the event. The responding method will be specified by the application instantiating the class, not the class itself.
  2. Define an event member associated with your delegate to ensure your delegate will be executed when the event occurs.
  3. Raise the event when the specific situation occurs.

To make things clear, let’s use a simple but real-life example. Let’s suppose you have a Customer class that holds customer records. As using your class is the only way applications can remove customer records from the system, you have been asked to find a way to notify the applications using your class anytime a user tries to delete a customer record, allowing them to validate and log the request before it actually takes place. You can also give applications a way to abort the process if the request is not authorized.

Following the scenario above, let’s apply the three main steps to raise an event.

public class Customer
{
// Step 1. Define a delegate
public delegate void DeletingCustomerEventHandler(object sender, EventArgs e);

// Step 2. Define an event member associated with your delegate
public event DeletingCustomerEventHandler DeletingCustomer;

// Method that raises the event
public bool DeleteCustomer()
{
//Step 3. Raise the event (occurs before the action takes place)
EventArgs e = new EventArgs();
if(this.DeletingCustomer != null)
{
this.DeletingCustomer(this, e);
}

// Continue deleting customer …
}
}

Breaking down the code: In step 1 above, the first parameter of DeletingCustomerEventHandler will be the object raising the event, and for the second parameter, you can either use the default EventArgs class or create your own class based on EventArgs. You’ll usually create your own class if you need to pass any extra information to the method responding to the event. Step 2 defines the DeletingCustomer event, which will be automatically exposed to application developers using your class. And step 3 basically verifies whether or not a method has been assigned to your delegate and raises the event if the delegate is not null.

Now that we have covered how to raise an event, let’s complete the post by talking about the part most developers are familiar with: responding to the event.

In order to respond to an event, application developers must follow two main steps:

  1. Create a method to respond to the raised event; the method must match the delegate signature for the event.
  2. Add an event handler associating your method created in step 1 to the event being raised; this step basically does the magic and allows the event to be raised (see step 3 in the previous section).

Let’s dive into the sample code to respond to the DeletingCustomer event of the Customer class:

// Step 1. Create a method to respond to the event
private void ValidateDeleteRequest(object sender, EventArgs e)
{
// If necessary, cast object back to Customer type
Customer oCust = (Customer)(sender);

// Log Request
LogRequest(oCustomer, oCurrentUser);

// Validate Request
if (!FunctionToValidateDeletion(oCust))
{ // Cancel Operation if allowed by the class }
}

// Step 2. Add event handler when creating the object
Customer oCustomer = new Customer();
oCustomer.DeletingCustomer += new Customer.DeletingCustomerEventHandler(ValidateDeleteRequest);

This code to respond to the event is simple… in step 1 we create a method matching the delegate signature for the event handler. This method will be called anytime a customer record is about to be deleted from the system. So, within the method, application developers can validate and log details of the request for later use. If needed, you can also allow the application to cancel the process when the validation fails by creating a new class based on EventArgs class, in which you would expose a member to trigger the cancellation process.

And in step 2, we ensure that the event will be actually raised by adding the event handler and associating our method with it. If you remember step 3 from the raising an event section above, before raising the event, we must check whether or not a method has been associated with our delegate. The step 2 in this section takes care of this association.

That’s all for now. I hope I have been able to clarify a little bit about how you can raise and respond to events in .NET. As we can see, there’s no mystery in the process; it’s just a matter of understanding how each part fits together to accomplish the goal.

Happy coding!

US and UK Android Developers Get Support for Priced Applications On Android Market

Google will finally allow Android developers to charge for their applications distributed via Android Market. That was a great move from Google; the ability to charge for applications will not only allow current Android developers to get compensated for their hard work, but also make Android more attractive to new developers. As a result, end users, who own Android-based devices, can expect to see an increase in the number of applications offered by Android Market in the near future.

Priced applications will be available to end users in US starting next week. If you live in Germany, Austria, France, or Spain, priced applications will be available later in the quarter. And for other countries, an announcement will be made by the end of the first quarter of 2009.

Now, the most important part… how will Android developers get paid? According to Google, consumers and developers will have to use Google Checkout for all transactions processed via Android Market. So, if you are an Android developer and don’t have a Google Checkout merchant account, you’ll need to sign up for one before you’re able to sell your applications. 

If you’re wondering how much you’ll be able to charge for your applications, here’s the answer from Google: the cost of Android applications for end users must be in the following price range: $0.99 – $200 (USD) and 0.50 GBP – 100 GBP.

Two important notes if you already have a free application available to users on Android Market. First, if you are planning on charging for your application once it has already been offered for free, you’ll have to re-upload it as a priced application. And second, take a look at the following quote obtained from the section 3.3 of the Developer Distribution Agreement about a free upgrade requirement to end users:

“3.3 You may also choose to distribute Products for free. If the Product is free, you will not be charged a Transaction Fee. You may not collect future charges from yours for copies of the Products that those users were initially allowed to download for free…”

In other words, even if you decide to convert your free applicatin to a priced application, you’ll still be obligated to provide free upgrades to end users who have installed the free version of your application prior to the switch.

After this initiative, I can wait to see how far Android will take Google. What about you?