Upgrading to NBusiness 2.1

I finally spent some time last night updating this blog site. I still have a few things that I want to do but I got some of the big things out of the way. The first big one was upgrading to NBusiness v2.1, actually it was pretty easy to do but I wasn’t sure how it would work out.

For anyone out there running 2.0.1 and thinking about upgrading to 2.1 I’ll try to list some issues you are bound to encounter. The first one is the change from using the static CreateNew() method to using constructors. so if you have code like this:

Blog blog = Blog.CreateNew();

You will need to change it so that it looks like this:

Blog blog = new Blog();

Much better if you ask me! Also the old create new methods will still be generated but it will give you an obsolete error message so you can find and change them easily. You may also have to change references to NBusiness in your website, i had to alter a web.config file that had version information in it. Other than that I had to run the sql stored procedures it created on my new site to get it to work which is fine.

Also there is one big problem I encountered and that is that the scripts will generate sibling relationship tables and scripts and keys at the bottom of “complete.sql” not at the top with the rest of the tables! Which means if you try to run just the scripts be sure to search for ALL of the table drop/create scripts because I accidentally dropped my BlogsTopics tables when upgrading. Which turned out to be ok because I wanted to redo them anyway (I had too many useless topics) but it could have been really bad in a bigger site.

I’ll probably make NBusiness v2.1 available as the primary download on codeplex later today (you can get it right now from the planned release section).

The biggest new feature of NBusiness 2.1 is the ability to use some generated objects to create dynamic sql. So when you go to create custom fetch methods its much faster than the current system. The other features are listed on the download page.

Worse Than Win32 Programming

Here is my quote of the day from a conversation I had via instant messenger earlier today:

[13:04] justin chase: It’s not a native capability of .net winforms apparently
[13:04] justin chase: http://blogs.msdn.com/pedrosilva/archive/2005/03/09/391381.aspx
[13:04] Pat Cichanski: eck… win32 programming?
[13:04] justin chase: worse…
[13:04] justin chase: VB
[13:04] justin chase: :-X

Drop In

 

Last night I attended the monthly Twin Cities XNA User Group meeting. Instead of having a single presenter we have six members of the group stand up and talk about some projects they’ve been working on for 15 minutes or so. I have a feeling that everyone could have just gone on and on about what they were doing but, alas, there was no time.
I gave a presentation of the XNA game I have been working on called Drop In. Drop In is a pretty simple game with 3 screens. Also all of the artwork was created with Paint.NET and the music as created by Zach Adams along with some of the sound effects being created using a free tool called sfxr by DrPetter. So you can say that Drop In was created entirely with free tools!
Main Menu
 
Credits
 
Main Game
 
Code
The source code is broken up into an engine and Drop In specific projects. Currently it will only run on a PC but with some minimal hacking you could probably get it to work with an Xbox. I think the main problem is loading up XML files for settings off of the disk which I’m not sure if it will work.
One of the most interesting parts of the game is the AI used for one player mode. I created a reusable MinMax evaluator in the game engine library. I looked at a great applet created by Yosen Lin at Berkley as a reference for improving my implementation of the MinMax algorithm with Alpha Beta Pruning. It actually seems to work pretty well too. There are some deficiencies with how I evaluate states I think and also there is a problem where the computer will evaluate all states and determine that every move it makes will result in a loss and therefore it ends up making an effectively random choice. It doesn’t account for human error and should still probably try to pick the “best” of the losing moves.
Anyway, I have posted the code in its full form so you can play Drop In and also as prebuilt binaries if you don’t care about the code. You’ll need the XNA runtime to play it or the XNA Game Studio 2.0 to build it. I have also posted just my game engine in case anyone else is interested in creating a 2D game or just taking a look at the MinMax algorithm I have created in C#.
Next Steps
Next month’s user group meeting might focus on AI if so then I can talk more about the MinMax algorithm I implemented for anyone interested. I might actually be looking to improve this AI a little by then too, I’m thinking of including some sort of mechanism for machine learning for example. I am also toying with some ideas for changing the goal of the game and adding in some features for complexity. For example perhaps the goal shouldn’t be to just get 5 in a row but instead to get as many in a row as you can when the board fills up. I’m also toying with ideas of special pucks that do more than just drop, such as pucks that push other pucks down and pucks that blow up and pucks that change the colors of other pucks. Etc.
I also want to make the AI evaluate the state continuously, not just on the computers turn and include the possibility of network play… which should be pretty easily actually since I have abstracted the players pretty well.
If anyone out there has any motivation to create a 3D Puck model for me I’d be pretty happy about that! I’m looking to take this game engine (and Drop In) to the next dimension and to do that I will need some good models.

Twin Cities XNA User Group December 2007

This month at the Twin Cities XNA User Group meeting is a “Member Project” event, where members will show and talk about their various XNA projects instead of having a guest speaker. It should be pretty intesting.

I’m planning on showing a demo of a game I created called DropIn. I have an post about the game with source code on an old abandoned blog somwhere but I will probably repost everything to this blog sometime in the near future (once I get it working again that is).

So if you’re interested in XNA, pizza or swag then you should definitely come on down and check it out. At the very least you should get a good laugh watching me trying to show off my game!

Come on down to Magenic, on December 20th, 2007 at 6:00PM.

Dynamic SQL for NBusiness

I have been working on adding the ability to do dynamic SQL for NBusiness business objects. The point of this basically to allow a developer to quickly add new Fetch factories. Currently if you want to add a new fetch factory you need to do a few steps.

·         Create the factory method

·         Create the Criteria class

·         Add a handler to the Fetching event

·         Add a case to the fetching handler for your criteria object

·         Then call the Database Provider

·         Create the necessary stored procedure

Since needing to create new Fetch factories is a pretty common task I wanted to add a way to make it easier. NBusiness will generate all of the most common Factories and stored procedures for you (such as factories for fetching all entities or fetching by id’s or relationships) but if you want to be able to fetch by some other column type you’re stuck with creating your custom factories. For example if you wanted to search for all Customers with the first name of “justin” you’d need to create a FetchByFirstName(string name) factory.

So now rather than going through all of the steps above you can simple create your Fetch factory using dynamic SQL and pass that into the Database Provider instead. There is an object model for creating this dynamic SQL and NBusiness default templates will generate for you all of the Table and Column objects corresponding to your entities.

So for example if you have a Customer entity and you want to fetch by first name you might create a factory method that looks like this:

public static TopicCollection FetchByFirstName(string name)

{

    IQuery query = Topic.Queryable.Table.Where(

        Topic.Queryable.Name == “@name”);

       

    return new TopicCollection(

        query,

        new Parameter(“@name”, name));

}

NOTE: exact syntax may change; this is just an example of how I have it now.

Also, when we upgrade to Visual Studio 2008 these objects will be LINQ queryable. Meaning if you query your entities within a LINQ statement it will generate dynamic SQL for you to fetch the data for your entities (yes, like DLINQ).

Different Database providers will be able to implement their own Query classes so that SQL can be generated for different types of databases. For now I will just implement it for SqlServer 2005, in fact I’m probably going to push back the release of the MySql provider stuff just because as far as I know there isn’t really a demand for it at this point and it’s more work than it’s worth given that fact.