Click here to close now.

Welcome!

Microservices Journal Authors: John Treadway, Charles Rich, Lori MacVittie, Pat Romanski, Tech Spot

Related Topics: Cloud Expo, Wireless, Microservices Journal, .NET, Silverlight, Apache

Cloud Expo: Article

Windows Azure Mobile Services

Windows Azure Mobile Services is the bomb, but how can we work with enum values?

Now, in order to do this, it makes some assumptions.  It looks at the JSON object, and if it sees a certain type of data, it creates a certain type of column to support the data.  The easiest thing that it could have done would be to just create text columns in the underlying SQL database, since any type of data can be stored as a string.  Instead, it does something quite a bit smarter, and creates data types that are quite a bit more “appropriate”.  Here’s the strategy that it uses:

JSON / CLR Data Type T-SQL Type in underlying SQL Azure database table
Numeric values (integer, decimal, floating point) float(53) – this is the maximum precision float.
Boolean bit
DateTime DateTimeOffset(3)
String nvarchar(max)

OK, so this is great.  Dynamic schema is pretty cool.  However…

When I work on a database schema, I often run into a case where I want to create a “code/decode” style table.  In my world, a “code/decode” table is typically a two column table, where the primary key is the “code” and the other column is a textual description.  The canonical example is a “States” table (in the US).  Like this:

Code Decode
AL Alabama
AK Alaska
AZ Arizona
IL Illinois
WY Wyoming

Then, with this table defined, I’ll just use it anywhere I need a State… like this:

Column DataType Notes
FirstName nvarchar(50)
LastName nvarchar(50)
Address1 nvarchar(100)
Address2 nvarchar(100)
City nvarchar(100)
State char(2) Foreign Key to State Code
ZIPCode char(5)

Now, in my current project, it wasn’t a state code that I needed, it was a “CurrencyType”.  And moreover, I wanted to be able to have an “enum” value of CurrencyTypes to be able to work with in my application.  This led me to wonder how WAMS could handle storing and retrieving an “enum” in the database.  It’s not immediately clear that it would know what to do with it as a JSON type.  The JavaScriptSerializer seems to turn enum values into an integer value, which would probably work, but I really wanted my underlying SQL table to store “IL” for Illinois, and not the number 14 as a 53 bits of precision float.  So, how can I turn my enum values into the underlying state codes as a 2 character string on the way in, and reconvert them back to my enum values on the way out?

To start with, here’s the (truncated) version of my enum for my CurrencyType.

public enum CurrencyType
{
	UnitedArabEmiratesDirham,
	AfghanistanAfghani,
	AlbaniaLek,
	//...
	UnitedStatesDollar,	
	//... 
	Unknown
}

Next, the secret sauce turns out to be an IDataMemberJsonConverter .  This interface exists within the Microsoft.WindowsAzure.MobileServices assembly, and has 2 methods that you need to implement – ConvertFromJson and ConvertToJson.  Here’s the type converter that I created to massage my enum into a string going in, and from a string back to the enum on the way back out…

First, the ConvertToJson method:

public IJsonValue ConvertToJson(object instance)
{
	if (instance is Types.CurrencyType)
	{
		switch ((Types.CurrencyType)instance)
		{	
			case Types.CurrencyType.UnitedArabEmiratesDirham:
				return JsonValue.CreateStringValue("AED");
			case Types.CurrencyType.AfghanistanAfghani:
				return JsonValue.CreateStringValue("AFN");
			case Types.CurrencyType.AlbaniaLek:
				return JsonValue.CreateStringValue("ALL");
// SNIP
			case Types.CurrencyType.UnitedStatesDollar:
				return JsonValue.CreateStringValue("USD");
// SNIP
			default:
				return JsonValue.CreateStringValue("XXX");
		}
	}
	else
		return JsonValue.Parse("null");
}

Next, the ConvertFromJson method:

public object ConvertFromJson(IJsonValue value)
{ 
	CurrencyType result = Types.CurrencyType.Unknown; 
	if (value != null && value.ValueType == JsonValueType.String) 
	{ 
		switch (value.GetString()) 
		{ 
			case "AED": 
				return Types.CurrencyType.UnitedArabEmiratesDirham; 
			case "AFN": 
				return Types.CurrencyType.AfghanistanAfghani; 
			case "ALL": 
				return Types.CurrencyType.AlbaniaLek;
// SNIP 
			case "USD": 
				return Types.CurrencyType.UnitedStatesDollar;
// SNIP 
			case "ZWD": 
				return Types.CurrencyType.ZimbabweDollar; 
			case "XXX": 
				return Types.CurrencyType.Unknown; 
			default: 
				return Types.CurrencyType.Unknown; 
		} 
	}
	return result;
}

Now, the only thing remaining is to decorate the CLR class that we’re using to hold our object with enough information to get the serializer to use our type converter as necessary.  In my case, the column for CurrencyType is contained in a class called FamilyGroup.  Here’s that implementation:

public class FamilyGroup
{
	public long Id { get; set; } 
	public string Name { get; set; }

 	[DataMemberJsonConverter(ConverterType = typeof(CurrencyTypeConverter))] 
	public CurrencyType CurrencyType { get; set; }
}

And that’s it.  We have our enum to work with in our code, we’re able to store and retrieve our values to WAMS and the data in the tables is readable to boot.

Happy coding.

More Stories By Adam Hoffman

Adam is an technical evangelist working for Microsoft. By day, you can likely find him somewhere in the Midwest, driving to somewhere, ready to figure out how the cloud can save your family from certain doom, and make you rich and successful in the process. Before he started evangelizing, Adam was a Senior Developer Lead for Microsoft in Redmond, working on Office 365, BPOS, and Office Live. He misses Redmond, and the excitement of the mother ship, but the call of bitter cold and lots of snow in Chicago was too much for him, and he had to return.

Prior that that he developed software and ran teams for Thomson Reuters, Method Engine (which he co-founded), VSA Partners, Navigant Consulting, Andersen Consulting, and a couple of CASE tool companies way back in the day. His favorite possession is a clone of the original Altair computer, running BillG's 8K BASIC, which he's still intending to hook up to the cloud, someday, somehow.

You can read his Windows Azure Blog at http://stratospher.es, and tweeter-er him at http://twitter.com/stratospher_es.

Additionally, if you'd like to keep track of his cloud connected car, you can follow it on Twitter at http://twitter.com/cloudcar1.

@MicroservicesExpo Stories
Operationalizing the network continues to be a driving force behind DevOps and SDN. The ability to solve real problems using programmability to automate and orchestrate infrastructure provisioning and configuration across the application release process remains the hope for many interested in one or the other - and often times both. A recent Avaya sponsored, Dynamic Markets survey (reg required) dove deep into the demesne of SDN and found that many of the problems companies have - and expect ...
We just finished the first O’Reilly Software Architecture Conference and the overwhelming most popular topic was microservices. Why all the hype about an architectural style? Microservices are the first post-DevOps revolution architecture. The DevOps revolution highlighted how much inadvertent friction an outdated operations mindset can cause, starting the move towards automating away manual tasks.
SYS-CON Media announced today that Blue Box as launched a popular blog feed on Cloud Computing Journal. Cloud Computing Journal aims to help open the eyes of Enterprise IT professionals to the economics and strategies that utility/cloud computing provides. Blue Box Cloud gives you unequaled agility, without the burden of designing, deploying and managing your own infrastructure. It’s the right choice when public cloud just won’t do. Blue Box Cloud is a managed Private Cloud as a Service (...
Back in 2009 I posted about the “Great Cloud Shakeout” and the coming market consolidation into a few very large clouds. Nearly 5 1/2 years later and it’s about (long past?) time I took another look to see how I did. Back then I predicted that the market would be dominated by “mega CSPs” by the name of Amazon, Google and Microsoft. Note that this was during a period of Cambrian Explosion in the CSP market – it seems like everybody in the hosting business wanted to be a cloud provider....
SYS-CON Events announced today that Ciqada will exhibit at SYS-CON's @ThingsExpo, which will take place on June 9-11, 2015, at the Javits Center in New York City, NY. Ciqada™ makes it easy to connect your products to the Internet. By integrating key components - hardware, servers, dashboards, and mobile apps - into an easy-to-use, configurable system, your products can quickly and securely join the internet of things. With remote monitoring, control, and alert messaging capability, you will mee...
With the advent of micro-services, the application design paradigm has undergone a major shift. The days of developing monolithic applications are over. We are bringing in the principles (read SOA) hereto the preserve of applications or system integration space into the application development world. Since the micro-services are consumed within the application, the need of ESB is not there. There is no message transformation or mediations required. But service discovery and load balancing of ...
Chef and Canonical announced a partnership to integrate and distribute Chef with Ubuntu. Canonical is integrating the Chef automation platform with Canonical's Machine-As-A-Service (MAAS), enabling users to automate the provisioning, configuration and deployment of bare metal compute resources in the data center. Canonical is packaging Chef 12 server in upcoming distributions of its Ubuntu open source operating system and will provide commercial support for Chef within its user base.
A few weeks ago, SmartBear hosted API Craft Boston with the folks from Akana, Ian Goldsmith and Laura Heritage, to talk about microservices. It was an extremely informative presentation of where microservices came from, what it solves, and considerations around how it might fit into an organizational API strategy. It’s one thing to read everyone else’s opinions on blogs, twitter, etc. It’s great to go to workshops and conferences, but this was so intelligently presented (and for a meetup too)...
While DevOps most critically and famously fosters collaboration, communication, and integration through cultural change, culture is more of an output than an input. In order to actively drive cultural evolution, organizations must make substantial organizational and process changes, and adopt new technologies, to encourage a DevOps culture. Moderated by Andi Mann, panelists will discuss how to balance these three pillars of DevOps, where to focus attention (and resources), where organizations m...
Today, the demand for new applications is growing at an unprecedented rate throughout lines of business and across industries. Customer expectations for mobile and e-commerce capabilities are transforming software development speed and quality into a competitive differentiator for even the most unlikely businesses. For existing software development shops, the proliferation of platforms, increasing need for total global uptime, and accelerating pace of industry disruption by fast-paced startups h...
of cloud, colocation, managed services and disaster recovery solutions, will exhibit at SYS-CON's 16th International Cloud Expo®, which will take place on June 9-11, 2015, at the Javits Center in New York City, NY. TierPoint, LLC, is a leading national provider of information technology and data center services, including cloud, colocation, disaster recovery and managed IT services, with corporate headquarters in St. Louis, MO. TierPoint was formed through the strategic combination of some of t...
How do you securely enable access to your applications in AWS without exposing any attack surfaces? The answer is usually very complicated because application environments morph over time in response to growing requirements from your employee base, your partners and your customers. In his session at 16th Cloud Expo, Haseeb Budhani, CEO and Co-founder of Soha, will share five common approaches that DevOps teams follow to secure access to applications deployed in AWS, Azure, etc., and the frict...
SYS-CON Events announced today that Soha will exhibit at SYS-CON's DevOps Summit New York, which will take place on June 9-11, 2015, at the Javits Center in New York City, NY. Soha delivers enterprise-grade application security, on any device, as agile as the cloud. This turnkey, cloud-based service enables customers to solve secure application access and delivery challenges that traditional or virtualized network solutions cannot solve because they are too expensive, inflexible and operational...
SYS-CON Events announced today that Vicom Computer Services, Inc., a provider of technology and service solutions, will exhibit at SYS-CON's 16th International Cloud Expo®, which will take place on June 9-11, 2015, at the Javits Center in New York City, NY. They are located at booth #427. Vicom Computer Services, Inc. is a progressive leader in the technology industry for over 30 years. Headquartered in the NY Metropolitan area. Vicom provides products and services based on today’s requirements...
What exactly is a cognitive application? In her session at 16th Cloud Expo, Ashley Hathaway, Product Manager at IBM Watson, will look at the services being offered by the IBM Watson Developer Cloud and what that means for developers and Big Data. She'll explore how IBM Watson and its partnerships will continue to grow and help define what it means to be a cognitive service, as well as take a look at the offerings on Bluemix. She will also check out how Watson and the Alchemy API team up to off...
Thought experiment: let’s say your app gets a message from somewhere, perhaps from another app, but you don’t know from where. The message contains the number 47 but no other information. What should your app do with the message? The answer: nothing. There’s no way for your app to make any sense out of a single datum with no context, no additional information or metadata about the datum itself. Now, let’s scale up this thought experiment to a data lake. There are a few common definitions o...
The 17th International Cloud Expo has announced that its Call for Papers is open. 17th International Cloud Expo, to be held November 3-5, 2015, at the Santa Clara Convention Center in Santa Clara, CA, brings together Cloud Computing, APM, APIs, Microservices, Security, Big Data, Internet of Things, DevOps and WebRTC to one location. With cloud computing driving a higher percentage of enterprise IT budgets every year, it becomes increasingly important to plant your flag in this fast-expanding bu...
Change becomes the central principle of today’s enterprises, and thus business agility becomes the most important characteristic our organizations must exhibit. Agile Architecture lays out a best practice approach for achieving this agility – and thus drives and coordinates the other revolutions, as both digital and DevOps are about being able to deal with change better as well.
The concept and subsequent adoption of 'Containerization'' is growing at a rapid speed with the support of almost every other major player in the industry. This concept is much more efficient than the Virtualization which has been a major option for Infrastructure optimization in the past decade. The following factors distinguish a Container from a Virtual Machine. Containers contain Only the Application Specific libraries and binaries. They do not include a guest operating system. Rather ...
There's a real buzz about microservices and containers in the application development and DevOps communities, and of course these are topics we've been talking about a great deal lately here at XebiaLabs too. Microservices and containers offer many attractive features, not least the potential for enhanced flexibility, and a robust architecture based on best-fit services. What we at XebiaLabs are really interested in is how organizations can effectively deliver microservices-based apps to bett...