Home | Blog | Publications | Photos | Services | About | Contact

Blog Archive - July, 2008

Back to Blog index.

Tue, 29 Jul 2008 15:05:27 GMT:
Adobe Lightroom 2.0 available

Adobe has today announced the availability of Photoshop Lightroom 2 with the upgrade price of USD $99. I'm currently using Lightroom 1.4.1 myself, and the 64-bit support and localized editing are interesting features to me.

I'm not immediately going to upgrade, however. But, I'm monitoring feedback, and then probably upgrading at the same time as I'm purchasing a new PC later this year. See also the Lightroom Journal's blog post about the announcement.

Mon, 28 Jul 2008 14:58:00 GMT:
What is a .NET generic delegate?

If you are using C# 3.0 already, you've no doubt also trying out lambda expressions. However, lambda expressions are often seen in LINQ statements, but they are also useful elsewhere.

To help with this, the System namespace (in the System.Core assembly) defines several so-called generic delegates, such as one called "Func". These generic delegates let you easily define delegates with common signatures, such as a delegate taking one parameter and returning a value. Since generics are supported, you can also specify those datatypes that you want.

Here's an example. Say, you wanted to quickly implement a method to convert an integer value to a string. Furthermore, you might need to pass this method as a parameter (delegate) to another method. To do this, you could use the Func<T, TResult> generic delegate, and define the method like this using a lambda expression:

Func convert = num => num.ToString();

Now, you have defined the method "convert", which takes in an int and returns a string. In case you are interested, here's the CIL (Common Intermediate Language) of the above C# code:

.method private hidebysig instance void button1_Click(
  object sender, class [mscorlib]System.EventArgs e)
  cil managed
{
.maxstack  3
.locals init ([0] class [System.Core]
  System.Func`2 convert,
         [1] int32 'value',
         [2] string str)
IL_0000:  nop
IL_0001:  ldsfld     class [System.Core]System.
  Func`2 WinFormsTestApp.Form2::
  'CS$<>9__CachedAnonymousMethodDelegate4'
IL_0006:  brtrue.s   IL_001b
IL_0008:  ldnull
IL_0009:  ldftn      string WinFormsTestApp.Form2::
  'b__3'(int32)
IL_000f:  newobj     instance void class [System.Core]
  System.Func`2::.ctor(object,
  native int)
IL_0014:  stsfld     class [System.Core]
  System.Func`2 WinFormsTestApp.Form2::
  'CS$<>9__CachedAnonymousMethodDelegate4'
IL_0019:  br.s       IL_001b
IL_001b:  ldsfld     class [System.Core]
  System.Func`2 WinFormsTestApp.Form2::
  'CS$<>9__CachedAnonymousMethodDelegate4'
IL_0020:  stloc.0
IL_0021:  ldc.i4.s   123
IL_0023:  stloc.1
IL_0024:  ldloc.0
IL_0025:  ldloc.1
IL_0026:  callvirt   instance !1 class [System.Core]
  System.Func`2::Invoke(!0)
IL_002b:  stloc.2
IL_002c:  ldloc.2
IL_002d:  call       valuetype [System.Windows.Forms]
  System.Windows.Forms.DialogResult [System.Windows.Forms]
  System.Windows.Forms.MessageBox::Show(string)
IL_0032:  pop
IL_0033:  ret    
}

-------

.field private static class [System.Core]
  System.Func`2
  'CS$<>9__CachedAnonymousMethodDelegate4'
.custom instance void [mscorlib]
  System.Runtime.CompilerServices.
  CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) 

-------

.method private hidebysig static string
  'b__3'(int32 num) cil managed
{
  .custom instance void [mscorlib]System.Runtime.
    CompilerServices.CompilerGeneratedAttribute::
    .ctor() = ( 01 00 00 00 ) 
  // Code size       12 (0xc)
  .maxstack  1
  .locals init ([0] string CS$1$0000)
  IL_0000:  ldarga.s   num
  IL_0002:  call       instance string [mscorlib]
    System.Int32::ToString()
  IL_0007:  stloc.0
  IL_0008:  br.s       IL_000a
  IL_000a:  ldloc.0
  IL_000b:  ret
}

Being able to use delegates properly is a great aid in many C#/.NET programming situations. Combining lambda expressions and generic delegates to the equation gives you a powerful set of tools.

Fri, 25 Jul 2008 14:30:00 GMT:
How to detect installed operating system language in C#

Sometimes, you need to know in your application in which language the operating system has been installed. For example, you might need to differentiate between an US English and a Norwegian Windows.

However, this seemingly simple thing becomes more complicated because Windows enables you to specify regional settings and enable Multilingual User Interfaces (MUIs). MUIs are especially common nowadays with the introduction of Windows Vista. That said, the user could be running Windows that is installed in English, but with Finnish regional settings. This is what I do all the time. And with MUI support, I could have a basic Windows Vista in US English, and then install/enable a Finnish MUI package. Then, all the operating system texts would change to Finnish.

There's a simple and important rule about these things: if you want to display messages to the user in their own language, don't detect the current regional settings, but detect the operating system language. It is irritating when users have a, say, English language Windows, but some applications, especially installation utilities try to be clever and detect the current regional settings, and display their texts in that language. This quickly leads to message boxes with the in Finnish (say) and buttons in English. Very ugly, and it quickly gets worse from there.

Ranting aside, in the Win32 API world, you could call the GetUserDefaultUILanguage and GetUserPreferredUILanguages API functions to get the information you need. In the .NET and C# world, things are even easier with the CultureInfo class from the System.Globalization namespace. This class has the static properties called CurrentCulture and CurrentUICulture which give the same information as the API functions. In fact, .NET is using P/Invoke to call the GetUserDefaultUILanguage API behind the scenes.

Now, I want to repeat what I said earlier. When displaying texts on your own, don't detect the regional settings language, but use the operating system (MUI) language. CultureInfo.CurrentUICulture returns the operating system language, and CultureInfo.CurrentCulture returns the selected regional settings culture.

Here are simple examples. English Windows Vista with U.S. regional settings:

Same English Windows Vista, but this time with Finnish regional settings:

Finnish Windows Vista, but with Danish regional settings:

In these property names, two characters can make a big difference. Knowing what to do is the key to correct programs.

Keywords: How to detect operating system language, howto detect windows os language, windows language.

Wed, 23 Jul 2008 16:11:07 GMT:
Some quick physics Phun

Well, this isn't exactly a .NET programming post, but nonetheless something for the technical audience. I noticed, that a Swedish university has developed a nice, visually slick physics simulation application called Phun.

They have a nice wiki page with a YouTube video that shows how it works. If I have time, I'll surely give it a spin. I hope you like it too.

Sun, 20 Jul 2008 13:55:36 GMT:
ASP.NET MVC information on MSDN and more

ASP.NET's next phase will be the support for MVC patterns (Model-View-Controller). The forthcoming MVC model can be seen as a departure from the traditional web form world, and in case you are interested, there are two great web pages to start.

Firstly, there's MSDN Magazine's introductory article titled "Building Web Apps without Web Forms" from the March, 2008 issue.

Secondly, there's a complete new section for MVC information on ASP.NET. So, if you are interested in learning more, be sure to check these resources out!

Fri, 18 Jul 2008 05:09:46 GMT:
Getting started with Office development in Visual Studio 2008

On Developer.com, there's a nice article about getting started with Microsoft Office development with the latest Visual Studio version. The article is titled "Using Visual Studio Tools for Office in Visual Studio 2008", and is available here. Recommended reading if you are interested in Office development.

Wed, 16 Jul 2008 05:40:26 GMT:
Getting Started with Microsoft Hyper-V

Windows Server 2008 with the RTM version of the Hyper-V virtualization is here, and now it's a great time to start learning it, in case you already haven't. On MSDN blogs I found a nice little introduction to the subject, and how to get started.

Check it out.

Tue, 15 Jul 2008 10:12:45 GMT:
RAID level performance comparison

I'm planning to upgrade my development workstation later this year, and at the same time I'd like to implement a proper hardware RAID solution. Now, for example Wikipedia has good information about RAID, but it's difficult to find a concise table of RAID performance levels compared. Luckily, I found such a table from Adaptec's RAID controller user's guide, available here. That said, my current favorite is the Adaptec Unified Serial RAID Controller 3805, which supports up to eight drives, both SATA and SAS.

Here's the table, copied from the said user's guide:

RAID Level Redundancy Disk Drive Usage Read Performance Write Performance Built-in Hot Spare Minimum Disk Drives
RAID 0 No 100 % X X X X X X No 2
RAID 1 Yes 50 % X X X X No 2
RAID 1E Yes 50 % X X X X No 3
RAID 10 Yes 50 % X X X X No 4
RAID 5 Yes 67% – 94% X X X X No 3
RAID 5EE Yes 50% – 88% X X X X Yes 4
RAID 50 Yes 67% – 94% X X X X No 6
RAID 6 Yes 50% – 88% X X X No 4
RAID 60 Yes 50% – 88% X X X No 8
Spanned Volume No 100 % X X X X X X No 2
RAID Volume No 50% – 100% X X X X X X No 4

As you can see, there are many different RAID levels nowadays, in addition to those standard RAID levels we all learned long time ago.

Keywords: RAID, performance, RAID levels compared, perfomance comparison.

Sat, 12 Jul 2008 16:51:19 GMT:
Announcement: My Finnish Visual Studio 2008 book now available

Announcement: my new book, the Finnish "Visual Studio 2008 -käsikirja" is now available for purchase from local bookstores and from the publisher's web pages. For details about the book, see Docendo's web pages, or my Publications page.

The book is aimed at the professional developer, and talks about the Visual Studio 2008 IDE and how to best use it in production. Visual Studio Team System is also included as a topic -- the first Finnish book to cover the topic.

The bookstores Akateeminen Kirjakauppa and Suomalainen appear to sell my book. I hope you enjoy the book as much as I did writing it!

Thu, 10 Jul 2008 18:27:30 GMT:
SQL Server 2008 is ready soon

I noticed from The Register today, that Microsoft is getting ready to publish ("RTM") SQL Server 2008 quite soon. One indication of this is the fact that the new server release will appear in the August price list.

Another interesting thing is that Windows Small Business Server 2008 is about the appear as a Release Candidate soon. Windows Small Business Server 2003 was/is a nice product, and I'd expect the forth-coming new version to be at least equally good. We'll see soon how it all turns out.

Tue, 08 Jul 2008 05:22:49 GMT:
Information about IE8's new cross-site scripting prevention techniques

On MSDN Blogs, there's a new article about Internet Explorer 8's forth-coming features. This time, the blog talks about cross-site scripting (XSS) and the prevention of such attacks automatically.

Sounds good to me to have such prevention built-in. However, the detection algortihm must be good as not to prevent web applications from working normally. However, I believe this to be not a big issue in any case.

Sun, 06 Jul 2008 07:15:57 GMT:
Summer reading from MSDN Magazine

Summer is a great time to hone your development skills, and as far as time allows, the MSDN Magazine doesn't fail to contain great content. Since I've been pretty busy this spring and summer so far, I confess I haven’t been able to read all those articles from MSDN Magazine that I'd have liked.

Just in case it happens that you are in a similar situation, here are three great articles of interest:

Be sure to check these out, if the .NET CLR internals interested, you enjoy doing Silverlight development, and have an eye for concurrency.

Fri, 04 Jul 2008 15:07:31 GMT:
New protocol specifications published on MSDN

Just few days ago, Microsoft opened up many protocols and binary file formats that are related to Office applications, such as the Office application communication protocols and .DOC, .XLS and .PPT file format specifications.

The documentation is now available on MSDN, and the topic "Open Specifications" on the MSDN Library should be your starting point.

Enjoy!

Fri, 04 Jul 2008 15:00:50 GMT:
Some fun for a change: the July 4th test

Especially if you are living in the USA, you are probably aware that it's July 4th.

Even though you're not a citizen of the United States, it is fun to test whether you could be one. There's a test on MSNBC which you can take. I confess I didn't pass it the first time, but on second though the history lessons popped into my mind. How do you score?

Wed, 02 Jul 2008 16:42:17 GMT:
Improvements in SQL Server 2008's INSERT statement

For a long, long time, the syntax of the INSERT SQL statement has been pretty much stationary, and SQL Server hasn't been an exception. Surely, SQL Server has its own non-standard additions just like Oracle, DB2, and Progress, but overall, the syntax is pretty standardized.

However, the latest version of SQL Server 2008 brings a new feature to the INSERT statement: the ability to insert multiple rows in a single SQL statement. This feature is officially called "Transact-SQL Row Constructors".

With this new feature, you could run INSERT statements like this in SQL Server 2008:

INSERT INTO customers
VALUES (1, 'J. Doe'),
       (2, 'O. Osborne'),
       (3, 'M. Gibbs')

Naturally, such statements would fail on SQL Server 2005 and older, giving an error message about invalid syntax. But, if you are (going to, as the current release is the candidate RC0) running the latest 2008 version, then this addition sounds cool to me in its own right.

 

› Blog Archive