chris carter's web log

Home |  Contact |  Admin
 

WPF And Visual Studio Crashes

Posted on January 6, 2009

I don't know what changed in the last week or so with my dev environment, but [seemingly] randomly, when working on WPF projects, Visual Studio kept crashing.  I found a link yesterday(can't remember where), that suggested repairing my .NET 3.5 SP1 installation.  I did that and and now no more crashes, since yesterday anyway.  So that's weird, why was that happening just in the last week? I haven't installed anything recently....at least not to my knowledge(Windows Update maybe??)

Looking Forward To 2009

Posted on January 1, 2009

Here are some of the things I'm looking forward to in 2009.

This Blog

I wrote the code for this blog, but it's not great.  Why write my own blog software? I write code for a living, and I write code for fun, it's what I do.  Part of the fun for me is using my creations, dogfooding if you will.  It gives me insight on how to build better software.  I'm no usability expert but I know what I like, so using my own shite helps to get better at usability.

Finding stuff on this blog is nearly impossible.  I have google search hooked up but the way it's set up is not helpful.  Either it's the way I post stuff or my lack of understanding of how to search my own crap with google, but I need to improve my blog search capability, that's a biggy on my todo list.  I've implemented my own search tool for the admin area, once I'm fairly confident that I can fend off a sql injection attack I'll put it on the main page.

Offline capability.  Blogging online is not fun.  Connectivity is annoyingly inconsistent, I don't know if it's my host, my connection, just the way it is, but it's annoying.  I would love to be able to compose everythingoffline and if it automagically stay in syc with panteravb.com.  Windows Live Writer? Nah, that sounds like a job for me and WPF, perfect chance to play in DirectX goodness.

The topics of this blog are not always technical.  This isn't going to change, HOWEVER, I do want to make sure those who couldn't give a crap about anything I have to say that's non-technical have the option to exclude that content. 

I tried tagging the content on this blog before but I didn't do a good job of it so that's on my todo list.

Screencasts/Codecasts

My 2009 plan involves at least one codecast per week on anything software related.  Huh, I guess that means one is due tomorrow, I better get crackin!

Personal Software Projects

I have so many little projects I'm working on, I want to set a schedule for getting them all done. I believe that having project plans and schedules works not just for stuff you get paid to do for work but also for personal projects. So I'm tasking myself with coming up with a timeline for all of my little projects.

Books

I have soooooooooooooooooooo many books I need slash want to read.  If you don't plan to read you won't, at least that's me, so in the new year I want to plan on reading  my non-tech books.  First on my list is a little one, The Art of War.  The rest of the books on my todo list in no specific order include Kitchen Confidential, Wisdom of our Fathers, Big Russ and Me, Notes From The Underground,The Omnivore's Dilemma,The Heroin Diaries: A Year in the Life of a Shattered Rock Star,The Forgotten Man, and World Without End.

Other Platforms and Tools

Sometimes(or most of the time) the best way to learn is to look outside of the platform and or tools that you're familar with and see how others do it.  Platforms that I want to take a look at include those running on a non-windows os, probably linux.   Php, Ruby on Rails, Java(yes, I said Java), and anything else to help me learn how to build better software faster.

Fitness

Today starts my serious commitment to my local crossfit affiliate, Emerfit.  I've been going zero to four times a week since September but have yet to follow the nutritional plan(which is the cornerstone to any fitness program).  So for the next 6 weeks, my commitment involves no eating out and no alcohol.  Also no food(or drink[except water]) after 7pm any night of the week.  I've taken on the The Power of Less challenge, and you can follow my progress at the forum here.

Balsamiq Mockups In Action

Posted on December 28, 2008

The Mockup

Click to go to Balsamiq Mockups!

The WPF Version(First Cut)

http://www.balsamiq.com/products/mockups

Taaz

Posted on December 25, 2008

Via Justine, I tried out Taaz, here are my results(click to enlarge):

Joking aside, try uploading your own photo, there's a slick little process you have to go through to identify the points of your eyes, lips, hair line, etc, it's really pretty cool.

OK...no more wine for me today.

Object.ConvertTo

Posted on December 23, 2008

Is this bad?

public static class ObjectExtensions
{
  public static T ConvertTo<T>(this Object @this)
  {
    return ConvertUtils.ChangeType<T>(@this);
  }
}
1
2
3
4
5
6
7

Testing the usage looks like this:

[Test]
public void ObjectConverter()
{
  Assert.AreEqual(1, "1".ConvertTo<int>());
}
1
2
3
4
5

ChangeType was stolen from http://aspalliance.com/852.  That looks like this:

public static class ConvertUtils
{
  public static object ChangeType(object value, Type conversionType)
  {
    if (conversionType == null)
    {
      throw new ArgumentNullException("conversionType");
    }

    if (conversionType.IsGenericType &&
      conversionType.GetGenericTypeDefinition().Equals(typeof(Nullable<>)))
    {
      if (value == null)
      {
        return null;
      }

      NullableConverter nullableConverter = new NullableConverter(conversionType);
      conversionType = nullableConverter.UnderlyingType;
    }
    return Convert.ChangeType(value, conversionType);
  }

  public static TResult ChangeType<TResult>(object value)
  {
    return (TResult)ChangeType(value, typeof(TResult));
  }
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28

 

Inside HyperActive

Posted on December 22, 2008

I'm finally getting around to documenting how to use this thing.  HyperActive is a tool I wrote to help generate Castle ActiveRecord classes by inferring details from a database schema. 

Hyperactive uses my SchemaProber to read a database schema, and the Dominator helps with generating the code. 

Step 1: Download the Code

 The latest release is 1.3.1.9 and can be downloaded here.

Step 2: Create the HyperActive Config File

Here is a config file for setting up HyperActive to run against the Northwind database running on your local system:

<hyperactive>
	<config>
		<add key="namespace" value="HyperActiveNorthwindSample.Data" />
		<add key="outputpath" value="Data/Generated" />
		<add key="basetypename" value="Castle.ActiveRecord.ActiveRecordBase"></add>
		<components>
			<component
				service="HyperActive.Core.NameProvider, HyperActive" />
			<component
				service="HyperActive.SchemaProber.IDbHelper, HyperActive"
				serviceimpl="HyperActive.SchemaProber.DbHelper, HyperActive">
				<param name="connectionString"
					   value="integrated security=SSPI;server=(local);database=Northwind;" />
			</component>
			<component
				service="HyperActive.SchemaProber.IDbProvider, HyperActive"
				serviceimpl="HyperActive.SchemaProber.SqlServerProvider, HyperActive">
				<param name="helper" type="System.String" value="$IDbHelper" />
			</component>
			<component
				service="HyperActive.Core.Generators.ActiveRecordGenerator, HyperActive"
				serviceimpl="HyperActive.Core.Generators.BasicActiveRecordGenerator, HyperActive" />
		</components>
	</config>
</hyperactive>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25

Things you need to provide.  namespace, all of your generated classes will be contained in this namespace.

outputpath is where the generated files will be saved; it can be relative to your project or absolute, in the config above I've chosen to go with a directory relative to my project's root.  I like putting generated files into their own directory.  Most of the time I generate partial classes and into the Data/Generated directory and then if i choose to extend any partial classes, I'll put those in the Data directory.

basetypename indicates what generic class the generated classes will subclass.  There are several ways of handling this, most of the time I use ActiveRecordBase or ActiveRecordValidationBase.

Components...

I ended up rolling my DI Framework.  Mostly it was because I needed to minimize dependencies on other frameworks but also because I wanted to see what it takes to make a my own dependency injection tool.  It was fun, brings up a good point though, how do you do dependency injection without having to also include Ninject, Windsor, StructureMap, or whatever the cool framework of the day is.

The different components that can be swapped out, are the NameProvider, SchemaProvider, and the ActiveRecordGenerator implementation.  There are some included in the HyperActive assembly or you can roll your own.

Step 3: Setup Visual Studio External Tools

I have directory located at C:\lib where I put common libraries that I reference alot.  Assuming that the HyperActive and hactive assemblies are located in that directory you can set up an external tool in Visual Studio with the following configuration:

Step 5: Got Database?

I know this works with the Northwind database.  You can download my script from me here or grab the installer from codeplex or use your own database.

Step 6: Set Up Your Solution and Generate!

I'm going with a picture is worth a thousand words. Here's what the solution looks like before code gen:

After code generation, we'll have this:

The generated Products class looks like this:

//------------------------------------------------------------------------------
// <auto-generated>
//   This code was generated by a tool.
//   Runtime Version:2.0.50727.3053
//
//   Changes to this file may cause incorrect behavior and will be lost if
//   the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------

namespace HyperActiveNorthwindSample.Data {


  [Castle.ActiveRecord.ActiveRecordAttribute("Products")]
  public partial class Products : Castle.ActiveRecord.ActiveRecordBase<HyperActiveNorthwindSample.Data.Products> {

    private int _productID;

    private string _productName;

    private string _quantityPerUnit;

    private System.Nullable<decimal> _unitPrice;

    private System.Nullable<int> _unitsInStock;

    private System.Nullable<int> _unitsOnOrder;

    private System.Nullable<int> _reorderLevel;

    private bool _discontinued;

    [Castle.ActiveRecord.PrimaryKeyAttribute(Castle.ActiveRecord.PrimaryKeyType.Identity, "ProductID")]
    public virtual int Id {
      get {
        return _productID;
      }
      set {
        _productID = value;
      }
    }

    [Castle.ActiveRecord.PropertyAttribute("ProductName")]
    public virtual string ProductName {
      get {
        return _productName;
      }
      set {
        _productName = value;
      }
    }

    [Castle.ActiveRecord.PropertyAttribute("QuantityPerUnit")]
    public virtual string QuantityPerUnit {
      get {
        return _quantityPerUnit;
      }
      set {
        _quantityPerUnit = value;
      }
    }

    [Castle.ActiveRecord.PropertyAttribute("UnitPrice")]
    public virtual System.Nullable<decimal> UnitPrice {
      get {
        return _unitPrice;
      }
      set {
        _unitPrice = value;
      }
    }

    [Castle.ActiveRecord.PropertyAttribute("UnitsInStock")]
    public virtual System.Nullable<int> UnitsInStock {
      get {
        return _unitsInStock;
      }
      set {
        _unitsInStock = value;
      }
    }

    [Castle.ActiveRecord.PropertyAttribute("UnitsOnOrder")]
    public virtual System.Nullable<int> UnitsOnOrder {
      get {
        return _unitsOnOrder;
      }
      set {
        _unitsOnOrder = value;
      }
    }

    [Castle.ActiveRecord.PropertyAttribute("ReorderLevel")]
    public virtual System.Nullable<int> ReorderLevel {
      get {
        return _reorderLevel;
      }
      set {
        _reorderLevel = value;
      }
    }

    [Castle.ActiveRecord.PropertyAttribute("Discontinued")]
    public virtual bool Discontinued {
      get {
        return _discontinued;
      }
      set {
        _discontinued = value;
      }
    }
  }
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113

Step 7: Take It For A Spin

 So to test out our generated code, I added a nunit test fixture that just does a simple query for a specific product.  That code looks like this:

using System;
using System.Configuration;
using Castle.ActiveRecord;
using Castle.ActiveRecord.Framework;
using HyperActiveNorthwindSample.Data;
using NHibernate.Criterion;
using NUnit.Framework;

namespace HyperActiveNorthwindSample
{
  [TestFixture]
  public class SmokeTests
  {
    [TestFixtureSetUp]
    public void TextFixtureSetup()
    {
      IConfigurationSource source =
        ConfigurationManager.GetSection("activerecord") as IConfigurationSource;
      ActiveRecordStarter.Initialize(typeof(Products).Assembly, source);
    }
    [Test]
    public void CanGetOneProduct()
    {
      Products product = Products.FindOne(Expression.Eq("ProductName", "Chai"));
      Assert.AreEqual("Chai", product.ProductName);
    }
  }
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28

Thoughts and Caution

OK. So the caution part of this has to do with how I do databases. HyperActive, in it's current form, supports how I and my co-workers slash colleagues currently develop databases.  This may differ drastically from the way you the reader develops against a database.  I almost always use sql server 2005+ and identity columns. HyperActive will most likely puke on schemas that have tables with non-identiy column primary keys.

HyperActive is not as flexible as it needs to be. Frameworks should be easy to extend if you are not the orginal developer.  HyperActive is easy to extend if you are me or really bored and feel like working through the framework's source, so to that end I need to refactor and simplify.

So anyway, there it is, I may have some more posts on this, but I have better ideas on how to improve it, so I might spend more time doing that.

The Code

Get it all right here http://panteravb.com/downloads/HyperActiveNorthwindSample.zip.

Unit Testing NHibernate and Castle ActiveRecord With SQLite

Posted on December 18, 2008

NOTE: This is about a topic that is NOT a new concept, only new to me.

As I'm working through incorporating S#arp Architecture ideas into my own architecture strategery, today(well, starting yesterday) I made the transition to using SQLite for unit tests.

There's not alot to add to the code I scraped from the web.

I started with using straight up ADO.NET and trying to create a table, do an insert, and query it. Then I moved into some code based on Ayende's post here to get NHibernate tests working.  I then moved on to Brian Genisio's ActiveRecord testing sample to get ActiveRecord testing under way.  Way cool. 

Here's my test test project.  It should work straight out of the gate, but lemme know if it doesn't(it's a 2.4 meg download, VS2008 SP1, latest code from Castle trunk).  I've included the SQLite .NET wrapper downloadable from here.

Sock And Awe

Posted on December 17, 2008

This is awesome: http://play.sockandawe.com/

Eva's a Bitch

Posted on December 17, 2008

This is Eva:

5 rounds of the following, 40 minutes max:

750 meter row

30 Kettlebell Swing(wmv)(2 POOD)

30 Pull ups

I only got 3 rounds.

This is my hand after Eva got through with me.  At least I didn't puke after the workout...

There Will Be Porn

Posted on December 17, 2008

I'm a fan of Zed Shaw.  He has nothing to do with .NET or anything I do on a daily basis but reading or listening to him rant about whatever has given me some good ideas for stuff I do or wanna do. 

Anway, he's got this farewell to Ruby and Rails thing.  INFOQ recorded his goodbye presentation at RubyFringe entitle There Will Be Porn.  It's about 49 minutes long.  I made it through the first half before skipping around to the end.  The last 5 minutes or so discussing what he'll be doing next was the most interesting to me.