Tuesday, May 29, 2007

Aerofoil 0.1.1 update

I've made a small update to aerofoil so you can now disable Aero Glass on demand via the tray icon rather than just relying on automated on AC/on battery switching.

Final 1.4 version available here

Get the update here
Source available here

Friday, May 25, 2007

Blindy following OO design paradigms

My personal belief is that design paradigms are there to assist with good software design, but there are times when they should be left out in the cold. I should state this is my personal view, against the herd (can't think for themselves) mentality - but hear me out I have very good reason:

- Interface all your BOs (business objects)
Now this is just silly - I have a large three tier system, with some 30-40 BO classes alone. The specification doesn't say these will be swapped out - so why interface them? Another senior developer of the group got into a heated argument with me that you just should, because it was "good practise" and we "may" need to swap it out in future but couldn't give me any reason why or when (and against design for now agile methodology), why we couldn't interface at a later date or accept how during dev we modify the implementation extensively and need to also do extra work changing the interfaces. I understand that interfaces are useful for unit tests but there ways around this and it is trade off between testing convenience and readability. As an aside, interfaces actually add slightly to the running performance overhead!

- Singletons are always good, especially for your constants.
The singleton pattern is actually classed as an anti-pattern. From a pure OO perspective this can completely break the concept, e.g. keeping all constants in the a single class, from your DB strings, to your hash keys in BO, to error message keys in the UI. The constants should be in separate base classes, for each package's classes to extend from. Admittedly this is not always possible, but it's not an excuse to plonk everything in a central singleton - which can get very unwieldy.

- Always use object to relational database mapping libraries (e.g. Java's hibernate/toplink)
The traditional approach of executing raw sql is sometimes better. There is a lot to be gained by using the relational mapping libraries - which I won't go into - however they are not always the best tools for the job. For example, you have limited memory, your application executes ~10 or less statements or you need code visibility as to what is actually happening whilst debugging without looking in log files. Executing raw sql can often be more efficient because you can specify sql exact to your requirements (no blanket selects) and can use less memory - one result set.

- Three tier hierarchies are better/are the future
If you're programming on a limited device (such as a hand held pc) you shouldn't be using a three tier system, you don't need the system to scale to hundreds of users at once - it only has one. Simple is nearly always better in this situation, two tiers will do, forms and a backend with some limited business logic. If you have central server to synchronise with defer and offload as much logic as you can there - obviously not form validation or similar, I'm talking middle tier content that doesn't need to be shown or used in real time on the limited device.

There are many other examples, but remember that designs patterns and paradigms are there to help you, to prevent common design and coding pitfalls and deficiencies in programming languages. They don't dictate how you must design, try and use common sense and know when not to use them! :)

Sunday, May 13, 2007

Vista, Visual C# Express Edition, UnauthorizedAccessException and SecurityException just to use PerformanceCounter - the Solution!

So like me you've just 4 hours researching System.Security just to allow you to use a PerformanceCounter in Visual Studio Express Edition without getting SecurityException and UnauthorizedAccessException.

You've looked at the project security tab and seen "ClickOnce" settings and added what you thought was the relevant setting "PerformanceCounterPermission" for the Intranet realm, but it didn't work.

You've added permissions declaratively (using assembly attribute) and imperatively (by using the permissions object directly) trying to get the code to prompt a UAC box on access in Vista, basically the stuff this article talks about.

You've even considered a hack to add the user to the relevant groups.

None of them worked or were ideal.

Save yourself some time - here's the quick solution (important bit is the requested permission in the manifest xml) - note some of the lines are wrapped below use common sense :)

- If you've only installed Visual C# Express (or other express version) install the .Net SDK (this is for .Net 2.0 - you may want 3.0). You need this for the tools that are missing from the Express install that you can find in the full Visual Studio (i.e. we need mt.exe - manifest tool)

- Modify the manifest associated with your Express project (in the built-in editor to ensure saved as UTF-8 encoding) to something resembling this:

<?xml version="1.0" encoding="utf-8"?>
<asmv1:assembly manifestVersion="1.0" xmlns="urn:schemas-microsoft-com:asm.v1"
xmlns:asmv1="urn:schemas-microsoft-com:asm.v1"
xmlns:asmv2="urn:schemas-microsoft-com:asm.v2"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<trustInfo xmlns="urn:schemas-microsoft-com:asm.v2">
<security>
<requestedPrivileges>
<requestedExecutionLevel level="requireAdministrator" />
</requestedPrivileges>
<applicationRequestMinimum>
<defaultAssemblyRequest permissionSetReference="Custom" />
<PermissionSet class="System.Security.PermissionSet" version="1" ID="Custom"
SameSite="site" />
</applicationRequestMinimum>
</security>
</trustInfo>
</asmv1:assembly>


- Add under "Post-build event command line" in the project build events tab (note -manifest points to the modified application's manifest mentioned above - so you may need to change its location):

"$(DevEnvDir)..\..\SDK\v2.0\bin\mt.exe" -manifest "$(ProjectDir)Properties\app.manifest"
–outputresource:"$(TargetDir)$(TargetFileName)";#1


This procedure alters the application manifest to ensure that the code is built requiring administrator permission to run. The command line argument updates the modified manifest into the application post build replacing the default app manifest already included.

Now under Vista your built project will have a small shield on the icon meaning it prompts for administrator rights on startup - hoorah!

Sunday, May 06, 2007

Free laptop utility to disable Aero's Glass when on battery

"Hot" on the powersave/cooling subject of my last post yesterday evening I threw together a small tray icon application Aerofoil to disable Aero's Glass interface when on battery power. Hopefully this should cut heat and increase battery length a bit!

I'm hoping Microsoft add this functionality into the standard power manangement features of Vista at some point and this isn't needed anymore, but if they don't and the utility proves popular, I may add some other powersave functionality not currently available - although I don't know what yet, maybe options to disable sound, slow down gpu clockspeeds via atitool profile or similar!

GPL'd source code will be available shortly - I've not got time at the moment to bung in the relevant licence comments, readme and package up nicely. This should be in the next day or two.

Updated version

Get Aerofoil here!
Source code


If you find this useful and want the new features please post a comment or suggestions!