Improving Agility in Visual Studio
31.01.2008 13:46:00
|
Sebastian Jancke
What Visual Studio (2005) Professional lacks out of the box, is a good support for unit testing and build scripting. Actually, VS2005 Pro does not provide any support for it. So in case you don't want to buy the Team Edition (for testing support), looking for a free alternative, the following might be a solution.
TDD (with NUnit) is definitely at the heart of my day-to-day development process. But I was in a snit to call NUnit-GUI-Runner from the custom tools menu. Further, I needed a possibility to automate my release processes (compile, test, commit, tag, zip, name with version). On the java side of our dev world, I was used to Ant. And happily, there is a .NET alternative to crude MSBuild: NAnt.
Without going into the details of NAnt, one can say: NAnt is XML-based, easy to use, has a bunch of tasks and plugins for all sort of things (vcs's, io, vs-solution stuff, compression, ...) and can be easily extended with your own tasks/plugins. What's really cool about NAnt is the fact that it's Ant for .NET - I don't need to relearn anything and can reuse my knowledge of Ant (which is the standard build scripting system in the Java/eclipse world).
Using these visual studio addins:
saved my day-to-day dev life.
|
| Courtesy of Eric Harth and Olivier Chekroun |
|
| Courtesy of Eric Harth and Olivier Chekroun |
Running NAnt scripts is fairly easy. Running NUnit tests directly within the IDE (without buying TestDriven.NET) made my day. Both addins are written for Visual Studio 2005 (I don't know about compatibility with 2008). They are easy to install and use.
Both addins accelerated my development process a lot, because I don't need to leave the IDE any more for testing and my release process is now automated
Perhaps, one day someone ports these for VS 2008 (if they incompatible). Both are open source, so this task should be pretty easy.
Matrizenoperationen mit Extension Methods
30.01.2008 17:47:30
|
Thomas Schissler
Mit Hilfe der neuen Extension Methods in C# 3.0 können einfache Matrizenoperationen
ganz einfach als Methoden auf bestehende Objekttypen eingefügt werden. Ich habe hier
mal ein Beispiel mit SortedDictionaries. Diese Extension Method erlaubt das addieren
zweier Matrizen.
public static void AddDictionary(this SortedDictionary<int, decimal>
resultDictionary, SortedDictionary<int, decimal>
insertDictionary) { foreach (int key in insertDictionary.Keys)
{ if (!resultDictionary.ContainsKey(key)) resultDictionary.Add(key,
insertDictionary[key]); else resultDictionary[key]
+= insertDictionary[key]; } }
Der Aufruf gestaltet sich dann sehr einfach:
SortedDictionary<int, decimal>
a = new SortedDictionary(); SortedDictionary<int, decimal>
b = new SortedDictionary(); //Werte
in Dictionaries einfügen a.AddDictionary(b);
Ich finde die Extension Methods ne feine Sache. Natürlich sind auch beliebige andere
Operationen möglich.
.NET-Forum.de launched
29.01.2008 13:21:00
|
Thomas Freudenberg
A couple of days ago Jan Welker launched a new German .NET related community site, .NET-Forum.de. I didn't expect the developsphere to require just another site, but there are already 51 users registered, even though the site wasn't advertised anywhere except the dotnet-snippets.de newsletter.
Jan set up Community Server 2007.1 to drive the site (Did you know that .NET related non-profit communities may receive a free license?) I try to support Jan whenever he experiences issues with CS or has a configuration question. So for me it's an appreciated opportunity to get to learn CS's forum capabilities (Till now I only used the blogging part.)
I wish Jan success, and maybe this post will lead some more people to his site.

Mein erster Webcast zum Team Foundation Server SDK
26.01.2008 20:58:18
|
Thomas Schissler
WorkitemControl aus dem TFS SDK 2008
26.01.2008 20:30:05
|
Thomas Schissler
Des TFS SDK enthält ein Control um Workitems in Winforms zu bearbeiten. Dieses Control
löst damit das Problem, wie die hochflexible Struktur von Workitems in einer eigenen
Anwendung dargestellt und bearbeitet werden kann. Mit dem neuen TFS SDK 2008 gibt
es allerdings ein kleines Problem beim Einsatz des Controls. Wird das Control in eine
Winform eingebaut, kommt es zu einer NullReferenceException.
Object reference not set to an instance of an object.
Dieses Problem konnte ich bei mir umgehen, indem ich nicht die DLL aus dem SDK sondern
aus dem TeamExplorer. Ich habe die beiden DLLS, die ich hier ausgetauscht habe hier
zum Download bereitgestellt.
String.IsNullOrEmpty as Extension Method
25.01.2008 13:53:00
|
Thomas Freudenberg
Most you will probably know about Extension Method introduced with C# 3.0. If not, I strongly recommend to read ScottGu's explanation.
Anyway, a couple of days ago Brad Wilson posted an experiment:
What I wasn't sure was whether or not you could call these extension methods when you have a null instance of the object, since they're instance methods. The C++ guy in me said "sure, that should be legal", and the C# guy in me said "it's probably illegal, and that's too bad". Amazingly, the C++ guy in me won!
This code executes perfectly:
using System;
public static class MyExtensions {
public static bool IsNull(this object @object) {
return @object == null;
}
}
public class MainClass {
public static void Main() {
object obj1 = new object();
Console.WriteLine(obj1.IsNull());
object obj2 = null;
Console.WriteLine(obj2.IsNull());
}
}
When you run it, it prints out "False" and "True". Excellent!
When I read that I immediatley thought of another application. I guess all my readers are familiar with String.IsNullOrEmpty which was introduced with .NET 2.0. So I asked myself if you can make IsNullOrEmpty a parameterless extension method:
using System;
public static class MyExtensions
{
public static bool IsNullOrEmpty(this String s)
{
return String.IsNullOrEmpty(s);
}
}
public class MainClass
{
public static void Main()
{
string s1 = "Hello world";
Console.WriteLine(s1.IsNullOrEmpty());
string s2 = null;
Console.WriteLine(s2.IsNullOrEmpty());
}
}
Again, it prints out False and True. And in my opinion this syntactic sugar looks much more elegant than the ordinary String.IsNullOrEmpty(s2).
If only C# would support extension properties...

Problem beim Abfragen des Namen eines TFS-Servers über die API
24.01.2008 09:14:11
|
Thomas Schissler
Über die TFS-API kann der Namen eines TFS-Servers einfach abgefragt
werden. Dazu kann folgender Code verwendet werden:
private
TeamFoundationServer tfs;
NetworkCredential account = new NetworkCredential(user,
password);
tfs = new TeamFoundationServer(server, account);
string ServerName = tfs.Name;>
Dabei habe ich allerdings folgendes Problem festgestellt: Der Servername
ist nicht konsistent. Ist der Server im Team-Explorer noch nicht geristriert, enthält
der Servername auch den Port. Nachdem der Server im Team-Explorer dann registriert
wurde, wird nur noch der Server-Name zurückgegeben. Das sollte man auf jeden Fall
berücksichtigen, wenn man mit dem Name-Property vom tfs arbeitet.
Die nächsten fünf Geburtstage mit Access SQL berechnen
08.01.2008 22:10:00
|
Jürgen Gutsch
für eine kleine Communityanwendung die ich, zum 10 Jährigen Klassentreffen meiner alten Schulklasse und für meine alte Schulklasse, geschrieben habe, benötigte ich eine Funktion zum anzeigen der nächsten fünf Geburtstage. Voraussetzung war, so wenig Logik wie möglich in die Anwendung zu bringen um den Pflegeaufwand klein zu halten, das heißt: Alles was per SQL gemacht werden kann soll auch per SQL gemacht werden.
Die Herausforderung war jetzt anhand eines eingetragenen Geburtsdatums, das Datum des kommenden Geburtstages zu berechnen. herausgekommmen ist folgende Formel:
IIF(
DateAdd('yyyy', DateDiff('yyyy', [geburtsdatum], Now()), [geburtsdatum]) <= NOW(),
DateDiff('d', Now(), DateAdd('yyyy', DateDiff('yyyy', [geburtsdatum], Now()) + 1, [geburtsdatum])),
DateDiff('d', Now(), DateAdd('yyyy', DateDiff('yyyy', [geburtsdatum], Now()), [geburtsdatum]))
)
Erklärung:
Zuersteinmal berechne ich das Datum des Geburtstages im aktuellen Jahr, hierfür ziehe ich einfach das Geburtsjahr vom aktuellen Jahr ab und addiere die Differenz zu dem Geburtsjahr hinzu:
DateAdd('yyyy', DateDiff('yyyy', [geburtsdatum], Now()), [geburtsdatum])
In der IIF methode prüfe ich nun ob das berechnete Datum vor, oder nach dem aktuellen Datum liegt. Ist es älter, rechne ich ein Jahr dazu und ziehe das aktuelle Datum davon ab um die Diferenz in Tagen zu erhalten:
DateDiff('d', Now(), DateAdd('yyyy', DateDiff('yyyy', [geburtsdatum], Now()) + 1, [geburtsdatum]))
Ist das Datum neuer als das aktuelle, wird ohne ein Jahr hinzuzuzählen, die Differenz in Tagen zum heutigen Datum berechnet:
DateDiff('d', Now(), DateAdd('yyyy', DateDiff('yyyy', [geburtsdatum], Now()), [geburtsdatum]))
Auf diese Art erhalte ich die Anzahl der Tage bis zum Geburtstag und kann diese ebenfalls ausgeben. Nachteil an Access SQL ist, dass man scheinbar nicht nach Spaltenaliasen sortieren kann wie beim SQL Server. Daher muss die komplette Formel auch bei der Sortierung (ORDER BY) angegeben werden (es wird logischerweise aufsteigend nach dem berechneten Wert sortiert).
Der komplette SQL String sieht daher (etwas formatiert) so aus:
SELECT TOP 5 * ,
IIF(
DateAdd('yyyy', DateDiff('yyyy', [geburtsdatum], Now()), [geburtsdatum]) <= NOW(),
DateDiff('d', Now(), DateAdd('yyyy', DateDiff('yyyy', [geburtsdatum], Now()) + 1, [geburtsdatum])),
DateDiff('d', Now(), DateAdd('yyyy', DateDiff('yyyy', [geburtsdatum], Now()), [geburtsdatum]))
) AS unterschied
FROM [adressen]
ORDER BY
IIF(
DateAdd('yyyy', DateDiff('yyyy', [geburtsdatum], Now()), [geburtsdatum]) <= NOW(),
DateDiff('d', Now(), DateAdd('yyyy', DateDiff('yyyy', [geburtsdatum], Now()) + 1, [geburtsdatum])),
DateDiff('d', Now(), DateAdd('yyyy', DateDiff('yyyy', [geburtsdatum], Now()), [geburtsdatum]))
), [name]
Um das SQL mit SQL Server zu nutzen, müssen natürlich die entsprechenden Datumsfunktionen zum Berechnen verwendet werden.
Zugriff auf SQL-Server mit Access 2007
07.01.2008 18:16:04
|
Thomas Schissler
Unter Access 2003 gabe es Access-Datenbankprojekte (*.adp) mit denen man wunderbar
auf bestehende SQL-Datenbanken zugreifen konnten. Sind diese mit Access 2007 verloren
gegangen? Das nicht, aber sie sind jetzt gut versteckt. Um ein Datenbankprojekt mit
Access 2007 anzulegen geht man wie folgt vor:
-
Access ganz normal starten
-
Access fragt nun nach einer Vorlage für eine neue Datei. Hier das Icon "Blank Database"
auswählen.
-
Im rechten Bereich kann man nun den Dateiname angeben. Hier den File-Dialog öffnen.
-
In diesem Dialog kann man nun als Dateityp "Microsoft Office Access Projects" auswählen.
-
Wenn mann dann auf den "Create"-Button klickt kann man noch auswählen, ob man sich
zu einer bestehenden Datenbank verbinden möchte oder eine neue anlegen will. Der Rest
dürfte dann wieder vertraut erscheinen.
Workitem aus Visual Studio Fehlermeldung erzeugen
02.01.2008 14:45:07
|
Thomas Schissler
Aus dem Fenster mit Fehlermeldungen und Wahrnungen im Visual Studio heraus kann man
direkt Workitems auf dem Team Foundation Server anlegen. Dazu einfach die entsprechende
Zeile mit der rechten Maustaste anklicken und im Kontextmenü "Create Work Item" wählen.
Es werden automatisch Informationen in den Titel und den Verlauf übernommen, wobei
meiner Meinung nach die Details eher in das Beschreibungs-Feld gehören als in den
Verlauf.