The Hoju Saram

Friday, December 22, 2006

Merry Christmas Everyone

Hi All,

Well it is that time of year again, so "Merry Christmas and a Happy New Year", and to my friends who are in countries who don't care to much for Christmas I hope you have a nice day at work.

I will be enjoying the pool and my new deck on the big day, with family and friends.

And don't forget. Santa likes milk and cookies ( and sometime something a little stronger ) and the reindeers need some carrots and a bucket of water. Hope you have all been good this year and the elfs have made you something special

Blog again in the new year.. Ho Ho Ho

Thursday, December 21, 2006

Source for Drag & Drop, Paging , filtering gridview page



kick it on DotNetKicks.com

Note: There is an updated version of this here

I finally got around to putting a useable C# website solution file together for the Drag & Drop, Paging , filtering gridview page. You can download the zipped vs2005 solution Here .

There are a couple of steps to get it working.

You need to create a new empty database on your SQL server and run the SQL code file that is in the DatabaseSetup folder of the solution this will:

  • Create a customer table
  • Create a stored procedure to query the customer table as required
  • Fill in the customer table with some test data.

You will then need to grant access to those SQL elements so that you can access them from your .net solution.

The solution file contains a single aspx page that holds a standard gridview and code that does all of the logic. The data is accessed from the database via DataClass. I have created an Interface called IpagingFilterDataSource that matches what is required if you want to write your own class to do the datahandling. This will obviously be required if you are going to extend this in anyway.

public interface IPagingFilterDataSource
{
int GetDataSize();
int GetDataSize(string FilterField, string FilterVal);
DataSet GetPage(int Pagesize, int CurrPage, string SortCol, string SortDirection);
DataSet GetPage(int Pagesize, int CurrPage, string SortCol, string SortDirection, string FilterField, string FilterVal);

}

In this solution I put together a class MyCustomSQLPageFilterDataSource which supports the IpagingFilterDataSource and retrieves data from the customers table of the test database via a stored proc called up_Customers_list.

In the page_load event in the default.aspx.cs file there is a line

MyCustomSQLPageFilterDataSource MyDataSource = new MyCustomSQLPageFilterDataSource("SQLServer", "CustomerTestDatabaseName", "Uid", "passwd");

You will need to change this to suit your setup based on the database that you created and the userid and passwd for it.

The solution provides a page with a gridview that supports the following features:

  • Click on headers to sort columns
  • Drag & Drop headers to re-order columns, changes persist over pages.
  • Right click on Column headers and filter on entered values
  • Page through data and page size is adjustable in the URL (Count Parameter)
  • Exporting to excel and a highly experimental mail merge via word using the “client siding” techniques I have blogged about before.

Here are some additional screen shots of it in action:

Drag and drop in action
Right-click on column header and filter
After Filter Applied
After adjustment of pagesize to 5

Labels: , ,

Wednesday, December 20, 2006

The brakes in the middle !!



I'm not going to say who this is, he know who he is. $135 dollars and 3 points. Ouch!!!


Interestingly though the red lights in the photo look like they have been enhanced by a 2 year old with a very bright crayon.

Extending SQLRoleProvider to Support Active Directory Group Membership.

This is a ASP 2.0 + solution, for ASP .Net Apps using Integrated Windows Authentication. Please note this post has been updated.

The System.Web.Security.SqlRoleProvider allows you to store and manage Roles for your .net web applications in an SQL Database. This is very useful for building ASP .Net application where you want to a group of “admin” end-users to be able manage who can access a system and what they can do. ( I will talk about building a AD integrated System access management system in a later blog, right now I will concentrate on the nuts and bolts).

Using the standard SQLProvider system roles are provided on a per user basis, so if you have thousands of users for the system then you would need to actually add each user individually. The whole point of this is to provide “end-user” system management, so I want to make it as easy as possible.

Then I thought that it would be much easier if I could extend the default SQLProfileprovider to support Active Directory groups. That way if a set of users where already defined in Active Directory group then all the “admin” users would need to do is grant that group the role in the application and that would give everyone in that group access, and keep the system far more manageable.

If you haven’t already used an SQL Roleprovider then you need to go the http://msdn2.microsoft.com/en-us/library/ms998314.aspx and follow the instructions related to the SQLRoleprovider. This will install a default installation of the Role provider database that integrates with the standard system.Web.Security.SqlRoleProvider. Make sure that if you run the stored procedures the application name matches the applicationName in the Providers Key in your web.config and make sure that the name you use is your Domain\User name.

So for example if I have AppName of SQLProviderTest a Role called Admin and my user is MYDOM\User1 so I issue the commands.

EXEC aspnet_Roles_CreateRole 'SQLProviderTest', 'Admin'
EXEC aspnet_UsersInRoles_AddUsersToRoles 'SQLProviderTest', ' MYDOM\User1', 'Admin', 8

And the web.config section would look something like this

<roleManager enabled="true" defaultProvider="SQLRoleProvider" cacheRolesInCookie="true"> <providers> <add name="SQLRoleProvider" type="System.Web.Security.SQLRoleProvider" connectionStringName="SqlRoleManagerConnection" applicationName="SQLProviderTest" /> </providers> </roleManager>


If you then compile and run default.aspx as specified in the instructions you it should display that you are in the role.

So we need to extend the standard SqlRoleProvider to support groups. Below is the code for the ADSQLRoleProvider class. To implement this do the following steps:

In visual studio create a App_Code folder under the root directory of your web project.


Add new class file in this folder called ADSQLRoleProvider.cs
Paste the following code into the class code file and save it.

using System;
using System.Collections.Generic;
using System.Text;
using System.Web.Security;
using System.Web;
using System.Security.Principal;

/// <summary>
/// Summary description for ADSQLRoleProvider
/// </summary>
public class ADSQLRoleProvider : System.Web.Security.SqlRoleProvider{

public ADSQLRoleProvider(){}

#region ADLookup & Support Methods

private string[] getusersADgroups(IIdentity User)
{

//HttpContext.Current.User;
WindowsIdentity Wident = (WindowsIdentity)User;
List<string> groups = new List<string>();

IdentityReferenceCollection UGroups = Wident.Groups;

foreach (IdentityReference Grp in UGroups)
{

NTAccount acc = (NTAccount)Grp.Translate(typeof(NTAccount));
groups.Add(acc.Value);
}

return groups.ToArray();

}
private string[] GetRolesForGroup(string groupname)
{
return base.GetRolesForUser(groupname);
}
#endregion

#region Extended SQLRoleProvider Methods
public override bool IsUserInRole(string username, string roleName)
{
if (base.IsUserInRole(username,roleName))
{
return true;
}
else
{
string[] Ugrps = getusersADgroups(HttpContext.Current.User.Identity);
string[] GroupsRoles;

foreach (string g in Ugrps)
{
GroupsRoles = GetRolesForGroup(g);
foreach (string grole in GroupsRoles)
{
if (grole == roleName)
{
return true;
}
}
}
}
return false;
}

public override string[] GetRolesForUser(string username)
{
System.Collections.Generic.List<string> roleList = new List<string>();

string[] ActualUserRoles = base.GetRolesForUser(username);

//Only do the next check if the username matches the current web user and the users roles are empty

if ((ActualUserRoles.Length == 0) && (username.ToLower() == HttpContext.Current.User.Identity.Name.ToLower()))
{

string[] Ugrps = getusersADgroups(HttpContext.Current.User.Identity);
string[] GroupsRoles;

foreach (string g in Ugrps)
{
GroupsRoles = GetRolesForGroup(g);
foreach (string grole in GroupsRoles)
{
if (!(roleList.Exists(delegate(string s) { return s == grole; })))
{
roleList.Add(grole);
}

}
}
return roleList.ToArray();
}
else
{
return ActualUserRoles;
}
}
#endregion
}



Open the web.config file and make sure that the original connection string for the Roleprovider database is correct.
Change the role provider section in the web.config to

<roleManager enabled="true" defaultProvider="ADSQLRoleProvider" cacheRolesInCookie="true"> <providers> <add name="ADSQLRoleProvider" type="ADSQLRoleProvider" connectionStringName="SqlRoleManagerConnection" applicationName="SQLProviderTest" /> </providers> </roleManager>

Compile the website to make sure you don’t get errors.

You have now update the application to use a custom sqlroleprovider that will first check for roles of a user, and if it doesn’t find any it will then check for any roles belonging to any Active Directory groups that user is a member of.

To test that this is working remove yourself from the role by running the stored proc aspnet_UsersInRoles_RemoveUsersFromRoles

For my example above this is

EXEC aspnet_UsersInRoles_RemoveUsersFromRoles 'SQLProviderTest', 'MYDOM\User1', 'Admin'

Re-run the application to make sure that you are not in any roles.

Now add a domain group that you are a member of to the Admin role. For my example the user MYDOM\User1 is a member of MYDOM\IT_Apps group so I will add that one with the Stored proc command

EXEC aspnet_UsersInRoles_AddUsersToRoles 'SQLProviderTest', ' MYDOM\IT_Apps', 'Admin', 8

If you run the application again you will see that you are in the role.

In up and coming blogging I will talk about how to build the user-front end to this, that allows users to search, select and assign roles to AD users and groups. This will allow you to build easy use managed applications with role based security. Some screen shots of what I am talking about are below:




Labels: , ,

Taxi Claus brings retro electronics joy


Thanks for the present Taxi Claus !!! Oh and also to your little elf Toxi.

Nothing like a bit of retro electronic gaming to make Christmas fun !!

Tuesday, December 19, 2006

Deck is finished


Well after many early mornings I finally finished the deck this morning, just in time for Xmas. Still need to give it a coat of decking oil, but that can wait for a bit later.

Swim anyone ??
If your interested in seeing the evolution of the deck on the blog the previous posts are:


Friday, December 15, 2006

Worst Cars Ever Sold


Saw this book in a book shop yesterday, had a bit of a read through it. Pretty fun.
I noted that it did mention the Reliant Robin. The car described by many as the car you buy “when you can’t afford a proper bike”.

I personally think the Lada Niva should have been included.

Labels: ,

New LG mobile

I got a new mobile phone. Took a a couple of pics to test it out.

Hands!!

And the amazing boy snail !!.
Thanks to Simon for Tricking me out !!

죽겠다, 마졌다 – and “your driving me nuts”

죽겠다 (R:Chook-get-da) literally means “will die” and미졌다 (R:me-chyot-da) literally means “will be crazy”. These are used in korean to over emphasise something. For instance in english you would say “I am so hungry I could die”, in korean you pretty much say the same thing.

배고 파서 죽겠다 (R: bea-go-pa-soh Chook-get-da)

미졌다 – can be used the same way.

배고 파서 미졌다

A much more interesting use of crazy is in the following sentence.

내가 미져,너 때문에 내가 못 사라 (R: nae-ga me-chyo , no dae-num-eh nae-ga mot sa-ra )

Literally in english this “I’m crazy, because of you I can’t live”, but its true english meaning is something like “your driving me nuts”.

Labels: ,

Friday, December 08, 2006

꿀꿀 != Oink

It is obvious that words have different sounds in different languages, but did you know that “oink,oink” is completely unrecognisable as a pig sound to a lot of the world. This lead me to wonder if some sort of international animal noise conversion services is required, or some international standards body to sort this out.

In korean a pig noise is꿀꿀 (R: Kul Kul ), and a cow goes 음매 (R: eermae) not “moo” , someone definitely needs to sort this out. I call for a symposium on the matter !!!

Research into Computer Vision

Lately I have been doing some thinking about research into computer vision, specifically in the area of motion detection and object recognition. I want to get a handle on the basics before I make a decision into whether or not I would like to study this as part of a Masters of IT. As part of this I have come up with an idea to help me along the way. My approach is going to be two fold:

1) Develop a system to simplify objects in a video stream.
2) Develop a system to classify and/or recognise objects of interest based on their attributes and persist these objects across frames.

1. is obviously dependent on 2. so I am starting with 1.
I currently have under development an application that takes a video stream from a webcam/IP Camera and simplifies the image. Basically I am working on the idea that objects boundaries are found be determining areas of rapid pallette change in a given video frame.

The video simplify system basically works this way.

1. Get a frame from a video stream
2. Pre-Process the frame with some despeckling routines to remove the noise.
3. Pass the frame through two filters, both do the same thing put with different parameters. The filters to the following:
Edge detect the image
Binarise the edges based on a threshold
Skeletalise the binarised edges

The process looks like this:

Original Image


Edge Detected



Thresholded and sketalised




Merged results


So from a video stream we now have a simplified wire frame model of the view. Note this is in real-time ( about 11 fps on my mobile centrino ).
I am getting quite a bit of noise in the images because I am using a really cheap web camera for this. I will definitely need to upgrade if I want to take this further.

The other part of this is object persisitance, the reason I want this is because if you can persist (recognize and remember) an object across more that one frame then it is possible to build a system that can judge distances with a single camera. If you can judge distances then you can navigate obstacles. Will post more on this when I have done some more.