Posted by admin in .NET
Today I tried to fix an automatic build on TFS. The build was failing because of the unit tests. The reason was simple but hard to figure. Let’s imagine the following scenario.
We have an interface IPet and we implement it in two dll’s, HousePets in a class Cat and in GardenPets in class Badger.
namespace HousePets
{
public class Cat : IPets.IPet
{ ... }
}
namespace GardenPets
{
public class Dog : IPets.IPet
{ ... }
}
namespace IPets
{
public interface IPet
{ ... }
}
And extra we have another class which is a loads an assembly and returns an implementation of IPet from one of the 2 dll’s.
public IPets.IPet GetCat()
{
Assembly catAssembly = Assembly.Load("HousePets.dll");
return (IPets.IPet)Activator.CreateInstance(catAssembly.GetType("Cat"));
}
Naturally this class is in a project that has no refference to either HousePets nor GardenPets.
If we have a unit test that uses it, in order for it to run, we just add the two projects as references to ensure that HousePets.dll and GardenPets.dll will be present in the bin directory of the unit test project.
While this works on the local machine, when ran in a TFS build environment it will crash. The reason is the static analysis that the TFS is starting. This is not detecting any object of type Cat or Badger and thus the libraries HousePets.dll and GardenPets.dll are not copied in the run directory.
The sollution is simple. Add a class in your unit project:
public class AssemblyInjector
{
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance",
"CA1804:RemoveUnusedLocals", MessageId = "c")]
public AssemblyInjector()
{
// make a call to a class of the library we want to be also copied in the
// test directory
HousePets.Cat c = new HousePets.Cat();
}
}
{ Disclaimer: don’t mind the implementation, it’s only there for illustrating the problem and the sollution }
No Comments »
Posted by admin in .NET
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 …
No Comments »
Posted by admin in .NET, tags: silverlight
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:
- There is no double click event on a row
- 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 »
4 Comments »
Posted by admin in .NET, tags: c#, html, xml
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:
- 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)
- 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.
2 Comments »
Posted by admin in .NET
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;
}
}
No Comments »
The past two days I tried to make a file server out of an older pc I had lying around. It had an MSI KT6V-LSR with an Athlon processor on it. Toghether with one 400Gb and one 500Gb harddrive I thought I could crop a machine for storing files. My primary OS of choice was Windows 7. I had also an XP around but I consider it too outdated to use and the Vista would be too slughish on this old hardware.
The problem I encountered was that Win7 was not booting on this pc. This is because on the Win7, Microsoft changed the boot sector (don’t ask me why) and older systems do not recognize this as a valid bootable disk and the only message I was getting was a “cannot boot from cd code 5” error. After scouring the net I finally found a sollution which I want to post here.
1. Get a Windows Vista boot disk. It does not matter it’s from a “friend” or yours. You won’t actually intall Vista, just piggy-back on it’s boot capabilities.
2. Boot from the Vista disk.
3. After selecting the language select repair. Afterwards, depending on the state of your harddrive and other stuff you should be getting the choice of running a command prompt. Do it.
4. Change the disks such that your drive now contains the Windows7 disk.
5. In the command prompt navigate to the drive with the Windows7 disk, go to the sources directory and type setup.exe and press enter.
6. Now the Windows7 will start installing and everything will go on normally.
Happy installing!
2 Comments »
Posted by admin in .NET
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
No Comments »
Posted by admin in .NET, tags: ASP.Net 4.0
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 »
1 Comment »
I just finished modding my computer with the goal of making it more silent. It all started with an Antec Sonata III 500 which was supposed to hold my new Core2Duo. I like this case. Sturdy build and quite heavy. It has springs for the harddrive mounts to dampen the shocks and sound, a good 500Watt source and gorgeos looks and also it is very easy to work with, especially with me poking my head inside it to check and modify stuff.
At that time I stuck with the Intel stock cooler which of course proved too loud. From the perfomance it was ok. I am not an overclocker so it was enough for the job. Still I needed to change it because it was loud as hell. I chose A Scythe Ninja 2 which can normally be used also in a fanless mode but I did not risk and installed also the provided fan, which is a 120×120 – 800rpm one (very quiet also).
My shock was of course that my system was as loud as before so I turned my head to the cooler on the VGA. This was a Saphire 4850 with a Zalman cooler; Noisy as hell as I saw, and thus I had to go for yet another upgrade which turned to be an Arctic Accelero S1 Rev.2. Also this is designed as a fanless sollution but again I wanted to play safe and added the turbo module which consists of 2 low rev fans barely audible.
All in all the system is now quiet and yet powerfull to play anything I throw at it. I could not make it dead silent but its miles from where it started. Below are some pictures I took along the process.
Read the rest of this entry »
No Comments »