Alex Mueller on Software and Technology 
Friday, March 28, 2008

I had to disable Internet Explorer Enhanced Security Configuration for my Windows2008 VMs today. I just couldn't take it anymore. I have been warned. I understand its importance. I am still turning it off. Don't try this at home.

IEESCWarning

Friday, March 28, 2008 11:32:27 AM (Mountain Standard Time, UTC-07:00) | Comments [0] | Technology#
Thursday, March 27, 2008

I am currently working in a new development environment, unlike any that I have used in the past. It is different for two reasons, magnitude of dependencies and build process. The warning I have been given is, "this is a complex beast with lots of stuff in it, and much can go wrong." That statement pretty much covers the magnitude of dependencies stuff. As for the build process, my first question asked was, "you mean we don't use 'Ctrl+Shift+B' (in Visual Studio)?" No, we build using a command-line style approach, outside of the IDE.

Due the dependencies and build process, I wanted to schedule nightly builds on my local machines. This was when I discovered Windows PowerShell. PowerShell uses the .NET CLR and the .NET framework to provide new tools and methods for administering Windows environments. While similar in some aspects as DOS, PowerShell is much more. It is a command-line shell and scripting language that allows administrators to use C#.

Each night I want to backup certain files, sync files, clean and build my projects for 32 and 64 bit systems, update my environment with dependency changes, and email myself the log files generated during this process. I am not a DOS command nor scripting guru, but I could figure this out with some time. With PowerShell, I can leverage my C# knowledge to do all these tasks in a short amount of time.

If you want more control over administering your environments and would like to use C#, check out PowerShell. There is a good amount of support and tutorials to help get started.

 

Trivial Examples

The following is a trivial example of how to connect to a SQL database, query the Employees table of the Northwind database, and write those results to the screen. The PowerShell scripting syntax can be seen below.

   1: $conn = New-Object System.Data.SqlClient.SqlConnection
   2: $conn.ConnectionString = "Data Source=.;Database=Northwind;"
   3: $cmdText = "SELECT TOP 10 * FROM EMPLOYEES"
   4:  
   5: $conn.Open()
   6: $cmd = New-Object System.Data.SqlClient.SqlCommand($cmdText,$conn)
   7: $rdr = $cmd.ExecuteReader()
   8:  
   9: while($rdr.Read())
  10: {
  11:     $id = $rdr["EmployeeID"].ToString()
  12:     $fn = $rdr["FirstName"].ToString()
  13:     $ln = $rdr["LastName"].ToString()
  14:     Write-Host "$id $fn $ln"
  15: }
  16:  
  17: $conn.Close()

While that example is extremely trivial, it does show the power of using C# logic with the PowerShell language. It is easy to see how the code example above was translated from C# into PowerShell. The differences are syntactic.

For my nightly build scenario, I am able to create a scheduled task that calls a batch file, with similar contents as below.

   1: REM Calling Nightly Build
   2:  
   3: REM do the necessary to clean and build my environment
   4: call MyBuildLogicFile.bat
   5:  
   6: REM call powershell scripts
   7: powershell -command "& C:\PowerShellScripts\MyBuildScript.ps1

The batch file does the building then calls a PowerShell script I created to do help me parse my log files and email the contents. It actually call two scripts, one for parsing the content of my resulting log file, and the other to email the contents of the log file. The contents of the two files can be seen below.

PowerShell provides a number of predefined methods that can be used out of the box. Since I am interested in reading a log file, parsing its contents, and emailing the results, there are some functions available for making this scenario easier. For example, I do not need to recreate the wheel to read in a file's contents. I can use Get-Content. Before getting carried away with writing too much C#, check the available cmdlets (commandlets) to see if your desired functionality exists.

My file content parser script, using Get-Content.

   1: # Create a StringBuilder to retain our log file contents
   2: $sb = new-object System.Text.StringBuilder
   3:  
   4: # append a line break point, <br/> for the log file contents
   5: foreach ($line in get-content "C:\Output.log")
   6: {
   7:   $sb.Append($line).Append("<br/>")
   8: }
   9:  
  10: # Call our Emailer.ps1 to send this content to us
  11: powershell -command "& C:\PowerShellScripts\Emailer.ps1 -param '$sb'"

My email script that is called from the above code.

   1: param($param1) 
   2:  
   3: $message = new-object System.Net.Mail.MailMessage("me@mail.com", "me@mail.com")
   4: $message.IsBodyHtml = $True
   5: $message.Subject = "Automated Build Update"
   6: $message.Body += $param1;
   7:  
   8: $smtp = new-object Net.Mail.SmtpClient(”smtp.mail.com”, 587) 
   9: $smtp.EnableSsl = $True
  10: $smtp.Credentials = new-object System.Net.NetworkCredential("username", "password")
  11: $smtp.Send($message)

 

Pretty simple. Thanks to PowerShell, I have more control over administering my development and test environments using my preexisting knowledge of C#. One command that was always useful in Unix/Linux is grep. PowerShell uses Regex to simulate similar functionality, and you can find examples of those online.

Thursday, March 27, 2008 9:41:57 PM (Mountain Standard Time, UTC-07:00) | Comments [0] | Technology | Tools#
Monday, March 24, 2008

I am using Internet Explorer 8 Beta right now after learning about the new features it provides beyond its previous version, IE7. I hate to admit this, but some time ago I gave up on using FireFox when it starting consuming nearly 100% of my CPU. This was happening all too frequently and I tried to resolve the issue using several approaches I found posted on blogs. After not having any luck, I started thinking, "why do I prefer FireFox over IE?"

What I liked about FireFox I could now install in IE7 with IE7Pro, an add-on for IE7 managed by a multi-national team, not a Microsoft affilate. FireFox does have a strong community creating and sharing browser niceties that make the web experience easier and more pleasant. Internet Explorer has this as well in the form of IE7 add-ons. At this point, I am happy with IE7 running IE7Pro. My browser experience is great, and when I absolutely need to use one of my FireFox extensions, I will start-up FireFox and run the extension, hopefully before it consumes my CPU.

Since I installed the latest version of Internet Explorer, IE8 Beta, FireFox is that much further from my mind. IE8 provides a number of built-in tools that make the browsing experience that much sweeter. For a web developer, the integrated developer tools are a must have, and for someone new to web developing, these tools will certainly shorten the learning curve. The JavaScript debugging capabilities are great. I am no longer dependent upon my Visual Studio IDE since a built-in IDE-like tool is provided for accessing and manipulating HTML, CSS, and JavaScript.

Another great feature is how Ajax navigation history is retained in IE8. This is perfect for mapping software where you constantly interact with the map by zooming in or out. The window.location.hash is set with a value to enable managing the page history. This is possible in previous versions of IE, but it requires some work, usually in the form of installing and configuring a framework to use with your site, something like the ReallySimpleHistory library.

I will spare you more details on IE8. I do encourage you to try it out for yourself. There are a number of other nice features not mentioned. IE8 integrates nicely with Live Writer, which makes posting easier.

Monday, March 24, 2008 8:54:09 PM (Mountain Standard Time, UTC-07:00) | Comments [0] | Technology | Tools#
Friday, March 21, 2008

If you are looking for resources such as presentations, tutorials, and labs, using Visual Studio 2008 and C# 3.5, then download this training kit. According to the description, "The content is designed to help you learn how to utilize the Visual Studio 2008 features and a variety of framework technologies including: LINQ, C# 3.0, Visual Basic 9, WCF, WF, WPF, ASP.NET AJAX, VSTO, CardSpace, SilverLight, Mobile and Application Lifecycle Management."

This kit is a goldmine and will take me some time to get through it all. Free development training, take advantage of it.

Visual Studio 2008 and .NET Framework 3.5 Training Kit

Friday, March 21, 2008 8:06:38 PM (Mountain Standard Time, UTC-07:00) | Comments [0] | #

After three years, I decided to finally update my blog engine to the latest version of DasBlog. What I have discovered over three years is that finding time to blog can be difficult, and finding time to maintain the blog site takes a backseat to blogging. Now that I have updated to the latest DasBlog, I inherit a number of nice security features to battle spam, as well as some cool usability features. Thanks to the DasBlog team for their efforts in creating this project, one of the few blog engines that does not require a database.

I have not spent much time skinning this site and I do not plan on it right now. I use the built in RSS capabilities of Microsoft Office Outlook for aggregating my feeds, so I rarely view the actual websites that I read. I am guessing that most readers use a similar approach, so with this in mind, my current site theme works for now.

What RSS readers are you using?

Friday, March 21, 2008 8:54:42 AM (Mountain Standard Time, UTC-07:00) | Comments [0] | Misc | Technology | Tools#
Friday, March 14, 2008

This is a nice example using the new ASP.NET MVC framework. It is a clone of the Digg site, so it shows some more practical functionality, well beyond "Hello World." Not that there are not other practical examples out there, but the site goes into good detail on the MVC framework.

Friday, March 14, 2008 5:28:47 PM (Mountain Standard Time, UTC-07:00) | Comments [0] | Design | Frameworks/Patterns | Technology#

When John Denver spoke about spring time, he spoke about he passing of winter. The green of the new leaves and of life going on. The promise of morning and the long days of summer. I am John Denver fan and obviously not afraid to admit it. What John failed to mention in any of his songs in regards to spring time is Code Camp, but John did not live long enough to experience this.

In recent years, the Code Camp movement is starting to become synonymous with spring time. The Boston .NET User Group has a code camp schedule that shows the various code camp events across the US, with most, if not all of them occurring during late winter and early spring. As I am looking through several camp's sessions, each seems to offer similar presentations on agile, MVC, Web Client Software Factory, and best practices, just to name a few. I think it is exciting to see the community support for these events in every city. I will be checking back with these sites to see how their support faired.

For me, it used to be the anticipation of a new baseball season that marked my spring, now its code camp. In Boise, spring and code camp both tends to come early. Code camp rejuvenates those desires to investigate new technologies that tend to become dormant during the winter.

Would John Denver have mentioned Code Camp in any of his songs? It is highly unlikely. However, he was an activist, caring for the environment and those who care for it. Code Camp involves a similar activism in the community. It is good to see it emerging.

Friday, March 14, 2008 10:54:36 AM (Mountain Standard Time, UTC-07:00) | Comments [0] | Misc | Technology#
Sunday, March 09, 2008

Boise Code Camp 2008 was awesome. Thank you to David Starr and his wife, Eleanor, for taking ownership of this event and dedicating many months of their time to make this a reality. Thank you to the presenters for having the passion and desire to present technologies and practices, both new and not-as-new. Thank you to the many volunteers who put in countless hours to help coordinate the weekend's events. Thank you to the campers for attending and making this year's code camp a success.

I am sure everyone will be blogging about all the great sessions they attended at code camp. I enjoyed all of the presentations I attended, and I am excited to explore some new material.

I want to share a few thoughts on my presentation dealing with Model-View-Presenter in ASP.NET after listening to Scott Hanselman's session on the ASP.NET MVC Project. I may have the percentage incorrect, but Scott mentioned something like it is predicted that only 10% of the ASP.NET community currently using Web Forms will adopt and use the MVC framework. The MVC framework is an addition to ASP.NET, it is not a replacement. What this means is that Model-View-Presenter will still be a viable pattern to implement with your ASP.NET applications, and it is not going away. ASP.NET Web Forms will not be going away either.

Use MVP to get your third party controls under test. Use MVP to provide that separation of concerns in your legacy applications. Use it entirely or in conjunction with the MVC framework. It is all about testability. Glenn Block presented on the Web Client Software Factory, and what pattern does this implement? Model-View-Presenter.

I am providing my presentation and source code (3.67 MB) from my talk on MVP. It will be available via the Boise Code Camp site as well.

Again, thank the many individuals and their families who sacrificed their time to bring to the local community this years code camp.

Around the office's water cooler on Monday, I will be able to say, "and this one time, at code camp..."

Sunday, March 09, 2008 7:32:09 PM (Mountain Standard Time, UTC-07:00) | Comments [0] | Design | Frameworks/Patterns | Technology#
MuellerDesigns.net
Search
On This Page
SketchPath XPath Editor
Software Testing - Revisited
Architecting Buildings and Software
NBCOlympics.com with Silverlight
Marker Interfaces and C# Attributes
The Phone Screen
Working with ASP.NET MVC and MvcContrib
Thanks to BDD
Twitter
The Opposite of a Singleton?
Removing Duplicate Code in Functions
Add Vista Themes to Longhorn
Changing File Ownership In Vista and Longhorn
ReSharper Type Completion
Caring for the Team
Most Popular
JavaScript ReplaceAll Functionality
What is polymorphism?
What is composition?
Sorting with IComparable and IComparer
Applying the Observer Pattern in ASP.NET
MVP in ASP.NET
What is abstraction?
What is encapsulation?
What is a class?
What is inheritance?
Authentication in ASP.NET
Calendar Controls
SQL Server 2005 Connection Issues
XPathNavigator.CheckValidity new for 2.0
Auto-attach to process '[####] aspnet_wp.exe' on m...
What is an object?
FreeTextBox
VMWare and VPC
An Example of Reflection using C#
A New NHibernate Blog
Archive
Links
Categories
My Local Blog Map
Blogroll
About
Powered by:

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

© Copyright 2008
MuellerDesigns.net

Sign In

Help Those In Need
The Hunger Site
Ronald McDonald House Charities (RMHC) of Western Washington & Alaska