Monday, 16 December 2013

Case namings

I've always referred to Camel Case as the case whereby the first letter is lower case and all compound Words thereafter are uppercase.

e.g. backColour or orderRefundId

this is how you'd name fields in .NET.

and Pascal Case is whereby the first letter is capitals (e.g. properties in .NET).

e.g BackColour or OrderRefundId

....confusingly though Camel Case can refer as upper camel case (Pascal case) or lower Camel Case. Typically though if it is not specifically mentioned then Camel Case is lower camel case.

Saturday, 16 November 2013

FIX: Battlefield 4 - 2 player disconnect on a home LAN

If you play Battlefield 4 with 2 players with separate copies and separate accounts on a home network you may find an annoying problem whereby when one user logs in the other is disconnected.

 This can be solved by:

1. Log in to your home router and disable uPnP.

 then, for both computers:

2. In Windows, Go to Start > Run and type in Services.msc
3. Stop the "UPnP Device Host" service.
4. Stop the "SSDP Discovery" service.

 And restart BF4. Hey-presto - it works!

Monday, 11 November 2013

Adding a SqlParameter with a null reference - Procedure or function 'Foo' expects parameter '@Name', which was not supplied.

I was debugging a historical issue raised in some legacy code over a year ago.
The problem was reported that the database was raising an error under peak load whenever a payment service was unavailable.

The database error was:

 Procedure or function 'Foo' expects parameter '@Name', which was not supplied.

After some digging it transpires that the error was due to a little gotcha in the database access code.
The code was similar to:

using (var connection = new SqlConnection("Server=localhost;Database=TestDatabase;Integrated Security=SSPI"))
{
    connection.Open();
    using (var cmd = new SqlCommand())
    {
        cmd.Connection = connection;
        cmd.CommandText = "Foo";
        cmd.CommandType = CommandType.StoredProcedure;
        cmd.Parameters.Add(
            new SqlParameter
            {
                ParameterName = "@Name",
                SqlDbType = SqlDbType.NVarChar,
                Size = 255,
                Value = results.Reference
            }
            );
        cmd.ExecuteNonQuery();
    }
}

If results.Reference is a .NET null reference, then the SqlParameter is NOT added. In this scenario if you want to add a NULL database value then you would need to modify the code to:


    Value = results.Reference ?? DbNull.Value;

Monday, 21 October 2013

In-House NuGet

ProGet is package that can be used to source in-house NuGet feeds.

Monday, 12 August 2013

StyleCop versus FxCopy versus Code Analysis and MSBuild integration

What is the difference between StyleCop and FxCopy? It is described here.

StyleCop and FxCop overlap in functionality. But StyleCop analyses source code whereas FxCop analyses binaries, so StyleCop is able to pick up on source code rules whereas FxCop cannot.  FxCop tends to focus more on design rules and StyleCop is focusing on coding style (casing, white space, indents, etc).

Code Analysis in Visual Studio contains FxCop plus mode (code metrics etc).

StyleCop can be manually added to the project so that it runs as part of MSBuild. However there are issues about it sharing the same custom dictionary as Code Analysis.

Removing weekends from the TFS Sprint Burndown report

This blog describes how to remove weekends from the Sprint Burndown report in TFS.

Essentially:

Open the report in SQL Server 2012 Report Builder. Save As a new report filename in order to keep the original intact!

Right click outside of the white report canvas and select Report Properties.
Select the Code tab item.

Add the following function:
Function NumberOfDaysToAdjustForWeekends(ByVal valNow as Date, ByVal startOfSprint as Date) AS Int32

  Dim valCurrent As Date = startOfSprint
  Dim weekendDaysPassed As Int32 = 0

  Do While valCurrent < valNow

  valCurrent = valCurrent.AddDays(1)
  If (valCurrent.DayOfWeek = DayOfWeek.Saturday Or valCurrent.DayOfWeek = DayOfWeek.Sunday) Then
  weekendDaysPassed = weekendDaysPassed + 1
  End If

  Loop

  Return weekendDaysPassed

 End Function

Click on the chart, Select Work_Item_Count from the Values fact table and edit the Expression.
Change it to:

=Code.Burndown
(
Sum(Fields!Remaining_Work.Value),
Fields!DateValue.Value.AddDays(-Code.NumberOfDaysToAdjustForWeekends(Fields!DateValue.Value, Parameters!StartDateParam.Value)), Parameters!EndDateParam.Value.AddDays(-Code.NumberOfDaysToAdjustForWeekends(Parameters!EndDateParam.Value, Parameters!StartDateParam.Value))
)

Now the today line is out as it is not taking into account the weekends.
Turn on the Properties Tool Window if it is not already.
Select View menu tab and tick the Properties checkbox.
Click on the date axis.
In the Properties tool window find the Striplines property.
Edit the collection and the IntervalOffset property.
Enter the following value:
=CountDistinct(Fields!DateValue.Value, "dsBurndown") - DateDiff("d", Today(), Max(Fields!DateValue.Value, "dsBurndown")) - Code.NumberOfDaysToAdjustForWeekends(Today(), Parameters!StartDateParam.Value)

Save the report back to the server.