Paul Maddox

Software development team leader specialising in Microsoft Visual C# and C++ from the Northwest of England. Experience working in a globalised business and team; understanding of enterprise business operation and practices; experience reporting to executive management Skills in numerous languages and technologies; knowledge of formal software development lifecycle; experience of architecture design

Wednesday, April 22, 2009

Visual Studio 2008 Errors

Recently I had my VS 2008 RTM/RC installation go pear shaped. Overnight I stopped being able to create VC++ smartdevice projects with the error

“Creating Project '<ProjectName>'... project creation failed”

‘No problem’, I thought, ‘I’ll just run setup and do a repair’.  Unfortunately, I got an error with the setup of

“A problem has been encountered while loading the setup components. Canceling setup.”

Luckily I came across a post on StackOverflow (which is running turning out to be a useful resource from the author of CodingHorror.com) pointing to a Microsoft tool to ‘force’ uninstall various Microsoft products, including Visual Studio:

http://msdn.microsoft.com/en-us/vstudio/bb968856.aspx

image

Tuesday, April 21, 2009

SQL Server 2008 Truncating Log File

First find the filename labels for your database:

select name from <DatabaseName>.dbo.sysfiles

Next truncate the log:

BACKUP LOG <DatabaseName> WITH TRUNCATE_ONLY

Finally shrink the database based on the log file in step 1:

DBCC SHRINKFILE('NameAbove_log',2048)

2048 is the resultant file size in MB.

Screen Real Estate Wastage

Usually I’m a fan of Microsoft UI design, however having installed the latest version of Windows Live Messenger (or more accurately had it forced on me) I’m astounded by the amount of screen real estate squandered.  Clearly Microsoft have been buying too many 24” monitors.  After turning off as much of the unneeded fluff as possible I was still left with a window far larger than necessary, with no real benefit.  See below!

image

SQL Quiz of the Day



Let’s say you have raw data as so:

Id Counter Ident
----------- ----------- -----
1 1 A
2 2 A
3 1 A
4 3 B
5 3 B
6 2 A
7 1 A
8 4 C
9 2 C
10 1 B
11 1 B
12 4 B

And you want to group by the Ident field, but
only contiguous blocks. So you want to display
the following:

Counter Ident
----------- -----
4 A
6 B
3 A
6 C
6 B

Naturally one can’t use GROUP BY, because this would
aggregate multiple A’s and B’s.

Answers on a postcard!

====

CREATE TABLE [dbo].[Test](
[Id] [int] IDENTITY(1,1) NOT NULL,
[Counter] [int] NOT NULL,
[Ident] [varchar](3)
COLLATE Latin1_General_CI_AS NOT NULL,
CONSTRAINT [PK_Test] PRIMARY KEY CLUSTERED
(
[Id] ASC
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]

Monday, April 20, 2009

MaddogTCP network TCP/IP fuzzer

A while ago - almost three years in fact - I wrote a fuzzer to test network security of TCP/IP connections. Due to one reason and another I never really released it, and despite being published on the net it was hidden from Google, and hence remained undiscovered.

Looking back, it was a reasonably succinct little program that deserves the light of day, so here it is:

http://www.calcaria.net/MaddogTCP/

Wednesday, April 8, 2009

Generic type parser using Generics C# .NET

Recently I had the need to safely parse multiple types from text ignoring exceptions. Microsoft did not implement an IParsable interface (despite requests) so I thought a solution was crying out for using generics.

The concept was simple: pass in an object of type T and call T.Parse.  The .NET compiler can check at compile time that the type supports Parse, right?  Unfortunately not.  Although generics allows constraints such as new(), it does not support arbitrary method constraints.

Lack of method constraints means attempting to call T.Parse won't work.  The result is having to use reflection to get around this.  Of course passing in a type that does not support Parse will  throw an exception, but by virtue of the design this will be handled and the type will return the default.

private T SafeParseAndAssign<T>(string val)
where T : new()
{
try
{
T ValOut = new T();

MethodInfo MI = ValOut.GetType().
GetMethod("Parse", new Type[] { val.GetType() });

return (T)MI.Invoke(ValOut, new object[] { val });
}
catch
{
// swallow exception
}
return default(T);
}