Oct 17

Today we received a task –create a TreeView Control in C# and list all files and directories within. Fair enough. You start off with grabbing the TreeView control onto your form, then you start writing your code, recursive directory calls…etc. You put it together. You start it off and the first thing that hits you in the face is the amount of time that you have to wait for your application to populate the TreeView.

My first thing was to modify the exercise; I added a ComboBox Control, populated it with the available drives and then created the SelectedIndexChanged() event which launched the population of the TreeView.

Life is easy, this exercise is easy - one might say. If you run this program on your local machine (or even better, on a laptop) you have no problem at all.

The first problem you might come across is the fact that older machines still have the precious “A:\” drive. Why is that a problem? When you populate your ComboBox it will check whether the drive is available. “A:\” drive is active and available, therefore it wants to go deeper into it and well, the drive is empty. Two possibilities exist to eliminate this error.

1. Try-catch :) But we definetly don’t want to go for the usual solution.

2. Instead of creating a string array to display the drives:

string[] drives = Environment.GetLogicalDrives();

you could create a DriveInfo array as shown below:

DriveInfo[] drives = DriveInfo.GetDrives();

(note that if you don’t use the System.IO namespace you need to write System.IO.DriveInfo.GetDrives();).

You then use a foreach loop to populate your ComboBox and you use the .IsReady() method to determine whether a drive is ready.

foreach (DriveInfo aDrive in drives)
{
 if (aDrive.IsReady == true)
 {
  comboBox1.Items.Add(aDrive);
 }
}

Okay, now you got rid of the problem, your code runs smoothly. Again, life is not that easy :)

When I tried to run my code at the uni, it keept throwing me a SecuritException. As you can imagine there are various policies used on the machines back there, with different permissions, etc. After doing some research I managed to find a great article on how to avoid this error message.

Let me introduce the procedure in brief. What you have to do first, is to create a Strong Name Key Pair. You can achieve this by running Visual Studio 2005 Command Prompt. There simply enter sn -k mykey.snk“. This will create the appropriate file (mykey.snk) for you. Don’t forget to copy this to your actual project folder!!! If the file is at the correct location open the AssemblyInfo.cs file within Visual Studio. (This file can be found in the Solution Explorer, under the “Properties”). Add the following line to your code:

[assembly: AssemblyKeyFile("mykey.snk")]

(note, you don’t put a semicolon after this line!)

Now you need to modify your security policy with the Microsoft .NET Framework Configuration utility. To start this up, enter “mscorcfg.msc” to your Visual Studio 2005 Command Prompt. Navigate to the following: .NET Framework X(version) Configuration > Runtime Security Policy > Machine > Code Groups > All_Code. (as shown on picture)
.NET Framework 2.0 Configuration
Here do the following:

  1. Right click on All_Code, and select New
  2. Create a new code group for your strong name, and hit next
  3. Select a strong name membership condition from the drop down box
  4. Hit the import button, and select your assembly. The configuration tool will import your public key. If you want to trust everything you sign with this key, leave the name and version boxes unchecked
  5. Select the FullTrust permission set

(at step 4 please note that an assembly is a .dll or a .exe file).

After you are done with the previous steps continue with these:

  1. Expand the All_Code code group
  2. Right click the LocalIntranet_Zone code group, and select properties
  3. Switch to the Permission Set tab, and select FullTrust

If you now compile and run your program, the SecurityException won’t appear! For further information and detailed explanation I recommend that you read the article previously mentioned.

Oct 08

We received our first task to be submitted till the 11th January 2008, please read it below:

Task: to develop a computer game called Wumpu’s world using Prolog. An hunter walks into the Wumpu’s world where there are a monster called Wumpu who can eat the hunter, pits that can trapped the hunter, and a heap of gold. By carefully playing this game, the hunter should avoid to be eaten by the Wumpu, avoid to fall into pits, try to pick up gold and try to explore the entire Wumpu’s world.

Now putting together the “world” is really straightforward:

1
2
3
4
5
6
7
8
9
10
11
location(hunter, r11). %start position, first row
location(breeze, r12).
location(hole, r13).
% second row
location(stench, r21).
location(glitter, r22).
location(breeze, r23).
% third row
location(wumpu, r31).
location(gold, r32).
location(hole, r33).

If we have all the fields, we can now establish the map:

1
2
nextto(r11, r12).
nextto(r11, r21).

where r11 is the start position and we have a 3×3 square so the fieldnames are r[row number][coloumn number].

Now we need to set the start position of the hunter which is:

1
here(r11).

I would like to mention one important thing. As we will move within our map we need to constantly update there here() function. As we declare here to have the value r11 it is a static declaration, therefore it cannot be updated. For example examine the following set of rules for the movement:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
% set up the movement between the locations
connect(X, Y) :- nextto(X, Y).
connect(X, Y) :- nextto(Y, X).
 
goto(Place) :-
can_go(Place),
move(Place),
look.
 
can_go(Place) :-
here(X),
connect(X, Place).
can_go(Place) :-
write('You can''t get there from here'),
nl,
fail.
 
move(Place) :-
retract(here(X)),
asserta(here(Place)).

Now if you’d try and run the following giving it the command goto(r12). would result in an error (No permission to modify static_procedure [procedure name]).

To avoid this the here procedure should be declared dynamic:

1
2
:- dynamic here/1.
here(r11).

Problem solved.

I will continue to post my updates on this assignment.

Oct 05

Requirements engineering form an important part of the Software Development Life Cycle. Over the years methodologies have changed, the whole SDLC changed and got replaced. Below is a diagram about the past and present approaches of the SDLC:

Requirements Engineering
1. Requirements Engineering
2. Analysis
3. Design
4. Implementation (incl. testing)

The diagram clearly shows the difference between the time and effort. If you put a sufficient effort into the requirements engineering right in the beginning of your development (yes that includes investing much more money into it as well) means that as you proceed on with the projects the less effort it takes to e.g. maintain the software being created. Whereas in older approaches less effort was put into the RE therefore making the implementation a nightmare. That meant, not gathering enough information caused many side-effects that needed to be corrected at the end of the project life cycle.

RE is not only important because of effort and time measures but the diagram also implies that if you spend more money on the RE then you have lower costs on the final stage. Assume you did not gather the necessary requirements in the first place, and you need to hire additional developers to keep up with the work-phase, it would really increase your costs.