Click here to close now.

Welcome!

Apache Authors: Nikita Ivanov, Carmen Gonzalez, Sematext Blog, Pat Romanski, Ruxit Blog

Related Topics: Cloud Expo, Wireless, SOA & WOA, .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.

@ThingsExpo Stories
Roberto Medrano, Executive Vice President at SOA Software, had reached 30,000 page views on his home page - http://RobertoMedrano.SYS-CON.com/ - on the SYS-CON family of online magazines, which includes Cloud Computing Journal, Internet of Things Journal, Big Data Journal, and SOA World Magazine. He is a recognized executive in the information technology fields of SOA, internet security, governance, and compliance. He has extensive experience with both start-ups and large companies, having been involved at the beginning of four IT industries: EDA, Open Systems, Computer Security and now SOA.
SYS-CON Events announced today that GENBAND, a leading developer of real time communications software solutions, has been named “Silver Sponsor” of SYS-CON's WebRTC Summit, which will take place on June 9-11, 2015, at the Javits Center in New York City, NY. The GENBAND team will be on hand to demonstrate their newest product, Kandy. Kandy is a communications Platform-as-a-Service (PaaS) that enables companies to seamlessly integrate more human communications into their Web and mobile applications - creating more engaging experiences for their customers and boosting collaboration and productiv...
When it comes to the Internet of Things, hooking up will get you only so far. If you want customers to commit, you need to go beyond simply connecting products. You need to use the devices themselves to transform how you engage with every customer and how you manage the entire product lifecycle. In his session at @ThingsExpo, Sean Lorenz, Technical Product Manager for Xively at LogMeIn, will show how “product relationship management” can help you leverage your connected devices and the data they generate about customer usage and product performance to deliver extremely compelling and reliabl...
From telemedicine to smart cars, digital homes and industrial monitoring, the explosive growth of IoT has created exciting new business opportunities for real time calls and messaging. In his session at @ThingsExpo, Ivelin Ivanov, CEO and Co-Founder of Telestax, shared some of the new revenue sources that IoT created for Restcomm – the open source telephony platform from Telestax. Ivelin Ivanov is a technology entrepreneur who founded Mobicents, an Open Source VoIP Platform, to help create, deploy, and manage applications integrating voice, video and data. He is the co-founder of TeleStax, a...
The industrial software market has treated data with the mentality of “collect everything now, worry about how to use it later.” We now find ourselves buried in data, with the pervasive connectivity of the (Industrial) Internet of Things only piling on more numbers. There’s too much data and not enough information. In his session at @ThingsExpo, Bob Gates, Global Marketing Director, GE’s Intelligent Platforms business, to discuss how realizing the power of IoT, software developers are now focused on understanding how industrial data can create intelligence for industrial operations. Imagine ...
The 3rd International @ThingsExpo, co-located with the 16th International Cloud Expo - to be held June 9-11, 2015, at the Javits Center in New York City, NY - is now accepting submissions to demo smart cars on the Expo Floor. Smart car sponsorship benefits include general brand exposure and increasing engagement with the developer ecosystem.
Operational Hadoop and the Lambda Architecture for Streaming Data Apache Hadoop is emerging as a distributed platform for handling large and fast incoming streams of data. Predictive maintenance, supply chain optimization, and Internet-of-Things analysis are examples where Hadoop provides the scalable storage, processing, and analytics platform to gain meaningful insights from granular data that is typically only valuable from a large-scale, aggregate view. One architecture useful for capturing and analyzing streaming data is the Lambda Architecture, representing a model of how to analyze rea...
SYS-CON Events announced today that Vitria Technology, Inc. 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. Vitria will showcase the company’s new IoT Analytics Platform through live demonstrations at booth #330. Vitria’s IoT Analytics Platform, fully integrated and powered by an operational intelligence engine, enables customers to rapidly build and operationalize advanced analytics to deliver timely business outcomes for use cases across the industrial, enterprise, and consumer segments.
The explosion of connected devices / sensors is creating an ever-expanding set of new and valuable data. In parallel the emerging capability of Big Data technologies to store, access, analyze, and react to this data is producing changes in business models under the umbrella of the Internet of Things (IoT). In particular within the Insurance industry, IoT appears positioned to enable deep changes by altering relationships between insurers, distributors, and the insured. In his session at @ThingsExpo, Michael Sick, a Senior Manager and Big Data Architect within Ernst and Young's Financial Servi...
SYS-CON Events announced today that Open Data Centers (ODC), a carrier-neutral colocation provider, will exhibit at SYS-CON's 16th International Cloud Expo®, which will take place June 9-11, 2015, at the Javits Center in New York City, NY. Open Data Centers is a carrier-neutral data center operator in New Jersey and New York City offering alternative connectivity options for carriers, service providers and enterprise customers.
When it comes to the Internet of Things, hooking up will get you only so far. If you want customers to commit, you need to go beyond simply connecting products. You need to use the devices themselves to transform how you engage with every customer and how you manage the entire product lifecycle. In his session at @ThingsExpo, Sean Lorenz, Technical Product Manager for Xively at LogMeIn, will show how “product relationship management” can help you leverage your connected devices and the data they generate about customer usage and product performance to deliver extremely compelling and reliabl...
SYS-CON Events announced today that SoftLayer, an IBM company, has been named “Gold Sponsor” of SYS-CON's 16th International Cloud Expo®, which will take place June 9-11, 2015 at the Javits Center in New York City, NY, and the 17th International Cloud Expo®, which will take place November 3–5, 2015 at the Santa Clara Convention Center in Santa Clara, CA. SoftLayer operates a global cloud infrastructure platform built for Internet scale. With a global footprint of data centers and network points of presence, SoftLayer provides infrastructure as a service to leading-edge customers ranging from ...
SYS-CON Events announced today that CodeFutures, a leading supplier of database performance tools, has been named a “Sponsor” of SYS-CON's 16th International Cloud Expo®, which will take place on June 9–11, 2015, at the Javits Center in New York, NY. CodeFutures is an independent software vendor focused on providing tools that deliver database performance tools that increase productivity during database development and increase database performance and scalability during production.
The IoT market is projected to be $1.9 trillion tidal wave that’s bigger than the combined market for smartphones, tablets and PCs. While IoT is widely discussed, what not being talked about are the monetization opportunities that are created from ubiquitous connectivity and the ensuing avalanche of data. While we cannot foresee every service that the IoT will enable, we should future-proof operations by preparing to monetize them with extremely agile systems.
There’s Big Data, then there’s really Big Data from the Internet of Things. IoT is evolving to include many data possibilities like new types of event, log and network data. The volumes are enormous, generating tens of billions of logs per day, which raise data challenges. Early IoT deployments are relying heavily on both the cloud and managed service providers to navigate these challenges. Learn about IoT, Big Data and deployments processing massive data volumes from wearables, utilities and other machines.
The explosion of connected devices / sensors is creating an ever-expanding set of new and valuable data. In parallel the emerging capability of Big Data technologies to store, access, analyze, and react to this data is producing changes in business models under the umbrella of the Internet of Things (IoT). In particular within the Insurance industry, IoT appears positioned to enable deep changes by altering relationships between insurers, distributors, and the insured. In his session at @ThingsExpo, Michael Sick, a Senior Manager and Big Data Architect within Ernst and Young's Financial Servi...
“In the past year we've seen a lot of stabilization of WebRTC. You can now use it in production with a far greater degree of certainty. A lot of the real developments in the past year have been in things like the data channel, which will enable a whole new type of application," explained Peter Dunkley, Technical Director at Acision, in this SYS-CON.tv interview at @ThingsExpo, held Nov 4–6, 2014, at the Santa Clara Convention Center in Santa Clara, CA.
SYS-CON Events announced today that Intelligent Systems Services 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. Established in 1994, Intelligent Systems Services Inc. is located near Washington, DC, with representatives and partners nationwide. ISS’s well-established track record is based on the continuous pursuit of excellence in designing, implementing and supporting nationwide clients’ mission-critical systems. ISS has completed many successful projects in Healthcare, Commercial, Manufacturing, ...
PubNub on Monday has announced that it is partnering with IBM to bring its sophisticated real-time data streaming and messaging capabilities to Bluemix, IBM’s cloud development platform. “Today’s app and connected devices require an always-on connection, but building a secure, scalable solution from the ground up is time consuming, resource intensive, and error-prone,” said Todd Greene, CEO of PubNub. “PubNub enables web, mobile and IoT developers building apps on IBM Bluemix to quickly add scalable realtime functionality with minimal effort and cost.”
The major cloud platforms defy a simple, side-by-side analysis. Each of the major IaaS public-cloud platforms offers their own unique strengths and functionality. Options for on-site private cloud are diverse as well, and must be designed and deployed while taking existing legacy architecture and infrastructure into account. Then the reality is that most enterprises are embarking on a hybrid cloud strategy and programs. In this Power Panel at 15th Cloud Expo (http://www.CloudComputingExpo.com), moderated by Ashar Baig, Research Director, Cloud, at Gigaom Research, Nate Gordon, Director of T...