Tag Archives: Microsoft Tag

Part 1. Harnessing the power of IExtensibleDataObject

One of the first things people tend to do when there are building an application (at least I do!), is try to identify the models (POCO’s) which will be used throughout the application.  Because we added a service refence to WCF service provided by Micorsoft, a base for the models are already provided.  I created a class diagram to give some more insight on the way the models are constructed.

 

 This class diagram shows us a couple of things. First of all, we have a base class which serves as a base for all the possible tag types. A more important observation is that this base class implements the IExtensibleDataObject interface (http://msdn.microsoft.com/en-us/library/system.runtime.serialization.iextensibledataobject.aspx ).  The implementation of this interface ensures us that the properties marked with the DataContractAttribute attribute are preserved while serializing and deserializing. Even better, when serialized to a parent or child class the data is preserved in the ExtentionData property provided by the interface.

At this moment we have successfully identified the main part of the models provided by the API. It is now time to make sure we can take advantage of these models and their behavior. In some cases you can use the models as-is and you can build your software on top of the base classes provided but more often you’ll need some additional properties on the model to make it usefull for this specific environment.

For this post I’ll extend the base classes with a minimal amount of properties, so we can use these properties in Part 3 of this multi-post. I usually work a lot with interfaces and abstracts to minimize the amount of duplicate code and minimize the risk of built-in dependencies. In this case I’ll introduce a couple of interfaces and an extension method  to work with the IExtensibleDataObject interface.

 

 

 

As you can see in this class diagram, all extended objects implement an interface which inherits from ITag and they inherit from the classes provided by the API.  The ITag interface inherits from the IExtensibleDataObject in order to accommodate the extension method.  The concrete (and simple!) implementation of UriTagExtended looks like this:

The next step is to implement an extension method which allows us to go back and forth to the base object and our extendedobject. The extension method hooks in on the IExtensibleDataObject interface and equips every class inheriting from that interface with an additional method: ConvertTo<T>. This extension serializes the object and deserializes it into T (and store any additional info in the DataExtension property). Our extension method is implemented as follows:

 

 

 

With the implementation of our extension method we are able to revert our extended objects back to the base objects that are supplied to the methods of the API.   In the next part of this multi-part blog post I will wrap the API in a repository pattern and make some more use of the extended properties and the extension method we created.  

Tagged , ,

Building Software using the Microsoft Tag API

A recent chat with Ken Levy from Code magazine, inspired me to write this multi-part blog on Tagging.
Microsoft Tag is Microsoft’s answer on the growing adoption and use of QR codes. While QR codes are a common technology in Asia, the people in Europe (and as I understood also in the US) are getting up to speed with the technology right now.

For the people who don’t know what a QR code is, a small introduction can be helpful to understand it’s potential. Microsoft describes a Tag as: “a new kind of bar code that connects almost anything in the real world to information, entertainment, and interactive experiences on your mobile phone. Tags are free to create and use. You can add them to your ads, posters, product packages, display it on your website, billboards, clothing…” (source: http://tag.microsoft.com )

To be able to use the Tags, people need to download the Microsoft Tag reader app by downloading it from http://gettag.mobi (browse to this site using your mobile phone).  When a tag is scanned, the phone will open a webpage, download a v-card, receive a text message, or dial a number.  Microsoft provides a ready to use Tag manager, but in some cases you would like to create Tags programmatically.

Microsoft lets you register for the tag manager and you can get access to their API, which is actually a WCF service. Although this is great, some things need to be overcome to work efficiently with the API. The API lets you create, manipulate and retrieve single tags. It is however, not possible to search or delete a Tag using the API.  Although this might sound as a big disadvantage we can turn it around and make it into an opportunity.

The “missing” functionality in the API forces developers to create local storage to make the tags searchable. By choosing the right Architecture and technologies we can develop a flexible implementation of the API which can connect to any Storage with minimal effort.  This blog consists of four parts, where every part will present a solution or approach to work with the API.

Part 1. Harnessing the power of IExtensibleDataObject
Part 2. Wrapping the service in the Repository Pattern
Part 3. Reading the .Tag format
Part 4. Decouple the Persistor with Dependency Injection

Tagged