My blog has moved!!

Tuesday, March 11, 2008
Tuesday, March 11, 2008 12:10:58 PM (GMT Standard Time, UTC+00:00) |  | #
Monday, March 03, 2008
Last week I slipped an update in to Mini SQL Query - version 0.9.37.
Just minor fixes, updates, a quick start help page and I added a "Templates" tool window plugin...

Monday, March 03, 2008 10:30:11 AM (GMT Standard Time, UTC+00:00) |  |  | #
Friday, February 01, 2008

Mini SQL Query is one of those tools that I have had in my self coded toolbox for a long time now. Last year I almost released it to the public but a few things happened and the release sadly didn't. My apologies to those that were waiting, I had plenty of emails in the months to follow asking where the editor was!

 

Well, I finally uploaded the beta - see http://www.pksoftware.net/MiniSqlQuery/

 

 

Mini SQL Query hitting an MSSQL database.

 

Make sure you register so that when fixes or major releases are made you know – there is also the Mini SQL Query product RSS feed). Keep in mind its in no way intended as a replacement for Microsoft's "SQL Server Management Studio". I use it for making quick queries or updates to my databases. I find it particularly good for managing a remotely hosted database. I don't use it for modeling databases etc but I do plan on making a bunch of plugins to help with quickly putting together a NetTiers focused database model.

Mini SQL Query hitting an MS Access database with a table window floating.

 

The application itself it an exercise in minimalist coding. I made use of open source libraries such as the ICSharpTextEditor giving lots of edit functionality with little effort. I used Weifen Luo’s docking library which has been great (I need to track down the correct links etc will post later). The design employs a service model with commands which keeps code nicely separated and easily extendable (see the API docs on making plugins if you have the geekish urge to!) The testing is done with a combination of stubs and mocks (I use Rhino Mocks, just love the style...)

 

The whole application was actually coded with Microsoft Visual C# Express Edition. I wanted to see what a hobby developer IDE could come up with.

 

Some notes...

 

Multiple Connection Types

One of the main features is the fact that you can connect to pretty much any database so long as you know the Provider type and connection string. I have only had MSSQL and Access databases to test against so far but I might try and ressurect my Oracle instance just to check out the schema details.

Probaby the main usability thing to keep in mind is that if you change the provider type and/or the connection string you should hit the 'Refresh Database Connection' button/menu item. The 'Database Inspector' gets reloaded at this point too. 

 

Database Inspector

The inspector window shows basic details that are taken from the DBConnection.GetSchema output. I have noticed that some of the types for the access databases are not actually defined and so come though as a number with a question mark (e.g. 130? with is actually a variable string) .

 

Settings Persistance

There is none! I have not worried about it to date but that will turn up in time.

 

 

Let me know what you think, PK  :-)

Friday, February 01, 2008 2:43:45 AM (GMT Standard Time, UTC+00:00) |  |  | #
Monday, December 24, 2007

I was working with the new MS MVC framework but with express, I used Lazycoders post as a helper to what lead to this template. I have put together a simple C# project template for Visual Web Developer 2008 Express Edition. Just dump it into your

  "(my docs)\Visual Studio 2008\Templates\ProjectTemplates\Visual Web Developer"

folder and choose “new website” etc (may need to restart the IDE to pick up the files).

It puts together the basic structure using the "App_Code" restriction in the express edition of the IDE (well, and some others...)

 

There is also a simple “view page” item template, drop this into

  "(my docs)\Visual Studio 2008\Templates\ItemTemplates\Visual Web Developer"

I did not worry about the controller (simgle page + simple change etc)...

Merry Christmas! PK :-)

 

Files:

Monday, December 24, 2007 3:09:14 AM (GMT Standard Time, UTC+00:00) |  | #
Wednesday, October 31, 2007
It's common practice for developers to make small "TODO" notes in code as they work for themselves or others to clarify at some time...

// TODO: confirm this business requirement...
// TODO: make this better!
// TODO: bread, butter, eggs and milk...

Issues can arise when the TODO's are not taken care of for whatever reason or get lost in the mayhem of meeting deadlines. A worst case scenario could arise when there is a production defect for an obscure situation and the maintenance programmer finds something like this:

// TODO: Not sure if there are any more response codes for this one, check before release.

Opps! Now that's expensive.
Now I am not saying this is good or bad (!) practice - but what I have started to do within my team is create either a failing or ignored unit test (depending on the importance) marking what would normally be an innocent "TODO" item. The unit test stays in the build as either a fail or ignore and does not drop off the radar.

[Test]
public void Need_to_confirm_foo()
{
  Assert.Fail();
}

Or...

[Test]
[Ignore("Confirmation required from the business")]
public void A_foo_only_has_a_bla()
{
}

It's much harder to miss a bunch of ignored or failing unit tests before that production release than some well hidden TODO comments!

kick it on DotNetKicks.com

Wednesday, October 31, 2007 9:40:05 AM (GMT Standard Time, UTC+00:00) |  |  |  | #
Thursday, October 04, 2007

Scott Guthrie talks about Microsoft releasing the .Net framework source code later this year.
A very good move by Microsoft I think :-)

http://weblogs.asp.net/scottgu/archive/2007/10/03/releasing-the-source-code-for-the-net-framework-libraries.aspx

Thursday, October 04, 2007 2:22:05 AM (GMT Standard Time, UTC+00:00) |  |  | #
Tuesday, September 04, 2007

Make that version 1.0.0.3!

I did not quite get this feature into the previous version and just posted the updates in case I got busy.

The big (and very useful) change for build 3 is that you can "paste" unit test code into the tool and the phrases will be extracted - if they use underscores and the code is C# (sorry, minor bug, I'll fix that shortly!) In practice I have found the underscore styke far more readable.

For example, if you have the following unit test code, copy it to the clipboard...

namespace Tests
{
    [TestFixture]
    public class PersonEntityTests
    {
        [SetUp]
        public void TestSetUp()
        {
            // ...
        }
        
        [Test]
        public void A_method_will_be_extracted_from_the_clipboard()
        {
            // asserts etc
        }
    }
}

...and use the new "Paste beaviours from clipboard" menu option (or ALT+F5) and you get the method name extracted.

The full round trip. Whe you want to continue working on a unit test class you can use this feature to get the current context of the testing... have fun! PK :-)

  http://www.pksoftware.net/BehaviourToUnitTest/


Quick note - now at v1.0.0.2 - the main changes are:
  • The use of the ICSharp.TextEditor for better editing
  • The defaults are C# with the underscore style
  • A few more word substitutions by default

Enjoy!

Tuesday, September 04, 2007 10:49:31 AM (GMT Standard Time, UTC+00:00) |  |  |  |  | #
Monday, August 27, 2007

I have uploaded a small development tool that I put together recently, its called "Behaviour to Unit Test". Basically it converts code functionality from plain sentences (or stories) into unit test stub code. You could also think of it as a cure for TDD writers block!

For an example of the usage, use the Generation -> Fill out example menu option and hit Convert. Basically it takes a set of plain language behaviours for an object such as "person":

  • Check that the default values of all string properties are empty
  • The ToString method renders the first and last names
  • If the date of birth is null, calculate age will return -1
  • If the date of birth is not null, calculate age will return a value

...and converts them into something like:

using System;
using NUnit.Framework;
using NUnit.Framework.SyntaxHelpers;

namespace Tests
{
    [TestFixture]
    public class PersonEntityTests
    {
        private PersonEntity person;
        
        [SetUp]
        public void TestSetUp()
        {
            person = new PersonEntity();
        }
        
        [Test]
        [Ignore("Currently only a unit test stub")]
        public void CheckThatTheDefaultValuesOfAllStringPropertiesAreEmpty()
        {
        }
        
        [Test]
        [Ignore("Currently only a unit test stub")]
        public void TheToStringMethodRendersTheFirstAndLastNames()
        {
        }
        
        [Test]
        [Ignore("Currently only a unit test stub")]
        public void IfTheDateOfBirthIsNullCalculateAgeWillReturnMinus1()
        {
        }
        
        [Test]
        [Ignore("Currently only a unit test stub")]
        public void IfTheDateOfBirthIsNotNullCalculateAgeWillReturnAValue()
        {
        }
    }
}

There are C# and VB.NET templates for now. Check it out:

  http://www.pksoftware.net/BehaviourToUnitTest/

My intention is to keep the tool small and simple. The main thing I want to add at the moment is some load/save functionality and drop in the ICSharp.TextEditor for more friendly editing...

kick it on DotNetKicks.com

Monday, August 27, 2007 9:43:04 AM (GMT Standard Time, UTC+00:00) |  |  |  |  |  | #
Thursday, July 19, 2007

This is just a quick heads up to say that I think the Castle Project rocks!

I have been using it allot of late especially Active Record. I'll blog more detail later but it's what I have been looking for all these years! Many time I have implemented simple subsets of the functionality that Castle provides to help get the job done. Castle wraps up all those funky framework fragments and more with a great "action pack" flavour to it in the form of Mono Rail (i.e. 'ruby on rails' for .Net)

Very cool  ;-)

Thursday, July 19, 2007 11:21:35 AM (GMT Standard Time, UTC+00:00) |  |  | #
Wednesday, June 13, 2007

Just a quick note that could drive you completely mad if you were not aware...

If you are using NUnitForms for testing your GUI and have code in the forms "Shown" event, it will not run unless you follow the Form.Show call with Application.DoEvents(), see sample code below

This example is just a Label (label1) dumped on a Form with the Load and Shown events updating the label with the respective event text:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace NUnitFormsDemo1
{
    public partial class ShownTestForm : Form
    {
        public ShownTestForm()
        {
            InitializeComponent();
        }

        private void ShownTestForm_Load(object sender, EventArgs e)
        {
            label1.Text = "Load";
        }

        private void ShownTestForm_Shown(object sender, EventArgs e)
        {
            label1.Text = "Shown";
        }
    }
}

Here is some sample NUnitForms test code, the first test asserts that after the Form.Show call the label text is "Load" and the second test shows that the label text is "Shown".

using System;
using System.Windows.Forms;
using NUnit.Framework;
using NUnit.Extensions.Forms;

namespace NUnitFormsDemo1.UnitTests
{
    [TestFixture]
    public class TestFormShownIssue : NUnitFormTest
    {
        [Test]
        public void TestFormShow()
        {
            ShownTestForm frm = new ShownTestForm();
            LabelTester label1Tester = new LabelTester("label1");
            frm.Show();
            Assert.AreEqual("Load", label1Tester.Text);
        }

        [Test]
        public void TestFormShowWithDoEvents()
        {
            ShownTestForm frm = new ShownTestForm();
            LabelTester label1Tester = new LabelTester("label1");
            frm.Show();
            Application.DoEvents(); // allows the 'Shown' event to fire
            Assert.AreEqual("Shown", label1Tester.Text);
        }
    }
}

I will take an educated guess that this is due to the GUI message pump etc.

In general if I come across this any of this type of unexpected behavior with NUnitForms I will try a DoEvents before tearing my hair out.

Wednesday, June 13, 2007 9:30:07 AM (GMT Standard Time, UTC+00:00) |  |  |  |  | #
Thursday, June 07, 2007

I have had some questions regarding the icons (or rather images) that I use in my applications (such as the 'pending' Mini SQL Query tool)...

They are by Mark James - he has a bunch of great free stuff available at:
http://famfamfam.com/ - more so the "Silk" set at http://famfamfam.com/lab/icons/silk/

The images are licensed under a Creative Commons Attribution 2.5 License.

Thursday, June 07, 2007 10:05:56 AM (GMT Standard Time, UTC+00:00) |  |  | #
Thursday, May 17, 2007
This is the line of code that I keep forgetting...

AppDomain.CurrentDomain.SetPrincipalPolicy(PrincipalPolicy.WindowsPrincipal);

Use it in (for example) the Program.Main function when the application starts up and the threads currrent principal is now the windows user. So...

Thread.CurrentPrincipal.Identity.IsAuthenticated

Will now be true and you can make use of the Identity.Name property etc.

Self reminder over...

More Notes...

If for example you need to perform unit tests as a windows user (to access the username or hit a resource) you can make use of the AppDomain.CurrentDomain.SetPrincipalPolicy method in the test fixture setup/teardown methods - see example below. I put the UnauthenticatedPrincipal setting in the teardown so that subsequent tests do not have their principal modified by accident...

using System;
using System.Security.Principal;
using System.Threading;
using NUnit.Framework;

namespace Tests.SetPrincipalPolicyExample
{
    [TestFixture]
    public class TestSomethingUsingCurrentWindowsPrincipal
    {
        /// <summary>Called once before all tests are run.</summary>
        [TestFixtureSetUp()]
        public void TestFixtureSetUp()
        {
            AppDomain.CurrentDomain.SetPrincipalPolicy(PrincipalPolicy.WindowsPrincipal);
        }

        /// <summary>Called once after all tests have run.</summary>
        [TestFixtureTearDown()]
        public void TestFixtureTearDown()
        {
            AppDomain.CurrentDomain.SetPrincipalPolicy(PrincipalPolicy.UnauthenticatedPrincipal);
        }

        [Test]
        public void VerifySomething()
        {
            string expectedUsername = Thread.CurrentPrincipal.Identity.Name;
            // more testing stuff
        }
    }
}


Thursday, May 17, 2007 1:32:42 PM (GMT Standard Time, UTC+00:00) |  | #
Monday, May 14, 2007

NOTE - Mini SQL Query has been released now - see http://www.pksoftware.net/blog/2008/02/01/Beta+Release+Of+Mini+SQL+Query.aspx.

 

This is not a product release, but a notice of release (!) for my latest pet project, "Mini SQL Query".

What is Mini SQL Query?...

"Mini SQL Query from PK Software is a minimalist SQL query tool for multiple providers (MSSQL, Oracle, OLEDB, MS Access files etc). The goal of the Mini SQL Query tool is to allow a developer or trouble-shooter to quickly diagnose issues or make changes to a database using a tool with a small footprint, that is fast, expandable and easy to use."
Some Features:
  • Multiple database type connections (e.g. MSSQL, Oracle, Access etc)
  • Syntax Highlighting
  • Object Inspector (Browse the tables, columns etc for the connection)
  • Easy to utilize Plug-In system that has access to all the applications internals
Sample Screenshot - The Mini SQL Query tool in use against the Northwind Sample DB:



I call it "mini" because I wanted to keep it simple and fast. I uses a straight forward but powerful plugin architecture that makes adding menu or toolbar options as simple as adding a reference in a DLL project and implementing a few functions from the IPlugIn interface. I will be pushing out a few posts about the service and command style of coding soon due to its implicit focus on issues such as dependency injection (DIP) and (dare I say it) service-oriented architecture (and no I am not talking about web services!) These techniques in turn improve code quality, testing and in turn maintenance (and again in turn our sanity as programmers...)

I will publish a core product and then make other plugins available for download.

Plugin Example 1...

Here is a simple example - display connection...



Below is the example C# plugin code that displays the current connection string in the editor window.

namespace MiniSqlQuery.Plugin.Example
{
    /// <summary>
    /// This example command inserts the current connection string details into the editor text.
    /// </summary>
    public class DisplayConnectionCommand : CommandBase
    {
        public DisplayConnectionCommand(IServiceContainer services)
            : base(services, "Display Connection Example")
        {
        }
        public override void Execute()
        {
            IEditor editorService = this.ServiceManager.CurrentEditor;
            editorService.Query = string.Format(
                "-- Connection: {0}\r\n\r\n{1}",
                this.ServiceManager.DatabaseConfigurationManager.ConnectionString,
                editorService.Query);
        }
    }
}

Running the menu command:



Simple I know but I wanted to show the command execution approach using services.

Plugin Example 2...

OK - not that exciting! Here is another example where a business object is generated from the result set...

Public Class MakeBusinessObjectFromResultsCommand
    Inherits CommandBase

    Sub New(ByVal services As IServiceContainer)
        MyBase.New(services, "Make BO from Results")
    End Sub

    Public Overrides Sub Execute()
        Dim editor As IEditor = Me.ServiceManager.CurrentEditor

        If Not editor.Result Is Nothing AndAlso _
         editor.Result.Tables.Count > 0 Then
            ' create some simple code gen using the results
            editor.Messages = GenerateClass(editor.Result.Tables(0))
        Else
            editor.Messages = "No results to generate code from."
        End If

    End Sub

    ''' <summary>
    ''' Given a DataTable (<paramref name="dt"/>), a basic VB.NET class is generated.
    ''' </summary>
    ''' <param name="dt">A DataTabel to generate a class from.</param>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Private Function GenerateClass(ByVal dt As DataTable) As String
        Dim code As New Text.StringBuilder()
        Dim fieldName As String
        Dim typeName As String

        code.AppendFormat("Public Class {0}{1}", dt.TableName, vbCrLf)
        code.AppendLine()
        code.AppendFormat(" Public Sub New{0}", vbCrLf)
        code.AppendFormat(" End Sub{0}", vbCrLf)
        code.AppendLine()
        For Each column As DataColumn In dt.Columns
            fieldName = "_" + column.ColumnName
            typeName = column.DataType.FullName
            code.AppendFormat(" Private {0} As {1}{2}", fieldName, column.DataType.FullName, vbCrLf)
            code.AppendLine()
            code.AppendFormat(" Public Property {0}() As {1}{2}", column.ColumnName, typeName, vbCrLf)
            code.AppendFormat(" Get{0}", vbCrLf)
            code.AppendFormat(" Return {0}{1}", fieldName, vbCrLf)
            code.AppendFormat(" End Get{0}", vbCrLf)
            code.AppendFormat(" Set(ByVal value As {0}){1}", typeName, vbCrLf)
            code.AppendFormat(" {0} = value{1}", fieldName, vbCrLf)
            code.AppendFormat(" End Set{0}", vbCrLf)
            code.AppendFormat(" End Property{0}", vbCrLf)
            code.AppendLine()
        Next

        code.AppendFormat("End Class")

        Return code.ToString()
    End Function

End Class


Running this command against the "select * from customers" query produces the following:

Public Class Table

    Public Sub New()
    End Sub

    Private _CustomerID As System.String

    Public Property CustomerID() As System.String
        Get
            Return _CustomerID
        End Get
        Set(ByVal value As System.String)
            _CustomerID = value
        End Set
    End Property

    Private _CompanyName As System.String

    Public Property CompanyName() As System.String
        Get
            Return _CompanyName
        End Get
        Set(ByVal value As System.String)
            _CompanyName = value
        End Set
    End Property

    Private _ContactName As System.String

    Public Property ContactName() As System.String
        Get
            Return _ContactName
        End Get
        Set(ByVal value As System.String)
            _ContactName = value
        End Set
    End Property

    Private _ContactTitle As System.String

    Public Property ContactTitle() As System.String
        Get
            Return _ContactTitle
        End Get
        Set(ByVal value As System.String)
            _ContactTitle = value
        End Set
    End Property

    Private _Address As System.String

    Public Property Address() As System.String
        Get
            Return _Address
        End Get
        Set(ByVal value As System.String)
            _Address = value
        End Set
    End Property

    Private _City As System.String

    Public Property City() As System.String
        Get
            Return _City
        End Get
        Set(ByVal value As System.String)
            _City = value
        End Set
    End Property

    Private _Region As System.String

    Public Property Region() As System.String
        Get
            Return _Region
        End Get
        Set(ByVal value As System.String)
            _Region = value
        End Set
    End Property

    Private _PostalCode As System.String

    Public Property PostalCode() As System.String
        Get
            Return _PostalCode
        End Get
        Set(ByVal value As System.String)
            _PostalCode = value
        End Set
    End Property

    Private _Country As System.String

    Public Property Country() As System.String
        Get
            Return _Country
        End Get
        Set(ByVal value As System.String)
            _Country = value
        End Set
    End Property

    Private _Phone As System.String

    Public Property Phone() As System.String
        Get
            Return _Phone
        End Get
        Set(ByVal value As System.String)
            _Phone = value
        End Set
    End Property

    Private _Fax As System.String

    Public Property Fax() As System.String
        Get
            Return _Fax
        End Get
        Set(ByVal value As System.String)
            _Fax = value
        End Set
    End Property

End Class


Motivation

My main motivation was the lack of speed I experience (no matter how fast my dev box) in using the "default" tools for SQL development. No way of customizing things easily further frustrated me. With a tool such as Mini SQL Query I can quickly add extras as I need them. For example, one plugin I plan of adding is focused on Access databases, I want to be able to write a query in an editor and push the .Net code to execute that query straight into my development project.

I will but publishing a first cut within the next couple of weeks and from there get some feedback etc.

Monday, May 14, 2007 2:38:15 AM (GMT Standard Time, UTC+00:00) |  |  | #
Friday, May 04, 2007

I don’t normally just post a link but this one caught my eye... From http://omg.worsethanfailure.com/

A blurb from the site:

The first ever Olympiad of Misguided Geeks contest at Worse Than Failure (or OMGWTF for short) is a new kind of programming contest. Readers are invited to be creative with devising a calculator with the craziest code they can write. One lucky and potentially insane winner will get either a brand new MacBook Pro or comparable Sony VAIO laptop.

Sounds really tempting!

Friday, May 04, 2007 2:12:41 AM (GMT Standard Time, UTC+00:00) |  | #
Tuesday, March 20, 2007