Nothing at all and Everything in general.

Getting to my Isolated Files (Windows Phone 7)

Download the Code (211 Kilobytes)

A frequent question I see in the MSDN forums is how does one copy their files from Isolated Storage in Windows Phone 7 to their desktop computer. The file system on WP7 isn't exposed so unlike WM6.x you can't just connect it to your desktop and get to any and every file. The general answer given is to create a service that will write files to your desktop's storage and have your WP7 application send the data to that application. There are a lot of ways to do this, so this answer hasn't been enough for some users. I put together this example as an illustration of one of the many ways in which this solution can be built.

In the solution attached to this article you'll find three projects. One project is a Windows Phone 7 application that is made to send data to a service. Another project is the implementation for that service. And the last project is a WPF based GUI that does nothing more than host the service (alternatively the service could have been hosted in IIS or in a service application).

The service has two methods: CopyString(String fileName, string content) for copying string data and CopyBytes(string fileName, byte[] content) for copying binary data

To run the example you would need to start both the WPF application on your desktop (to receive the files) and the application on the phone. On the phone you will enter the name or IP address of your machine (So the phone knows what machine to send the file to) and the port on which the service runs (Default 8001). When you press the upload button on the phone within a few seconds you should see the file's name listed on the PC. The file will be in My Documents\WP7Files\.

If you want to change the port over which the application works you can edit the file that ends with .config in the WPF application.

In this first version of this solution my goal was to only make it work. In a future version I plan to add the ability to transfer large files in chunks, transfer everything in isolated storage, support copying files in both directions, and add security.

This isn't code that you would run in a production environment. Since it is communicating over HTTP instead of HTTPS you don't want to send any sensative data. Currently there's also nothing stopping a rouge client from sending malicious files to the computer (hence the need to add security).

This entry is more geared to some one that has some familiarity with using services in .Net. I'll write step by step instructions for every one else after I further refine this code. If you wanted your own WP7 application to use the service you would need to first run the service locally and then from within Visual Studio right-click on your Windows Phone project, select "Add Service Reference" and type http://localhost:8001/FileCopy/mex/ to add the service reference to your app.

I'll close with the code that was used in the example to read the configuration and then upload a file to the machine identified by the configuration.

public void BeginUpload()
    if (IsUploading)
    string serviceAddress = string.Format("http://{0}:{1}/FileCopy/", this.MachineName, TargetPort);
    ChannelFactory myChannelFactory = new ChannelFactory(new BasicHttpBinding(), new EndpointAddress(serviceAddress));
    //_copyServiceClient = myChannelFactory.CreateChannel(new EndpointAddress(serviceAddress));

    var copyServiceClient = new CopyServiceClient(new BasicHttpBinding(), new EndpointAddress(serviceAddress));
        var encoder = System.Text.UnicodeEncoding.Unicode;
        var byteList = encoder.GetBytes(Content);
        copyServiceClient.CopyBytesCompleted += new EventHandler(copyServiceClient_CopyBytesCompleted);
        copyServiceClient.CopyBytesAsync(FileName, byteList);
        IsUploading = true;
        copyServiceClient.CopyStringCompleted += new EventHandler(copyServiceClient_CopyStringCompleted);

Running the Windows Phone Dev Tools on Windows XP

And now for something completely unsupported.

I'm the type of person that prefers to run the latest and greatest operating system. For Windows 2000, XP, Vista, and Windows 7 I started running them while they were still betas. Unfortunately I'm in possession of a machine running Windows XP for a Silverlight project. The Windows Phone tools require Windows Vista or higher with a DirectX 10 video card, so the WP7 tools were a no-go for this machine. For various reasons I wanted the machine to be capable of opening a WP7 projects. The machine was already running Visual Studio 2010 Ultimate and I have other Silverlight development components installed. So I made an attempt to get things up and running and successfully have a machine that will do WP7 development (though the emulator won't run).

Just an FYI, since I already had Visual Studio 2010 and several Silverlight development components installed I didn't need Visual Studio 2010 Express. I'm not sure how things will go for a person without VS2010 preinstalled.

I grabbed the ISO for the Windows Phone 7 tools from http://developer.windowsphone.com. After unpacking the ISO and running setup I received a message about a problem loading the setup components.  I didn't expect that to work. I next started looking at the files that were in the ISO and saw the familiar "wcu" folder (Windows Component Updates). Inside of the WCU folder there were several subfolders. The only one that was important to me was the Windows Phone folder.

Installing these components individually I found that each one of them would run without any complaint or problem. I started with the Expressions Blend trial and XNA Game Studio. After installing the both of those I found that I could create (but not compile) XNA projects and run Expressions Blend for Windows Phone. I installed the other components and was then able to create and compile Windows Phone 7 projects.

When I first tried to run a Windows Phone 7 project I immediately received an error from the emulator. I changed the target device from the emulator to "Windows Phone 7 Device" and ran the project again and it successfully deployed and ran. Now that my Windows XP machine has been elevated to being cable of developing for Windows Phone 7 I'm happy. Onto better things; VMWare just released an update for VMWare Workstation that is said to improve the graphic capabilities. I've already got a virtualized WP7 dev environment in which the emulator doesn't run because of the emulated video card not meeting minimum requirements. I need to see if this update addresses that.

Where Can I Sell my Apps?

I frequently come across a reoccurring question in the MSDN forums. The question usually looks like the following:

I don't see my country listed for the Marketplace, how can I register so I can sell my apps?"


The answer to that question is "You can't." It is sometimes followed by a question about trying to register within another country. I don't think that will work; when I validated my identity for the Marketplace it was against a government issued ID, a bank, address, and one of the national credit reporting agencies was involved in addition to a notary. I wouldn't have been able to validate against all of those things unless I had residency in another country. So there doesn't seem to be a way to circumvent that. HAving hit that brick wall the usual response from the would be Windows Phone 7 developer is a rather emotionally charged statement declaring that Microsoft needs to get it's act together and ad their country. 

One might wonder why those other countries are not yet able to access the Marketplace. At present there are 31 countries that have access to it (at launch it was 28 countries). Why can't Microsoft just add the other countries? Answering that question requires that one knows what's involved in adding another country. Unfortunately Microsoft doesn't disclose its commercialization processes nor everything that it does to add another country. What is known is that when a country is added there's matters related to tax treties and international trade, identifying local decency standards, establishing agreements with carriers, establishing agreements with a financial institution that takes care of the deposits, agreements with content providers, and so on. Adding a country requires that Microsoft do more than just add another name to the country drop-down list. 

As things stand right now Apple has the largest footprint for their online Marketplace covering a total of about 90 countries. Microsoft is in second place with 31 countries (though it is less than that for Windows Phone 7), and Android is in third with 11 nations for paid apps  (but 46 if you want to distribute free applications).

Firestarter Event for Windows Phone 7 : Atlanta Area

If you live in the Atlanta area and wanted to get started with Windows Phone 7 development now is a pretty good time. On the 24th of August there will be two back-to-back events just for you. The first is a Windows Phone 7 Firestarter event. It will start off with an introduction to the Windows Phone 7 platform, Silverlight, and XNA and then cover what you need to know about the Windows Marketplace for mobile, using Windows Phone Services, and creating compelling user experiences with Windows Phone 7.

The second event that evening is more interactive and hands on. For the second event you'll need to bring your computer with the Windows Phone 7 tools preloaded and you go through interactive labs to get you into Windows Phone 7 development. The seating for these events is limited and expected to sell out fast, so if you are interested register promptly.

Click here to register for the Windows Phone 7 Firestarter.

Click here to register for the hands on labs.


Detect Shaking Motion on Windows Phone 7

Download the code

The other day on the MSDN forums some one asked about how to detect a shaking motion on Windows Phone 7. I've been playing with the accelerometer lately so I took great joy in answering this along with providing a working implementation. The question was asking about shaking motion in a left-right direction. I made a class that detects left-right and up-down motion (totally ignoring the Z-axis all together for now). Though extending it to consider the Z-axis wouldn't be hard.

The code for detecting the motion has been abstracted in a class called ShakeDetector. The algorithm used has a few variables/constants defined that can be modified to tune the behaviour of the class. The classes constructor accepts an [optional] parameter of how many times the phone should be shaken before the motion is considered acceptable. can be raised or lowered to control how hard the device needs to be shaken to be considered acceptable. And MinimumShakeTime takes a time span that defines the maximum length of time overwhich a shake sequence must occur to be considered acceptable. One the user moves the phone in a way that meets the requirements for the type of shake we wanted to detect a ShakeDetected event is raise

I've reduced the direction in which the device is moving to one of 8 directions (North, East, South, West, and the directions inbetween those). I could have kept the direction as an angle and just ensured that there was atleast a minimum difference between the angles but I thought using the directions on a map would make it easier for some one else to understand.

void _accelerometer_ReadingChanged(object sender, AccelerometerReadingEventArgs e)
    //Does the currenet acceleration vector meet the minimum magnitude that we
    //care about?
    if ((e.X*e.X + e.Y*e.Y) > MinimumAccelerationMagnitudeSquared)
        //I prefer to work in radians. For the sake of those reading this code
        //I will work in degrees. In the following direction will contain the direction
        // in which the device was accelerating in degrees. 
        double degrees = 180.0*Math.Atan2(e.Y, e.X)/Math.PI;
        Direction direction = DegreesToDirection(degrees);

        //If the shake detected is in the same direction as the last one then ignore it
        if ((direction & _shakeRecordList[_shakeRecordIndex].ShakeDirection) != Direction.None)
        //This is a shake we care about. save in in our list
        ShakeRecord record = new ShakeRecord();
        record.EventTime = DateTime.Now;
        record.ShakeDirection = direction;
        _shakeRecordIndex = (_shakeRecordIndex + 1)%_minimumShakes;
        _shakeRecordList[_shakeRecordIndex] = record;



void CheckForShakes()
    int startIndex = (_shakeRecordIndex - 1);
    if (startIndex < 0) startIndex = _minimumShakes - 1;
    int endIndex = _shakeRecordIndex;

    if ((_shakeRecordList[endIndex].EventTime.Subtract(_shakeRecordList[startIndex].EventTime)) <= MinimumShakeTime)

The example code can be found in my SkyDrive account here. If you want to see the program in action there is a video on YouTube.

Investments Extended: Infragistics on Windows Phone

Understandably some developers were a bit upset when they found out that their native Windows Mobile code couldn't be moved forward to Windows Phone 7. Their effort investment had essentially reached a dead end. While the decision to use Silverlight as a core technology for Windows Phone broght an end to the usefulness of some code it also opened the door for other existing code to become useful in the mobile space. I was playing with an accelerometer driven program that I had written and was working on making a desktop component that would let me visualize my recorded accelerometer data. I was using the Infragistic Silverlight Data Visualization Controls (version 9.2) for Silverlight 3. I couldn't help but think "Man, if I could use these controls on Windows Phone 7 then I wouldn't need to make a desktop component." Then I decided to try it. I made a simple chart in a Windows Phone 7 project and deployed it to both an emulator and a real device and to my surprise it worked!


I personally invested a lot more in managed code than I did native code and feel that it's nice to be able to share more of my desktop development knowledge with my mobile development activities. But I'm overjoyed to see that my Silverlight 3 investments extend into Windows Phone 7

Avoiding Tight Hardware Coupling

As a Software Engineer I'm interested in how tightly coupled that one piece of code is to another. Coupling is the amound of dependencies that one entity has on another and tightly coupled code tends to be less portable and adaptable. But the concept of coupling doesn't stop at software. Coupling is also applicable to the relationship between hardware and software and I'm interested in avoiding tight coupling between the hardware and software for my code too.

With real implementations of Windows Phone 7 devices floating around it would be easy for some one to attempt to write an application that is tightly couple to that implementation. In some cases these low risk associated with doing this; for example if one tightly couples to screen resolutions (and there will only be two screen resolutions) it could be some time before some one needs to address another screen resolution. I'm writing a piece of code that is going to be sensative to the sampling rate of the accelerometer. And easy but tightly coupled way to handle this would be to measure the sample rate of the accelerometer and then write my code accordingly. But if I do this then I assume quite a few things. I would be assuming that other phones have the same sample rate. I would assume that the same phone will always have the same sample rate. I don't know that either of these assumptions are true.

The time information returned in the from DateTime.Now is precise enough for me to perform the measurements that I needed. So I wrote a quick application that would measure the accelerometer sample frequency and display it in a text box.

Here is my initial code

       private Accelerometer _accelerometer;

        // Constructor
        public MainPage()
            this.DataContext = this;

            _accelerometer = new Accelerometer();
            _accelerometer.ReadingChanged += new EventHandler(_accelerometer_ReadingChanged);

        void _accelerometer_ReadingChanged(object sender, AccelerometerReadingEventArgs e)
            DateTime previousUpdate = LastUpdate;
            LastUpdate = DateTime.Now;
            double period = LastUpdate.Subtract(previousUpdate).TotalSeconds;
            double frequency = 1.0/period;
            if (frequency > HighestFrequency)
                HighestFrequency = frequency;


// LastUpdate - generated from ObservableField snippet - Joel Ivory Johnson
  private DateTime _lastUpdate;
  public DateTime LastUpdate
    get { return _lastUpdate; }
          if (_lastUpdate != value)
              _lastUpdate = value;
// HighestFrequency - generated from ObservableField snippet - Joel Ivory Johnson
  private double _highestFrequency;
  public double HighestFrequency
    get { return _highestFrequency; }
          if (_highestFrequency != value)
              _highestFrequency = value;
              Dispatcher.BeginInvoke(() => { OnPropertyChanged("HighestFrequency"); });

        void OnPropertyChanged(string propertyName)
                PropertyChanged(this, new PropertyChangedEventArgs(propertyName));

        #region INotifyPropertyChanged Members

        public event PropertyChangedEventHandler PropertyChanged;


Ofcourse there may be those that are curious as to what value a real device will currently returned. Of course publishing that type of information could result in more tightly coupled code being written. I'll post more once the code I am writing is done.

Just In: My Windows Phone 7 Hardware

LG Windows Phone 7

When I arrived at home on Friday I had a notice from Fedex that they attempted to deliver a package. Speculating that it was something from Microsoft I jumped back in my car without going into the house and immediatly drove to the Fedex to pick up the Package. It was an LG Windows Phone 7 device.

It's nice to be able to run my code on real hardware. The first thing I did was run the acelerometer example in the Windows Phone 7 page and I found a simple bug in the code that I would have never found on the emulator. The device uses an AT&T 3G radio (I am on T-Mobile USA) so I've not been able to use it in 3G mobile, only in edge. But this is more than sufficient for my purposes. I'm about to hop in my car right now to test out a location based application I had written.

Obfuscation Available for Windows Phone 7

PreEmtive Solutions announced that it now has support for the Windows Phone 7 variant of Silverlight for its Dotfuscator product. Dotfuscator will obfuscate ones XAP file by renaming the elements within it. While this doesn't make the assembly impossible to reverse engineer it does make the process more difficult. For some one attempting to reverse engineer your code their decompilation tools will still work but will produce something with less meaningful names. There is a cognitive component to reverse engineering and obfuscation interferes with that component of the process.  More information on the product can be found on PreEmptive's site.

Original Story: WmPowerUser.com

Windows Phone 7 Initial Languages

Yesterday the Windows Phone team announced the languages and countries that will see the first Windows Phone 7 devices this year. The five languages that will be supported at launch are English, French, Italian, German, and Spanish.  The 17 nations that will see the initial devices are Australia, Austria, Belgium, Canada, France, Germany, Hong Kong, India, Ireland, Italy, Mexico, New Zealand, Singapore, Spain, Switzerland, UK and United States. Also in case you missed it the first preproduction Windows Phone devices ship this upcoming Monday to developers (I'm keeping my fingers crossed and hoping that by some miracle I receive one!). 

source: Windows Team Blog