mostlylucid

March 2008 Entries

Merging Directories...dumb little code sample

As I've posted about a few times recently I've moved back to a far more technical role and as a result I've been goofing around with some code...The first thing (which I can talk about ;-)) is a little directory merging utility I've been working on...pretty simple but it was fun to play with. You can find it here if you're interested...along with the main bit of source below...more interesting stuff to come (a lot of the stuff I've been writing is using pre-release bits so I will put it here when you can actually use it!)

using System;

using System.Collections.Generic;

using System.Collections;

using System.Collections.Specialized;

using System.Text;

using System.IO;

 

namespace MergeDirs

{

    class Program

    {

 

        /* Sample code for default config creation

        * Config cfg = new Config() { SourceDirectory = sourceDir, DestinationDirectory = destDir, ClearDestination = true, ExtensionsToExclude = new List<string>(new string[] { "vssscc", "dll", "pdb", "vspscc" }), DirectoriesToExclude = new List<string>(new string[] { "bin" }) };

            cfg.Serialize(@"C:\TestConfig\Config.xml");

            return;

            */

        private Config Cfg { get; set; }

        private const string CONFIG_FILE = @"C:\TestConfig\Config.xml";

        static void Main(string[] args)

        {           

            Program pgm = new Program();

            pgm.Run(args);

        }

 

 

        public void Run(string[] args)

        {

            Cfg = new Config();

            if(args.Length==0)

            {

                Cfg.Deserialize(CONFIG_FILE);

            }

            if (Cfg == null)

            {

                Console.WriteLine("No config file at " + CONFIG_FILE + " and no arguments...I can't guess!");

                Console.ReadLine();

                return;

            }

 if(!string.IsNullOrEmpty(Cfg.SourceDirectory) && !string.IsNullOrEmpty(Cfg.DestinationDirectory))

            {

                if (Directory.Exists(Cfg.SourceDirectory) && Directory.Exists(Cfg.DestinationDirectory))

                {

                    CompareDirs(Cfg.SourceDirectory, Cfg.DestinationDirectory, Cfg.ClearDestination, Cfg.ExtensionsToExclude, Cfg.DirectoriesToExclude);

                }

                else

                {

                    Console.WriteLine("Both source and destination directories must already exist!!");

                }

            }

            else

            {

                Console.WriteLine("You must specify both source and destination directories!");

            }

            Console.WriteLine("Finished!");

            Console.ReadLine();

        }

 

 

        private bool CompareDirs(string sourceDir, string destDir, bool clearRight, List<string> extensionsToExclude, List<string> directoriesToExclude)

        {

               List<string> srcFileNames = new List<string>(GetFSItems(new DirectoryInfo(sourceDir).GetFiles()));

               List<string> dstFileNames = new List<string>(GetFSItems(new DirectoryInfo(destDir).GetFiles()));

               foreach(string fileName in srcFileNames)

               {

                   Console.WriteLine(string.Format("Comparing:{0} and {1}", Path.Combine(sourceDir, fileName), Path.Combine(destDir, fileName)));

                   bool excludeFile = false;

                   foreach (string excludeExt in extensionsToExclude)

                   {

                       if (fileName.EndsWith("." + excludeExt))

                       {

                           excludeFile = true;

 

                           break;

                       }

                   }

                   if (excludeFile)

                       continue;

                       if (!dstFileNames.Contains(fileName))

                       {

                           File.Copy(Path.Combine(sourceDir, fileName), Path.Combine(destDir, fileName));

                       }

                       else

                       {

                           DateTime srcInf = new FileInfo(Path.Combine(sourceDir, fileName)).LastWriteTime;

                           DateTime dstInf = new FileInfo(Path.Combine(destDir, fileName)).LastWriteTime;

                           if (dstInf != srcInf)

                               File.Copy(Path.Combine(sourceDir, fileName), Path.Combine(destDir, fileName), true);

                       }

 

               }

               foreach (string fileName in dstFileNames)

               {

                   if (!srcFileNames.Contains(fileName))

                   {

                       File.Delete(Path.Combine(destDir, fileName));

                   }

               }

            List<string> sourceNames = new List<string>(GetFSItems(new DirectoryInfo(sourceDir).GetDirectories()));

           List<string> destNames = new List<string>(GetFSItems(new DirectoryInfo(destDir).GetDirectories()));

            foreach (string dirName in sourceNames)

            {

                if (directoriesToExclude.Contains(dirName))

                {

                    Console.WriteLine("Skipping: " + dirName);

                    continue;

                }

                Console.WriteLine(string.Format("Comparing:{0} and {1}",Path.Combine(sourceDir, dirName),Path.Combine(destDir, dirName)));

               if (!destNames.Contains(dirName))

               {

                   string newDestDir = Path.Combine(destDir, dirName);

                   Directory.CreateDirectory(newDestDir);

                   CompareDirs(Path.Combine(sourceDir, dirName), newDestDir, clearRight, extensionsToExclude, directoriesToExclude);

               }

               else

               {

                   CompareDirs(Path.Combine(sourceDir, dirName), Path.Combine(destDir, dirName), clearRight, extensionsToExclude, directoriesToExclude);

               }

            }

 

           foreach (string dirName in destNames)

           {

               if (!sourceNames.Contains(dirName))

               {

                   Directory.Delete(Path.Combine(destDir, dirName));

               }

           }

            return false;

        }

 

        private IEnumerable<string> GetFSItems(FileSystemInfo[] dirInfos)

        {

            foreach(FileSystemInfo dinf in dirInfos)

            {

                yield return dinf.Name;

            }

        }

 

    }

}

Incidentally using the CopySourceAsHtml 2008 version from here

The ASP.NET MVC Framework Source goes live on Codeplex!

This is the first big thing I worked on in the ASP.NET team, the release of the ASP.NET MVC Source Code to Codeplex. Scott Guthrie announced this  a few minutes ago and as he says it's the first of a number we have planned over the next while.
What is surprising is how much time and how many people it takes to pull a release like this together...but I really think it's the start of something really amazing and to quote a corny phrase 'you ain't seen nothing yet!'

End of a long day...

Well I've been working (with numerous others...well regularly annoying them throughout the day) for a release in then next short while onto Codeplex. Takes a surprising amount of work, but I'm getting excited to see the reaction of the community (one into which I'm slowly filtering back in to).  Anyway, I'm off to bed as I have to get up early and clean before my new cleaner comes (don't ask...I'm not a tidy person). I also wanted to give a shout out to someone who has worked on this release way before I arrived, Bertrand Le Roy and his blog. Your patience with an insufferable frantic scotsman (namely moi) has realy been appreciated!

Now, I leave you with a song (and inducement for people to actually visit the blog proper!) Oldish song by The Postal Service, Such Great Heights...which I think is truly lovely...

 

My surreal life...

I'm slowly starting to get used to my new job...I've been an ASP.NET fanboy since my first sight of it about 8 years ago (I think it was called something like NGWS then???). It has been odd, on my bookshelf I have pictures of the people I work with (in books, not in some odd 'stalker' way), I've read the blogs of others for years, and I still have to pause for a second when I wind up talking to them (Mr. Hanselman, that's why I seemed 'distracted' when we talked today!). But I'm starting to get over it...I'm learning more and more every day. Here's some things which amazed me:

How small the team is...the ASP.NET team is very small, very smart and very passionate. The productivity of these people still leaves me in awe.

More and more I'm seeing just how much the company I work for trusts the people who work for it; we make big decisions every day..I'm still amazed that the vast majority of them are 'just right'

Different bits of the company are very different; I loved working in Project and I still have friends there but it is surprising quite how differently different groups run in the same company.

Anyway, another embarassing post...but it really feels like I've reached the place I want to be...now to follow through (incidentally, look out for MVC on Codeplex...that's one of my things...the Codeplex bit, Phil is ALL about MVC :-))

Ack Ack!

Well, it's the last day in my first week with the ASP.NET team (kind of, a few people are off to MIX) . It's been a pretty interesting week...lots to learn etc...I'm still getting used to the team dynamic and my place in that (I think everyone else is a senior...I'm not due to some dubious career choices over the years). Still, I have lots of responsibility and a lot of work to do over the next short while...mostly focused around releases and our process for some future work (I *did* come from Project remember ;-)). It has been a blast playing with all the latest and greatest features (many of which we just released new previews of) and getting a lot of insight as to where ASP.NET is going (and yes, having pangs for my old life where I got to use this stuff to build applications for customers). Still I have a ton to learn and it's going to be an interesting journey...whish me luck!

I've seen the future and it will be

I took an hour out of my day to walk around Techfest today...it's an internal Microsoft event with all the latest and greatest ideas Microsoft Research comes up with every year. I know there's lots of press coverage of this but remember - the public stuff you've seen represents about 25% of what's actually there! This thing really acts as a pick-me-up for me...there's just such amazing stuff there and a lot of the stuff is of the 'aha' type...where you've seen all the public information around but never really got why it was such a big deal...it will be!

Anyway, stopping before I break the vast numbers of 'don't talk about this' posters that were everywhere...so tempting!

Live for MIX 08 - new ASP.NET releases

Strangely coinciding with MIX o8 (not really :-)) my team has made a bunch of new releases available to the public: these are all betas or CTPs so obviously don't reelect final quality (you can still do a whole bunch with this stuff though!). This is a remarkable about of work which (as the new boy) I've not really been involved in so far. That will change as we have a ton of other stuff ready to make it out the the developer audience VERY soon! I also fancy putting a sscreencast together on some of this stuff a la Hanselman (though the unsung hero is Phil Haack who pulled this release together over the past few weeks, overcoming illness to do so!)

Downloads:

- MVC Preview 2 is live at:

o English - United States

o http://download.microsoft.com/download/7/9/a/79a7153c-4cb4-4898-a984-6f01d565cba9/AspNetMVCPreview2-setup.msi

- Silverlight tools (includes the ASP.NET server controls for Silverlight) is live at:

o http://www.microsoft.com/downloads/details.aspx?FamilyId=E0BAE58E-9C0B-4090-A1DB-F134D9F095FD&displaylang=en

- ASP.NET 3.5 Extensions Preview (December) Download page is updated and live at:

o http://www.microsoft.com/downloads/details.aspx?FamilyID=a9c6bc06-b894-4b11-8300-35bd2f8fc908&displaylang=en

ASP.NET Updates:

- ASP.NET home page announcement:

o http://www.asp.net/

- ASP.NET 3.5 Extensions download “page” is updated and live at:

o http://www.asp.net/downloads/3.5-extensions/

- ASP.NET 3.5 Extensions quickstarts is live at:

o http://quickstarts.asp.net/3-5-extensions/default.aspx

- ASP.NET MIX readme is live at:

o http://www.asp.net/downloads/3.5-extensions/readme/Preview2.aspx

- Forums Updates are live:

o http://forums.asp.net/default.aspx?GroupID=7. New ASP.NET server controls for Silverlight forum added.

o http://forums.asp.net/1147.aspx

- Videos are new and live at:

o http://www.asp.net/learn/3.5-extensions-videos/default.aspx#mvc

First day in my new job...

Phew, it's almost over. I made the mistake of coming in really early to move some bits out of my old office...making a 12 hour work day for myself (I am a total dolt sometimes!). I should add that by 'bits' I mean a huge great reclining chair which won't fit in my new, shared office (sharing with Phil). Anyway I have lots to learn, doing a lot of process stuff at first before moving on to 'owning features' (basically means doing the design, writing the specs etc..). I'll post here when I make any releases for the new ASP.NET 3.5 stuff (which I'll be managing...not actually my features). So stay tuned (first one will be pretty soon!).