Browsing:

Month: December 2009

SubSonic will be your friend

Subsonic claims to have a solution when you have better things to do than worry about Data Access. I, for one, am not very fond of the datalayer in my apps. I rather spend my time on the code instead of stored procedures and SQL queries. So, let’s go ahead and see if SubSonic lives up to its promise.

Let’s open the FrotMachine project from a few posts earlier.
Dowload SubSonic 3.0.0 and add a reference to the SubSonic.Core.dll in the Binaries folder:

reference

Next, create a database. I usually fire up SQL Studio Management Express and create a database by typing:

CREATE DATABASE FrotMachine
GO

Oh well, that’s almost too simple to mention.

Anyway, after that I go back to Visual Studio and add a new App.Config item and make sure it looks like this:

appconfig

Let’s create an instance of a Frot right now and see if a table and a record in the database are being made. But wait, we need to add the using statement for Subsonic first:

using SubSonic.Repository;

Now we can add to our Main method:

var f = new Frot();
            f.FrotID = 1;
            f.FrotName = "GUI Goodness";
            f.FrotDescription = "Create a nice GUI with whatever tool";

//this is the SubSonic part:
            var repo = new SimpleRepository("FrotMachine", SimpleRepositoryOptions.RunMigrations);
            repo.Add(f);

Let’s check out the database now:

table

Isn’t that nice.. it worked. SubSonic created a table and a record in my database. Quite good, isn’t it? It sure is a lot easier than NHibernate. And twice as cool at that.

This may be a trivial example. I’m sure I’ve got my point accross though.


Vista Hack “Requested registry access is not allowed” in Visual Studio projects.

How to hack Vista to get your Visual Studio installation to work on Windows Vista.

As we all know Vista can sometimes be a pain in the ass when it comes to permissions, on my journey for the installation of Visual studio I encountered the problem:”Requested registry access is not allowed”. Visual Studio can’t create any new projects because of restrictions in the registry.

How can we beat Vista security? well, once you have figured it out, it’s quite easy, although it took me 2 days and 3 system restores, the power is in the order of altering.

First you need to alter the authorization settings in your registry, make sure you are comfortable working in your registry, since you can cause a lot of damage to your pc if you do not know what you are doing.
select HKEY_CLASSES_ROOT right click ‘permissions’, this part of the registry doesn’t have any assigned users, so we will add ‘Administrators’ and ‘Users’ and assign them the privilege ‘ full control’ and click Ok. Now sit back, for this can take a while.

NOTE: make sure you have a back up of your registry and a system restore available, just to be safe!

hkeyclassrootmod

After this you can close the registry.

The second step will be to download a program called SubInAcl.exe and install this little program to your computer.
http://www.microsoft.com/downloads/en/confirmation.aspx?familyId=e8ba3e56-d8fe-4a91-93cf-ed6985e3927b&displayLang=en

next we’ll need to make a script to be able to hack our registry to alter the security settings:

open a notepad and insert the following lines:

cd /d "%programfiles%\Windows Resource Kits\Tools"
subinacl /subkeyreg HKEY_LOCAL_MACHINE /grant=administrators=f /grant=system=f
subinacl /subkeyreg HKEY_CURRENT_USER /grant=administrators=f /grant=system=f
subinacl /subkeyreg HKEY_CLASSES_ROOT /grant=administrators=f /grant=system=f
subinacl /subdirectories %SystemDrive% /grant=administrators=f /grant=system=f
subinacl /subdirectories %windir%\*.* /grant=administrators=f /grant=system=f

save the textfile as fix_registry_permissions.cmd

You can run the file by double clicking it, this is the part where you can leave the house and do some groceries shopping and start making dinner. Don’t worry, just sit it out.

registry_perVS

When the modifications are done, the cmd screen will disappear and you can restart your computer.

Now you will be able to successfully start Visual Studio. Good Luck!


Back to Basics: how to build a FrotMachine

Ever wanted to build a Frotmachine? I guess you would.

But, whatever is a Frotmachine?

A Frotmachine is a place where you can store your Frots.
A Frot is something you did to solve a problem quickly.

Well, let’s just start and create a prototype.
Let’s say that the Frot has a description and a category. So, there would be 2 classes in our program. Frot and Category.

Start Visual Studio (2010 or 2008, you’ll need the .NET Framework 3.5) and create a new Project. Choose Console Application.

Then create a new class and make it look like this:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace FrotMachine
{
    public class Category
    {
        public int CategoryID { get; set; }
        public string CategoryName { get; set; }
    }
    
    public class Frot
    {
        public int FrotID { get; set; }
        public string FrotName { get; set; }
        public Category FrotCategory { get; set; }
        public string FrotDescription { get; set; }
    }
}

That’s very nice, but nothings happens, yet. We should do something with this in the Main method in Program.cs.

So put the following code in the Main method from Program.cs:

Frot f = new Frot
  {
     FrotID = 1,
     FrotDescription = "Runas command",
     FrotCategory = new Category { CategoryName = "Windows" }
  };

   Console.Write("laatst heerlijk gefrot ");
   Console.WriteLine("in de categorie {0} met de {1}",
   f.FrotCategory.CategoryName, f.FrotDescription);

Now, build the program and then press Ctrl+F5 to run it.

This is the result:

laatst heerlijk gefrot in de categorie Windows met de Runas command
Press any key to continue . . .

Next time we’ll add the Frot to a database for retrieval.


Nog maar eens

Het is prachtig. Hierna begint het serieuze gedeelte .

private string FrotMachine(Frot f) {
throw new NotImplementedException();
}

itslet

itsltitslet de; m-v [ietselet]

if {scriptwerkt.2.0} = {F5}
then {mellie.happy = ok}
else mellie.happy = fail} end if