Amazon.com Widgets

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??

 

Published 20 April 07 12:21 by BradA
Filed under: , , ,

Comments

# Robert Burke's Weblog said on April 20, 2007 6:03 AM:

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

# Jason said on April 20, 2007 10:39 AM:

I don't know if I would necessarily call this a success story.  Less code is definitely nice... but I think that readability suffers with all of that on one line.

And, I imagine that debugging this would be nearly impossible.

# Joku said on April 20, 2007 12:28 PM:

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.

# Joku said on April 20, 2007 12:34 PM:

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

# - said on April 20, 2007 3:27 PM:

Success story?

That in-line SQL and string manipulation of an XML file could easily be refactored to the same amount of lines by using VS 2005/.NET 2.0 in combination with good coding practices.  Or even proper understanding of things like XPath.

I would be more interesting in seeing an example where Orcas/LINQ provided benefit, not just when "Steve" was able to refactor poorly written code.

# Steve said on April 20, 2007 11:42 PM:

So, what is new about it?

I haven't seen a list of what is different anywhere yet.

# KNOCKS said on April 21, 2007 4:31 AM:

Isn't good debugging the primary skill of a good developer?

# zahira said on April 21, 2007 7:25 AM:

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!!!

# Mike said on April 22, 2007 5:23 AM:

I can't believe you named your connection object objConn. That's sooo 90's ;-)

# Team System News said on April 23, 2007 9:18 AM:

Willy-Peter Schaub on Redmond Sabbatical - Day 5. Brad Abrams on Orcas Beta1 Success Story The Microsoft...

# Aaron Ruckman's Web Log said on May 4, 2007 12:15 PM:

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

New Comments to this post are disabled

Search

Go

This Blog

Syndication

Page view tracker