Jesper Niedermann's .NET Blog
about .NET and related technologies RSS 2.0
# Wednesday, March 11, 2009

Currently I am looking into taking over a huge enterprise legacy system written mostly in C#, but also some C++. The numbers are staggering several million lines of code, 1200 GUI screen, mostly WinForms, about 750 C# projects, 150 solution files, just to mention a few. In all about 4 times larger than the largest enterprise system I have previously been working on.

Just building and deploying the system is a pretty big task since due to events beyond my control I basicly only have the sourcecode and nothing else. Not quite true because there are some documentation, but buried in the thousands of files.

When I managed to modify a build file and build the entire monster with it, it took 2½ hours to complete.

I won't even try to include all projects in a single Visual Studio file. I wonder if it would load ? This gives me a problem though. How about debugging ? I cannot press F5 for any of the visual studio projects because the build process using the build file set up a ton of config files with IP adresses, connection strings and the like. So it doesn't make sense to run the thing from Visual Studio.

But if I start up the exe assembly how do I attach a debugger ? Well, I decided to use a simple trick. I added a line of code in the top of the main() method:

static void Main(string[] args) 
{
Debugger.Break();
...

Debugger.Break() is basicly a programmatic breakpoint, but it is more than that. If no debugger is attached it asks the user for a debugger. Smart! And for the process to debug I can just choose the Visual Studio process with the project containing the exe assembly. Henceforth the control is mine.

I could even consider writing this method and using it instead:

[Conditional("DEBUG")]
private static void DebuggerBreak()
{
if(!Debugger.IsAttached)
Debugger.Break();
}

This gives me the advantage that the IL code is only build in DEBUG mode and that the Debugger is only attached if one is not attached already.

Wednesday, March 11, 2009 6:23:39 AM (GMT Standard Time, UTC+00:00)  #    Comments [0] -
.NET | Tips & Tricks
# Sunday, March 8, 2009

When I post code blocks in this blog. It would be nice if they look like, well, code. So I looked at what Scott Hanselman had done, he is after all one of the creators of the blogengine I use: "Dasblog"

In this post Scott explains how to do it. He explains how to add Javascript from a project called SyntaxHighlighter and use a plugin called precode for Windows Live Writer. Well I use WLW too, so this is perfect for me.

But I had a few problems. I took me some time to figure out that the newest edition of SyntaxHighlighter didn't work with precode.

So I have now settled on SyntaxHighlighter version 1.5.1 and precode version 3.0.0

SyntaxHighlighter is nice because it has support for multiple languages, and it is easy to add support for more. The caveat is that it hasn't got any knowledge of the language. Which means that it just parses the text and looks for keywords. So stuff that looks like keywords will be color highlighted too. I consider this a minor problem.

I chose to add the Javascript in the scripts folder of my blog, and the SyntaxHighlighter.css file in template folder.

Know I could easily add the required code in the bottom of my homeTemplate.blogTemplate file, immediately before the closing <body> tag, like so:

<script class="javascript" src="scripts/shCore.js"></script>
<script class="javascript" src="scripts/shBrushCpp.js"></script>
<script class="javascript" src="scripts/shBrushCSharp.js"></script>
<script class="javascript" src="scripts/shBrushJScript.js"></script>
<script class="javascript" src="scripts/shBrushSql.js"></script>
<script class="javascript" src="scripts/shBrushXml.js"></script>
<script class="javascript">
dp.SyntaxHighlighter.ClipboardSwf = 'scripts/clipboard.swf';
dp.SyntaxHighlighter.BloggerMode();
dp.SyntaxHighlighter.HighlightAll('code');
</script>

Of course if you don't use DasBlog you just put the code in the bottom of each page.

Furthermore you need to refer to the stylesheet in the top of each page.

The last thing I did was to modify the stylesheet to make the color scheme look a bit more like visual studio.

And now I can post code like this nice c# one-liner that shows the name of every file in the current directory:

using System;
using System.IO;
using System.Linq;

namespace ListNames
{
class Program
{
static void Main(string[] args)
{
(from file in Directory.GetFiles(Directory.GetCurrentDirectory(), "*", SearchOption.AllDirectories)
select file).ToList().ForEach(file => Console.WriteLine(file));
Console.ReadLine();
}
}
}

A coworker of mine showed me a program that could do this, and I said well I can do that in one line - it is always nice to show off :) - (disclaimer:  I do not generally advocate to code in as few lines as possible. :) One issue you must always consider is readibility, though generally I must say that one of the great advantages of C#3.0/Linq syntax is that it tends to make stuff more readable when used correctly.

Speaking of Linq, as you can see the Syntaxhighlighter doesn't recognize Linq syntax. The "from" and "select" keywords are not highlighted (unless you read this when I have updated the shBrushCsharp.js script).

Sunday, March 8, 2009 12:07:11 PM (GMT Standard Time, UTC+00:00)  #    Comments [2] -
.NET | blog
# Tuesday, February 24, 2009

This is the first post of my new blog. Hope you will like it. My plan is to blog about my favourite topic - .NET and other more or less related technologies. I hope to post regularly but I will keep my ambitions low and plan only to post once every month ! Perhaps with a larger more in-depth blog post every second month. This is not for lack of subjects, but because I know myself. Work, family and fitness training often comes before late night programming and researching new stuff.

 

Though my mother-tongue is danish I plan to keep this blog in English to reach a wider audience.

 

Take care…

Tuesday, February 24, 2009 10:39:57 PM (GMT Standard Time, UTC+00:00)  #    Comments [2] -
.NET
Archive
<March 2009>
SunMonTueWedThuFriSat
22232425262728
1234567
891011121314
15161718192021
22232425262728
2930311234
About the author/Disclaimer
I am a software architect with focus on Microsoft Technologies. I have been working with these in different large companies since 1995. I am currently employed at Logica.
Here is my View Jesper Niedermann's profile on LinkedIn

Disclaimer
The opinions expressed herein are my own personal opinions and do not represent my employer's view in any way.

Privacy policy
The privacy policy of this site.

© Copyright 2014
Jesper Niedermann
Sign In
Statistics
Total Posts: 28
This Year: 1
This Month: 0
This Week: 0
Comments: 32
All Content © 2014, Jesper Niedermann
DasBlog theme 'Niedermann' created by Jesper Niedermann, based on 'Business' created by Christoph De Baene (delarou)