Windows Mobile Device Emulator Programmability - A Simplified Wrapper

You Can Take it With You

Syndication

News

  • Don't miss the next Windows Mobile Webcast... Unit Testing for Mobile Devices: http://msevents.microsoft.com/CUI/WebCastEventDetails.aspx?EventID=1032382824&EventCategory=4&culture=en-US&CountryCode=US.

In Tuesday's post I talked about the new Device Emulator Manager Automation API. I'm a big fan of this new API because of the ease with which it lets you control the emulators. In that post I expressed the opinion that the one thing that would make working with the API even easier is for the classes to be a little more .NET friendly.

As I mentioned on Tuesday, the API works very well with scripting environments and also fits naturally into the C++ COM model. The API provides a .NET Assembly that makes the features available in .NET but the COM interfaces are directly imported and therefore don't offer some of the common .NET features like enumerators or indexers that simplify working with collections.

If we just had some simple .NET wrappers over the COM interfaces, managing the Device Emulator Manager hierarchy could also be simple ... and from that thought ... DeviceEmulatorManagerEx was born.

DeviceEmulatorManagerEx and the related classes are the result of a few hours I spent last night and today, putting together some wrapper classes that make the Device Emulator Manager Automation API feel a little more .NET friendly.

Note: I've written these classes to simplify common Device Emulator Manager-related tasks. I would not consider them to be a "rich" implementation so don't be surprised if you can't do a LINQ query over them or other high-end tasks. J
Note: I've tested the code but I've not exercised it the way a professional class library is exercised. You should fully verify any and all behaviors and usage of the classes.

There are 4 main DeviceEmulatorManagerEx-related classes.

Wrapper Class

Corresponding COM Interface

DeviceEmulatorManagerEx IDeviceEmulatorManager
DeviceEmulatorCategory IDeviceEmulatorManager
DeviceEmulatorSdk IEnumManagerSDKs
DeviceEmulator IDeviceEmulatorManagerVMID

Some Example Usage.

The two classes that one is most likely to use are the Emulator class and the DeviceEmulatorManagerEx class. The Emulator class provides wrappers over the emulator-related functions provided by the COM IDeviceEmulatorManagerVMID interface such as Connect, Cradle, Shutdown, and so on.

There are also a few things that one might find useful with the DeviceEmulatorManagerEx class. It's most useful feature is the FindEmulator method which allows you to retrieve a reference to an emulator by passing the emulator's name (as it appears in Device Emulator Manager).

DeviceEmulatorManagerEx demManager = new DeviceEmulatorManagerEx();
DeviceEmulator wm6Pro = demManager.FindEmulator("Windows Mobile 6 Professional Emulator");
wm6Pro.Connect();
demManager.Dispose();
  // always call Dispose when done

The other features of the DeviceEmulatorManagerEx class that one is likely to use is the RefreshRequired event and Refresh method. The RefreshRequired event signals when something has changed in the Device Emulator Manager hierarchy. When the RefreshRequired event signals, you should call the DeviceEmulatorManagerEx.Refresh method which clears any saved state that the DeviceEmulatorManagerEx  may have and assures that it returns the most up-to-date information.

Collections

There are also 3 collections which provide standard .NET collections over the COM interfaces. The collections include support for enumerators so language constructs like foreach (C#) and For Each (VB) can be used.

Collection Class

Enumerates Over

DeviceEmulatorCategoryCollection IDeviceEmulatorManager
DeviceEmulatorSdkCollection IEnumManagerSDKs
DeviceEmulatorCollection IEnumVMIDs

With the collections, you can loop through the hierarchy naturally. The following code populates a list box with all of the Device Emulator Manager categories, SDKs, and emulators.

_lbDisplay.Items.Clear();
foreach (DeviceEmulatorCategory category in _deviceEmulatorManagerEx.Categories)
{
    _lbDisplay.Items.Add(category.Name);
    foreach (DeviceEmulatorSdk sdk in category.Sdks)
    {
        _lbDisplay.Items.Add("\t" + sdk.Name);
        foreach (DeviceEmulator deviceEmulator in sdk.DeviceEmulators)
       {
            _lbDisplay.Items.Add("\t\t" + deviceEmulator.Name);
        }
    }
}

Compare the above looping code to the 80-or-so lines of looping code within the DEMUtility.FindEmulator function in Tuesday's post. Quite a big difference. J

One last point on the collections. The collections all expose Indexers that allow you to access the members by name. Here's some examples.

Get the DataStore category
DeviceEmulatorCategory dataStore = demManager.Categories["DataStore"];

Get the Windows Mobile 6 Professional SDK within the DataStore category
DeviceEmulatorSdk wm6ProSdk = demManager.Categories["DataStore"].Sdks["Windows Mobile 6 Professional SDK"];

Get the Windows Mobile 6 Professional Emulator within the Windows Mobile 6 Professional SDK within the DataStore category.
DeviceEmulator wm6Pro = demManager.Categories["DataStore"].Sdks["Windows Mobile 6 Professional SDK"].DeviceEmulators["Windows Mobile 6 Professional Emulator"];
Note: In the case of locating a specific emulator, one would generally use the DeviceEmulatorManagerEx.FindEmulator method shown earlier

The Code and a Sample App

Alrighty, that's the highlights. If you'd like a copy of the DeviceEmulatorManagerEx wrapper classes along with an example application showing their usage, download DeviceEmulatorManagerAutomationWrapperExample.

If there are other features that you'd like to see in these wrapper classes, let me know. I'll do what I can to get them included.

As always, questions are welcome.


Posted Nov 01 2007, 05:56 PM by jim-wilson

Comments

Noel wrote re: Windows Mobile Device Emulator Programmability - A Simplified Wrapper
on 11-15-2007 10:51 AM
Great stuff, will save me a ton of time
Jim Wilson wrote re: Windows Mobile Device Emulator Programmability - A Simplified Wrapper
on 11-15-2007 11:13 AM
Noel;

Glad to hear it helps.

If you run into any problems or have ideas for improvements, please pass them along. I'll do my best to get them incorporated.

Thanks,
Jim
Constanze's Mobile Musings wrote Thanks for attending yesterday's webcast on "Device Emulator and Cellular Emulator"
on 09-11-2008 8:58 PM

I wanted to thank everybody who attended yesterday's Webcast on "Device Emulator and Cellular Emulator."

a-foton » Thanks for attending yesterday’s webcast on “Device Emulator and Cellular Emulator” wrote a-foton » Thanks for attending yesterday’s webcast on “Device Emulator and Cellular Emulator”
on 09-11-2008 9:04 PM

Pingback from  a-foton » Thanks for attending yesterday’s webcast on “Device Emulator and Cellular Emulator”

Thanks for attending yesterday’s webcast on “Device Emulator and Cellular Emulator” : EasyCoded wrote Thanks for attending yesterday’s webcast on “Device Emulator and Cellular Emulator” : EasyCoded
on 09-11-2008 9:06 PM

Pingback from  Thanks for attending yesterday’s webcast on “Device Emulator and Cellular Emulator” : EasyCoded

discount furniture » Thanks for attending yesterday’s webcast on “Device Emulator and Cellular Emulator” wrote discount furniture » Thanks for attending yesterday’s webcast on “Device Emulator and Cellular Emulator”
on 09-11-2008 9:09 PM

Pingback from  discount furniture » Thanks for attending yesterday’s webcast on “Device Emulator and Cellular Emulator”

car insurance » Thanks for attending yesterday’s webcast on “Device Emulator and Cellular Emulator” wrote car insurance » Thanks for attending yesterday’s webcast on “Device Emulator and Cellular Emulator”
on 09-11-2008 9:14 PM

Pingback from  car insurance » Thanks for attending yesterday’s webcast on “Device Emulator and Cellular Emulator”

funny wallpaper » Thanks for attending yesterday’s webcast on “Device Emulator and Cellular Emulator” wrote funny wallpaper » Thanks for attending yesterday’s webcast on “Device Emulator and Cellular Emulator”
on 09-11-2008 9:28 PM

Pingback from  funny wallpaper » Thanks for attending yesterday’s webcast on “Device Emulator and Cellular Emulator”

Pocket.info - Mobile 2.0 wrote Thanks for attending yesterday's webcast on "Device Emulator and Cellular Emulator"
on 09-12-2008 12:29 AM

I wanted to thank everybody who attended yesterday's Webcast on "Device Emulator and Cellular

Add a Comment

(required)  
(optional)
(required)  
Remember Me?