|
 Friday, May 18, 2007

Wireless Rest Areas

During this last week I've been in the process of relocating back to the south west area of the United States. During the drive back to the south west area I noticed something I've never seen before. Wireless Internet at Rest Areas!!!

Apparently this has been up and running for some time now but I was unaware of it. I noticed it at first in Louisiana. While in Texas I really began to notice how it was advertised on the Rest Area Signs. A nice little Wireless symbol was present on the signs.

So, if you're in dire need of a wireless connection, be sure to Google for wireless rest areas in the state you're traveling in. I've looked around and noticed tons of states have this set up already. I'd post links to all of them, but I dont have time to post 50 links right now. :) Enjoy!

#    Comments [0] |
 Thursday, May 10, 2007

Simplifying Database Modeling in Visio 2002/2003 through SQL Generation

 

During the development of any new greenfield project you're going to probably need to interact with a datastore.
From my experience, 8 out of 10 times this is going to be a database acting as the datastore, and in my case, it's normally SQL Server.

Database Modeling

When in the design phase we're modeling. Creating a representation of what we're going to build. In the design of a database I use Visio to do this by building an ERD Diagram.

If you're like me you're still probably using Visio 2002/2003. If you're also like me, you don't have the Enterprise Architect version of Visio that allows you to forward engineer the database from the ERD Diagram that you've created.

So, therein lies a problem. I have to design my database in Visio, then manually create the SQL and run it in query analyzer to get my database. Seem's like double the work to me.

1. Create the diagram and all the types and relationshiops
2. Copy it by hand into SQL Server Management Studio or the Query Window

I've always felt that Microsoft should have included forward engineering for Visio, regardless of the version. Unfortunately they didnt feel the same way.

Model to SQL

Fortunately there is a solution. A company called Orthogonal Software has a Visio plug-in called Orthogonal Toolbox that will allow you to export the data from the Visio document to an XML File.

Orthogonal has provided a couple XSLT's that you can apply (look for XSLT on that page). One of which has been altered to export SQL.

The XSLT file that originally was found with the product exported the SQL into one long string. No line breaks, nothing. Just a long string. After some futz'n around with the XSLT I was able to format the SQL that was transformed into readable SQL.

For example, a XSLT generated SQL Code that looks like this:

CREATE TABLE dbo.Employee( 
   [Employee_Id] bigint NOT NULL,
   [Name] nvarchar(100) NOT NULL
);
GO

How to implement

1. Download Orthogonal Toolbox and install it.
2. Create your Visio ERD Diagram.
3. Click the Orthogonal Toolbox Button in the toolbar.
4. Export to XML.
5. Put the XSLT files (download at the bottom of this post) into the same file as the XML File.
6. Open the newly created XML File and add this line after the XML Definition.
    <?xml-stylesheet type="text/xsl" href="ERD-SQL2005.xslt"?>
6. Open the XML file in Internet Explorer
7. Copy/Paste what you see into Query Analyzer and run.

Thats it. You've now gone from Database ERD Model to SQL Code in a few quick steps. TONS of time saved.

Update for SQL Server 2005

The original XSLT was for use with SQL Server 2000. Schemas were not supported in 2000, therefore everything started with "dbo". To get around this, I reworked the XSLT and changed it to use the table name.

When I'm designing for a SQL Server 2005 database I'll give my tables names such as [My_Schema].[Table_Name]. Therefore when I export and apply my XSLT, the new exported SQL will look like this:

CREATE TABLE [HumanResources].[Employee]( 
   [Employee_Id] bigint NOT NULL,
   [Name] nvarchar(100) NOT NULL   
);
GO

Where "HumanResources" is the schema and "Employee" is the table name.

 

Downloads

2000and2005XSLTs.zip (2.96 KB)

 

kick it on DotNetKicks.com
#    Comments [2] |
 Wednesday, May 09, 2007

New Version Notepad++

A new version of Notepad++ came out last week. I just got around to installing it and there are a few new features such as the enhancements made to the search/replace function. You can now search/replace through many different files through an improved interface and also search recursively.

There were some changes made to fix some bugs and a cool new feature that transforms all links that are typed into N++ to clickable links.

One of my favorite new features is the NppExec that allows you to run your own preconfigured scripts from within N++. Pretty cool. I wonder if you can run Powershell scripts from within there? Its worth checking out.

Also, if you have Aspell installed you can use it as a spell checker for Notepad++. I normally don't use Notepad++ for this but I can see its usefulness.

Links

Notepad++ Release Notes

64 Bit Version of the Shell integration (right click on any file and open it witn Notepad++).

Running Notepad++ from the command line (by typing "n" into the command prompt)

#    Comments [0] |
 Tuesday, May 08, 2007

Temporary Projects in Visual Studio 2005

Recently while poking around in Tools --> Options of Visual Studio 2005 I found a setting that allows for the creation of temporary projects. I wish I had found a long time ago, yet for some reason I breezed right over it.

The Visual Studio 2005 Temporary Project

The temporary project will be created in memory and will not be persisted to the disk. Another benefit is that it will not show up in your recent project list. If you decide to close the project Visual Studio 2005 will prompt you with this dialog box:


Supported Project Types

All C#, VB.NET, and J# projects are supported. If you have the Web Application Project installed, you can even create throw away web projects projects too.

 

How To Enable


Go to Tools --> Options and uncheck "Save new projects when created" as seen below.

 

See this MSDN topic for more information.


kick it on DotNetKicks.com
#    Comments [2] |
 Monday, May 07, 2007

C# Microsoft MapPoint 4.5 Geocode (Latitude and Longitude) Class

A while back I created a Geocode Class that retrieved its Geocode information from Google Maps and its been downloaded a ton. I've also received a few emails asking if I had a Microsoft MapPoint implementation of the Geocode address. Apparently the examples in Microsofts SDK are not as easily accessible compared to that of Googles (from what others have said). So here it is, a Geocode class for Microsoft MapPoint.

I actually saved this as a project because you need the web reference and also a few settings in the app.config. You can download it, change a configuration setting, update a web reference, and then build and go. Please note, to test this, you'll need NUnit or something similar. I have included a test class that has one unit test in it. This is so you can be sure that the code is working correctly. The actual Geocode class is in the project.

The Microsoft MapPoint SDK

The SDK is full featured with a TON of classes to help with Geospatial programming. Check out the SDK when you get a chance.

Steps To get it up and running

1. Download the project at the bottom of this post
2. Get a developer account here.
3. Put the User/Pass word in the app.config file. It should be on line 10 of the app.config.
4. Update your web reference (right click on the web reference and click "Update Web Reference").
5. Run the unit test. I use TestDriven.NET for this.

Options

The code has a class called FindOptions which allows you to set the threshold of how close you want the search result to be. Look at the MapPointGeocode.cs file below for more info.

Code

The GeoCodeClass (please note, for this to work, you'll need the web reference to the MapPoint webservice. Download the example at the bottom of the post which has all references included.)

using System;
using System.Collections.Generic;
using System.Text;
using System.Net;
using System.Configuration;
using MapPointGeocode.MapPointService;
using System.Web.Services.Protocols;
using System.Diagnostics;

namespace MapPointGeocode
{
   public class MapPointGeocode
   {
      /// <summary>
      /// These are the actual instances of the objects that call the MapPoint .NET service
      /// </summary>
      private MapPointService.RenderServiceSoap renderService;
      private MapPointService.FindServiceSoap findService;



      public MapPointGeocode()
      {
         InstantiateServices();
      }

      private void InstantiateServices()
      {
         // Create and set the logon information (note comment in web.config -- here would be the place to
         // decrypt/unhash the user/password from the config file).
         //NEW - Revised configuration settings (add ref to System.Configuration first):

         NetworkCredential ourCredentials = new NetworkCredential(ConfigurationManager.AppSettings["MPUser"], ConfigurationManager.AppSettings["MPPass"]);

         // Create the render service, pointing at the correct location
         renderService = new MapPointService.RenderServiceSoap();
         renderService.Credentials = ourCredentials;
         renderService.PreAuthenticate = true;

         // Create the find service, pointing at the correct location
         findService = new MapPointService.FindServiceSoap();
         // set the logon information
         findService.Credentials = ourCredentials;
         findService.PreAuthenticate = true;
      }

      /// <summary>
      /// Returns the geocode coordinates of an address. 
      /// </summary>
      /// <param name="addressLine">The address</param>
      /// <param name="city">The city</param>
      /// <param name="postalCode">The postal/zip code</param>
      /// <param name="country">The country. e.g.: USA, Canada</param>
      public LatLong GeocodeAddress(string addressLine, string city, string state, string postalCode, string country)
      {
      // Set up the address
         Address address = new Address();
         address.AddressLine = addressLine;
         address.PrimaryCity = city;
        address.PostalCode = postalCode;
        address.Subdivision = state; 
        address.CountryRegion = country;
        
        // Set up the specification for the address
        // Set up the specification object.
        FindAddressSpecification findAddressSpec = new FindAddressSpecification();
        findAddressSpec.InputAddress = address;
        findAddressSpec.DataSourceName = "MapPoint.NA";
// More info: http://msdn2.microsoft.com/en-us/library/ms982198.aspx and http://msdn2.microsoft.com/en-us/library/aa493004.aspx

        // Set the find options. Allow more return values by decreasing
        // the value of the ThresholdScore option.
        // Also, limit the number of results returned to 20.
        FindOptions myFindOptions = new FindOptions();
        myFindOptions.ThresholdScore = 0.5;
        myFindOptions.Range = new FindRange();
        myFindOptions.Range.StartIndex = 0;
        myFindOptions.Range.Count = 20;
        findAddressSpec.Options = myFindOptions;

        // Create a FindResults object to store the results of the FindAddress request.
        FindResults myFindResults;
        LatLong latLong = new LatLong(); 

        try
        {
           // Get the results and return them if there are any. 
            myFindResults = findService.FindAddress(findAddressSpec);
            FindResult[] myResults = myFindResults.Results;
            if(myResults!= null)
            {
               latLong = myResults[0].FoundLocation.LatLong;
            }

         }
         catch (SoapException myException)
      {
      // Your exception handling process goes here.
      Debug.Write(myException);
      }

      return latLong; 
      }
   }
}

Conclusion

The Microsoft MapPoint SDK might be a little more difficult to grok at first but one you start working with it you can see that it is full featured with many more options than the Google provided services.

Microsoft MapPoint 4.5 SDK Online Link

Download

MapPointGeocode.zip (276.41 KB)


kick it on DotNetKicks.com
#    Comments [1] |