Archive for the “.NET” Category

This weekend was all about Braidwood. For those not in the know, Braidwood is the reincarnation of Intel’s Turbo Cache memory. The buzz started with an article from Objective Analysis posted on InforWorld, here.
While the article was let’s say a nice report, it lacked on the technical part as the details on how it functions are very sketchy. This made me wonder what could you gain from using 16Gb of SLC memory on a mainboard. No, it is not intended to act as a harddrive and boot windows from it, but rather to act as cache memory between the harddrive and the system.
I guess we should look at the two operations a harddrive should perform, read and write. When writing the processor has most of the time the data in the memory and it sends it in chunks to the harddrive, this stores it in it’s cache memory and in mean time starts the spinning of the platters to begin the finding of a place to write the bits. Unfortunately this process is a long one, somewhere around 10ms, whereas the processor can get information from the memory under 1ms and thus at some point the processor has to wait for the harddrive to finish the writing and then it sends the next chunk. If we would have some more memory available on the harddrive, the processor could send more chunks and thus not wait until the harddrive finishes. This cache would be the SSD integrated in the mainboard, so we could see some improvements here, especially on many small files that need to be written. Of course for the user the feeling would be that yes, the files were written but the hdd led would still blink for a while, until the cache is emptied.
On the read part … well, there is not much where a greater cache can help, maybe only to store some very often used files such that reads on the harddrive are limited.

Somehow I don’t buy the panic the article starts spreading (OMG the SSD market will crash, there is no need for SSD’s anymore) . Jeez, while I think there are some improvements coming out, the harddrive is still an issue. It can only write so quick and read so quick. The initial begin of an operation will take the same amount of time, no matter the cache dimension or speed.
Also there is another big point to be made. While an SSD costs around 200$, to get the new turbo cache you would have to go through an upgrade to an I5 processor and a compatible motherboard, and that would set you down around 300$ and you still don’t get the same performance improvements.

Just my 2cents …

Comments No Comments »

These days I started looking into Silverlight and unfortunately my time was spent more on finding sollutions than actually implement something. I am so used to ASP and WinForms that somehow the new way of doing things in SilverLight is making me dizzy.

I started looking into DataGrid mostly and found two strange things:

  1. There is no double click event on a row
  2. The <enter> key is not caught in the OnKeyDown handler.

Of course there are solutions to this and based on some nice community posts I made my own implementation for the datagrid which is listed below
Read the rest of this entry »

Comments 4 Comments »

I guess every developer was asked at some point about making a website for a friend only to be taken aback by the technological limitations of the hosting provider.

I am a professional Asp.Net developer (of course I am versed also in winforms and all the other areas of .Net programming, but web applications are my specialty) and I am accustomed to work in relation with databases. When someone wants a website that normally requires at least a few tables and there is no database engine available, what do you do? Over the years I used two techniques: use xml based storage and javascript storage. Of course they are limited but the whole point is that for small scale applications they are sufficient. Here are some examples:

  1. http://www.orionmodels.ro : this is a javascript storage based application. It comprises of classic HTML, asynchronous loading using XMLHttpRequest and a script containing object definition and object instances (the models are actually javascript objects that are instanciated and then processed in the various pages of the application)
  2. http://www.mcmserv.ro: this is an xml storage based application. It is written in ASP.Net 2.0 and all the objects are serialized in xml on the web server. Pretty nifty and also has an html editor which saves html in the actual xml serialization (unfortunately that is on the administration side which is not available to outside)

Overall I am pleased with the results but it’s a technical trick and not something I endorse. Buy the heck a subscription with a database, normally it’s just a few dollars more.

P.S. Don’t mind the website’s design, I am not a designer … only a developer.

Comments 2 Comments »

I am certain that many of you encountered a need for a code like this:

switch (controlVariable)
{
    case 1:
        int i = 10;
        Console.Out.WriteLine(i);
        break;
    case 2:
        int i = 20; // compiler error here
        Console.Out.WriteLine(i);
        break;
}

This is not possible because the whole switch acts as a “declaration space” and only one declaration of the “i” variable is allowed. In order to overcome this, one has somehow to trick the compiler into considering each case as having its own declaration space. How we make this? Use the brackets:

switch (controlVariable)
{
    case 1:
    {
        int i = 10;
        Console.Out.WriteLine(i);
        break;
    }
    case 2:
    {
        int i = 20;
        Console.Out.WriteLine(i);
        break;
    }
}

Comments No Comments »

Read about it on ScottGu’s blog

Comments No Comments »

I was researching today how one connect to an Oracle database from .Net using Visual Studio 2008 and ODP.Net (Oracle Data Provider for .Net). What I initially tried and what I will talk about is to add a new datasource to a project. I will not go into specific programatic access but into configuration.

First thing you have to do is download ODP.Net from the link above and install it. In the installer two things have to be done. Select the type of install and pass the prerequisites. On the type of install I could not understand the choices mainly because the texts for the two available was 90% identical, but the ideea is that the first one is for instalation on a machine that does not have the oracle installed on it, while the second was for the machines with it.

The second part of the install is also nasty from a usability point of view. I am running Windows 7 RC1 and at this time the installer does not recognize it as a supported OS. Fair enough, but you have to guess that you need to tick the checkboxes of the failed prerequisites in order to be able to continue. Afterwards it was click and continue until, again you are dumbfounded at the end screen. It says everything is done and you have a close button and that asks if if you are sure you want to exit. Are you crazy ?! What else can be done on that screen!

So we now have ODP on our machine. Fire up Visual Studio and open your project and the “Add new data source” wizard. Select New connection and ODP and that should do it. NOPE! This is not an MS driver, you have to work to get things done. You have to go now to the directory where ODP was installed, in the Network\Admin subdirectory and copy from the sample subdirectory into its root the two files “tnsnames.ora” and “sqlnet.ora”. Then modify them according to your oracle configuration (you can find examples on the web).

After modifying the configuration files go to Visual Studio again but make sure (if you’re on Vista or Win7) to run it as administrator. In the add new connection when selecting the ODP.Net driver you are now presented also with an option for your particular connection specified in the tnsnames.ora. Another trick needed here is that when filling in the user name this is automatically transformed to uppercase. If you have a username in lowercase you need to go to advanced and change it to lowercase from there.

Done. Really … done. You have now a data source connection and can create your datasource from an Oracle database. What it’s left is to get your hands on a linq connector for Oracle … but you have to go to other parties like DevArt because Oracle can’t be bothered.

Cheers

Comments No Comments »

All of us heard of the upcoming ASP.Net 4.0 and Visual Studio 2010 due in Q4 2009 so I thought on listing the highlights on the ASP side. You can find the original whitepaper here.

  Read the rest of this entry »

Comments 1 Comment »

One of the challenges of today’s projects is automatic tests. When we speak of automated testing we always target repeatability, meaning what we test today we must be able to test tomorrow and later. This is easy for database independent applications but when your testing functionality that modifies data you always find yourself wondering how can you ensure that when the tests start you have correct data.

Just to exemplify we will give an example. Suppose you have a table User with fields Id and Name. Your functionality needs to make an insert into this table but only if a user with the same name does not exist. You make an NUnit that tests the insert, when the tests runs a new user is inserted. But what happens when you run the second time the test? Well the insert will not execute as the user already exists. To avoid this situations you have 3 choices:

  • run a script at the end of the test that will clean up any existing data (you can do this also at the begining of the test). The main problem with this is that it is hard to maintain, especially when the database changes or there are many foreign keys involved.
  • restore a fresh copy of the db at the beginning of the test so you always have the same initial data. This is time consuming and the initial state of the database might change over time so you might have to manually maintain the “fresh” database.
  • use the rollback mechanism of the database.

If we are using NUnit and SqlServer the third choice is an easy one both in implementation and maintenance. There is a mechanism provided by TeamAgile which lets you specify that a test should have the data rolled back when the test ends. The idea is simple. When the tests starts, it informs the database that all the operations in the current thread context will be executed in a transaction and at the end it will instruct the database to do a rollback. The maintenance is eased because the database you use can be a copy of the live database and this suffers no data changes from test to test.

Now we get to the hard part. NUnit test data rollback is solved but lately all big web application also use automatic tests for the interface. The tools vary: Selenium, QTP, WatiN (our choice) or others. Now for this tests data rollback cannot be used like in the case of NUnit because each request gets it’s own thread context and all the other methods have their problems as stated above. So we get to the same problem. How can we do data rollback in automated web tests?

The solution I chose is easy, but depends on the data access layer implementation. For example we have a single point where SqlCommand’s are created and that is good because we can use transactions. The idea is simple; any time a database call is made we check if we have a transaction started and if so then we will execute the call within the existing transaction. But this is implemented in the data layer and our tests are done on the interface layer and we have to somehow connect them.

Create a special page where you  have two buttons and a textbox. One button is for starting a web transaction and one for rollback -ing a transaction. When the start button is pushed we make a call to the data layer to create a web transaction. This looks in a dictionary and gets us an unique id (i.e. an int) which will identify our transaction and this id we will show in the textbox and our tests records it for later use. Then we do our tests in the web pages like usual. When we finished we go to the same page enter in the textbox the transaction id and instruct to rollback.

I will post later some code to this so stay tuned …

Comments 1 Comment »

Ok, this should be a nobrainer for most of C# developers, me included. Still it happened to me and believe me I was dumbstruck.
I wrote a piece of code like the one below:

namespace TestInheritance
{
public class BaseClass
{
public BaseClass(string parameter) {}
}

public class ChildClass : BaseClass
{
public ChildClass() {}
}
}

Nothing special here but on compile time you get an error: “No overload for method ‘BaseClass’ takes ’0′ arguments“. Doh! how come? We don’t expect this to happen ussually but the little devil here is the inheritance and the non default constructor of the base class. When the constructor of the child class is called, it calls first the constructor of the base class with the same parameters. But if the compiler does detect a non default constructor it will not create the default one. So you get this error.

Cheers!

Comments No Comments »

Once upon a time in Developer Land, a developer was instructed to build a page that will show the great achievements of the ancients. He diligently started to create a model and used all that he could think of in order to make it good and make its employers proud. He added text and used nice fonts and alignment tags. He used lists to enumerate battles and deeds, and images to depict the stories.

The developer was good in his work and always printed his masterpieces at InternetExplorer’s shop because they were good friends and got to know each other well. And so his latest work got printed there also and it was looking marvelous.

Unfortunately this developer never got to read all 100 Commandments passed down to developers and stopped just short of 57 where it said:

“All tags should be finished by /> or </ …>”

But his friend, the apprentice from InternetExplorer shop knew him well, and if he found a tag not looking like it should he tried to make the best out of it and it was always good.

One day the employers hired a new developer and he was good also, but this one had read the commandments and even though he did not remember them all he had a tool that checked those rules and saw that in his colleague work an <img> tag was missing the end tag and he added it. When printing it at InternetExplorer shop it was looking fine. But there was you see something wrong, as this infamous tag was looking at first like this:

<img id=”imgAchievement” >

but after the second developer with his tool had modified it, it looked like this:

<img id=”imgAchievement” alt=”" />

Now the apprentice at InternetExplorer shop saw this but did not know where is the image that he should put in place and he said to himself that the developer erred and he went about his work and everything was good.

But one day a client said “I don’t like the guys at InternetExplorer shop and I want to use FireFox shop to print” and so he did, but there the apprentice of FireFox was a genius and knew all commandments and when looking at the <img> tag, he saw it was not saying where the image was and so he went about and did what he knew was right and showed there a picture of the whole artwork. But this was not good for the customer and so they tried to fix it but the developer could not speak with the apprentice from FireFox shop because they spoke different languages and only knew what the client said and so they struggled for what seemed to be an eternity.

Then the original developer remembered that a long time ago another client used to print this work at FireFox shop and that there was no problem and so he said “Why don’t we give this customer what I gave the customer from a long time ago ?”. And this was good ’cause the print was fine and wonderful and this because of one tiny thing. The old print had the old <img> tag which the apprentice from FireFox shop saw it was wrong and incomplete and ignored the troublemaker.

But our story does not end here because the new developer was a perfectionist and his proofing tool never failed and when he saw that the model was wrong again he modified it unaware of the troubles it would bring. A while later another client went and used the FireFox shop and the problems were there again. But this one was determined to find out why, and so he took the long journey to the city where FireFox Inc. had shop and through endless discussions and sign languages he found what the problem was, and then he was struck. He did not need that <img> tag, it was not doing anything but trouble and so he removed it and that model was still printed for years to come even on the shop of Safari Inc.

Conclusion

You see young developers we all must abide by the commandments, because by them work also the print apprentices ,and while some learn our habbits and move and make shop in other countries calling themselves FireFox 2 or FireFox 3.0.3 or Internet Explorer 6.1 or 7.0 they all know the commandments. And if we make the model by those commandments we can be sure the prints are as we envision them.

Comments 2 Comments »