Creating Silverlight MEWA

I started playing with live framework bits and learning a little bit. I created a silverlight MEWA.
The creation of silverlight MEWA is no different for the most part. So I wanted to work with Feeds, entries and resources
I have some samples that I have done previously. What I wanted to do is to store the XAP file, Title of the sample and some description in the entries and load the XAP file of the selected sample directly by reading the resource

SO I created a Silverlight MEWA in VisualStudio. with some basic UI with listBox to hold the list of samples and Contentcontrol to display the selected sample

For storing the data I created a feed like this after getting loading the MeshObjects

LiveOperatingEnvironment loe;
loe = new LiveOperatingEnvironment();
NetworkCredential creds = new NetworkCredential(“hotmail id”,”password”);
DataFeed samples = new DataFeed(“Samples”);
loe.Mesh.MeshObjects.Entries.Where(q => q.Resource.Title == “Sample SL MEWA”).Single().DataFeeds.Add(ref samples);

Once I created a feed, I had to add some entries(1 for each sample)

//feed is the variable whch holds a reference to the feed I added

DataEntry entry = feed.DataEntries.Add(File.OpenRead(XAP filename), “ExtendedAutoCompleteBox”);
entry.Resource.SetUserData<XapData>(new XapData { Description = “This sample shows an extended Auto completebox to select multiple items”, MainDll =”Name of the dll”, StartPage = “Page”, Title = “ExtAutoCompleteBox” });
feed.DataEntries.Add(ref entry);

XAPData is another class I added which holds the different properties I want to access for the sample

public class XapData
        public string StartPage { get; set; }   
        public string MainDll { get; set; }   
        public string Title { get; set; }   
        public string Description { get; set; }

That’s all for setting up the data to be used in the application

Now back in the Silverlight MEWA, After the MeshApp is loaded we will have access to the feeds and entries. So in the MeshAppLoaded eventhandler. I added a SelectionChanged event handler for the ListBox  and set the ItemsSource of the listbox to be the list of entries

listSamples.SelectionChanged += new SelectionChangedEventHandler(listSamples_SelectionChanged);           
DataFeed feed = meshApp.DataFeeds.Entries.First();
listSamples.ItemsSource = feed.DataEntries.Entries.ToList();

In the SelectionChanged eventhandler, we get the selected DataEntry, get the corresponding data we stored for the sample and Load the XAP file from the MediaResource

 void listSamples_SelectionChanged(object sender, SelectionChangedEventArgs e)
            if (e.AddedItems != null && e.AddedItems.Count > 0)
                entry = e.AddedItems[0] as DataEntry;
                selectedItemData = entry.Resource.GetUserData<XapData>();
                entry.ReadMediaResourceCompleted += new EventHandler<MediaResourceAsyncEventArgs>(entry_ReadMediaResourceCompleted);

Once the Resource(XAP file in this sample) is loaded, we load all the dlls in the XAP file and create an instance of the startpage for the sample

 void entry_ReadMediaResourceCompleted(object sender, MediaResourceAsyncEventArgs e)
            stream.Seek(0, SeekOrigin.Begin);
            string appManifest = new StreamReader(Application.GetResourceStream(new StreamResourceInfo(stream, null), new Uri(“AppManifest.xaml”, UriKind.Relative)).Stream).ReadToEnd();
            Assembly asm = null;
            XElement deploymentRoot = XDocument.Parse(appManifest).Root;
            List<XElement> deploymentParts = (from assemblyParts in deploymentRoot.Elements().Elements()
                                              select assemblyParts).ToList();
            Assembly MyAssembly = null;
            foreach (XElement xElement in deploymentParts)
                string source = xElement.Attribute(“Source”).Value;
                AssemblyPart asmPart = new AssemblyPart();

                StreamResourceInfo streamInfo = Application.GetResourceStream(new StreamResourceInfo(e.Result, “application/binary”), new Uri(source, UriKind.Relative));
                if (source.EndsWith(“dll”)))
                    asm = asmPart.Load(streamInfo.Stream);

                    if (source == selectedItemData.MainDll)
                        MyAssembly = asm;

            UIElement ele = MyAssembly.CreateInstance(selectedItemData.StartPage) as UIElement;
            SampleContent.Content = ele;


As the Data is stored in the sample itself, I need to share the instance of this sample. if any one is interested in sharing their sample or want to see this sample, I can send an invite if you leave a comment.


5 thoughts on “Creating Silverlight MEWA

  1. Regarding this line:

    DataEntry entry = feed.DataEntries.Add(File.OpenRead(XAP filename), “ExtendedAutoCompleteBox”);

    In my MEWA, I’m simply trying to add a picture and then once I accomplish that I’d like to retrieve/view it. However, when I try to add a picture I get a MethodAccessException. Any ideas why this is so? The code seems fairly simple and straightforward.

    Dim newFeed As DataFeed = New DataFeed(“SamplePics”)
    newFeed.Resource.Type = “PicFeed”

    Dim fileName As String = “C:\Users\Public\Pictures\Sample Pictures\Autumn Leaves.jpg”
    Dim fs As New FileStream(fileName, FileMode.Open)
    Dim newEntry As DataEntry = newFeed.DataEntries.Add(File.OpenRead(fileName), “TestFileName”)

    ‘ ———————-

    MethodAccessException …
    Attempt to access the method failed: System.IO.FileStream

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s