Mike Reagan's Blog

Technology and Kayaking

Been a while...

clock May 17, 2009 15:56 by author Mike Reagan

Its been a while since I posted, so for those of you that are reading my blog and wondering whats happened to me, here is the skinny. On the technology front, I have been doing a lot of work with the ASP.NET MVC framework and WPF (Windows Presentation Foundation). So far I really like the MVC framework, and am having a lot of fun with it. I have also been rewriting an application for work that I wrote using the Windows Forms tools, with WPF. The cool part about this, is I actually have something real to build and learn WPF with.

 On the personal front, my wife and I have been doing some more kayaking. About a month ago, Christine went on a trip with our friends Pat and Mickey to the Merced and the Kern rivers to do her first real class IV kayaking. After taking the last 9 months off from kayaking to let my neck/back heal I got back on the water a few weeks ago and have gotten the kayaking bug again. o far we have been out every weekend and I feel great. 



LINQ to XML

clock December 11, 2008 17:07 by author Mike Reagan

 

The past few months I have been slowly converting code that used the System.Xml namespace and the XML DOM to generate and read XML documents on various projects to use the System.Xml.Linq namespace instead (LINQ to XML). Not only is the programming API much simpler to use (once you understand it), it is in most cases dramatically faster in both reading and writing XML. I keep asking myself, how where they able to improve performance so much over the DOM?

I still don’t have the answer but in one simple case, I was using the DOM to generate a sitemap file that google and other search engines could use. Since all the content on the site I was using the sitemap for are served via complex links (url’s with querystrings) I was roughly generating 500 xml elements worth of data. My solution before was to write an ASPX page that would generate a physical XML file using the DOM. That age would take 15-20 seconds to finish executing. After redesigning the sitemap to be a custom HTTP Handler (ashx file) and using System.Xml.Linq, the execution time went down to .5 seconds. That is a vast improvement.

So, in other words, if you have access to .NET 3.5 and VS2008, I would suggest using the LINQ to XML capabilities as much as possible.



Silveright 2.0 Released!

clock October 16, 2008 15:14 by author Mike Reagan

Now that Silverlight 2.0 was released I have been really started to play with it. I was hesitant to play around with it/get serious about it until the final release came due to my experience with ASP.NET AJAX (formerly ATLAS). When ATLAS was CTP and Beta, it was quite a moving target. This time I let the dust settle before playing with it. I did do a little bit of stuff recently with Silverlight 1.0, mostly just hooked it up on my site, didn’t actually develop any Silverlight based products.

This time around, that will change as I am really impressed with how easy it is to get a functional product with it in just a little bit of time. Like most things, dedicate some time to it and you’ll pick it up fast.

I started Tuesday morning with Scott Guthrie’s series of posts on how to get started and quickly was able to get through the process of building this simple project. Since Tuesday I have been taking what I have learned and trying to build a few things with it, that I will share soon.

One of the great things about this technology is the server side aspects of this tool. My weakness has always been user interfaces and client side scripting. I typically spend more time in the middle tier writing business logic, and/or ASP.NET Server controls and developer tools. Frankly, I HATE writing Javascript by hand and having to deal with the intricacies of each and every browser. I like server side programming where I can write code in C#.

As I side effect of learning Silverlight 2.0, I was also exposed to LINQ to XML. Of course I read about it, but since I don’t necessarily spend a lot of time querying and/or generating XML, I really haven’t spent much time or needed to spend much time learning about it. I was more excited about LINQ to Objects, LINQ to SQL, etc. But after doing Scott’s walkthrough and in particular this post, I love LINQ to XML.

This is such a powerful and *simple* way to generate XML and parse XML. Tonight I was working on generating sitemap file that Google could use to index a site I am working on, and essentially, I wanted to loop through a product catalog and build a <url> node for each product returned in the data set.

See the code below for an example.

   1: var allProducts = (from products in DataContext.Products
   2:                            let ProductSubCategoryID = DataContext.ProductSubCategory_Product_XREFs.Where(p => p.ProductID == products.ProductID).Take(1).SingleOrDefault().ProductSubCategoryID
   3:                            let ProductCategoryID = DataContext.ProductCategory_ProductSubCategory_XREFs.Where(p => p.ProductSubCategoryID == ProductSubCategoryID).Take(1).SingleOrDefault().ProductCategoryID
   4:                            let LinkPath = "http://www.msrfx.com/ProductDetails.aspx?ProductID=" + products.ProductID + "&ProductCategoryID=" + ProductCategoryID + "&ProductSubCategoryID=" + ProductSubCategoryID
   5:                            select new
   6:                            {
   7:                                products.ProductID,
   8:                                products.Voided,
   9:                                LinkPath,
  10:                                ProductCategoryID,
  11:                                ProductSubCategoryID
  12:                            }).Where(p => p.ProductCategoryID != null && p.ProductSubCategoryID != null && p.Voided == false);
  13:  
  14:         XNamespace ns = "http://www.sitemaps.org/schemas/sitemap/0.9";
  15:         XDocument doc = new XDocument(
  16:             new XDeclaration("1.0", "UTF-8", "yes"),
  17:             new XElement(ns + "urlset", 
  18:               from p in allProducts select new XElement(ns + "url", 
  19:                   new XElement(ns + "loc", p.LinkPath),
  20:                   new XElement(ns + "lastmod", string.Format("{0:yyyy-MM-dd}", DateTime.Now)),
  21:                   new XElement(ns + "changefreq", "monthly"),
  22:                   new XElement(ns + "priority", "0.9")
  23:                 )
  24:             )
  25:         );

This was a way cleaner way to generate the XML document I needed than using the “old” System.Xml namespace.

These tools just keep getting better and better!



Google Chrome

clock September 28, 2008 16:46 by author Mike Reagan

I was excited to hear that Google was going to be releasing their own browser. It made a lot of sense for them to do it. As soon as the download link started working I downloaded it. My first impression of it was “sexy”. While I am not crazy about the icon they used to represent the program, the tabs were implemented in a clean and classy way. I like the subtle animations they did when you create a new tab.

One of the other exciting things about Chrome is the V8 javascript engine. In all the sites I have been to, I have noticed a significant performance improvement in loading times between IE7. I tried IE8 Beta 2, but after a few days I took it off, it still felt like a beta. With Google, everything is labeled Beta. Come to think about it, I have used Gmail for 4 years and it still in beta!

I like how lean and fast Chrome is, and I think it’s just going to get better.



Visual Studio 2008 LINQ to SQL Visualizer

clock September 27, 2008 15:54 by author Mike Reagan

I am really glad that Scott Guthrie made the  LINQ to SQL Visualizer available since it has helped me tremendously figure out what is wrong with my LINQ queries. One of the things that really annoyed me about it however, was when you check Original Query it shows you the SQL query that it generated, and it shows a list of the parameters at the bottom. It is nice to see what the parameters are and their values but umm, small problem, what if I wanted to copy and paste the query into SQL Server Management Studio to run it there? Well, you can do it, but you have to scroll forever highlighting the code, and you have to take the parameter list at the bottom and refactor it as DECLARE and SET statements to get a runnable query! Not quite sure why someone didn’t go the extra mile and do this. Luckily the source code is available with the download from Scott's blog,  because I was able to implement this feature in less than 30 minutes.

As you can see in the screen shot below, when “Original Query” check box is checked, it now generates a complete script that can literally be copied and pasted and ran within SQL Server Management Studio. I also added a “Copy to Clipboard” button so you don’t have to scroll any longer highlighting the text.

image

The only thing is, currently int, bigint, bit, datetime, and varchar’s are ONLY supported in the generation of  the parameter declaration since that was all I was intent on doing to solve the problem at hand before I got side tracked on this thing.

Download the source code here. The only modifications to this code were for these small changes, otherwise the rest of the credit goes to Scott Guthrie and pals.

Enjoy!



Calendar

<<  March 2010  >>
MoTuWeThFrSaSu
22232425262728
1234567
891011121314
15161718192021
22232425262728
2930311234

View posts in large calendar

Sign in