Simplicity is the ultimate sophistication - Leonardo Da Vinci. RSS 2.0 Atom 1.0
# Thursday, June 12, 2008

The Zune launches in Canada this Friday, June 13. You can find them at Future Shop, Best Buy and other electronics retailers. To commemorate the event, here are links to free Zune XNA Games and Wallpaper. Enjoy!

XNA Games
http://zunerama.com/forum/index.php?topic=9811.0
http://forums.zune.net/233403/ShowPost.aspx

Canadian Zune Wallpaper
http://zunenews.ca/community.aspx

Posted at 2008-06-12 05:19 AM by jldavid 
 Permalink |  Comments [0] | Categories: Zune

Comments RSS | Email this | Technorati Links | Digg This! | Save to del.icio.us | Kick It!
# Thursday, June 05, 2008

In the Part 1, I talked about some of the applications you can build for the Zune today, and specifically, my plans to create a wrapper for the Zune user card Web service using LINQ to XML. Note that this is a quick and dirty class I baked in a couple of hours. If you are looking for a more robust implementation, be sure to check out Mehfuz's WebLog - specifically his posting on integrating REST with LINQ to XML, and his custom LINQ.Flickr provider. Let's take a look at the namespaces:

using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml.Linq;

You'll notice that System.Linq (to access the core LINQ functionality) and System.Xml.Linq (to access LINQ to XML) are included as namespaces. Then a class called ZuneCard is defined and a bunch of public auto-implemented properties are defined (a feature of C# 3.5 - each property corresponds to a node in the Zune Card XML tree):

namespace ZuneCardApi
{
    public class ZuneCard
    {
        // Exposed Properties
        public string id { get; set; }
        public string label { get; set; }
        public string firstName { get; set; }
        public string status { get; set; }
        public string tileBig { get; set; }
        public string tileSmall { get; set; }
        public string name { get; set; }
        public string location { get; set; }
        public string bio { get; set; }
        public string backgroundLarge { get; set; }
        public string backgroundSmall { get; set; }
        public string totalPlays { get; set; }

Then ZuneCard is implemented and the tag parameter is passed (corresponding to the user's Zune tag). The XDocument object is used to load in the XML data for the user card. Note that this operation happens only once, then the data can be manipulated and queried to your heart's content in memory (which has performance benefits).

public ZuneCard(string tag)
 {
     XDocument zCardXml = XDocument.
      Load(@"http://zcards.zune.net/zcard/usercardservice.ashx?zunetag=" + tag);

Next, we need to call our LINQ queries. Essentially, we are transversing the nodes of our XML tree (found here) starting at the user node. Anonymous Types (another C# 3.5 feature) are used liberally here (as you can see below):

var user = from u in zCardXml.Descendants("user")
                  select new
                   { 
                      _id = u.Element("id").Value,
                      _label = u.Element("label").Value,
                      _firstName = u.Element("firstName").Value,
                      _status = u.Element("status").Value,
                      _tileBig = u.Element("image").Value,
                      _tileSmall = u.Element("image").Value
                  };

               var userData = from uD in zCardXml.Descendants("userData")
                  select new
                  {
                      _name = uD.Element("name").Value,
                      _location = uD.Element("location").Value,
                      _bio = uD.Element("bio").Value,
                      _backgroundLarge = uD.Element("image").Value,
                      _backgroundSmall = uD.Element("image").Value,
                      _totalPlays = uD.Element("totalPlays").Value
                  };

Finally, we need to iterate through the collections and load the values into the public properties (as shown below):

        foreach (var u in user)
         {
             id = u._id;
             label = u._label;
             firstName = u._firstName;
             status = u._status;
             tileBig = u._tileBig;
             tileSmall = u._tileSmall;
             }

         foreach (var uD in userData)
         {
            name = uD._name;
            location = uD._location;
            bio = uD._bio;
            backgroundLarge = uD._backgroundLarge;
            backgroundSmall = uD._backgroundSmall;
            totalPlays = uD._totalPlays;
           }
        }
    }
 }

In the next part in the series, we'll take a look at how to handle collections corresponding to playlists, badges and other user preferences. In the meantime, if you have any suggestions on how to improve this code, feel free to post a comment.

Posted at 2008-06-05 03:14 AM by jldavid 
 Permalink |  Comments [0] | Categories: Development | Zune

Comments RSS | Email this | Technorati Links | Digg This! | Save to del.icio.us | Kick It!
# Wednesday, June 04, 2008

                

I'm a big fan of the Zune (I own four of them, believe it or not) - so as a developer, I'm naturally inclined to think about novel ways to write applications for the device. There are several different approaches I've uncovered so far:

In this blog post, I will focus on the before last bullet point - how to create a API wrapper for the Zune Card Web service. To access the Zune user card service, simply point your browser to the following URL (including your Zune Tag - in my case, stormpixel):

http://zcards.zune.net/zcard/usercardservice.ashx?lcid=1033&src=external&zunetag=stormpixel

You'll notice that the Zune Card (zCard) is based on a custom XML schema. The uri provides a link back to the user card service. The id denotes the Zune user id. The firstName, status message and tile images are self-explanatory. The manifest contains additional information about the user, badges, playlists, contact information and preferences:

             

I've created a preliminary API wrapper using LINQ to XML to access the information contained in the Zune cards. To access information about a Zune card, you can instantiate a variable of type "ZuneCard", passing into it the zune tag of the user. Once the object has been instantiated, you can then pull in user properties and collections (deserialized for your convenience). The example below is a console application where I'm querying the ID for the user stormpixel:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace DisplayZuneCard
{
    class Program
    {
        static void Main(string[] args)
        {
            ZuneCard zuneCard = new ZuneCard("stormpixel");
            Console.WriteLine(zuneCard.id);
            Console.ReadLine();
        }
    }
}

If I run the application, I get the console window shown below. In the next blog post, I'll explain in more detail how I implemented the API.

Posted at 2008-06-04 06:56 AM by jldavid 
 Permalink |  Comments [0] | Categories: Development | Zune

Comments RSS | Email this | Technorati Links | Digg This! | Save to del.icio.us | Kick It!
Archive
<January 2009>
SunMonTueWedThuFriSat
28293031123
45678910
11121314151617
18192021222324
25262728293031
1234567
About the author/Disclaimer

Disclaimer
The opinions expressed herein are my own personal opinions and do not represent my employer's view in any way.


Statistics
Total Posts: 11
This Year: 0
This Month: 0
This Week: 0
Comments: 1
All Content Copyright © 2009 - JL David
Sign In