Home ::  Admin

chris carter's web log

Silent Movies or RhinoMocks CodeCast without Sound

9:42 PM Wednesday Jul 25, 2007 Comments: 3

So I'm awaiting my super duper new microphone which according to the UPS site, is sitting in a warehouse about an hour from me, so I'm guessing I'll get it tomorrow.  In the meantime I thought I'd practice the art of the screencast.

I'm a firm believer in testing code that depends on an external resource without actually hitting that external resource.  Take webservices for example.  You call a webservice and get  back "something".  Your code depends on that something.  Your code shouldn't care about where that something came from; that said, then why hit the webservice for real? Why not make up the "something" that the webservice is supposed to return and code against that? 

Here's the code I'm working against. 

Basically we have a customer with an ID.  A customer manager who's responsibility is to update a customer.  And a service interface that's expected to supply the customer manager with what it needs, which is the latest details of a customer provided by a service which is out of our own control.

Here's the codecast in a Benny Hill style :)

Re-Post: First Screencast Is Up!

8:20 AM Saturday Jul 21, 2007 Comments: 2

OK, figured out the avi compression a little better. Tried out a few apps that convert video formats and settled on Digital Media Converter. One attempt compressed my 290 meg avi file down to about 6 megs, but the quality wasn't great, so I bumped it up a little bit, and settled on 22 megs. I still have a lot to learn on video compression though, totally new concept for me.

Anyway, here is the build provider demo(remember, it's about 22 megs), again, it's just a proof of concept(so be gentle on the critique), but this site is using it so I know it(the concept anyway) has possibilities.Here is an updated download of the code, it includes the source for the activerecord buildprovider and a sample website.

"Hello World" with Firebird SQL and ActiveRecord

2:54 PM Tuesday Jul 17, 2007 Comments: 0

Same Concept, Different Flavor DB

OK.  Same "Hello World" example, but using Firebird RDBMS.  This one is a little tricky and the example needed some minor tweaks.  The configuration properties are obviously different.  And it only worked with a beta version found here and included in the download at the end of this post.

Minor Bumps in the Road

CreateSchema only likes being run once.  Running it the second time throws an exception.  However I get the same exception when running the drop table command from the Isql command window.  Not until I restart the database am I able to drop the table.  This has to be user error on my part, from being a noob with Firebird.

It also choked on cust1.Save(), so I changed it to cust1.Create().  Haven't investigated that one at all, so not sure what's up.

Installing Firebird RDBMS

First go download the file Firebird-2.0.1.12855-1-Win32.exe database software from here and run it.  It's a quick little setup that takes care of everything needed for installing the database.

Is Firebird running?

If you accepted all of the defaults go to Start > All Programs > Firebird 2.0 > Firebird ISQL Tool.  With ISQL running it's good to know what to do next.  Well for this example we'll need a database located at C:\data and the name of the database file will be customers.fdb.  So type in CREATE DATABASE 'c:\data\customers.fdb' USER 'SYSDBA' PASSWORD 'masterkey'; The screen looks like this:  

Firebird SQL .NET Data Provider

OK, now we need the Firebird SQL .NET Data Provider.  We'll need Version 2.1.0 Release Candidate 1 for .NET 2.0, so download Data Provider for .NET Framework 2.0 from here.  Run the installer.  Once that's done, we're ready to hook up our code.(actually I've included the data provider assembly with the zip but the installer has some other goodies in there that might be worth checking out).

View the Code!

Here.

Download the Code!

Here.

ActiveRecord "Hello World" View Source

10:50 PM Monday Jul 16, 2007 Comments: 0

Using my trusty source code viewer, here's the complete listing of my hello world example.

Source Code Formatting

10:45 PM Monday Jul 16, 2007 Comments: 0

I didn't like how the code was posted in the last post so I whipped up a quickie little code formatter.  It just does csharp, using squishySyntaxHighlighter.  Click here to view the pretty formatted source to my source formatter.  Isn't that a circular reference?

Castle ActiveRecord "Hello World"

8:2 PM Monday Jul 16, 2007 Comments: 1

Today I was running some batch processes that made it nearly impossible to code up anything while the jobs were running.  That is, nearly impossible to code inside of visual studio(2005).  So I decided to fire up good ol' Notepad and write what I'm pretty sure is the simplest "Hello World" program for using Castle ActiveRecord. 

The only thing needed is a target database, in my example I used SQL Server 2005.  Armed with a ready and willing database, we need to set up our config settings for ActiveRecord.  Since this is a hello world program, I'm going to do this in code rather than use a config file.  Here are the config settings we need to set when the app first starts:

Hashtable properties = new Hashtable();
properties.Add("hibernate.connection.driver_class", 
    "NHibernate.Driver.SqlClientDriver");
properties.Add("hibernate.dialect", 
    "NHibernate.Dialect.MsSql2005Dialect");
properties.Add("hibernate.connection.provider", 
    "NHibernate.Connection.DriverConnectionProvider");
properties.Add("hibernate.connection.connection_string", 
    "user id=scratch;password=scratch;database=scratch;server=(local)");

I've basically taken the simple example posted here and swapped out my settings.

Next we initialize the ActiveRecord framework and call the very handy CreateSchema method. This gem will do exactly that, make all of our dreams come true in the database. But right now is a good time to actually make something.

Enter the Customer. They have a first name and a last name and that's as complicated as I'm going to make them. They also have an ID we'll use as the primary key. The Customer looks like this:

[ActiveRecord("customer")]
public class Customer 
    : ActiveRecordBase{
    private int _id;
    [PrimaryKey(
        PrimaryKeyType.Identity, 
        "customer_id"
    )]
    public int ID{
        get{ return _id; }
        protected set{ _id = value; }
    }
    private string _firstName;
    [Property(
        "first_name", 
        ColumnType="AnsiString(30)", 
        NotNull=true
    )]
    public string FirstName{
        get{ return _firstName; }
        set{ _firstName = value; }
    }
    private string _lastName;
    [Property(
        "last_name", 
        ColumnType="AnsiString(30)", 
        NotNull=true
    )]
    public string LastName{
        get{ return _lastName; }
        set{ _lastName = value; }
    }
}

The Customer is very simple to keep in line with "Hello World". So the app is going to do this. Initialize the ActiveRecord framework, create our database schema for us, create a new Customer, assign first and last name, save, and assert that we have an ID.

Compiling

Since we're not in visual studio we'll need to grab the assemblies needed for ActiveRecord.  This is a "Hello World" example so I think I've got only the bare minimum needed for this example.  I grabbed the latest successful build from the Castle Build Server found here.  The assemblies we'll need are the following:

  • Castle.ActiveRecord.dll
  • Castle.Components.Validator.dll
  • Castle.Core
  • Iesi.Collections.dll
  • log4net.dll
  • NHibernate.dll

These assemblies are included in the download accompanying this post. I've included my ghetto build script(buildme.cmd), ie a command file that contains the csc.exe commandline with options set. 

Download the code here.

The Design of Everyday Things

8:50 PM Sunday Jul 1, 2007 Comments: 1

I'm reading The Design of Everyday Things right now, it's pretty good, makes you think.  Unfortunately kit makes me think that I'm not liking Subtext right now.  There are features I like better than dasblog.  There are features that do not work for me as well. 

I was trying to post a blog entry on CoolCommands and had a picture to post.  There is no obvious way to do that in Subtext.  It's on my local drive, I need to post it to my blog, how? I'm not even saying that there is "no" way to do this, I'm saying that it's not obvious to me(as i still don't know how to do this).  Seems pretty simple, should be anyway. 

Showing code on the web is annoying too.  Why is it always one way? that is, you post your code snippet, it gets formatted and now there's no way to edit it.  Also, there's no way to get just the source code, you have to cut and paste html code, and inserting code is always a pain as well.  These are the reasons why I'm always writing some piece of blog related software; this goes hand in hand with my rants on everything should have an easy button.  Things should work just as the end user expects them to, if not, there should be a choice for the end user to pick something that does work...