Live Framework CTP #4 – .NET: LOE and data basics

Instead of creating new Silverlight applications, which run in your mesh and use the data, you can furthermore mesh-enable your existing .NET applications or create new mesh-enabled .NET applications from scratch. That’s pretty easy and in the following post I will show you some basics…

The Live Operating Environment (LOE)

First there is the Live Operating Environment, being the center point of all your operations to the mesh. With an object of type LiveOperatingEnvironment you can connect to your online mesh or to your local mesh storage sync or async and perform any operation you want. But that’s just the developer’s point of view. In fact, the LOE (every instance of it) is an agent component, responsible for providing an efficient cache and for background synchronization of data on your device to other devices (other instances of the LOE on those devices) in your mesh, including the „special“ LOE in the cloud. Running an LOE means exposing data through a RESTful interface at port 2048 of your machine – one could check the presence of this and either connect locally or to the cloud.

Connecting to your online/cloud LOE means that you have to provide your credentials on connect, whereas you can connect locally without those. I like to work on my local storage, it’s fast and safe. But there are some limitations (at the moment?) there. Due to the lack of file synchronization, files as data entries are not available from the local storage, so you have to connect to your online LOE instead. Furthermore you only get your local device in the Devices collection of your LOE and it’s not possible to have a look at your contacts and profiles for instance. What I expected first or want to have for the „final“ version of the Live Framework: just one connection method, which takes local data if it’s available and instead connects to the cloud LOE. It should be no problem, because the various LOEs (loal, cloud) are taking responsibility over synchronization… or have I forgotten to consider something?

Well, let’s take a look to connecting to your (online) LOE. Just create an instance of LiveOperatingEnvironment and connect via the Connect() method (local LOE: use ConnectLocally() instead). You have to pass your credentials as a parameter, which could come from a secure source or from user input:

var creds = new NetworkCredential("username", "password", "https://user-ctp.windows.net");
var loe = new LiveOperatingEnvironment();

loe.Connect(creds);

https://user-ctp.windows.net is the fixed base URI when connecting to your cloud LOE. After you’ve been connected, you get access to your mesh items (shown before) and can start meshing 🙂

Mesh Objects, Data Feeds and Data Entries

A mesh object is a container for concrete data in your mesh. There are several types of mesh objects and you are allowed to create your own application specific types, which your applications can work with. Mesh objects can be files, folders, applications, custom objects etc.. You have access to the mesh objects via loe.Mesh.MeshObjects.Entries and have the possibililty to easily iterate over them in this way.

Every mesh object consists of DataFeeds, Members, Mappings and News, as stated before. Interesting at this point are the data feeds. Those are further containers for the real data entries. Why this abstraction? Over data feeds you can group your data together, separating logically distinct data. Every DataFeed object finally contains a DataEntries collection, which gives you access to the underlying data and information about that. Note: there is no obvious possibility to store hierarchical data entries at the moment. There is one level of data entries and a data entry can’t contain other data entries. So that’s a drawback at this point and I don’t like/understand it much. The solution for that is: every data entry contains a parent ID and over that you can identify top level data entries and those, who are child entries of another data entry. But that’s not a good solution, isn’t it? Hopefully there will be done some work on that…

Well, a nice little .NET console application would be to show us the titles of all mesh objects, of their data feeds and data entries in there. That’s no problem and leads to the following little program:

var creds = new NetworkCredential("username", "password", "https://user-ctp.windows.net");
var loe = new LiveOperatingEnvironment();
loe.Connect(creds);
if (loe.IsRunning())
{
    foreach (var meshobj in loe.Mesh.MeshObjects.Entries)
    {
        Console.WriteLine("- " + meshobj.Resource.Title);
        foreach (var feed in meshobj.DataFeeds.Entries)
        {
            Console.WriteLine("  + " + feed.Resource.Title);
            foreach (var entry in feed.DataEntries.Entries)
                Console.WriteLine("    * " + entry.Resource.Title);
        }
    }
}
Console.ReadLine();

Create, Update, Delete

The creation, update and delete of all the three entities MeshObject, DataFeed and DataEntry is made really easy. Just call the Add() and Remove() methods of the particular collections. The rest is done automatically by the Live Framework. The update process isn’t problematic, too. Just change your entity and then make sure to call the Update() method of this entity. Because everything in your Live Operating Environment has LiveItem as base type, you have an integrated and consistent CRUD process.

Little example

The following screenshot shows a little WinForms application, that connects to my mesh and over which I can perform the CRUD process on my mesh entities. Further on I can navigate through my mesh and if I got images as data entries, those are downloaded automatically as media resource stream and then shown up at the picture box on the right. In the screen below is shown the (IKEA-powered 😉 ) couch corner of my little apartment…

Live Framework .NET WinForms example application

In upcoming blog posts I want to show you more information about handling data entries, media resources and hierarchical data. So stay tuned 🙂

kick it on DotNetKicks.com