Saturday, October 8, 2011

Metro style apps–loading an image from content

 

I’m writing a Win8 Metro style app and I wanted to expose an image from one of my view models. The image comes from a file that I have included in the project as content. After wandering through the samples, I was finally able to piece together this solution:

image

The XAML binds to the property using the Source attribute:

image

Some things to note. The image’s Build Action is set to Content and the path delimiters in the call to ResourceLoader.GetFile() use forward slashes (“/”). Using a backslash results the exception: NamedResource Not Found (HRESULT 0x80073B17).

Wednesday, September 28, 2011

Windows Phone 7 syncing to online Exchange results in Error 85010014

I upgraded my phone to the Mango update yesterday. Everything went fine except or so I thought. This morning I noticed that my phone hadn’t synced to the company’s Exchange account (Microsoft BPOS) for over 10 hours. When I forced a sync, it resulted in the following error message:

Not Updated
There’s a problem with red001.mail.microsoftonline.com. Try again later.
Last tried xx seconds ago
Error code: 8510014

I screwed around with the configuration for more time than I should have. I tried reentering the server. I tried entering the password again. I even removed the account from the phone and recreated it.

I even went to the Mobile Devices section on OWA and removed the device and then removed the account AGAIN.

Nothing worked.

This evening I stumbled onto something that did work.

I recreated the account on the phone (for the fourth or fifth time) and received the error again. On a whim, I unchecked all the content types under the Content to Sync section (Email, Contacts, Calendar and Tasks). I then issued a sync and it worked! I then added Email and re-synced. That worked! I continued to add the other three items, one at a time and followed by a re-sync.

Now everything is good again.

Thursday, September 22, 2011

Installing SQL Server “Denali” CTP3 on Windows 8 Preview

I, and I’m sure many other developers, have been eager to begin experimenting with developing on Windows 8 and building Metro style apps. I was fortunate to attend //build and receive one of the Samsung 700T tablets with Windows 8 and Visual Studio 11 already loaded. Unfortunately my wife and daughter also enjoy the tablet so it’s not available to me for long programming sessions.

So in order to make everyone happy, I have installed the Win8 Preview in a VM under VMware Workstation 8. Here’s the configuration:

Host: Windows 7 running VMware Workstation 8
Guest: Windows 8 Preview (build 8102), 2GB RAM, 2 processors and 40 GB SCSI hard drive

I installed Visual Studio 11 without any problem other than the fact that it installed SQL Server without giving me any choice for the configuration. The easiest way to remedy that was to uninstall SQL Server and then reinstall it.

You can probably guess that the reinstall didn’t go smoothly. If it had, there’d be no reason for this post, eh?

I started by download the installer from MSDN. There are a few choices depending on whether you wanted 32bit or 64bit, with or without tools. I pulled down the 64bit package that had the tools.

Then I copied it to the VM.

I double-clicked the .EXE, it unpacked into a temporary folder, a command windows briefly flashed and then nothing. So I did what anyone would have done. I double-clicked the .EXE again and watched the same sequence of events unfold. “Ah!” I said. I must need Admin privileges! No problem, I launched a command window as Administrator, navigated to the folder and ran the .EXE.

Same results as before.

I was confused because SQL Server had already been installed on the machine. I had just uninstalled it!

In the process of poking around on the machine, I ended up in the “Turn Windows features on or off” section of the Uninstall dialog. It was in there that I noticed that .NET 3.5 was not enabled. I enabled it, went back to the command prompt and retried the installer.

Something happen this time:

image

The installer can’t find .NET 4.0 but 4.5 is on the box! I hit Continue and the SQL Server Installation Center dialog appeared on the screen.

image

It was easy sailing from this point!

By the way, you’ll see this windows pop up a lot!

image

The installation continued without any problem and I was able to successfully install SQL Server “Denali” CTP3.

image

The unhandled exception dialog appeared again when I tried to close the SQL Server Installation Center dialog:

image

Hitting the Quit button finished closing the dialog.

If you’re curious, here are the SQL Server apps as they appear on the Win8 Start page:

image

And here’s the new SQL Server Management Studio

image

Monday, September 19, 2011

Notes from //build/ - Windows 8

I attended the Microsoft //build/ conference last week. This was the public world’s second introduction to the next version of company’s OS, Windows 8. It was also the first time that any real depth about the product was provided. The general consensus from those I spoke with was they were very pleased with the features shown.

Metro style apps

First, and most obviously, the Metro style from Windows Phone 7 has been brought forward as the primary user experience in Windows 8. Along with that, the OS has been optimized for touch but the stylus, mouse, and keyboard are all still supported.
 

image
(Attribution: Microsoft Corp.)

Note: It was pointed out that the correct capitalization is “Metro style apps” with a lowercase “S” on style and a lowercase “A” on apps.

The Start button has been morphed from a popup to an entire screen that consists of 1x1 or 2x1 “Live” tiles.
 image

The Start screen has all the apps that were pinned. There is an Apps screen that can be reached via Search. It contains all the apps that are installed:
 image
You can imagine that this screen could become quite crowded once a user starts installing apps. To help with this, Microsoft has introduced Semantic Zoom. Semantic Zoom used the “pinch zoom” gesture but instead of making the image larger, the entire view can be changed, providing something that is useful.

Using Semantic Zoom on the Apps page changes the view to:
 image
Semantic View was demonstrated on the Start page for the keynote, but it has been disabled in the Windows 8 preview that Microsoft released to the public.

Live Tiles

The content of the tiles can change to reflect information that is important to the user. The intent is to create a personal connection with the user. For example, the Stocks application will cycle the most recent information for each stock symbol that the user has added to the application. This will continue even if the application has been suspended.


 image

Suspended?

Yes. When the user navigates away from an app, the app will be suspended. The app will be notified that it is being suspended and given an opportunity to save any transient state. When the app is launched, it will be given an opportunity to restore that state. This is the Tombstone functionality that is currently used by Windows Phone 7 applications.
There is no concept of closing an app within the Metro style. Windows 8 will take of that for you.

Developing apps

A controversy was created when Windows 8 was first introduced to the public. Microsoft announced that HTML5 and JavaScript were the tools that would be used to create the new Metro style apps. At //build/ we learned the truth: Use what you know.


“Use what you know” was the tagline attached to the conference title and the message that Microsoft was delivering. At //BUILD/ Microsoft introduced a new development platform for Windows: Windows RunTime or WinRT. Using WinRT, a developer can create Metro style apps using:

-    C/C++
-    C#, VB.Net
-    HTML5 & JavaScript
 

image
(Attribution: Microsoft Corp.)

The best way to think of WinRT is as the Base Class Libraries for Metro style apps.
I plan to do another article that addresses WinRT.

And .NET?

.Net is still an applicable platform for developing both Metro style and Desktop (think traditional) apps. Not all of the .Net framework is exposed when developing a Metro style app. Where there is functionality that is duplicated with WinRT, or not allowed, those .NET APIs have been hidden.

Is Silverlight dead?


Microsoft did not deliver any message about Silverlight during the conference. Silverlight will be supported in the Desktop version of IE (The Metro style version of IE does not allow any plugins, for security and stability). I don’t expect Microsoft to make any announcement about Silverlight in the near term. This is a preview version of Windows 8. We are a long time from RTM.
There are still a lot of solutions to deliver, and since Silverlight will continue to be supported by Windows 8, I feel that Silverlight is still a valid solution platform.

Is a Metro style app written in HTML5 & JavaScript accessible via the browser?


Nope. A Metro style app is not a web page. They must be installed from the App store (consumers) or side-loaded (Enterprise).  Don’t let the HTML5 & JavaScript fool you. This is just the choice of presentation platform and language. It is no different from choosing XAML and C#.

Getting started

The keynotes, and most of the sessions, were recorded and are available on the //BUILD/ website (www.buildwindows.com).
The preview of Windows 8 can be downloaded from the Windows Dev Center (http://msdn.microsoft.com/en-us/windows/apps/br229516). One download contains a preview of both Visual Studio Express 11 and Expression Blend. If you’d rather install them yourself, you can download them separately from the Visual Studio website: (http://www.microsoft.com/download/en/details.aspx?displaylang=en&id=27543).

Monday, June 6, 2011

Messin’ with the WCF Web API, part II – Content Negotiation & Formatters

In the last post, I briefly introduced the WCF Web API and walked through the creation of the first service that I constructed as I was experimenting with the framework. WCF Web API has a couple more tricks that it does. In this post I’d like to look at Formatters and their part in Content Negotiation.

Content Negotiation

In section 6.3.2.7 of his dissertation, Architectural Styles and the Design of Network-based Software Architectures, Roy Fielding describes Content Negotiation:

All resources map a request (consisting of method, identifier, request-header fields, and
sometimes a representation) to a response (consisting of a status code, response-header
fields, and sometimes a representation). When an HTTP request maps to multiple
representations on the server, the server may engage in content negotiation with the client in order to determine which one best meets the client’s needs. This is really more of a “content selection” process than negotiation.

So what does this mean? Let’s take a look at this in action. I’ll use the service that I built in the last post.

Using Fiddler I captured the request to retrieve the Xbox game with the ID of 12. That request looks like:

GET http://localhost:1064/MessinWebApi/games/12 HTTP/1.1
Accept: application/xml
Accept-Language: en-US
User-Agent: Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0)
Accept-Encoding: gzip, deflate
Connection: Keep-Alive
Host: localhost:1064

And the response:

HTTP/1.1 200 OK
Cache-Control: private
Content-Length: 405
Content-Type: application/xml; charset=utf-8
Server: Microsoft-IIS/7.5
X-AspNet-Version: 4.0.30319
X-SourceFiles: =?UTF-8?B?QzpcVXNlcnNcTWlrZVxEb2N1bWVudHNcVmlzdWFsIFN0dWRpbyAyMDEwXFByb2plY3RzXE1lc3NpbldlYkFwaVxNZXNzaW5XZWJBcGlPbmVcTWVzc2luV2ViQXBpT25lXGdhbWVzXDEy?=
X-Powered-By: ASP.NET
Date: Mon, 06 Jun 2011 00:51:12 GMT

<?xml version="1.0" encoding="utf-8"?><Game><Id>12</Id><Description>James Cameron's Dark Angel</Description><Developer>Radical Entertainment</Developer><Genre><Id>53</Id><Name>Action</Name></Genre><Name>James Cameron's Dark Angel</Name><Price>49.990000</Price><Publisher>Radical Entertainment</Publisher><Rating><Id>4</Id><Name>T (Teen)</Name></Rating><ReleaseDate>2002-09-01T00:00:00</ReleaseDate></Game>

And again:

GET http://localhost:1064/MessinWebApi/games/12 HTTP/1.1
Accept: application/json
Accept-Language: en-US
User-Agent: Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0)
Accept-Encoding: gzip, deflate
Connection: Keep-Alive
Host: localhost:1064

And the response:

HTTP/1.1 200 OK
Cache-Control: private
Content-Length: 293
Content-Type: application/json; charset=utf-8
Server: Microsoft-IIS/7.5
X-AspNet-Version: 4.0.30319
X-SourceFiles: =?UTF-8?B?QzpcVXNlcnNcTWlrZVxEb2N1bWVudHNcVmlzdWFsIFN0dWRpbyAyMDEwXFByb2plY3RzXE1lc3NpbldlYkFwaVxNZXNzaW5XZWJBcGlPbmVcTWVzc2luV2ViQXBpT25lXGdhbWVzXDEy?=
X-Powered-By: ASP.NET
Date: Mon, 06 Jun 2011 00:53:54 GMT

{"Description":"James Cameron's Dark Angel","Developer":"Radical Entertainment","Genre":{"Id":53,"Name":"Action"},"Id":12,"Name":"James Cameron's Dark Angel","Price":49.990000,"Publisher":"Radical Entertainment","Rating":{"Id":4,"Name":"T (Teen)"},"ReleaseDate":"\/Date(1030852800000-0400)\/"}

Now I didn’t make any changes to the service between those two requests. I only changed the Accept header in the request. For the first request I used a value of application/xml and application/json was used in the second. This is Content Negotiation. The client (Fiddler in this case) is using the Accept header to indicate the response formats that it can handle.

Note: To be fair, Content Negotiation can also be used to specify other preferences like encodings and language.

The client is free to indicate more than one format, or Media Type, as the value for the Accept header. The convention is that the values are specified in order of preference. The service is then free to use any of the specified formats that it can reproduce.

The role of rendering a response into the requested media type falls to the Formatters. These are components of the pipeline that I mentioned in the first post. The reason that I’m bringing this up at this point in time, seemingly out of order, is to introduce the base functionality that you get for free: the ability to product XML and JSON straight out of the box.

Custom Formatters

Xml and JSON are covered. You’ll need a custom formatter for anything else and luckily Microsoft has made it super easy to create them. The complexity required is dependent on the representation of the response that you’re trying to create. To demonstrate this, I’m going to create a custom formatter that returns the cover image for each game. When Shawn Wildermuth put together the Xbox games sample database, he included the cover image, as a jpg, in the Games table. My custom formatter is going to take the image and stream it back to the caller.

Note: I wish I could claim this as an original idea but it’s not. The sample application that ships with the WCF Web API has similar functionality. I’m just translating the functionality as appropriate for this data set.

To start I need to have Entity Framework return the Image column when a game is retrieved. To accomplish this I just have to add a property to the Game class with the same name as the field in the table:

    public class Game
    {
        public int Id { get; set; }
        public string Description { get; set; }
        public string Developer { get; set; }
        public Genre Genre { get; set; }
        public string Name { get; set; }
        public decimal? Price { get; set; }
        public string Publisher { get; set; }
        public Rating Rating { get; set; }
        public DateTime? ReleaseDate { get; set; }
        public byte[] Image { get; set; }
    }



Next I create a new folder in the solution called Formatters and add the following new class, ImageFormatter:


    public class ImageFormatter : MediaTypeFormatter
    {
        public ImageFormatter()
        {
            this.SupportedMediaTypes.Add(new MediaTypeHeaderValue("image/jpeg"));
        }
 
        protected override bool OnCanReadType(Type type)
        {
            return false;
        }
 
        protected override bool OnCanWriteType(Type type)
        {
            return typeof (Game) == type;
        }
 
        public override object OnReadFromStream(Type type, Stream stream, HttpContentHeaders contentHeaders)
        {
            throw new NotImplementedException();
        }
 
        public override void OnWriteToStream(Type type, object value, Stream stream, HttpContentHeaders contentHeaders, TransportContext context)
        {
            var game = value as Game;
 
            // it would probably be better to write some null image - {shurg}
            if (null == game) return;
            if (null == game.Image) return;
            if (0 == game.Image.Length) return;
 
            stream.Write(game.Image, 0, game.Image.Length);
 
            contentHeaders.ContentType = new MediaTypeHeaderValue("image/jpeg");
        }
    }



I believe the code is pretty simple to follow. I just want to point out a couple of things. In the ctor, I’m adding the image/jpeg media type to the collection of media types supported by this formatter. I’ve also provided an override for the OnCanWriteType() method. With those two pieces in place, I’m instructing the WCF Web API pipeline that this formatter can create an image/jpeg representation of instances of Game.


The last piece is to adjust the configuration so that WCF Web API will include the formatter in the pipeline. This is done when the routes are registered in Global.asax:


        public static void RegisterRoutes(RouteCollection routes)
        {
            routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
 
            var config = HttpHostConfiguration.Create()
                .AddFormatters(new ImageFormatter());
 
            routes.MapServiceRoute<GamesResource>("games", config);
 
            routes.MapRoute(
                "Default", // Route name
                "{controller}/{action}/{id}", // URL with parameters
                new { controller = "Home", action = "Index", id = UrlParameter.Optional } // Parameter defaults
            );
        }



To retrieve the cover image, I make a request for a specific game, just as in the previous two examples, but use the value "image/jpeg” for the Accept header:


GET http://localhost:1064/MessinWebApi/games/12 HTTP/1.1
Accept: image/jpeg
Accept-Language: en-US
User-Agent: Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0)
Accept-Encoding: gzip, deflate
Connection: Keep-Alive
Host: localhost:1064


Fiddler is kind enough to render the image for me:


image



Note: the art of the cover image is probably copy written by someone. All rights belong to them.


Formatters are a key component of the pipeline. A formatter will be responsible for creating a representation of a resource and the WCF Web API will handle engaging the correct formatter based on the Accept header in the request.

Sunday, June 5, 2011

Messin’ with the WCF Web API

Back in April, Microsoft released the fourth preview of WCF Web API on CodePlex. The intent of the WCF Web API is to make it easier to expose application data and services over HTTP. I’ve seen a lot of people throw in the REST descriptor but I’m not ready to go there yet.

I’ve spent the last couple of weeks playing with the WCF Web API and I’ve decided to put what I’ve learned out there for others. I’m imagining a series of posts but we’ll have to see where my schedule allows me to go.

In this first post, I want to basically put down the steps that I used to get started; consider this a step above the traditional Hello World program.

It’s all about the data

To get started, I first needed something to serve up. There is always the typical Northwind or AdventureWorks database that everyone is probably already familiar with. Instead, I went for something different. Shawn Wildermuth has been kind enough to to make available a database of XBox games. I’m running SQL Server 2008 so I grabbed the appropriate zip file and attached the database that is contained within it.

Next I need a host. A WCF service can be hosted within a number of application. I going to use an ASP.NET MVC 3 Application.

As long as I’m playing with new tech, I’m going to use the Code First features of Entity Framework 4. If you’re following along at home and Entity Framework isn’t already installed, you can get it via NuGet. The package name is EntityFramework.

The next thing is to create some classes that EF will use to expose the data in the Xbox games database. I’ll create three: Game, Genre and Rating and put them in the Models folder. This seemed like a good enough place to store them for now. I can always move them later.

    public class Game
    {
        public int Id { get; set; }
        public string Description { get; set; }
        public string Developer { get; set; }
        public Genre Genre { get; set; }
        public string Name { get; set; }
        public decimal? Price { get; set; }
        public string Publisher { get; set; }
        public Rating Rating { get; set; }
        public DateTime? ReleaseDate { get; set; }
    }



    public class Genre
    {
        public int Id { get; set; }
        public string Name { get; set; }
    }



    public class Rating
    {
        public int Id { get; set; }
        public string Name { get; set; }
    }



The data is accessed through an instance of DbContext. Mine looks like this:


    public class XBoxGames : DbContext
    {
        public DbSet<Game> Games { get; set; }
        public DbSet<Genre> Genres { get; set; }
        public DbSet<Rating> Ratings { get; set; }
 
        protected override void OnModelCreating(DbModelBuilder modelBuilder)
        {
            base.OnModelCreating(modelBuilder);
 
            modelBuilder.Entity<Genre>().ToTable("Genres", "SimpleGames");
            modelBuilder.Entity<Genre>().HasKey(g => g.Id);
            modelBuilder.Entity<Genre>().Property(g => g.Id).HasColumnName("GenreID");
 
            modelBuilder.Entity<Rating>().ToTable("Ratings", "SimpleGames");
            modelBuilder.Entity<Rating>().HasKey(g => g.Id);
            modelBuilder.Entity<Rating>().Property(r => r.Id).HasColumnName("RatingID");
 
            modelBuilder.Entity<Game>().ToTable("Games", "SimpleGames");
            modelBuilder.Entity<Game>().HasKey(g => g.Id);
            modelBuilder.Entity<Game>().Property(g => g.Id).HasColumnName("GameID");
 
            modelBuilder.Entity<Game>()
                .HasOptional(g => g.Genre)
                .WithMany()
                .Map(m => m.MapKey("Genre"));
 
            modelBuilder.Entity<Game>()
                .HasOptional(g => g.Rating)
                .WithMany()
                .Map(m=>m.MapKey("Rating"));
        }
    }



The three properties Games, Genres and Ratings are used to access and manipulate the data using Linq. The OnModelCreating() override is the key to the Code First implementation. This method contains the mapping of the tables to the classes and defines the relationships between the tables, in terms of the classes.


The last item is to tell Entity Framework where to find the database. I’ve added the following connection string to the web.config file:


  <connectionStrings>
    <add name="XBoxGames"
         connectionString="data source=.\SQLEXPRESS; Integrated Security=SSPI; database=XBoxGames"
          providerName="System.Data.SqlClient"/>
  </connectionStrings>



 


Resources


The next step is to expose the game data over HTTP. If you were wondering when I’d get to WCF Web API, well, that’s now.


Like EntityFramework, WCF Web API can be added to the project using NuGet. The package to install is WebApi.All


image


The nice thing about using NuGet to add libraries to your solution is that it will automatically pickup any dependencies that are required. I needed four.


I’ve decided to create a resource called GamesResource and expose it over HTTP.


    [ServiceContract]
    public class GamesResource
    {
        [WebGet(UriTemplate = "")]
        public List<Game> GetGames()
        {
 
            using (var gamesRepository = new XBoxGames())
            {
                return gamesRepository
                    .Games
                    .AsNoTracking()
                    .OrderBy(g => g.Id)
                    .Include("Genre")
                    .Include("Rating")
                    .ToList();
            }
        }
    }



Accessing this resource will return a list of all the games, sorted by the game ID.



Note: Returning the entire table via HTTP is probably a very unlikely scenario, if for no other reason than you are stressing your network and server resources. The most common mitigation is to provide either filtering or paging capabilities. I plan to add paging in a future post.


The last thing that I have to do is add some configuration that exposes the new GamesResource. Within Global.asax.cs, I’ve changed the RegisterRoutes() method to:


        public static void RegisterRoutes(RouteCollection routes)
        {
            routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
 
            routes.MapServiceRoute<GamesResource>("games");
 
            routes.MapRoute(
                "Default", // Route name
                "{controller}/{action}/{id}", // URL with parameters
                new { controller = "Home", action = "Index", id = UrlParameter.Optional } // Parameter defaults
            );
        }



The call to MapServiceRoute() exposes the GamesResource as an Uri whose path starts with “games”. For example, the Uri http://localhost/games would be directed to our GetGames() method within GamesResource.


Starting the site with F5 and navigating to the games resource (for me is: http://localhost:1064/MessinWebApi/games) displays the list of games, encoded using Xml!


image


Returning a single game


I now want to allow the consumer of my service to fetch a single game using an Uri similar to http://localhost/games/12. This is easy and built into the WCF Web API via the UriTemplate parameter of the WebGet Attribute. This will look familiar if you’ve worked with ASP.Net MVC routing.


I’m going to add a new method to GamesResource called GetSingleGame():


        [WebGet(UriTemplate = "{id}")]
        public Game GetSingleGame(string id)
        {
            using (var gamesRepository = new XBoxGames())
            {
                int idToFind = int.Parse(id);
 
                return gamesRepository
                    .Games
                    .AsNoTracking()
                    .Include("Genre")
                    .Include("Rating")
                    .Where(g => g.Id == idToFind)
                    .FirstOrDefault();
 
            }
        }

 

 

GetSingleGame() is very similar to GetGames() with the exception that I have defined a token called {id} within the UriTemplate property of the WebGet attribute and I’ve added a parameter to GetSingleGame() to receive the value. The WCF Web API infrastructure will handle parsing the incoming request to get the ID and making the appropriate call to GetSingleGame().


When put into motion, a request for the game with an ID of 12 (http://localhost:1064/MessinWebApi/games/12) results in the following Xml:


image


This is just the “tip of the iceberg” for WCF Web Api. There is a very extensible pipeline built into the framework. I plan to explore some of these features in future posts.

Saturday, June 4, 2011

One week with the HTC Trophy

On May 26, Verizon made their first phone running the Microsoft Windows 7 OS available, the HTC Trophy. I placed my order before getting ready to go to work and Verizon was nice enough ship it FedEx Next Day (Thanks Verizon!). The phone came on Friday and a spent the entire weekend becoming familiar with it.

I’ve now had the phone for one week and I’ve enjoyed every bit of it. I love the user experience, especially the little jumps and nudges that get your attention and direct you to more features. Previously I had a Blackberry Storm 1 and the Trophy is 10x the phone.

My wife hated the Blackberry Storm. As a test, I gave her the Trophy and asked her to make a phone call. On the Storm, this simple task would frustrate the hell out of her. On the Trophy, she got past the lock screen (I had to give her the code obviously), launched the phone app and made the call. I asked how she knew to get to the keypad on the lock screen, given that she’d never used a WP7 phone before. She didn’t know. “I just did” she replied.

I love the phone but it’s not perfect. I used the Storm for two years and the Blackberry OS is much more mature. It’s only natural that I carried some expectations over to the Trophy. Here are the things that I don’t like or wish that WP7 supported (in no particular order):

- Integrated inbox.
WP7, just like the Storm, is capable of syncing with multiple email accounts. However, the Storm can present a unified inbox. I understand that this might be a feature in the next version of the WP7 OS, Mango.

- You can’t change the base font size
My eyesight isn’t what it used to be. I’ve been told that this is a common complaint from people over the age of 40. It would be nice if you could change the base font size for the device. It is nice that some apps and features support zooming but then you’re stuck panning around the screen.

- Battery life
My sense is that the Storm had a better battery life. I would frequently only recharge the Storm every other day, even though I had enabled Bluetooth and had a number of apps that would download data in the background. On the Trophy, turning off Bluetooth has helped a lot. I rarely enable Wifi. Now, to be fair, multiple people have expressed that “less than optimal” battery life is a common trait for HTC phones.

- Unable to flag an email
I had this on my list since it was something that I could do on the Storm and not WP7. However, I’ve recently discovered that I can flag messages but only for my Exchange and Gmail accounts. I can’t find a way to flag messages coming from my Hotmail account.

- No filters for message syncing
Blackberry supported defining filters as part of the email account subscriptions. I used them to exclude emails coming from discussion lists. I really miss this feature.

That’s it! Just five crummy complaints and none of them serious enough to drive me back to the Storm or another platform.

Tuesday, May 10, 2011

New laptop–update

In my previous post I discussed my new laptop. In that post I mentioned that my only disappointment was the discovery that the wifi card, a Atheros AR9285, was a single-band card. I’ve recently replaced it with an Intel 622AN.HMWWB Mini PCI Express 6200 Centrino Advanced-N Wireless Adapter. The card is working great and the installation was about 10 minutes.

Hopefully some other Asus G73SW owner will find this information useful.

Wednesday, May 4, 2011

New laptop

I recently purchased a new laptop I’ve had the previous one for a couple of years now so when an opportunity to purchase a new one presented itself,  who am I to pass on it!

I had been thinking about the features for a new laptop for a while. It had to be capable of 8GB of ram, 16 would be even better. I also wanted a quad-core processor.

When the time came to start looking around, I was able to narrow the field quite quickly. I’ve been a Dell user for quite a number of years. Every computer in the house, except for one, was purchased from Dell. It was then that I hit a snag. It seems that the laptop vendors are now doing displays using the HD resolutions: 720p, 900p and 1080p.

Sadly, there is no way that I can do a 1080p screen on a 15” laptop. My eyes just aren’t what they used to be. I was hesitant to go with 720p. It would be a lot of real estate to give up from the current laptop. 900p seemed to be a good compromise but there aren’t a lot of 15" laptops that have a 900p screen.

I decided that 720p was probably the way to go but, just to make sure, I visited the local Microcenter to see what 720p looked like on a 15” laptop.

And that’s where I found the new laptop. The Asus G73sw. Everything that I wanted but with a 17” screen. A 17” screen wasn’t in the original plans but I can read 1080p on a 17” screen!

Enough with the narrative. Here’s the specs on the (now) old laptop:

Dell Vostro 1500
4GB RAM
Core 2 Duo T9300 @ 2.5GHz
NVIDIA GeForce 8600M GT

image

The (now) current laptop:gallery_left

Asus G73sw
8GB RAM (capable of 16)
Core i7-2630QM @ 2GHz (boosts to 2.9Ghz)
NVIDIA GeForce GTX 460M
Dual hard-drive capable

The ‘Q’ in the processor name stands for Quad-Core!

image

The performance boost is quite nice.

The only aspect of the Asus that I’m disappointed with is the WLAN card. It’s an Atheros AR9285. While the card does do 802.11n, it only does so at 2.4GHz. It’s not a dual-band card. I can only use one of the bands that my dual-band DLink DIR-825 supports. Luckily the Atheros is just a PCIe card so I’m hoping to replace it at some point.

Also, the wife get a “new” laptop for her birthday

Sunday, April 24, 2011

Workout Update

Back on 8 Jan, I had finished up a workout cycle and posted my lifts at that time. Since then I’ve completed four more cycles. Here are the current numbers:

Life Weight (lbs) Reps Theoretical Max (lbs)
Military Press 140 1 145
Deadlift 300 3 329
Bench Press 240 5 330
Squat 230 4 260

Just looking at the weight, you would think that I’ve gotten stronger. In fact, I feel stronger. Yet, when comparing the theoretical max between 8 Jan and now, I have dropped in all the lifts except the bench.

My guess is that I underestimated my one-rep max (ORM) for all but the bench when I started the workout. Now the reps that I’m getting are closer to those on the workout. The third week of the cycle calls for three sets at 5,3 and 1 reps respectively. Previously I was getting 10s and 12s. Now the reps are closer to schedule.

The Bench Press results are most interesting. This is the lift that I was disappointed with the most since I wasn’t seeing the gains that I was seeing with the others. In fact, I was really considering changing this part of the workout. In reality, a 60lb increase in four months is probably pretty good.

Based on the two sets of results, I think I’ll stay on the workout, unchanged, for another three or four cycles.

Sunday, April 17, 2011

Greed Kata–Second attempt

When I wrote the post on my first attempt, I mentioned that I thought I was “missing something obvious.” It occurred to me after I put up that post.

A die can only be used in one scoring combination

This is probably obvious to everyone else but I’m only responsible for what goes on in my head.

This realization push me to think that calculating the score using the Pipes and Filters pattern would probably be a good fit. I started with the data that each scorer, the filter, would operate on:

   1: public class GameContext
   2:  {
   3:      public int Score;
   4:      public int[] DiceValues;
   5:  }

Each filter would use the die values stored in the DiceValues field and update the Score field.


For the scorers, I started with the single value rules:



A single one (1) is worth 100 points.
A single five (5) is worth 50 points.


Working through lead to the following:



   1: public class ValueScorer
   2: {
   3:     private readonly int _die;
   4:     private readonly int _value;
   5:  
   6:     public ValueScorer(int die, int value)
   7:     {
   8:         _die = die;
   9:         _value = value;
  10:     }
  11:  
  12:     public GameContext Compute(GameContext context)
  13:     {
  14:         if (0 == context.DiceValues.Length) return context;
  15:         var occurances = Array.FindAll(context.DiceValues, v => v== this._die).Length;
  16:         context.Score += occurances * this._value;
  17:  
  18:         List<int> diceValues = RemoveValuesUsedInAScoringCombination(context.DiceValues, occurances);
  19:         context.DiceValues = diceValues.ToArray();
  20:  
  21:         return context;
  22:     }
  23:  
  24:     private List<int> RemoveValuesUsedInAScoringCombination(int[] currentDiceValues, int occurances)
  25:     {
  26:         var diceValues = new List<int>(currentDiceValues);
  27:         foreach (var ii in Enumerable.Range(1, occurances))
  28:         {
  29:             diceValues.Remove(this._die);
  30:         }
  31:         return diceValues;
  32:     }
  33: }


The next set of rules:


A set of three ones (1) is worth 1000 points
A set of three of any other number is worth 100 time that number (ex. {2,2,2} = 200 points}.

For which I ended up with:

 


   1: public class TripleScorer
   2: {
   3:     public GameContext Compute(GameContext context)
   4:     {
   5:         if (0 == context.DiceValues.Length) return context;
   6:  
   7:         var triples = context.DiceValues.GroupBy(d => d).Where(g => g.Count() >= 3);
   8:  
   9:         context.Score += triples.Sum(g => (g.Count() / 3) * ((1 == g.Key) ? 1000 : g.Key * 100));
  10:  
  11:         List<int> diceValues = RemoveValuesUsedInAScoringCombination(context.DiceValues, triples);
  12:         context.DiceValues = diceValues.ToArray();
  13:  
  14:         return context;
  15:     }
  16:  
  17:     private List<int> RemoveValuesUsedInAScoringCombination(int[] currentDiceValues, IEnumerable<IGrouping<int, int>> triples)
  18:     {
  19:         var diceValues = new List<int>(currentDiceValues);
  20:         foreach (var tripleGroup in triples)
  21:         {
  22:             int digitsToRemove = (tripleGroup.Count()/3)*3;
  23:             foreach (var ii in Enumerable.Range(1,digitsToRemove))
  24:             {
  25:                 diceValues.Remove(tripleGroup.Key);
  26:             }
  27:         }
  28:         return diceValues;
  29:     }
  30: }


The method RemoveValuesUsedInAScoringCombination() is key to making this approach work. This method updates the DiceValues array in the context to remove the values that were used. This piece enforces the constraint that a die is only used once in a scoring combination.


The driver is really straight forward and look like:



   1: public class Scorer
   2: {
   3:     public int Computer(int[] diceValues)
   4:     {
   5:         if (0 == diceValues.Length) return 0;
   6:  
   7:         var tripleScorer = new TripleScorer();
   8:         var oneScorer = new ValueScorer(1,100);
   9:         var fiveScorer = new ValueScorer(5,50);
  10:  
  11:         var context = new GameContext() {DiceValues = diceValues, Score = 0};
  12:  
  13:         context = tripleScorer.Compute(context);
  14:         context = oneScorer.Compute(context);
  15:         context = fiveScorer.Compute(context);
  16:  
  17:         return context.Score;
  18:     }
  19: }

What I find really nice about this approach is that adding additional scoring combinations is just a matter of creating another scorer. For example, say that the ruling body for the game Greed introduces the following rule:



A set of five consecutive numbers (ex. {1,2,3,4,5} or {2,3,4,5,6}) is called a Straight and is worth 2000 points.


This is easily implemented with a Scorer such as:



   1: public class StraightScorer
   2: {
   3:     public GameContext Compute(GameContext context)
   4:     {
   5:         if (0 == context.DiceValues.Length) return context;
   6:  
   7:         foreach (int startingAt in Enumerable.Range(1,2))
   8:         {
   9:             if (this.DiceValuesContainStraight(startingAt, context.DiceValues))
  10:             {
  11:                 context.Score += 2000;
  12:                 context.DiceValues = this.RemoveValuesUsedInAScoringCombination(context.DiceValues, startingAt).ToArray();
  13:             }
  14:         }
  15:  
  16:         return context;
  17:     }
  18:  
  19:     private bool DiceValuesContainStraight(int straightStartsAt, int[] diceValues)
  20:     {
  21:         foreach (var n in Enumerable.Range(straightStartsAt,5))
  22:         {
  23:             if (!diceValues.Contains(n)) return false;
  24:         }
  25:         return true;
  26:     }
  27:  
  28:     private List<int> RemoveValuesUsedInAScoringCombination(int[] currentDiceValues, int startingAt)
  29:     {
  30:         var diceValues = new List<int>(currentDiceValues);
  31:         foreach (var n in Enumerable.Range(startingAt, 5))
  32:         {
  33:             diceValues.Remove(n);
  34:         }
  35:         return diceValues;
  36:     }
  37:  
  38: }

The driver gets modified as:



   1: public class Scorer
   2: {
   3:     public int Computer(int[] diceValues)
   4:     {
   5:         if (0 == diceValues.Length) return 0;
   6:  
   7:         var straightScorer = new StraightScorer();
   8:         var tripleScorer = new TripleScorer();
   9:         var oneScorer = new ValueScorer(1,100);
  10:         var fiveScorer = new ValueScorer(5,50);
  11:  
  12:         var context = new GameContext() {DiceValues = diceValues, Score = 0};
  13:  
  14:         context = straightScorer.Compute(context);
  15:         context = tripleScorer.Compute(context);
  16:         context = oneScorer.Compute(context);
  17:         context = fiveScorer.Compute(context);
  18:  
  19:         return context.Score;
  20:     }
  21: }

Modifying the previous version would not have been nearly as simple.