January 2007 - Posts

My favorite features of Vista #1

If you click on the time on the tray you will get the following window. Here you can set different clocks and you can click through the calendar as well. Very neat! Once you added more clocks try to hover over the date in the tray.  

ClickOnce for Orcas

ClickOnce has some new features in Orcas like support for WPF or alternative browser. To me the most interesting one is the ISV rebranding. I think this one lets you to modify the design of the publish.html page. I did a click through all the ClickOnce dialog side by side, but the only thing changed was a new checkbox called Use application manifest for trust information in the Publish Options dialog.

I hope that this will be changing in the next CTPs, because ClickOnce is one of my favorite technologies!

New C# 3.0 Languages features in Orcas

Local Variable Type Inference and Anonymous Types

Anonymous types let's you to create classes or structure with actually defining the class or structure first. So what you would do in Orcas to define a new car:

var myNewCar = new { Model= "Civic", Manufacturer = "Honda", Year = 2006};

instead of declaring the class first and providing value for all the fields:

public class Car
{
   public string Model;
   public string Manufacturer;
   public int Year;
}

Car c = new Car();
c.Model="Civic";
c.Manufacturer="Honda";
c.Year = 2006;

The var keyword in the first statement is called Implicitly Typed Local Variable. With this keyword you let the compiler guess what the type of the variable should be. 

Extension Methods

Extension Methods will let you to extend existing classes with the following syntax:

public static class myExtension
{
  public static void VeryNewMethod(this string s)
  {
     Console.WriteLine("VeryNewMethod says " + s);
  }
}

So if you check the parameters of the VeryNewMethod you will notice that parameters are looking a bit weird. The parameter definition this string s tells the compiler that you wish to extend the string class with this method. From now on you can call VeryNewMethod on any strings:

string s = "Hello World!";
s.VeryNewMethod();

Object and Collection Initializers

With the Object and Collection Initializers you will be able to instantiate objects and collections much easier:

public class Car
{
   public string Model;
   public string Manufacturer;
   public int Year;
}

Car myNewCar = new { Model= "Civic", Manufacturer = "Honda", Year = 2006};

or a collection

List<Car> myGarage = new List<Car>
{
   new Car{ Model= "Civic", Manufacturer = "Honda", Year = 2006}, 
   new Car{ Model= "Enzo", Manufacturer = "Ferrari", Year = 1999}
};

Query Expressions

Now with query expressions you can do the following type selections:

var cars = new List<Car>{
                  new Car{Manufacturer="Ferrari", Model ="Enzo", Year=200},
                  new Car{Manufacturer="Honda", Model="Civic", Year=2005}
                };

var newCars = from x in cars
                       where x.Year >= 1990
                       select new { CarName = x.Manufacturer + x.Model, Year = x.Year };

Lambdas Bound to Delegates and Expression Trees

   Car myDreamCar = cars.Find(c => c.Manufacturer == "Ferrari");

Lambda expressions are responsible that you can do the filtering for the cars without writing a new method.

Orcas' Very Large Number

The only living person ever known to count to infinity was Chuck Norris. He did it twice. No you can do this too with the help of the new numeric type BigInteger from the System.Numeric namespace. All you need to do is to reference the System.Core.dll and refrence the System.Numeric namespace in your app.

Counting to Infinity


I understand that the above example is not a really usefull one. See also: Introducing: System.Numeric.BigInteger for a more usefull example.

SQL Server Compact Edition

When first heard about the SQL Server 2005 Express Edition I thought this will be something like an updated MSDE - although even MSDE was a bit fat and heavy for my taste, especially for using to embedd DB to Winforms applications. I had hopes that SQL Express will be something lighter and easier to deply and embedd to your rich client apps. I could not be more wrong with this. I have new hope now and it is manifesting in this 5 letter acronym SQLSCE ( it is 6 letters actually, but I am not done with my first cofee yet).

SQLSCE stands for the SQL Server Compact Edition. It seems that they took SQL Server Everywhere from the Windows Mobile platform and made it possible to deploy and use on the PC as well, so this is now truly everywhere.

SQL Server Compact Edition product page at microsoft.com.

There are plenty of whitepapers available on the product page including a guide that helps you to decide, when to use Compact Edition and when to use Express:

SQL 2005 Compact Edition is recommended to use, when:

  • When you want essential relational database functionality in a compact footprint
  • Ideal for mobile and desktop applications, including occasionally-connected
  • Embeddable in applications
  • Free to download, develop, deploy, and redistribute

Not to use when:

  • When you need to run SQL as a service 
  • When you need multi user database server
  • When you need the full functionality of SQL Server

MSDN SQL Server 2005 Compact Edition How-to Tutorials.

There are some really good how-to articles on MSDN covering some of the features of the Compact Edition, but I missed the very basic one.

The one with starting from scratch

First you will need to create a database file. This is normally a file with a .sdf extension:

  1. Start the IDE and on Data menu choose Add New Data Source
  2. Select Database and click on New Connection
  3. Select Microsoft SQL Server 2005 Compact Edition
  4. In Connection Properties click on Cerate
  5. Specify the file name and password and click ok.
  6. The wizard will also ask you if you want to add this file to your project and if you want to store connection string in your application settings file.

RoboCopy is now part of Vista

This one alone makes me want to upgrade from XP :)

Robocopy, or "Robust File Copy" as it calls itself, is a command-line file copying tool introduced as a standard feature of Windows Vista, but which beforehand has always been available with the Windows Resource Kit, free to licensed users of Windows. Robocopy is designed for reliable copy or mirroring of entire folders of any size ensuring all NTFS attributes and properties are copied (except security-related ones unless specifically requested), particularly over network connections that are subject to disruption or outages. Robocopy's default settings are geared for this purpose, whereas other built-in utilities such as XCOPY require numerous command line switches in order to get this behavior. Copying of security information is supported, but isn't default and requires an explicit /COPYALL switch.

http://en.wikipedia.org/wiki/Robocopy

Blog it...

My attempt to design a blog header

My first attemp to design something good looking!