Friday, July 31, 2009

DevTnT 10 – Who to Blame for Code Changes?

In Visual Studio there is a feature called Annotate. In the Solution Explorer just right-click on a source code file and select Annotate. The result will be a view of this file where you have meta information for each line of code:

  • who did the latest change
  • when was it done
  • which changeset contains this modification

annotate

This can be useful in a code review or other situations where nobody remembers (or wants to remember ;-) who did the modifications.

DevTnT 10 – Debugging Windows Services with .Net

It depends on your architecture how easily you can debug the code running a Windows Service. Most propably you use a layered architecture which allows you to directly call the code doing the critical work. E.g. by a Winforms test application or via a administrative page in your web application.

But what if you have to find out what is going wrong in the service infrastructure itself? I usually install the service on my local machine directly from my <Service>\bin\Debug folder. Of course you will always have to make sure the service is stopped if you want to rebuild.

When running the service you can attach to the process and hopefully are fast enough to step in at the critical part of your code. Otherwise you can use the Debugger.Launch() method. I would suggest to put this call into the OnStart() of the service or into your Start() block :

debugger_launch

When the framework executes the Debugger.Launch() method and prompts you to select the debugger, select the VS instance that shows the service code and continue to run the service under the control of the debugger.

Be careful that the debugger dialog does not show up in a released version. To avoid this you can check with #if DEBUG or use command arguments which you provide in the service properties:

serviceproperties

Alternatively implement a while-loop which waits for the debugger to be attached. You can find a code snippet here.

DevTnT 9 – Transpose Functionality in Excel

In Excel, the Transpose function returns a transposed range of cells. For example, a horizontal range of cells is returned if a vertical range is entered as a parameter. Or a vertical range of cells is returned if a horizontal range of cells is entered as a parameter.

This can be useful especially if you have to copy rows from a database with a large number of fields. The transposed row-oriented result may be easier to read as the default column-oriented view:

transpose

  1. Highlight the cells that you want to copy.
  2. Then right-click on the cell where you'd like to paste the values and select Paste Special from the popup menu.
  3. Then select the Transpose checkbox and click on the OK button.

Wednesday, July 15, 2009

Follow-Up For “A SOLID Audio Rant”

A few weeks ago I sketched some waves that got high in the community concerning an in the first glance not so friendly episode of the StackOverflow Podcast (see post “A Solid Audio Rant”). Besides other topics, Joel Spolsky and Jeff Atwood, the guys performing on that podcast, talked about the SOLID principles advocated by Robert C. Martin (aka Uncle Bob).

Now by chance I found a letter that Uncle Bob published on objectmentor.com in reaction to the offensive StackOverflow-Episode: An Open Letter to Joel Spolsky and Jeff Atwood.

And that letter is really interesting if you just listened to the podcasts I mentioned in my earlier post. Because in that podcasts the climate changed from ranting to an almost esteeming atmosphere. But as we now can read from that letter mentioned above, Mr. Martin’s first reaction was not so friendly by really harnished (up to menacing steps towards legal contention).

So, check it out!

Sunday, July 5, 2009

DevTnT 8 - Tools: TotalCommander

If you're sick of the usual Windows-Explorer and want to try smth new, and in my Opinion smth improved, I would suggest to give TotalCommander a try.

Most of you will recognize the UI of this Tool from way back: like NortonCommander or MidnightCommander but TotalCommander is a really well done Port for the Windows-World and was already available in the Win3.11 times: and this is actually the one and only weakness: it looks rather old :)

Compared to its advantages, you might forget the Surface:
  • TabStructure: you can save your most used places as tabs and get them everytime the TC starts (lazy loaded for network/external devicec)
  • Splitted Screen to work with 2 folders in parallel
  • Queued copy/move for Files: no more blocking/slowing down parallel copyjobs (esp. for network transfers!)
  • Custom Fileassociations besides "open"
  • Integrated FTP/WEBDav: no use for special FTP-Software
  • Copying fully qualified filenames in the clipboard
  • Integrated RAR/ZIP handler
  • A large repository of plugins (Filesystems, Tools, etc.)
  • Showing all files in Subfolders
  • MultifileSelection via Wildcards/Regex
  • Multirenaming via Wildcards/Regex and common statements (Date, etc.)
  • Folder Synchronization
  • Commandline in the active Folder
  • File Splitting/Encoding/Hashing
  • fully customizable hotkeys
  • and a lot more!
The TC is a Shareware-Tool which is fully functional in the free Version and costs 26€ licenced.

Note: if you want to use it in an 64bit environment, I would suggest to try the current betaversion (7.50 beta6)

Friday, July 3, 2009

DevTnT 6 – ReSharper: Expanding the selection with Ctrl+W

In a previous post, Sebastian drawed our attention to a nice selection expansion feature of ReSharper. I also think this feature is cool, and want to present it here in more depth.

Visual Studio by itself supports the expansion of the current selection in a text editor window by pressing Ctrl+W.

With this command you can change a current selection like this …

Cursor in source code before expansion

… to a selection of the whole word:

Selection in source code after expansion

 

If your existing selection spans several words like this …

Selection in source code spanning two words

… after pressing Ctrl+W you end up with the word selected that is at the end of the selection:

Selection in source code after expansion

(Funnily, if you made your selection from right to left the left word gets selected:

image )

Further pressing Ctrl+W does not do anything more.

 

Text Expansion With ReSharper

ReSharper has taken that expansion feature to the max (that’s why we love this tool!).

Beginning with no selection …

image

… by pressing Ctrl+W ReSharper selects the whole word:

image

But now, you can press Ctrl+W several times more to expand the selection to several areas, one larger than the one before.

From the single word selection you get the selection of the whole string without the quotes:

image

Then ReSharper selects the string including the quotes

image

… then the whole concatenated string from the beginning of the expression

image

… and then incrementally the whole string expression line by line:

image

image

 

And so it goes on with every stroke on Ctrl+W until the whole file content is selected:

The whole statement

image

… the whole block without the braces

image

… the block including the braces

image

… the whole member

image

… the type’s content without the braces

image

  … the whole namespace’s content without the braces

image

… the whole namespace

image 

… and finally the complete content of the file:

image

As you may guess, the whole stuff can be done in reverse order pressing Ctrl+Shift+W.

Good to know!

DevTnT 8 – Defining an Environment Variable as a File Path

An environment variable is a dynamic value loaded into the memory that can be used by several programms in parallel. In Windows, the environment variables are placed between the "%" character. Thus to display the value of an environment variable, simply type following type of command:

echo %NAME_OF_THE_VARIABLE%

Examples for often used environment variables are: %PATH%, %TEMP%, %USERNAME% and %WINDIR%

For defining a variable as a file path inside a command window you can use the following shell command

set VariableName=value

or use the System Properties for global definition:

environmentvairables

You must be an administrator to modify a system environment variable. System environment variables are defined by Windows and apply to all computer users. Any user can add, modify, or remove a user environment variable. The changes are written to the registry, and are usually effective immediately

After applying your changes you can refer to this variable by entering %pp%. E.g.

environmentvairables2

The only limitation under Windows we know is that file dialogs in SQL Server Management Studio 2005 do not support it.

A nice usage Paul likes: saving downloads from the internet or other temporary files/folders to the sytem temp directory by typing %TEMP%.

DevTnT 8 - WINDOWS key+BREAK: Show System Properties

I guess there are many others like me who nearly never use the “Break”-key on their keyboard. Today I learned that pressing that WINDOWS key plus the BREAK key opens the System Properties control panel.

A second way to do this would be to hold the ALT key and double click “My Computer” on the desktop.

See a complete list of all shortcuts utilizing the WINDOWS key: http://www.seoconsultants.com/windows/key/

Or the list of all keyboard shortcuts available in Windows XP: http://support.microsoft.com/kb/301583/EN-US/