Thursday, August 26, 2010

Windows Phone 7 Show Case Partner Deep Dive

This week (8/22/2010) I was fortunate enough to be invited to Building 20 (technology adoption center) out in Redmond.  I have to give a big shout-out and thanks to DevFish for helping make this happen.  My company Software Logistics, LLC is working on a product that we will be announcing in the coming weeks and needed a little extra help from the Windows Phone 7 team.

image

image

 

 

 

 

 

 

 

While working on my application I had in my possession a Windows Phone 7 prototype device, it was the LG model and I was able to install a very fresh build of the operating system.  After having the privilege to play with the device for a week, all I can say is wow.  When they claim it’s really a different kind of phone, well they aren’t kidding.  You’ll just have to wait until you get one in your hands.  This is the sort of thing that needs to be experience, and can’t adequately be described.  I think the two words that would best describe the paradigm shift are “integrated experience”.  You don’t launch and application to deal with your “stuff”.  You find your “stuff” then have the opportunity to act upon it with applications.  This may sound like a subtle difference, but it really isn’t.

 

The number one tip I learned this week was to be aware of your “fill-rate” this is the amount of pixels that need to be acted upon by the device but aren’t actually being rendered on the 800x480 display.  To get live statistics about your fill rate, enable the following property in your application.

Application.Current.Host.Settings.EnableFrameRateCounter = true;

Once you do so, you can look at the fourth number on the right hand side of your screen.  This will tell you your fill rate < 2 is optimal > 3 or so is considered bad and will have a significant performance impact on your application.

image 

By the way, the screen shot above gives a sneak peak of a sliver of the application I’m building.  I really can’t wait to talk more about “Sea Wolf” that will be ready by the time Windows Phone launches later this year…stay tuned!

-twb

Tuesday, August 17, 2010

SW Florida .NET Developers Group

Tonight (August 17, 2010) I’ll be doing a little talk about about a hot technology you might have heard of called Windows Phone 7.

The first part of the talk will be dedicated to a quick overview of development for Windows Phone 7.  We won’t dwell on C# or Silverlight but will build three little applications that should give an overview of the development environment for Windows Phone:

  • W.O.P.R. – Slightly more exciting than “Hello World”
  • KLIK2WIN – Very simple silverlight game
  • John’s Game – Well you’ll have to attend to see what this one is about

The file for my presentation include both a step-by-step lab and the completed working applications.  You can download the files from here.

The second part of the talk should be a lot of fun, John asked that the user group members come up with Windows Phone 7 applications.  The group will then vote on the best app and we’ll talk about what it would take to implement it and start building the application frameworks.  We certainly won’t have time to finish the application but should be able to get an idea of what would be involved.

Hope to see you all there!

-twb

Sunday, August 8, 2010

Serialization Performance on Windows Phone 7

On a recent project of mine I needed to download a large file, do some massaging of the data and then write it to the device so it can quickly be accessed again.  The data was in a tree form and was populated in memory to populate a POCO.

I put this off a little bit since I knew it shouldn’t be that difficult to do something using the DataContractSerializer to serialize it to a stream created from Isolated Storage.  Something like:

using (var store = IsolatedStorageFile.GetUserStoreForApplication())
{
    using (var stream = new IsolatedStorageFileStream(name, System.IO.FileMode.Create, store))
    {
         var serializer = new DataContractSerializer(typeof(MyClass));   
         serializer.WriteObject(stream, _myInsance);
     }
}

and

using (var store = IsolatedStorageFile.GetUserStoreForApplication())
{
    using (var stream = new IsolatedStorageFileStream(name, System.IO.FileMode.Open, store))
    {
         var serializer = new DataContractSerializer(typeof(MyClass));    
         var myInstance = ser.ReadObject(reader, true) as MyClass;
     }
}

I put in the code and started to test.  Performance was terrible, my app would start, I clicked on “Break All” in Visual Studio .NET and found it was stuck on my new serialization code.  And this was on my P7 laptop so this wasn’t going to work once I put it on the device.  My instance had a larger number of arrays, each array had a considerable number of points.  I used List<T> for my arrays.  Next I too those out tried again.  At least it finished, but it took about 8 seconds, again that was on my P7 multi-core so this wasn’t going to work on the device.  Well maybe, once I download and process the array I figured I could start a background task to write the data, I could see some problems with this but it could be the best I could do.  Ok let’s try to reconstitute that instance, 24 seconds?!?!?    Time for a different strategy.

My solution came in two parts, the first which is specific to my application which as basically do the serialization myself.  Turn each instance in the object graph and arrays of points into an array of bytes.  Then just write those bytes to Isolated Storage. 

First I wrote the code to turn those objects into byte arrays and then recreate the instances.  This performed extremely well.  Next I needed to write those byte arrays to isolated storage.  This was slow relatively speaking.  My process was to scan the object graph grab the byte array and then write it to the Isolated Storage stream.  Not knowing how storage worked internally it might be slow to to lots of smaller writes.   So I tried writing the byte arrays to a memory stream, then read the memory stream in big chunks (100Kb) to write to Isolated storage.  So basically we are doing fewer larger writes instead of lots of smaller writes.  This worked awesome.  I was able to get my serialization process down for taking longer than I cared to wait, to a little over a second. 

For deserialization I just basically reversed the process, read all the bytes in big chunk (again 100Kb) from Isolated Storage into a Memory Stream and then read the memory stream in the right size chunks to re-populate my instances.  Still not 100% happy with the read, but most of that is creating instances and populating the data.

-twb

Saturday, August 7, 2010

Getting Started with Windows Phone 7 GPS and Location Services

It’s super simple and straight-forward to get started with using Location Services on Windows Phone 7.

The following source code is a quick snippet that shows you the key components for working with the GPS.

private void GpsTracking_Click(object sender, EventArgs e)
{
    if (watcher != null)
    {
        watcher = new GeoCoordinateWatcher(GeoPositionAccuracy.High);
        watcher.MovementThreshold = 20;

        watcher.StatusChanged += watcher_StatusChanged;
        watcher.PositionChanged += watcher_PositionChanged;
        watcher.Start();
    }
    else
    {
        if (watcher.Status == GeoPositionStatus.Disabled)
            watcher.Start();
        else
            watcher.Stop();
    }
}

void watcher_PositionChanged(object sender, GeoPositionChangedEventArgs<GeoCoordinate> e)
{
    Dispatcher.BeginInvoke(() =>
        Map.CenterOnLocation(
                        new Coord(e.Position.Location.Longitude, e.Position.Location.Latitude),
                        e.Position.Location.Course,  e.Position.Location.Speed, 
                        e.Position.Location.HorizontalAccuracy, e.Position.Location.VerticalAccuracy)
    );
}

void watcher_StatusChanged(object sender, GeoPositionStatusChangedEventArgs e)
{
    Dispatcher.BeginInvoke(() =>
        Map.UpdateGPSStatus(e.Status.ToString())
    );
}

The MSDN documentation is available here.

So now you are asking yourself, well Kevin, yes that is all very nice, but I don’t have a device, how the heck am I supposed to test this?  Simple – use this very cool little utility provided by Ali Tinwala

Enjoy!

-twb