Live Framework and custom resource types

I’ll start this post with a couple caveats. I’m learning the Live Framework SDK, just everyone else. This (and upcoming) blog posts on the Live Framework are based on my initial learning on Live Framework. All the usual disclaimers apply.

My plan is to work through some of the Live Framework SDK samples. As I’m doing that, my normal work pattern is to take lots of notes on what I’m learning. My blog seems as good a place as any. Unlike posts on technologies where I’ve spent lots of time, I’m a noob on the Live Framework too. But, there’s only one way to learn.

The Project Manager Sample

I decided to start with the WPF Project Manager sample. It’s a WPF application that lets you create projects. You can add milestones to those projects. Obviously, you can edit both projects and milestones. The projects are stored as MeshObjects. The milestones are stored as DataEntries in the MeshObjects (representing projects).

This first post is mostly looking at the application, with a small look at the code.

I ran the code, created a project and some milestones.  Cool enough.

Then, I went to the developer mesh website, and looked at my mesh desktop. I expected to see new folders, or something that showed the projects and milestones I created. I was surprised that nothing was there.

The answer was in the code. Remember from my first post on the Live Framework that the MyPhotos application used resource types of LiveMeshFolder, and LiveMeshFiles. That makes objects that are visible in the mesh, obviously as folders and files.

This sample uses different resources types. The sample defines a “Project” resource type for the project, and a “Milestone” type for the milestones.

Both Project and Milestone are C# classes. They are (more or less) POCO objects. They are decorated with the DataContract attribute (and their properties are decorated with the DataMember attribute).

Here’s the Project type:

   1: [DataContract(Namespace = "Microsoft.Samples.Workflow.ProjectManagerWPF")]
   2: public class Project
   3: {
   4:     /// <summary>
   5:     /// UUID of the parent MeshObject
   6:     /// </summary>
   7:     [DataMember]
   8:     public string MOID { get; set; }
   9:     /// <summary>
  10:     /// Title of the milestone (during save/update, this matches MeshObject.Resource.Title, 
  11:     /// but is stored here when the custom object is databound instead of the resource)
  12:     /// </summary>
  13:     [DataMember]
  14:     public string Title { get; set; }
  15:     /// <summary>
  16:     /// Date when project will be started
  17:     /// </summary>
  18:     [DataMember]
  19:     public DateTime KickOffDate {get; set;}
  20:     /// <summary>
  21:     /// Estimated Date for Completion
  22:     /// </summary>
  23:     [DataMember]
  24:     public DateTime CompletionDate {get; set;}
  25:     /// <summary>
  26:     /// Date when project was shipped
  27:     /// </summary>
  28:     [DataMember]
  29:     public DateTime ShippedDate {get; set;}
  30:     /// <summary>
  31:     /// Description of Project
  32:     /// </summary>
  33:     [DataMember]
  34:     public string Description {get; set;}
  35: }

Storing and retrieving the Project type from the Mesh is straightforward Live Framework code. Here’s the code to read a project:

 

   1: //grab the Project Instance object from the mesh object and populate an instance of our Project Domain Class
   2: Library.Project SaveProject = this.ExistingProjectMeshObject.Resource.GetUserData<Library.Project>();

You simply convert the Resource to the POCO type, using the GetUserData<T> method to convert the resource. Cool. Saving it back is just as easy:

   1: MO = ExistingProjectMeshObject;
   2: SaveProject = ExistingProjectMeshObject.Resource.GetUserData<Library.Project>();
   3: MO.Resource.Title = tbTitle.Text;
   4:  
   5: //Set the custom attributes of the mesh object to the values from the library/domain class, 
   6: //this will popualte the userfield data with the deserialized content from the Project object created above
   7: MO.Resource.SetUserData<Library.Project>(SaveProject);
   8:  
   9: //Set the type of the mesh object's resource to PRoject
  10: MO.Resource.Type = "Project";
  11:  
  12: //Update the object in the cloud.
  13: MO.Update();

The SetUserData<T> call converts the POCO Project object to a mesh resource. Then, you just need to send the data to the cloud.

Future posts will dive into the code in more detail, and start on some other mesh style programming. Just this little dive makes me think more about what I can build with this.

Published 09 April 2009 10:13 PM by wwagner
Ads by Lake Quincy Media

Comments

# Justin Etheredge said on 10 April, 2009 02:36 PM

I keep meaning to look into the Live Framework APIs. I look forward to your future posts on this.

# DotNetShoutout said on 10 April, 2009 06:06 PM

Thank you for submitting this cool story - Trackback from DotNetShoutout

# vikasahuja said on 12 April, 2009 09:28 PM

Thanks Bill for blogging about Live Framework and experimenting with this. as a tradition with Live Framework community - i have indexed your blog post for larger community at following:

delicious.com/.../LivefxBlogPost

social.msdn.microsoft.com/.../828d9a48-239a-4af8-8239-35931e514d37

also - you can find more detailed information about different user data elements available within Live Framework at:

nmackenzie.spaces.live.com/.../cns!B863FF075995D18A!163.entry?wa=wsignin1.0&sa=109468764

# Buy soma online. said on 05 March, 2010 11:35 PM

Buy soma. Buy soma online. Buy soma online without rx.

Search

Go

Blog Group Links

Nascar style badges