Archive for December, 2007

LiveNet 0.2 Released: Silverlight Streaming Added

Luke and I have released Version 0.2 of LiveNet. This release comes with the addition of Silverlight Streaming From Windows Live and allows you to add, delete and get your Silverlight applications that you’re hosting with Windows Live.

As part of the release, I have included a sample application that shows just how easy it is to us SLS with LiveNet, here is a sample of that code:

        LiveMedia m_livemedia;
        MediaFileSet[] sets;
        MediaFile[] files;

        private void button1_Click(object sender, EventArgs e)
        {
            listBox1.Items.Clear();
            if (string.IsNullOrEmpty(textBox1.Text) ||
                string.IsNullOrEmpty(textBox2.Text))
            {
                MessageBox.Show("Either you have entered no Account ID or Passkey", 
                    "Doh", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            m_livemedia = new LiveMedia(textBox1.Text, textBox2.Text);
            sets = m_livemedia.ListFileSets();
            foreach (MediaFileSet set in sets)
            {
                listBox1.Items.Add(set.Name);
            }
        }

        private void listBox1_SelectedIndexChanged(object sender, EventArgs e)
        {
            listBox2.Items.Clear();
            int i = listBox1.SelectedIndex;
            MediaFileSet set = sets[i];
            files = set.Files;
            foreach (MediaFile file in files)
            {
                listBox2.Items.Add(file.FileName);
            }
        }

And when run in the sample app, you will end up with the following:

Which you can preview the selected application. This has been done using a client app, but can just as easily be integration into an ASP.Net project.

SL

2 Comments

Announcement: LiveNet Wrapper for Windows Live Developing

My friend Luke Smith and I for the last month have been working on a new .Net wrapper for Windows Live, which we have called LiveNet. You might be thinking "what’s the difference between that and Windows Live Tools", and the answer is simple, a fair bit. Windows Live Tools has what you need for Windows Live ID web authentication, Silverlight Streaming and Contacts control, which we don’t do anything with. Now at this point, I would just like to say that the Contacts control is the embedded object, whereas what LiveNet will [eventually] have is from Windows Live Data.

We have made this a .Net 2.0 wrapper, so it can be used with any web application that is 2.0 or above and at the moment we have only implemented the Live Photos API into the wrapper. So what does this mean? It means that we have built a set of classes that will allow you to interact with the Live Photos API without having to worry about any of the back end goings on. I shall go into more detail with some examples in just a moment.

LiveNet is an opensource project that we have hosted on CodePlex, so feel free to check out the source code if you want to see what we’re doing under the hood.

Version 0.1 is now ready for you:
Home Page: http://www.codeplex.com/LiveNet
Download: LiveNet 0.1 Alpha (including documentation)

Now for an example. At the download page above, there is a download for the sample website that I have built to just quickly show what you can do with LiveNet, but for this example, I thought I would just show how you can change the sample site on MSDN to use LiveNet. First off, you need to add a reference to the LiveNet dll, then we need to add a few lines into our web.config file:

  <configSections>
    <section name="liveNet" type="LiveNet.Configuration.ConfigurationSectionHandler, LiveNet"/>
  </configSections>
  <liveNet applicationName="LiveNetSample" authenticationObtainerType="LiveNetSampleWebsite.LoadAuthentication, __code">
    <spacesAuthorization permissionString="ReadOnly" permissionReturnUrl="~/bob.aspx" privacyUrl="~/privacy.aspx" useHttps="false"/>
  </liveNet>
  <httpHandlers>
    <add verb="*" path="photo.lnet" type="LiveNet.Web.LivePhotoHandler, LiveNet" />
  </httpHandlers>

Default.aspx
<%@ Page Language="C#" AutoEventWireup="true"  CodeFile="Default.aspx.cs" Inherits="_Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
   <title>LiveNet Sample Site</title>
</head>
<body>
   <form id="form1" runat="server">
   <div>
   
       <asp:Label ID="lblUserName" runat="server" Text="Signed in as: "></asp:Label>
       <br />
       <br />
       <asp:Button ID="btnGetAlbums" runat="server" onclick="btnGetAlbums_Click" 
           Text="Get Albums" />
       <br />
       <br />
       <asp:ListBox ID="lbAlbums" runat="server" Height="208px" 
           onselectedindexchanged="lbAlbums_SelectedIndexChanged" AutoPostBack="true" Width="260px">
       </asp:ListBox>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
       <asp:ListBox ID="lbPhotos" runat="server" Height="207px" Width="248px" 
           onselectedindexchanged="lbPhotos_SelectedIndexChanged" AutoPostBack="true">
       </asp:ListBox>
   
       <br />
       <br />
       <asp:Label ID="lblPhoto" runat="server" Text="Photo:" Visible="False"></asp:Label>
       <br />
       <asp:Label ID="lblPhotoLink" runat="server" Text="" Visible="False"></asp:Label>
       <br />
       <asp:Image ID="imgPhoto" runat="server" Visible="False" />
       <br />
       <br />
       Simple, huh</div>
   </form>
</body>
</html>

Default.aspx.cs

using System;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using LiveNet.Photos;
using LiveNet.Authentication;

public partial class _Default : System.Web.UI.Page
{
    LivePhotos m_photos;
    protected void Page_Load(object sender, EventArgs e)
    {
        string DAT = "[Insert DAT here]";
        string userId = "example@live.com";
        lblUserName.Text = string.Format("Signed in as: {0}", userId);
        m_photos = new LivePhotos(userId, DAT, AuthenticationToken.DomainAuthenticationToken);
    }

    protected void btnGetAlbums_Click(object sender, EventArgs e)
    {
        Album[] albums = m_photos.ListAlbums();
        foreach (Album album in albums)
        {
            ListItem item = new ListItem(album.Name, album.AlbumUrl.ToString());
            lbAlbums.Items.Add(item);
        }
    }
    protected void lbAlbums_SelectedIndexChanged(object sender, EventArgs e)
    {
        Photo[] photos = m_photos.ListPhotos(new Uri(lbAlbums.SelectedItem.Value));
        foreach (Photo photo in photos)
        {
            ListItem item = new ListItem(photo.Name, photo.PhotoUrl.ToString());
            lbPhotos.Items.Add(item);
        }
    }
    protected void lbPhotos_SelectedIndexChanged(object sender, EventArgs e)
    {
        Photo photo = m_photos.GetPhoto(new Uri(lbPhotos.SelectedItem.Value));
        lblPhoto.Visible = true;
        lblPhotoLink.Text = photo.PhotoUrl.ToString();
        lblPhotoLink.Visible = true;
        imgPhoto.ImageUrl = string.Format("./photo.lnet?url={0}&oh={1}", photo.PhotoPath, photo.Owner.UserId);
        imgPhoto.Visible = true;
    }
}

As you can see, Default.aspx.cs is a lot smaller in size and much easier to look at and work with. There another file we need to add to the project so that it will work, for this, right click on your project and add new ASP.Net folder > App_Code:

LoadAuthentication.cs

using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;

namespace LiveNetSampleWebsite
{
    /// <summary>
    /// Summary description for LoadAuthentication
    /// </summary>
    public class LoadAuthentication : LiveNet.Authentication.IHttpAuthenticationObtainer
    {
        #region IHttpAuthenticationObtainer Members

        public void Get(HttpContext context, out string userId, out string token)
        {
            // This section is where you would have your code
            // to retrieve the userID and the token, whether it
            // be from a cookie, URL string or database.
            userId = HttpUtility.UrlDecode(context.Request.QueryString["oh"]);
            token = "[Insert DAT here]";
        }

        #endregion
    }
}

And there you have it. That will give you the same as what you get on the MSDN Sample Application. Please remember to change all instances of "[Insert DAT here]" with your actual DAT (which can be got from https://dev.live.com/livedata/sdk/) and "example@live.com" with your Windows Live ID.

As mentioned, at the moment, this only has Live Photos in it, but we plan on adding more Live APIs to the project very soon, so keep an eye on it. Any feedback is always appreciated and should be directed to the discussion section of the project site on CodePlex.

SL

1 Comment