All posts by caveman_dick

About caveman_dick

I'm a C# software developer (mainly asp.net but sometime I dabble in background services) working for a major recruitment company. My core skills are C#, Html, JavaScript, Css and Sql Server 2000-8.

Please sponosor me on my charity challenge!

This year at the end of September I am embarking on a charity challenge for the Princes Trust. This has been partially organised through my new employers (Advanced Health and Care Ltd part of the Advanced Computer Software Group) and they will be kindly sponsoring me to the tune of £100 but I need to raise the rest.

The challenge I’m entering is the Wild UK challenge which involves racing from the north coast to the south coast of Devon by cycling, hiking and kayaking a total of 100 miles!

So far I have managed to raise a bit at work by doing selling some cakes I have baked and will be doing a lottery next payday. I did plan to sort out a load of my junk to sell at a boot fair however this has been quite difficult to find the time (I moved out of London in Jan as my mum health was deteriorating and she has recently been diagnosed with Alzheimer’s :().

Unfortunately I’m still majorly short of the £800 target (£600 of which I need to raise by the end of August!), so hopefully this is where you will be able to help! 😉

My sponsorship page can be found here. Anything that you can spare would be very much appreciated. Just think if you don’t have that extra drink down the pub on Friday, you can easily spare a fiver! 😉

Thanks everyone! 🙂

Enabling a project to have multiple StyleCop targets.

As the RC is now out for StyleCop 4.5 I wanted to give it a go mainly to see if the ReSharper integration included works with Resharper 6 (unfortunately it doesn’t :(). Unfortunately it includes a breaking-change if you import the StyleCop.targets file (so that violations are shown as either errors or warnings when building the project) as the path has changed.

To enable me to continue to use the 4.5RC version and my workmates to carry on using 4.4 I had to make some changes to the csproj file to cater for both:

<PropertyGroup>
    <StyleCop4_4Path>$(MSBuildExtensionsPath32)\Microsoft\StyleCop\v4.4\Microsoft.StyleCop.targets</StyleCop4_4Path>
    <StyleCop4_5Path>$(MSBuildExtensionsPath32)\StyleCop\v4.5\StyleCop.targets</StyleCop4_5Path>
</PropertyGroup>
<Import Condition="!exists($(StyleCop4_5Path))" Project="$(StyleCop4_4Path)" />
<Import Condition="exists($(StyleCop4_5Path))" Project="$(StyleCop4_5Path)" />

This disables the 4.4 target if 4.5 is installed, however if neither are installed it will fail the build trying to find 4.4. If you need to disable both if they are not installed you can replace the first import with the following:

  <Import Condition="exists($(StyleCop4_4Path))" Project="$(StyleCop4_4Path)" />

Invoke-SqlCmd throws exception when trying to set the database via parameter

This was properly doing my nut today! Basically I created a generic script to fix orphaned users and replaced the database with the standard SqlCmd variable syntax:

use $(DatabaseName);

When running in SSMS setting the variables like this:

:setvar DatabaseName MyDatabase

works fine, as it does when setting as a param to the sqlcmd.exe:

sqlcmd -i C:\PathToScript.sql -v DatabaseName=MyDatabase

however when using the PowerShell Invoke-SqlCmd Cmdlet from the SqlServer PowerShell extensions it throws an exception that gives you absolutely no clue as to why:

Invoke-Sqlcmd : Object reference not set to an instance of an object.
At C:\Users\mayesr\Desktop\PowerShellScratchPad.ps1:22 char:14
+ Invoke-Sqlcmd <<<< -InputFile "$g_ScriptLocation\FixUser.sql" -ServerInstance "localhost" -Verbose + CategoryInfo : InvalidResult: (localhost:PSObject) [Invoke-Sqlcmd], NullReferenceExcep tion + FullyQualifiedErrorId : ExecutionFailed,Microsoft.SqlServer.Management.PowerShell.GetScriptComm and

I eventually noticed that the Invoke-SqlCmd has a parameter that you can set the database with. Once that was set and the use statement removed, the script worked fine! Luckily it didn’t take me too long to notice but hopefully if you come across this post it will save you some time!!

UPDATE

After I thought I had fixed this I realised that it wasn’t the Database param at all and in-fact was any param! I eventually found out there is a bug in the MSDN docs (and/or code)!! The docs say that the following format should be used:

$MyArray = "MyVar1 = 'String1'", "MyVar2 = 'String2'"
Invoke-Sqlcmd -Query "SELECT `$(MyVar1) AS Var1, `$(MyVar2) AS Var2;" -Variable $MyArray

However this doesn’t work and the following should be used instead (remove the spaces around the ‘=’):

$MyArray = "MyVar1='String1'", "MyVar2='String2'"
Invoke-Sqlcmd -Query "SELECT `$(MyVar1) AS Var1, `$(MyVar2) AS Var2;" -Variable $MyArray

I just wish I’d scrolled down to the bottom of the page as other people had added comments saying this!! 😡

A few “features” in MSBuild that caused me pain today…

Today I decided to work on deploying to both our internal load-balanced app servers directly from a manually run build. Unfortunately I came across the following issues that caused me to spend far too long on this task!!

Currently I have a library of MSBuild .targets files that load in generic tasks that I can run after a build has run. One of them is a DeployWebsite task that uses a couple of Properties and can clean down and deploy the latest code from the build. I realised that all I needed to do was modify the current build to set the deploy location first. However this turned out to be a lot harder than I thought it would be…

Firstly I tried the following code which doesn’t set the Global property “AppFolderPath”:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
<Project ToolsVersion="3.5" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
    <PropertyGroup>
        <AppFolderPath>[INVALID]</AppFolderPath>
    </PropertyGroup>
    <Target Name="SetDeployLocation">
        <PropertyGroup>
            <AppFolderPath>[SOME SHARE ON SERVER]</AppFolderPath>
        </PropertyGroup>
        <CallTarget Targets="DeployWebsite" />
    </Target>
    <Target Name="DeployWebsite">
        <Message Text="AppFolderPath=$(AppFolderPath)" />
    </Target>
</Project>

To fix this you need to seperate the tasks into two Targets and call them from a single parent Target and set the Property using CreateProperty (not declaratively and doesn’t matter if you have already created it!):

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
<Project ToolsVersion="3.5" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
    <PropertyGroup>
        <AppFolderPath>[INVALID SHARE]</AppFolderPath>
    </PropertyGroup>
    <Target Name="DeployToLive">
        <CallTarget Targets="SetDeployLocation" />
        <CallTarget Targets="DeployWebsite" />
    </Target>
    <Target Name="SetDeployLocation">
        <CreateProperty Value="[SOME SHARE ON SERVER]">
            <Output TaskParameter="Value" PropertyName="AppFolderPath" />
        </CreateProperty>
    </Target>
    <Target Name="DeployWebsite">
        <Message Text="AppFolderPath=$(AppFolderPath)" />
    </Target>
</Project>

Once I’d fixed those it still wouldn’t call the DeployWebsite multiple times. The first worked fine, however it turns out that MSBuild will not allow you to call a target with the same name twice. To get around this you can spawn a separate MSBuild task for each instance you need to run:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
<Project ToolsVersion="3.5" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
    <Target Name="DeployWebsiteToLive">
        <MSBuild Targets="DeployWebsite"
            Properties="AppFolderPath=[SHARE ON SERVER 1];BuildDirectory=$(BuildDirectory)"
            Projects="$(MSBuildProjectFile)" />

        <MSBuild Targets="DeployWebsite"
            Properties="AppFolderPath=[SHARE ON SERVER 2];BuildDirectory=$(BuildDirectory)"
            Projects="$(MSBuildProjectFile)" />
    </Target>
    <Target Name="DeployWebsite">
        <Message Text="AppFolderPath=$(AppFolderPath)" />
    </Target>
</Project>

One thing to notice there is you need to pass across ALL properties that are not set declaratively. If you do not pass anything these are all sent across automatically, but MSBuild still detects that the two tasks are exactly the same and only runs the first one.

Hopefully you won’t have to spend as long as I did on it now! 🙂

VDPAU stops working after you upgrade the NVIDIA drivers on debian based distros

The last week or so I’ve been having issues with the NVIDIA drivers on my Acer Apsire Revo and had to reinstall them several times (due to a failed update of the new DKMS package breaking everything). I took the opportunity to also upgrade them to the latest version. Eventually after lots of playing around I got them to work again but my 720p videos weren’t behaving. After a bit of digging I found the vdpauinfo tool and got the following message:

“Failed to open VDPAU backend libvdpau_nvidia.so: cannot open shared object file: No such file or directory”

This seemed a bit strange as I knew it was installed as I distinctly remember doing it. A bit more digging turns out that the previous installers add a symlink which what apps use instead [ref]. So it was a simple matter of adding it back in with the flowing command:

1
sudo ln -s /usr/lib/vdpau/libvdpau_nvidia.so.1 /usr/lib/libvdpau_nvidia.so

Hey presto everything was back to normal and the HD gods were smiling down on me! 🙂

Using a symlink to emulate the windows command cls in Linux

Even though the command “clear” is really obvious in Linux (you can also use CTRL+L) I always forget and try and use the windows “cls” command. All you need to do to make it work on Linux is create a symlink (same as a Junction point in windows, NOT a shortcut) pointing back to the clear command. This is actually very simple and is achieved by the following command (Tested on LinuxMint but should work on all versions of Linux):

1
sudo ln -s /usr/bin/clear /usr/bin/cls

Shop with Wiggle sports shop and raise money for charity!!!

If you haven’t heard on the 3rd-5th Sept I will be cycling from London to Amsterdam in aid of the charities “Hope and Play” and “Action for Children”.

To aid with my fundraising, I recent just negotiated with my favourite online Cycle store Wiggle to get 10% cashback of anything you buy on the site for 3 months after you create a new account!!

To setup an account and make your purchases use click on the banner below.

Please Note: This offer will only work if you setup a new account. If you have an existing account with wiggle you will need to setup another account for the money to go to the charity.

If you are not very sporty but still want to donate, you can use my fundraising page here: http://www.virginmoneygiving.com/team/haysL2A

[ad#WiggleBanner]

Headphone volume issue on HTC desire after upgrading to froyo

So I went ahead and upgraded my mobile with the OTA update that has showing on my mobile. I wanted to upgrade ASAP due to the fact that I have run out of space for apps on the internal memory and this upgrade will resolve it (apps can be moved to the SD card).

However I think I may have jumped the gun as now whenever I use headphones the volume is stuck at max and even when the phone software says the volume is silent it’s still blasting out! 🙁 Unfortunately spotify doesn’t have an internal volume control at all so it’s a no go there too.

I’ve had a search on Google and it looks like people are not experiencing the exact same issue, however there are a lot with issues with the volume in some way or another.

Hopefully this will be fixed pretty quickly as it now makes the phone unusable as a media player and I have to go back to using my iPod.

In the meantime if anyone finds a solution to this please let me know!

UPDATE: After searching for a resolution to this and not coming across anything much I managed to find someone saying recessed headphone jacks are quite problematic. The Desire doesn’t actually have a recessed jack but I do use a silicon case that makes the jack a bit recessed. This has not been a problem before, but I thought I’d give it a go without the case. Low and behold the volume buttons seemed to be working fine. I thought this was a bit strange so out the case back on and what’s even stranger is that is still worked fine. Now I have no idea why this happened and to me it seems a bit strange that this would even cause it in the first place (I would assume that it would be lower in volume or only one channel). Unless of course I came across a bug that has a 1 in 1,000,000 chance of hitting. Anyway I’m glad it’s working now!! 🙂

London To Amsterdam bike ride 2010

Basically I’m on the scrounge for sponsorship. On Friday September the 3rd, along with 100 other riders I will be participating in a bike ride to raise money for the charities “Hope and Play” and “Action for Children”. Over 3 days we will be cycling just over 182 miles, from Stanstead in London, to the centre of Amsterdam in Holland.

To put the distance of how far we will be riding into perspective, it will be the equivalent to doing the London to Brighton bike ride, every day for just over three days.

Here is how we will do it

Day 1:
Stansted Mountfitchet to Harwich – about 110km (68 miles) though undulating Essex countryside. At 9.30am we will leave Stansted Mountfitchet where we will make our way to Harwich.

Day 2:
Hook of Holland to Heemskerk – about 135km (83 miles) up the F1 cycle path on the Dutch coast. We will disembark the ferry at around 7.30 and straight onto the cycle path up the cost. Heading through the Kennemerduinen Nature Reserve we will make our way to Heemskerk.

Day 3:
Heemskerk to central Amsterdam – about 50km (31miles) This will be the final stage of the ride and will take us nicely in to the centre of Amsterdam

You can sponsor me at virgin money giving, http://www.virginmoneygiving.com/team/haysL2A . Any donations, no matter how small will hopefully help me reach my target of £500 of which all of it will be going directly to the charities as I am covering the £290 trip costs myself.

Last but not least, no we will not be cycling home!!

Thanks in advance for your generosity.

Not sure if anyone actually reads my blog, but anyway it’s worth a go and any extra pennies will be worth it!!! 🙂

UPDATE: If you use the below banner, setup a new account and make any purchases within the next 3 months, I will donate the proceeds to the charity page.

[ad#WiggleBanner]