PleaseWaitService for Windows Phone 7

by Geert 27. March 2012 20:24

For a long time, the PleaseWaitService is available for WPF and Silverlight in Catel. However, in the latest version (3.0), we have added support for Windows Phone 7 as well.

The PleaseWaitService is a service that can be used in MVVM scenario’s to show the user that a view model is currently performing an action. The cool thing about this is that Catel also offers test implementations that can be used during unit tests so all your view models maintain testability.

The advantages of this service are:

  1. You no longer have to put a busy indicator on every page
  2. You maintain testability
  3. No more “IsBusy” properties on your view model which are stupid

Below is a video demonstrating the default implementation of the PleaseWaitService:

 

How to use this beauty?

1) First, you have to register it in your IoC container. If you are using Catel, it is all done automatically for you!

  1: serviceLocator.RegisterType<IPleaseWaitService, PleaseWaitService>();

2) Resolve the service in your view model from the IoC container. If you are using Catel, you can use the GetService method:

  1: var pleaseWaitService = GetService<IPleaseWaitService>();

3) Last but not least, you need to show and hide it. Since on WP7, you are probably using lots of asynchronous calls, it is recommended to use the Push and Pop methods:

When starting an operation:

  1: pleaseWaitService.Push();

When an operation finishes:

  1: pleaseWaitService.Pop();

This way, the PleaseWaitService will hide the busy indicator when all operations are finished.

Tags: , , , ,

Catel | MVVM | Windows Phone 7

Catel 2.1 released

by Geert 16. September 2011 10:01

I am proud to announce that earlier this week we released Catel 2.1. This blog post contains the most important additions and changes, but the full release notes can be found here.

Brand new documentation

First, let’s start with a new feature I am very, very proud of. The biggest issue I hear from people about open-source MVVM frameworks is the documentation, or better said, the lack of documentation. For Catel, we wrote lots of articles on The Code Project, and also used the wiki to write all the documentation we could think of. However, we still got people that were confused of not finding the documentation. The main reason is that the wiki of CodePlex doesn’t have a very good navigation structure.

Now, we proudly present to you the brand new MSDN style documentation which contains both reference documentation as manually written documentation:

http://catel.catenalogic.com

Added support for MEF

Support for MEF was a much requested feature, so we are glad we could make it into the 2.1 release. If you have any other IoC containers that you want supported, just let us know!

ObservableObject

We already had the great DataObjectBase class which supports lots of interfaces such as INotifyPropertyChanged, INotifyPropertyChanging, IDataErrorInfo, IEditableObject, etc. However, sometimes you just need a new class with only INotifyPropertyChanged. In such a case, the DataObjectBase is a bit of an overkill so we decided to extract the INotifyPropertyChanged and INotifyPropertyChanging implementations into a new class called ObservableObject.

CameraService for Windows Phone 7 Mango

We also added the CameraService to Windows Phone 7 Mango. This way, you can use the PhotoCamera class in a service way. Of course we also provided a unit test implementation that can also be used in the emulator to actually emulate the camera so the code can be unit tested.

A full article about the CameraService can be found here.

What’s next?

Of course we are already working very hard on the new 2.2 release, which we expect to release in another month (our goal is to release a new version every month until the feature set is complete and the releases become smaller).

If you have any feature requests, just let us know!

Tags: , , , ,

C# | Catel | MVVM | Silverlight | Windows Phone 7

Sneak preview: Windows Phone 7 Mango CameraService

by Geert 2. September 2011 12:06

You have probably already heard the good news: in Windows Phone 7 Mango, we can actually get to the camera using the PhotoCamera class. However, I always like to write my applications for xaml based applications using the MVVM pattern. But if you want to use the PhotoCamera class inside a view model, you really got a problem, or actually 2 problems:

  1. How to test the behavior in the emulator
  2. How to write unit tests for the view models

So, as one of the developers of Catel, I decided to write a service which can be used by any MVVM framework (not just Catel) to emulate or unit test the view model that handles the camera stuff.

Below is video demonstrating the service inside the emulator:

 

 

The test implementation of the service is able to import an image and will animate it and submit it as thumbnail buffers. Then, when a final pictures is taken (all using exactly the same API calls as the PhotoCamera class), the current image is resized and becomes available for the view model.

A complete article including unit testing will become available soon, very soon!

Update:

The article can be found here.

Tags: , ,

C# | Windows Phone 7

Windows Phone 7 and MissingMethodException

by Geert 27. August 2011 13:44

Recently I was building a demo application for Windows Phone 7 to show how it can be used with Catel. I created a new Windows Phone 7 project (for Mango) and tried to run the example. I hit a strange exception when a view model was constructed:

image

Now I thought: WTF?! I am pretty sure that this method exists, and the same code works for WPF, Silverlight and Windows Phone 7 (non-mango). After a few hours and trying, I decided to comment out the content of the RegisterViewModelServices method. What seemed: it’s the content of the method responsible for the MissingMethodException.

Let’s take a look at the content of that method:

   1: /// <summary>
   2: /// Registers the known view model services.
   3: /// </summary>
   4: /// <param name="serviceLocator">The service locator.</param>
   5: protected override void RegisterViewModelServices(IServiceLocator serviceLocator)
   6: {
   7:     // Logger already created, no IoC required
   8:     if (!_injectedServices.ContainsKey(typeof(ILogger)))
   9:     {
  10:         _injectedServices.Add(typeof(ILogger), Log);
  11:     }
  12:  
  13:     try
  14:     {
  15:         Log.Debug(TraceMessages.RegisteringDefaultServiceImplementationsForIoCContainer);
  16:  
  17: #if WINDOWS_PHONE
  18:         serviceLocator.RegisterTypeIfNotYetRegistered<ILocationService, LocationService>();
  19:         serviceLocator.RegisterTypeIfNotYetRegistered<IMessageService, MessageService>();
  20:         serviceLocator.RegisterTypeIfNotYetRegistered<INavigationService, Services.NavigationService>();
  21:         serviceLocator.RegisterTypeIfNotYetRegistered<IVibrateService, VibrateService>();
  22: #if WINDOWS_PHONE_MANGO
  23:         serviceLocator.RegisterTypeIfNotYetRegistered<IAccelerometerService, AccelerometerService>();
  24:         serviceLocator.RegisterTypeIfNotYetRegistered<ICameraService, CameraService>();
  25:         serviceLocator.RegisterTypeIfNotYetRegistered<ICompassService, CompassService>();
  26:         serviceLocator.RegisterTypeIfNotYetRegistered<IGyroscopeService, GyroscopeService>();
  27: #endif
  28: #elif SILVERLIGHT
  29:         serviceLocator.RegisterTypeIfNotYetRegistered<IMessageService, MessageService>();
  30:         serviceLocator.RegisterTypeIfNotYetRegistered<INavigationService, NavigationService>();
  31:         serviceLocator.RegisterTypeIfNotYetRegistered<IOpenFileService, OpenFileService>();
  32:         serviceLocator.RegisterTypeIfNotYetRegistered<IPleaseWaitService, PleaseWaitService>();
  33:         serviceLocator.RegisterTypeIfNotYetRegistered<ISaveFileService, SaveFileService>();
  34:         serviceLocator.RegisterTypeIfNotYetRegistered<IUIVisualizerService, UIVisualizerService>();
  35: #else // WPF
  36:         serviceLocator.RegisterTypeIfNotYetRegistered<IMessageService, MessageService>();
  37:         serviceLocator.RegisterTypeIfNotYetRegistered<INavigationService, NavigationService>();
  38:         serviceLocator.RegisterTypeIfNotYetRegistered<IOpenFileService, OpenFileService>();
  39:         serviceLocator.RegisterTypeIfNotYetRegistered<IPleaseWaitService, PleaseWaitService>();
  40:         serviceLocator.RegisterTypeIfNotYetRegistered<IProcessService, ProcessService>();
  41:         serviceLocator.RegisterTypeIfNotYetRegistered<ISaveFileService, SaveFileService>();
  42:         serviceLocator.RegisterTypeIfNotYetRegistered<IUIVisualizerService, UIVisualizerService>();
  43: #endif
  44:  
  45:         Log.Debug(TraceMessages.RegisteredDefaultServiceImplementationsForIoCContainer);
  46:     }
  47:     catch (Exception ex)
  48:     {
  49:         Log.Error(ex, TraceMessages.FailedToConfigureIoCContainer);
  50:  
  51:         throw new Exception(Exceptions.FailedToConfigureIoCContainer, ex);
  52:     }
  53: }

As you can see, all services that should be available per platform are registered so the user doesn’t have to do this. After commenting out all services and adding them one by one, it seems that all services regarding sensors were causing the MissingMethodException.

Then I thought: hey, they all share a common base class, maybe something is wrong with the base class for sensor services. After checking out all the references, it seems the following were referenced in Catel, but not in the demo app:

  • mscorlib.Extensions
  • Microsoft.Devices.Sensors
  • Microsoft.Xna.Framework
  • System.Device
  • System.Runtime.Serialization
  • System.Xml.Linq

I decided to add them all, even though I knew that those references should be included automatically (or at least be available since they are part of the phone framework). Again, no luck, still got the MissingMethodException.

At this time, I was already bald because I pulled all my hair out…

I double checked all references and made sure they were all pointing to the same files (right version, right runtime, etc). Still no luck.

Then I thought: hey, I did change something in the ISensorService recently. Instead of this definition:

   1: public interface ISensorService<TValueInterface, TEventArgs> 
   2:     where TEventArgs : EventArgs

I used this definition:

   1: public interface ISensorService<out TValueInterface, TEventArgs> 
   2:     where TEventArgs : EventArgs

I added the out because ReSharper told me I could define it as covariant. What seems: changing it back to a non-covarient type parameter solves the issue.

Now I am still now sure: is this a bug in my code, or is it a bug in the runtime? If you know, please let me know!

Tags:

C# | Windows Phone 7

Sneak preview: Catel and support for Windows Phone 7 Mango

by Geert 30. May 2011 13:54

Since version 1.4, Catel fully supports the MVVM implementation of Catel for Windows Phone 7. Just after releasing Catel 1.4 (actually, the same evening), Microsoft announced the availability of the Mango SDK. For the ones that are unfamiliar with Mango: it’s the new big Windows Phone update that upgrades the framework to use Silverlight 4 instead of Silverlight 3 for Windows Phone development.

One thing that I missed in the Windows Phone emulator was the option to simulate the location service (GPS). When Microsoft showed that they implemented support for simulating the accelerometer and the location services, I was more than happy. However, what about the compass and gyroscope? No word about those sensors (which you want to simulate as well, right?).

When we as development team for Catel heard about the new Mango SDK, we immediately started implementing support for this new framework. One of the things we decided to build was a test implementation for every sensor available on the Windows Phone 7 device. This way, you can simulate all sensors in the emulator on your development machine in an MVVM manner.

Below is a video that shows how this actually works in the emulator and shows the differences between the Mango tools and Catel.

Sensors Demo sneak preview video

The demo application is already committed to the source control of Catel, so if you can’t wait until the official 2.0 release, you can already grab it here.

Tags: , ,

Catel | MVVM | Windows Phone 7


About the Author

Geert van Horrik is an independent freelance software developer since January 1st, 2007. Since then he was been working on several projects from C++ to C# (WPF, Silverlight, ASP.NET, etc). Currently he loves to write his software using WPF (or Silverlight if WPF isn't an option).

Lately, Geert is spending a lot of time on Catel, a free open-source MVVM Framework for WPF and Silverlight. Actually, it's more than "just" an MVVM Framework, it's a complete application library!