|
In the previous tutorial on Live Mesh , I took a brief look at the process of creating your first Mesh-enabled Web Application using Silverlight. It was a pretty quick tutorial, but the goal was really to whet your appetite for more in-depth Mesh programming.
So now you've got your Hello World application running and you're continually amazed by how cool it is that you've got a Silverlight application that can run from a Mac, Windows, Windows Mobile, and from the Web - and even runs in a way that makes it look like a full-on desktop application. What next?
Next you're going to need to store data in your Mesh application. You've got a couple options here, each with their own very clear purpose:
One of the most important concepts that a Mesh developer needs to learn is that everything in the Mesh is made up of Data Feeds and Data Entries. You can think of these as RSS feeds and entries within RSS feeds (because they actually ARE news feeds, and can be represented as RSS!). The way Mesh works is it uses a bi-directional news feed synchronization technology called FeedSync to deal with the synchronization of data across multiple devices and applications within your Mesh. In terms of data modeling you can think of a Feed as a collection or a container and an entry as a single piece of data.
Important note: You can attach your own serializable user data object instance to any entry. This allows you to extend the stock news feed model with your own domain-specific data. You can use this feature to extend the resource model to your application, allowing you to store all of your application data in the mesh. Also worth remembering is that the user data attached to entries does NOT have to be the same. Every entry can have its own entirely different user data schema - entries within the same feed need NOT have the same user data type. This can be very powerful, but can also be easily abused.
Before you can manipulate feeds and entries, you need a reference to the Mesh application service, which you can obtain with an extension method provided for Silverlight:
MeshApplicationService mesh = Application.Current.GetMeshApplicationService();
Now that you've got your mesh, you can create a new feed as follows:
DataFeed newFeed = new DataFeed("Cars");
newFeed.Resource.Type = "CarsFeed";
mesh.Feeds.Add(newFeed);
You have the ability to set an arbitrary string as the resource type on the feed. This gives you a way of querying for particular feeds that you want and embedding logic into your application that can give you some heuristics on how to deal with feeds.
And add an entry to that new feed:
DataEntry newEntry = new DataEntry("Aston Martin DBV");
newEntry.Resource.Type = "Car";
newFeed.Entries.Add(ref newEntry);
And finally, if you want to set custom resource information:
CarInfo carInfo = new CarInfo()
{
TotalMiles = 42660,
SalePrice = 93100,
Owner = "Kevin",
};
newEntry.Resource.SetUserData<CarInfo>(carInfo);
newEntry.Update();
I'll be posting more in-depth samples of dealing with data in Live Mesh applications, but this should give you a little bit of an idea of how you can pass around data among instances of your application within a secure, private Mesh without having to worry about the details of how that data gets transmitted - you just worry about what your data looks like and how you want to store that as feeds and entries, and the rest is taken care of for you.
Your posts on Live Mesh are the most lucid explanations I've seen. Please
continue!
Which is the best to use? (Isolated Storage, Central Storage via
Azure,Synchronized Storage,Sync / Global Hybrid)