Confluence Tree Surgeon

by Donn Felker 28. February 2007 07:31

Mike Roberts over at ThoughWorks have a project to help with continuous integration.

The product is called "Tree Surgeon". Tree Surgeon solves the problem of how to set up a development tree.

"Tree Surgeon is a .NET development tree generator. Just give it the name of your project, and it will set up a development tree for you in seconds. More than that, your new tree has years worth of accumulated build engineering experience built right in."

What the product does is it allows you to specify a project name and the application will create a development tree for you (code generation). This tree includes a solution, the tools (NUnit, NCover, NAnt) and a build file and script to execute the build. It saves TONS of time when creating a new project and needing to add it to your build.

Example

Creating a new development tree:

This will generate this tree structure:

Inside of the "ExampleApplication Folder" we have the build and the go script. The "go" script compiles, runs NUnit and NCover. Its the workhorse of the system. Run this from the command line. If you want to see the results while in a command window, I'd advise editing the go.bat file and adding @pause at the end of the script so you can see the results before the window closes.

The solution for the project is located in the 'src' directory:

You can execute the go.bat file and it will complile, and run NUnit and NCover on your application.

The best part about this is that its all configurable. Edit the cs.vm files in the C:\Program Files\Tree Surgeon\Resources\Templates directory and you'll be able to affect the output of the code generation. Plus, its all open source, so you can get the code from the site.

This could help a lot of companies get up and running with a development tree in their source control.

*Note: Currently Tree Surgeon only exports C# files.

I'll be writing more about Source Control Management as time continues... stay tuned.

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags:

.NET | Continuous Integration

Gemini 2.0.5 "The Redirect Loop"

by Donn Felker 27. February 2007 07:00

Yesterday while performing some maintenance on our internal Gemini website I ran into an error where the default.aspx page would redirect to the main.aspx page and then the main.aspx page would redirect to the default.aspx page. This loop would continue until windows gave me the classic DNS error page. Looking at the log files I see that the Default.aspx page is issuing a 401 (unauthorized) and then main is issuing a 302 (Redirect). Others have had this problem as well (but with a previous version), but their fix didnt work for me.

I didnt make any changes to the configuration, we just made a dns adjustment. Once the error started occuring we rolled back the change in our dns in attempt to eliminate the error. *NOPE* Didnt work. The redirect loop still existed.

We tried everything from changing security settings, to adjusting config file, rebooting servers, flushing DNS, everything. Nothing worked. The thing is, prior to this errror, we never made any code changes or configuration changes.

Resolution

I'm still baffled by what happened, but how I ended up fixing it is by uninstalling the Gemini application *note: copy your .config file to your local machine before doing this. You'll want it later*. After uninstalling I reinstalled it, and then updated the config file with values that were from the old config file.

I fired up the app through the browser and it works.

Its one of the strangest things I've seen in awhile, but at least its fixed. But the worst part is that it took 4 hours with help from our network team to troubleshoot and when it came down to it, we just had to reinstall. Not the desired method, but still, its an internal app only used by 10 people (max) so it wasnt that big of a deal.

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags:

.NET

Namespace Aliasing - The using directive

by Donn Felker 22. February 2007 08:11

You can easliy alias a namespace in .NET by doing the following:

using System;
using System.Text;
using myXml = System.Xml; // <-- myXml is the alias.

Then in the code you can reference it like this:

using System;
using System.Text;
using myXml = System.Xml;

namespace MetaDatdaGenerator
{
   class Program
   {
      static void Main(string[] args)
      {
         myXml.XmlDocument xmlDoc = new myXml.XmlDocument(); 
         // Do stuff
      }
   }
}

Uses

Perhaps you've named something with similar namespaces or you've encountered a product with a similar namespace. This will allow you to alias them in your projects.

Aliasing a class

You can also alias a class, to save on typing. Saved keystrokes = mo time. Mo time = mo money. Mo money = mo problems! Oh, wait, nevermind...anyway... here's the code.

using System;
using System.Text;
using myXml = System.Xml;
using myException = ExampleCompany.ExampleProduct.Common.Exception.SomeExceptionWithAReallyReallyLongName;

namespace ExampleCompany.ExampleProduct
{
   class Program
   {
      static void Main(string[] args)
      {
         if (args.Length == 0)
         {
            throw new myException("Please provide a parameter!"); 
         }
      }
   }
}

Conclusion

Though it may not be used often, I've found myself using it a couple times when I needed to resolve some names to save on typing as well as an instance where I had two classes with the same name.

MSDN link: The using directive.

   

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags:

.NET

Google Maps on your Mobile

by Donn Felker 21. February 2007 09:18

If you're like me, you visit new places quite often and you need to find your way around. Or, maybe you're just terrible with directions and you can't find your way out of a wet paper bag, either way, its Google to the rescue.

For awhile now Google has offered Google Maps for mobile devices.

I installed it on my Blackberrry 7105t. I swear to the gods that be, I use this thing DAILY.

Uses
Finding stores: "Target in Stamford, CT". BLAMMO! It finds it.

Directions: Get directions to and from a location.

Favorites: Store favorite locations, such as home, work, the wife's office, etc. This saves a TON of typing on a handheld.

How to get it

Go to www.google.com/gmm on your mobile phone.

Supported Devices:

  • Most Java-enabled (J2ME) mobile phones.
  • Palm devices with Palm OS 5 and above.
  • All color BlackBerry devices.
  • Windows Mobile devices with Windows Mobile 2003, 5.0 and above.

I've seen it installed on Razr's as well as a few Sprint phones (not sure what models) that have internet access.

Once you get this bad-boy installed, you'll never be lost.

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags:

Misc

Updated: Formatted XML From SQL

by Donn Felker 20. February 2007 13:51

In my previous post I showed you how to return XML from the SQL Server Database. To further this topic, you can also format your XML to use Xml elements. This time, we're going to take a list of Customers and view their orders along with some information from the order, thats right, its straight from MSDN (with a couple tweaks).

This SQL Query will return Xml formatted as formatted elements.

USE AdventureWorks;
GO

SELECT TOP 10
     Customer.CustomerID,
OrderHeader.CustomerID,
OrderHeader.SalesOrderID,
OrderHeader.Status,
Customer.CustomerType
FROM Sales.Customer Customer, Sales.SalesOrderHeader OrderHeader
WHERE Customer.CustomerID = OrderHeader.CustomerID
ORDER BY Customer.CustomerID
FOR XML AUTO, ELEMENTS, ROOT('Customers')

Returns:

<Customers>
   <Customer>
      <CustomerID>1</CustomerID>
      <CustomerType>S</CustomerType>
         <OrderHeader>
            <CustomerID>1</CustomerID>
            <SalesOrderID>43860</SalesOrderID>
            <Status>5</Status>
         </OrderHeader>
         <OrderHeader>
            <CustomerID>1</CustomerID>
            <SalesOrderID>44501</SalesOrderID>
            <Status>5</Status>
         </OrderHeader>
         <OrderHeader>
            <CustomerID>1</CustomerID>
            <SalesOrderID>45283</SalesOrderID>
            <Status>5</Status>
         </OrderHeader>
         <OrderHeader>
            <CustomerID>1</CustomerID>
            <SalesOrderID>46042</SalesOrderID>
            <Status>5</Status>
         </OrderHeader>
      </Customer>
      ...
<Customers>

 

Explanation

The XML AUTO mode tells SQL Server to return the data in a XML format. We have provided the Sales.Customer table an alias of "Customer". If I had not done this, the results would have printed each element as:

<Sales.Customer>...</Sales.Customer>

This is not desirable.

The ELEMENTS option tells SQL Server to return the data as Xml elements, not as attributes. Had we eliminated this from the query, our query would have returned this:

<Customers>
   <Customer CustomerID="1" CustomerType="S">
      <OrderHeader CustomerID="1" SalesOrderID="43860" Status="5" />
      <OrderHeader CustomerID="1" SalesOrderID="44501" Status="5" />
      ...
   ...
</Customers>

This can work, but this time I wanted to demostrate the ELEMENT option.

The ROOT('Customers') allows us to set a root Xml element named "Customers".

 

Conclusion

While this may not be the next best thing you've ever seen, its still cool and it can save you time in the long run. Possible uses might include a quick way to get data out of your system and into a XML format for a one time use. Or you could use it for your data access layer and have it return XML to the business layer that might be used in a web service.

Its been reported that working with large XML Docs in .NET can be memory intensive, so perhaps this might help in processing and in saving memory on that server thats running on an old desktop that your boss had laying around. (We've all worked at a company who had a 'server' which was nothing more than a beefy desktop sitting in the server room.) :)

kick it on DotNetKicks.com

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags:

.NET | SQL Server

Generate XML in SQL

by Donn Felker 19. February 2007 10:37

You can easily generate Xml from a DataTable by using the .WriteXml() method.

But you can also bypass this and retrieve the Xml directly SQL Server 2005 by running the following command:

USE Northwind;

SELECT    EmployeeID,
        LastName,
        FirstName
FROM    dbo.Employees
FOR XML AUTO;

 

This will return an Xml representation of the data that looks like this:

<dbo.Employees EmployeeID="1" LastName="Davolio" FirstName="Nancy" />
<dbo.Employees EmployeeID="2" LastName="Fuller" FirstName="Andrew" />
<dbo.Employees EmployeeID="3" LastName="Leverling" FirstName="Janet" />
<dbo.Employees EmployeeID="4" LastName="Peacock" FirstName="Margaret" />
<dbo.Employees EmployeeID="5" LastName="Buchanan" FirstName="Steven" />
<dbo.Employees EmployeeID="6" LastName="Suyama" FirstName="Michael" />
<dbo.Employees EmployeeID="7" LastName="King" FirstName="Robert" />
<dbo.Employees EmployeeID="8" LastName="Callahan" FirstName="Laura" />
<dbo.Employees EmployeeID="9" LastName="Dodsworth" FirstName="Anne" />

For more information on FOR XML and its modes, click here.

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags:

SQL Server

The hidden Trace page, trace.axd

by Donn Felker 13. February 2007 08:06
Most developers dont know about the virtual trace output page available in ASP.NET. This page allows you to see the Trace Output provided by ASP.NET. You can view many statistics about the pages that have been executed on the system.

The virtual page trace.axd is enabled by enabling tracing in your application by enabling tracing in the web.config file like this:

<trace enabled="true" />

You can now compile and run your web page. Hit refresh a few times to get some info into the trace cache.

Visit the trace.axd file by typing it manually into your browser address bar.

For Example: http://localhost:1234/TraceExample/trace.axd

When yo view this page, you should see something similar to this:



Click on the "View Details" links and you'll see the trace out put listed for that request. (Note: I have cut off the image because there is too much data listed to list in this post. Download the example and try it out yourself to see all the details.)




How To Write Info To The Trace
You can write information to the trace by using the Trace.Write method.

Trace.Write("We're writing to the trace output.");


In the downloadable example below, I override the OnPreRender event and write info to the trace. By doing this:

protected override void OnPreRender(EventArgs e)
{
Trace.Write("We're inside of the OnPreRender Event.");
base.OnPreRender(e);
}

This will write info to the trace, which can be viewed on the trace output page:


*Note: The trace.axd can only be viewed when executed on the local machine where the pages are being executed from.

Download Example

TraceExample.zip (1.77 KB)

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags:

ASP.NET

Simian Upgrade

by Donn Felker 7. February 2007 07:34

For those of you who use Simian, please be aware, they upgraded the product and the old "-recurse" option no longer works. Read below on how to fix it.

The Issue

I downloaded it last night to test it with my teams current continuous integration environment through Cruise Control .NET (CCNET).  I looked at some examples on the CCNET website on how to run this as a NAnt task and found that it should be fairly easy. I just needed to recurse through the directories and have it run on all C# files (*.cs). Unfortunately I was getting a "Invalid Option" each time I ran this code:

simian-2.2.13.exe -recurse=*.cs -formatter=xml:simian.xml

 

The Issue, Part 2

I finally figured out that the docutmentation on the CCNET site was incorrect. The new product removed the -recurse option and replaced it with -includes and -excludes options to resemble the file globbing method of retrieving files.

I then ran the command as they recommended on the site:

simian-2.2.13.exe -includes=**/*.cs -formatter=xml:simian.xml

I then got this error: "Error: Illegal characters in path."

 

The battle continues

I continue to battle this until I finally give up I try wrapping paths in quotes, executing using different syntax, passing in different wild cards. I combed the documentation with a fine tooth comb, only to find, NOTHING.

 

Resolution

I resorted to emailing support to ask for help.

To my amazement, I had a reply within 2 hours stating that I found a bug in the new release. They said they would fix it and upload a new version ASAP. 5 Hours later, the new version was live on the site.

I downloaded the new version, version 2.2.14, and ran the command

simian-2.2.14.exe -includes=**/*.cs -formatter=xml:simian.xml

I ran the command and the system placed my results into my requested XML File. I was now able to integrate it into my continuous integration system.

With it in place, I can now see my similiarity results.

Cruise Control .NET Website support link

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags:

Continuous Integration

Force HTTPS on all requests, HttpModule

by Donn Felker 2. February 2007 14:45
 Sometimes we have websites that are strictly HTTPS. No files whatsoever are served up through HTTP. We want our users to only access the HTTPS portion of our website but we dont want them to remember "https://" blah blah blah. Honestly, who really wants to type all of that anyway? No one. We want our users to type www.example.com and then we want the site to redirect to the local https site. I've found a few sites out there that have some very robust SSL transition handlers, this one especially , but it was just way too much for what I needed to do. I needed something simple. So I started thinking...

There are a couple ways to do this.

Force SSL through IIS.


But this wouldnt be the desired method because if the user typed in http://www.example.com/ they would be presented with a page that states this site requires SSL. We want it to redirect. Also, this means that if I move my site to another server I have to update configuration on the IIS site as well as any settings in my web.config. Mo-hassles, mo-problems, yuck.

Redirect Page
We could also leave one page not requiring SSL and execute the following code in Page_Load

// Redirect to HTTPS Site
Response.Redirect("https://www.example.com");

That works, but what if a user has a bookmark to a special part of the site such as: http://www.example.com/examplefolder/example.aspx  ??
This method would get bypassed and the user could easily access the page without SSL Encryption.

Http Module
This is the method I decided to go with.

The code implements the IHttpModule interface. Inside of the Init method we attach to the Application.BeginRequest event and then we let the handler decide what to do with the page. If the page is using a secure connection then we dont do anything with the request. If they are not using a secure connection, the code replaces the Uri scheme with "https" and then performs a redirect.

using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

/// <summary>
/// Redirects a request to the HTTPS site.
/// </summary>
public class RedirectToHttpsModule : IHttpModule
{
#region Constants

private const string HTTPS = "https";

#endregion

#region IHttpModule Members

public void IHttpModule.Dispose()
{
// Nothing to dispose.
}

public void IHttpModule.Init(HttpApplication context)
{
context.BeginRequest += new EventHandler(context_BeginRequest);
}

void context_BeginRequest(object sender, EventArgs e)
{
HttpApplication application = sender as HttpApplication;
if (!application.Request.IsSecureConnection)
{
// Grabs the current scheme, http, and replaces with https and redirects.
application.Response.Redirect(application.Request.Url.ToString().Replace(application.Request.Url.Scheme, HTTPS));
}
}

#endregion
}



Implementation
Download the RedirectToHttpsModule.cs file below and place it into the App_Code directory located in the root of your website.
Then add the following to your system.web configuration section of your web.config file.

<httpModules>
<add type="RedirectToHttpsModule" name="RedirectToHttpsModule" />
</httpModules>

Now, each request made to your site will be pushed to https.


RedirectToHttpsModule.zip (.57 KB)

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags:

.NET | ASP.NET

Prototype/Proof of Concept code is not production code!

by Donn Felker 2. February 2007 08:02

One thing that should be burned into the heads of many developers is that Prototype/Proof of Concept (PoC) code is NOT production code. Proof of Concept code is not production code.

Prototype code is, more or less, proof of concept. When you create a prototype or PoC, it’s something that can be shown to the client to create a common understanding of what is to be delivered. Now, some people will disagree with this, but … after the client agrees to this prototype/PoC this code should only be saved for reference. It should only be referenced to ensure the client is getting what they received. It should be compared to the final app to make sure it works in the same order.

When creating Prototype/PoC the goal is to save money. It helps set its viability, expose any technical issues and express any concern over any direction of the system. Feedback can be implemented quite easily at this point. This allows the developer and business analyst to quickly identify the noted issues without incurring a high overhead of development costs.

Once the Prototype/PoC is agreed upon, the development on the prototype ceases and the design phase of the new system should begin. Under NO circumstance should the prototype be taken and converted into the actual production site. Will you take snippets of code here and there? Yes, will you grab a piece of JavaScript from the client code you created for the prototype? Yes. Will you use the entire project as your production code? No.

The reason for this is simple; prototype code is ugly, messy, and nasty. It’s a conglomerate of blog posts, mixed with MSDN How-To articles, mixed with hacks and riddled with bugs. The code in these types of projects contain code that is far from anything pretty. The code would take longer to clean up than it would to take to write it from a fresh slate.

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags:

.NET | ASP.NET

Powered by BlogEngine.NET 1.4.5.0
Theme by Mads Kristensen

About the author

Donn Felker

Senior Consultant
MCTS
ScrumMaster
Agile Practitioner

About Me | Books I Recommend

Gotta Pay The Bills


Tag cloud

    Popular Posts

    RecentComments

    Comment RSS

    Calendar

    <<  December 2008  >>
    MoTuWeThFrSaSu
    24252627282930
    1234567
    891011121314
    15161718192021
    22232425262728
    2930311234

    View posts in large calendar