Orcas Beta1 Success Story

Wow -- it is great to be done with Orcas Beta1... I can't wait to see what the feedback is like...

As it would happen, today I had an "Orcas success story"...  

Steve Marx is helping me with a demo for Mix and we just today moved it over from VS2005+ASP.NET AJAX+Silverlight to Orcas+Silverlight.   In doing so Steve "touched up" a few of the lines of code I wrote to take advantage of Orcas. Here is one such example.... I needed to enumerate all the items in a database, in each row I open an xml file that is referenced from the database and then pull some data out of that file and finally return that data in IEnumerable...

The code I wrote:

 

public class VideoDatabaseSiteMapData : DynamicDataSearchSiteMapProvider

{

    public override IEnumerable DataQuery()

    {

        SqlConnection objConn = new SqlConnection(ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString);

        objConn.Open();

        SqlCommand objCmd = new SqlCommand("SELECT * FROM [Items] ORDER BY [Title]", objConn);

        SqlDataReader reader = objCmd.ExecuteReader();

        List<VideoDataBaseEntry> list = new List<VideoDataBaseEntry>();

 

        while (reader.Read())

        {

            string mediaDefinitionPath = reader["mediaDefinitionPath"].ToString();

            foreach (string s in this.GetTimeStamps(mediaDefinitionPath))

            {

                VideoDataBaseEntry v = new VideoDataBaseEntry();

                v.ID = reader["ID"].ToString();

                v.Timestamp = s;

                list.Add(v);

            }

        }

        objConn.Close();

        return list.ToArray();

    }

    public IEnumerable<string> GetTimeStamps(string path)

    {

        List<string> l = new List<string>();

       

        foreach (string line in File.ReadAllLines(HttpContext.Current.Server.MapPath(path)))

        {

            if (line.Contains("<timeIndex>"))

            {

                int i = line.IndexOf("<timeIndex>") + "<timeIndex>".Length;

                int j = line.IndexOf("</timeIndex>");

                l.Add(line.Substring(i + 1, j-i-1));

            }

        }

        return l;

    }

}

 

which he changed to:

public class VideoDatabaseSiteMapData : DynamicDataSearchSiteMapProvider

{

    public override IEnumerable DataQuery()

    {

        return from video in new VideoDatabaseDataContext().Items.ToList()

               where video.MediaDefinitionPath != ""

               from node in XDocument.Load(HttpContext.Current.Server.MapPath(video.MediaDefinitionPath))

                .XPathSelectElements("/mediaDefinition/mediaItems/mediaItem/chapters/mediaChapter/timeIndex")

               select new VideoDataBaseEntry { ID = video.ID, Timestamp = node.Value };

    }

}

 

Pretty good huh?   I am glad I have Steve helping with this demo!   BTW, Come to my talk at Mix, or watch my blog here for more details on what the demo does... but it sounds cool doesn't it??

How about you?  got any Orcas Success Stories??

Comments

  • Anonymous
    April 19, 2007
    I'm working on two projects in the evenings: One is an XNA app (no surprises there), and the other is

  • Anonymous
    April 20, 2007
    The comment has been removed

  • Anonymous
    April 20, 2007
    I have to agree - even after we become more familiar with the new constructs and syntax, there needs to be a "solid story" for when things go wrong. I haven't had time to try Orcas Beta 1 yet but back in LINQ May ctp some of the errors reminded me of C++ template/macro errors, very very long unreadable lines and little possibility to dive into step by step of what's happening behind the scenes. There has to be good story for figuring out what exactly is going on so it doesn't turn out like perl obfuscation.

  • Anonymous
    April 20, 2007
    (the above demo is still pretty readable but it's really easy to go overboard and already seen some do this)

  • Anonymous
    April 20, 2007
    The comment has been removed

  • Anonymous
    April 20, 2007
    So, what is new about it? I haven't seen a list of what is different anywhere yet.

  • Anonymous
    April 20, 2007
    Isn't good debugging the primary skill of a good developer?

  • Anonymous
    April 20, 2007
    that good !!!really i hope to have some mails with some exemples of applications or demo to lern more cause  i gegan to forgete some thing called programming!!!

  • Anonymous
    April 21, 2007
    I can't believe you named your connection object objConn. That's sooo 90's ;-)

  • Anonymous
    April 23, 2007
    The comment has been removed

  • Anonymous
    May 04, 2007
    WOOHOO!!! .NET Framework 3.5 Beta1 has been released. Other related blogs: JasonZ's blog: http://blogs.msdn.com/jasonz/archive/2007/04/27/net-framework-3-5-beta-1-redist-released.aspx