Monday, April 21, 2008

MSDN has a number of excellent "How Do I"-videos geared towards Windows Mobile-development. Don't miss it...

I've found the following to be very useful:

How Do I: Test Unit Tests for Devices?
How Do I: Update User Interface Controls in Multithreaded Applications?
How Do I: Efficiently Query a SQL Server Compact Database Using LINQ?

posted on Monday, April 21, 2008 7:23:18 AM UTC  by Andy  #    Comments [0]
 Friday, April 18, 2008

This time we will look a little closer at an important change on the user interface side of the architecture. We're talking about applying the MVC pattern (or rather its variation, the MVP pattern), and even if this change is far from recent (both mentioned patterns have been around for quite awhile), the importance of applying this pattern has increased. The reason is an increased focus on automatic testing, TDD, and continous integration. By applying the MVC pattern, the bulk of the logic of the user interface (located in a "controller"), can be tested independent of the actual user interface. This, and the more traditional benefits, that you can apply different "views" (user interfaces or more general, channels) to the same user interface logic, makes the MVC pattern a common part of any modern software architecture.

If you do some browsing on the Web, you quickly find that there are many implementation of the MVC pattern, but there are not that many specific to Windows Mobile developers (although most .NET implementations should migrate without much hazzle). One great initiative was the MCSF by Microsoft's patterns & practices team, which included a solid implementation of the MVC pattern (among many other) that was migrated from various application blocks for the full .NET Framework. However, the MCSF was so solid that it took a great deal of time to learn before you could be productive. Also, the MCSF is now a bit outdated, and judging from the lack of news or updates about it, our hopes are not up.

The community (and us too) wanted something simpler, and in some projects, we have used a very simple and straightforward implementation by our former fellow MVP, Alex Yakhnin (he's now employed by Microsoft), that he published as a small blog series last fall (see part 1 and part 2). In those blog posts Alex also showed a simple solution to a very common problem when building great UX for Windows Mobile, and that is to handle the caching of forms. Loading a form is an expensive task in terms of performance, and therefore it's necessary to cache the forms in memory.

In upcoming posts, we will continue with more of my thoughts on the changes in mobile architecture, and of course also some code samples to show the theory in practice.

posted on Friday, April 18, 2008 10:21:55 AM UTC  by Andy  #    Comments [0]
 Sunday, April 13, 2008

Don't miss the MSDN WebCast: Creating Location-Aware Applications for Windows Mobile Devices (Level 300)

"More and more Windows Mobile powered devices ship with integrated global positioning system (GPS) hardware. Since Windows Mobile devices are typically used on the road, it makes a lot of sense to add location awareness to your applications. In this MSDN webcast, Maarten Struys shows you how you can make use of the GPS Intermediate Driver to access GPS information from inside managed applications. Learn how to use the FakeGPS utility to test location-enabled applications without needing access to a physical GPS device. Of course, in this session, you also see a location-aware application on a device using real GPS data."

 

posted on Sunday, April 13, 2008 7:19:14 AM UTC  by Andy  #    Comments [0]
 Friday, April 11, 2008

I'm continuing the series that started with part 1 and part 2 by talking more about the changes in a modern mobile multi-tier architecture. We can see that the most important changes are happening on two levels, and the first is the tighter bond between the business logic and it's data that I talked about in my previous part in this series.

classicntier As I already mentioned in the previous post in this series, the second major change to the classic Application Architecture for .NET that you see on the left is the change in the way that clients exchange information with the server (or more general, the way that two systems or peers exchange information). As soon as Web Services arrived, we instantly understood that this would be the future way of communication between systems. At the time when we wrote our book, the basic plumbing wasn't in place, and most had to be done by hand. Since then the basic Web Service technologies (XML, SOAP, HTTP, etc) has been complemented with both new exiting ones to enable better support for security, sessions, transactions, etc, as well as much better tools support. The beauty of Web Services is that they can open up a "locked" architecture (that can only deliver a fixed UX, like most Web sites on the Internet) to any client. That client could be anything from a custom made application to another system that simply want to use only the services and the data. This is what my series on Windows Mobile Web Services (e.g. Movie Lookup Web Service) is all about. Most of you probably agree that cool sites like IMDB, and FlightExplorer become even better when they can participate in a mash-up application to deliver greater value.

One technology that is important in this change is WCF as it builds on the good things about Web Services, and also takes the concept one more step. It's what .NET Remoting should have been in the first place, and even if it can be confusing as a consequence if its versatility, the main message is that you can do everything that you can do with Web Services and so much more (and it also performs very well). Therefore, my recommendation is to take a hard look at this technology and evaluate if it brings something that you need in your mobile applications. Just to make you more interested, it can travel over a number of transports (HTTP, TCP, Named Pipes, MSMQ, etc). However, not all of these transports are supported out-of-the-box on .NET Compact Framework yet, but a great thing about WCF is that it can be extended on multiple levels (transport, bindings, etc). What is supported though, is the ability to solve a classic problem with mobile applications: How can I communicate efficiently with a device that may be shut down and that is very hard to address (changing IP addresses, etc)? It's possible using the WindowsMobileMailTransport class that allow messages to be sent as e-mail. In combination with Exchange Server, and it's push e-mail technology (a.k.a. DirectPush or Always-Up-To-Date), this means that mobile application can be built that communicate very efficiently with the server (or another peer).

In upcoming posts, I will continue with more of my thoughts on the changes in mobile architecture, and of course also some code samples to show the theory in practice.

posted on Friday, April 11, 2008 10:18:41 AM UTC  by Chris  #    Comments [0]

Developing sites that are well suited for use from mobile devices is a real challenge. I was recently interviewed by Computer Sweden on the subject and I highlighted five key areas to stay on top of:

 

  1. The browser
  2. The web site
  3. The resolution
  4. Bandwidth
  5. Input mechanisms

Be sure to not miss the following great MSDN-content that gets you started from the right place:

 

Walkthrough: Creating Web Pages for Mobile Devices

ASP.NET Mobile Web Development Overview

posted on Friday, April 11, 2008 6:44:16 AM UTC  by Andy  #    Comments [0]
 Friday, April 04, 2008

To continue this series that started with A New Mobile N-tier Architecture (part 1), we will talk more about the changes in a modern mobile multi-tier architecture.  We can see that the most important changes are happening on two levels, and the first is the tighter bond between the business logic and it's data.

classicntierBefore, we had a distinct separation in the two lower tiers between the logic and the data. The thinking was that the data services could be used by several parts of the business logic to handle basic CRUD operations. This is shown in the Application Architecture for .NET from 2002 that you see on the left where the business logic and the data access was divided into the lower two of the classic three tiers. However, the problem was that data without logic is almost useless, and even if the logic existed (in various business components) the natural relation with the data was not manifested.

The other change is the change in the way that clients exchange information with the server (or more general, the way that two systems or peers exchange information), and that will be the focus of the next part in this series.

newntier

If we look at technologies like LINQ and specifically LINQ2SQL (LINQ to SQL) the traditional separation between the logic and the data is encouraged. On the right you find an illustration what is happening in the lower two of the traditional three tiers. The observant note that the business entities is moving down to he data tier (where they belong), but more importantly, the two tiers are actually moving together. With a LINQ2SQL, the business logic can be implemented in the same data context (the ORM) class (by using the ability to define partial classes). We would like to call these merged entities domain components as they define and handle both the data and the logic for a specific business domain. So, the service interface (facade) would actually work with a number of domain components to deliver functionality to its clients. The challenge is how the functionality (logic + data) is spread among the domains to make them a perfect tradeoff between versatility and reusability. The bigger, the more versatile, the smaller, the more reusable. The general message is probably to keep them small and distinct.

In upcoming posts, we will continue with more of my thoughts on the changes in mobile architecture, and of course also some code samples to show the theory in practice.

posted on Friday, April 04, 2008 10:15:32 AM UTC  by Andy  #    Comments [0]
 Friday, March 28, 2008

When we wrote our book Pocket PC Development in the Enterprise back in 2001, one of our goals was to help developers with an architectural blueprint for building solid mobile multi-tier applications. At that time, most focus for mobile developers was on the user interface and the device side of the mobile solution.

Since then, a lot of things have changed. The Windows Mobile development platform with .NET Compact Framework as the foundation, has evolved into a very powerful offering to mobile developers. Technologies has constantly migrated from the desktop (full) framework, even if it sometimes seems too slow when one is eagerly waiting. Who else is eager to use LINQ to SQL with SQL Server Compact, full WCF support, or build mobile Silverlight applications?

But, some things remain the same, and one of these is the view on mobile solutions as being a part of a bigger whole. Almost no mobile applications live alone! In most cases, they are part of an integrated solution that extend existing business processes to reach further out in the hands of the employees. Therefore, a modern mobile architecture starts with a solid architecture on the server, and can be extended to support multiple channels (thin/rich clients, fixed/mobile devices, etc).

During the years since we wrote the book, the blueprint has evolved with the changes in technology. We say evolve, because most changes only meant that the architecture was upgraded to embrace the new technologies. Recently, however, some major changes has occurred that force some more drastic changes to the architecture. The most significant are LINQ (specifically LINQ to SQL and the upcoming ADO.NET Entity Framework), WCF, and Silverlight. The observant reader notes that these technologies span the whole architecture spectrum from data access, via communcation links to UX. In addition to these, there are also a number of enhancements for the mobile developer that spice up an architecture that in addition to support traditional clients, it also needs to support mobile clients as well.

As you will see, when we move forward in this series of blog posts, we're a big fan of the KISS principle. Therefore, the primary goal is to keep things as simple as possible to minimize the learning curve while at the same time still create a valid architecture that is easy to implement, test, and maintain.

In upcoming posts, we will continue with more of our thoughts on the changes in architecture in general and more specifically on architectures that suite mobile solutions.

posted on Friday, March 28, 2008 10:12:19 AM UTC  by Andy  #    Comments [0]
 Saturday, March 22, 2008

I continue my series (I Want More Mobile (Web) Services, Flight Lookup Web Service, and Package Lookup Web Service) of useful Web Services for Windows Mobile with a service to check movie info. I often find myself in discussions about movies, and have often wished for a simple app where I can get some quick info about a movie. My effort is a growing creation on CodePlex called Windows Mobile Web Services where you get to the code.

moviescrape As in previous posts, you find the UX on the right, and if we start on the client side with the right menu button (somewhat simplified)...

private void lookupMenuItem_Click(object sender, EventArgs e)
{
    if(lookupMenuItem.Text == "Lookup")
    {
       
Movie[] movies = null;
       
try
        {
           
Service ws = new Service();
           
//ws.Credentials = new NetworkCredential("uid", "pwd");
            movies = ws.MovieLookup(titleTextBox.Text);
        }
       
catch(Exception ex)
        {
            MessageBox.Show(ex.Message);
        }
        if(movies != null && movies.Length > 0)
        {
            titleComboBox.Items.Clear();
           
foreach(Movie movie in movies)
                titleComboBox.Items.Add(movie);
            titleComboBox.Visible =
true;
            titleTextBox.Visible =
false;
            lookupMenuItem.Text =
"Back";
        }
    }
   
else
    {
        titleTextBox.Text =
string.Empty;
        titleTextBox.Visible =
true;
        titleComboBox.Visible =
false;
        lookupMenuItem.Text =
"Lookup";
    }
}

...so when a title is entered in the text box, a search is made with the text box replaced with a combo box containing the search results. When an item in the combo box is selected...

private void titleComboBox_SelectedIndexChanged(object sender, EventArgs e)
{
   
Movie movie = titleComboBox.SelectedItem as Movie;
    resultTextBox.Text =
string.Format("Title: {0}\r\nYear: {1}\r\n\r\nPlot: {2}",
        movie.Title, movie.Year, movie.Description);
   
HttpWebRequest req = (HttpWebRequest)WebRequest.Create(movie.ImageUrl);
   
HttpWebResponse resp = (HttpWebResponse)req.GetResponse();
    pictureBox.Image =
new Bitmap(resp.GetResponseStream());
}

...the movie info is shown along with the box shot. On the server, the code looks like this...

[WebMethod]
public Movie[] MovieLookup(string movieTitle)
{
   
string url = string.Format("http://www.imdb.com/find?s=all&q={0}", movieTitle);
   
HttpWebRequest request = WebRequest.Create(url) as HttpWebRequest;
   
StreamReader responseReader = new StreamReader(request.GetResponse().GetResponseStream());
   
string responseData = responseReader.ReadToEnd();
    responseReader.Close();

   
int i = responseData.IndexOf("<b>Popular Titles</b>");
   
if(i <= 0)
       
return new Movie[] { };
   
int j = responseData.IndexOf("</p>", i);

   
string table = Regex.Match(responseData.Substring(i, j - i), "<table.*?>(.*?)</table>").ToString();

   
var q = from Match match in Regex.Matches(table,
                "<a\\shref=[\"\"\"\"'](?<url>.*?)[\"\"\"\"'].*?>(?<title>.*?)</a>")
           
where !match.Groups["title"].ToString().Contains("<img")
           
select new Movie { ID = Regex.Match(match.Groups["url"].ToString(),
                "(?<=\\w\\w)\\d\\d\\d\\d\\d\\d\\d").ToString(),
                Title =
HttpUtility.HtmlDecode(match.Groups["title"].ToString()) };

   
Movie[] movies = q.ToArray<Movie>();

   
foreach(Movie movie in movies)
    {
        url =
string.Format("http://www.imdb.com/title/tt{0}", movie.ID.ToString());
        request =
WebRequest.Create(url) as HttpWebRequest;
        responseReader =
new StreamReader(request.GetResponse().GetResponseStream());
        responseData = responseReader.ReadToEnd();
        responseReader.Close();

       
string title = Regex.Match(responseData, "(?<=<(title)>).*(?=<\\/\\1>)").ToString();
        movie.Title =
HttpUtility.HtmlDecode(Regex.Match(title, ".*(?=\\s\\(\\d+.*?\\))").ToString()).Replace(
            "\"", string.Empty);
        movie.Year =
Regex.Match(title, "(?<=\\()\\d+(?=.*\\))").ToString();
        movie.ImageUrl =
Regex.Match(Regex.Match(responseData, "(?<=\\b(name=\"poster\")).*\\b[</a>]\\b").ToString(),
           
"(?<=\\b(src=)).*\\b(?=[</a>])").ToString().Replace("\"", string.Empty).Replace("/></", string.Empty);

       
try
        {
           
if(movie.Title.Contains("(VG)"))
            {
                i = responseData.IndexOf(
"<h5>Plot Summary:</h5>") > 0 ?
                    responseData.IndexOf("<h5>Plot Summary:</h5>") :
                    responseData.IndexOf(
"<h5>Tagline:</h5>");
               
if(i > 0) j = responseData.IndexOf("</div>", i);
            }
           
else
            {
                i = responseData.IndexOf(
"<h5>Plot:</h5>") > 0 ? responseData.IndexOf("<h5>Plot:</h5>") :
                    responseData.IndexOf(
"<h5>Plot Summary:</h5>");
               
if(i <= 0) i = responseData.IndexOf("<h5>Plot Synopsis:</h5>");
               
if(i > 0) j = responseData.IndexOf("<a class=", i);
               
if(j <= 0)
                    j = responseData.IndexOf(
"</div>", i);
            }
           
string plotOutline = responseData.Substring(i, j - i).Remove(0, "<h5>Plot:</h5> ".Length);
            plotOutline =
HttpUtility.HtmlDecode(plotOutline);
            movie.Description =
Regex.Replace(plotOutline.Contains("is empty") ||
                plotOutline.Contains("View full synopsis")
                ?
string.Empty : plotOutline, "<a.*?href=[\"'](?<url>.*?)[\"'].*?>(?<name>.*?)</a>", string.Empty);
        }
       
catch
        {
            movie.Description =
string.Empty;
        }
    }
   
return movies;
}

...and as you can see, I'm using the excellent IMDB to get the movie info. Of course, there's a lot more info to be retrieved about a movie, its actors, etc. My recommendation if you want to build further on this example, take a look at Imdb Service project on Codeplex.

Note that we save a lot of coding by the extensive use of regular expression (regex) to extract the data from the web page. First, a request is made to do a search for the movie title, and from the search results the matching movies in the category "popular titles" is captured as a list of movies. Then, for each movie in the list a request is made to the movie details page, and each movie object is updated with the data about the movie (as well as the image URL). Then all is returned to the client, and note that the nicely typed movie data is kept in a small helper class...

public class Movie
{
   
public string ID { get; set; }
   
public string Title { get; set; }
   
public string Year { get; set; }
   
public string ImageUrl { get; set; }
   
public string Description { get; set; }
}

...which is transferred to the client via the Web Service proxy. For more details, check out the project on CodePlex.

posted on Saturday, March 22, 2008 10:21:11 AM UTC  by Chris  #    Comments [0]
 Monday, March 17, 2008

Microsoft just released the Windows Mobile Line of Business Solution Accelerator 2008. This is a sample line of business application that shows relevant design principles for .NET CF-development. You'll find in the package: ADO.NET Sync Services, LINQ, MapPoint, and so on!

Cool!

posted on Monday, March 17, 2008 7:17:22 AM UTC  by Andy  #    Comments [0]