December DevJam – Talk Lineup

Subject to any last minute changes, here is the line-up of talks for Thursday’s DevJam event :

  • Doug Paice – Using Reactive Extensions and Caliburn.Micro to simplify event chaining in WPF
  • Jake Ginnivan – Real World MVVM
  • Michael Minutillo – Crankpad
  • Alistair Waddell – Compare and Synchronize your Database with VS2010
  • Piers Williams – Kinect SDK
  • Adrian McGrath – Testing Async
  • Ben Leane – SP2010 Client Object Model

It’s happening at our usual venue:

  • DATE:    Thursday, Dec 1st, 5:30pm
  • VENUE:  Enex100 Seminar Room, Level 3, 100 St Georges Terrace, Perth
  • COST:    Free. All welcome

If you are attending, please sign up at EventBrite (http://www.eventbrite.com/event/2402588206) so I can get an idea of catering numbers.

If you have any questions, please send me an email.

http://perthdotnet.org/blogs/events/archive/2011/10/22/december-devjam-2011.aspx

December DevJam 2011

For December’s meeting of the Perth .NET User Group (Thurs, 1st Dec), we are running another DevJam style community event, where local developers give a short talks about something .NET software development related.

  • DATE:    Thursday, Dec 1st, 5:30pm
  • VENUE:  Enex100 Seminar Room, Level 3, 100 St Georges Terrace, Perth
  • COST:    Free. All welcome

There are still several talk slots available. For presenter entry details see here: http://perthdotnet.org/blogs/events/archive/2011/10/22/december-devjam-2011.aspx

The prize for the best audience voted talk is an Xbox 360 with Kinect. There will also be a door prize of an Xbox 360 with Kinect!

There will be pizza and refreshments provided. Please sign up at EventBrite (http://www.eventbrite.com/event/2402588206) so I can get an idea of catering numbers. If you have any questions, please send me an email.

Perth .NET User Group Meeting, Thurs Nov 3rd, 5:30pm: Hosting in Azure – without the blues: Joe Albahari

Had enough of your data centre or web hosting company?

Join us at the Perth .NET user group, Thurs Nov 3rd 5:30pm, and find out how to move your MVC or Web Forms apps into the cloud and enjoy high availability, security and scalability – without the responsibility of OS installation, updates or security. This session will be full of practical advice and lessons learned from Joe’s own experience migrating two web sites and a licensing server into Azure, all of which now run inexpensively on a redundant pair of extra small instances.

  • TOPIC:   Hosting in Azure – without the blues: Joe Albahari
  • DATE:    Thurs Nov 3rd, 5:30pm – 7:00pm
  • VENUE:  Enex 100 Seminar Room, Level 3, 100 St Georges Terrace, Perth
  • COST:    Free. All welcome

Joe Albahari is a C# MVP and author of ‘C# 4.0 in a Nutshell’ and LINQPad. He has presented at TechEd and JAOO and is a regular speaker at the Perth .NET User Group.

More details here: http://perthdotnet.org/blogs/events/archive/2011/10/16/hosting-in-azure-without-the-blues-joe-albahari.aspx

Perth .NET User Group Meeting, Weds 19th Oct, 5:30pm: Amazon Web Services (AWS) in Action with Andy Marks

Join us at the Perth .NET user group, Weds Oct 19th 5:30pm, where Andy Marks will introduce the philosophy and principles behind AWS and briefly describe some of the key components around storage and compute capabilities. The session will include a short hands-on activity for participants to build and deploy their own cloud-based application.

  • TOPIC:   Amazon Web Services (AWS) in Action with Andy Marks
  • DATE:    Wednesday, Oct 19th, 5:30pm – 7:00pm
  • VENUE:  Enex 100 Seminar Room, Level 3, 100 St Georges Terrace, Perth
  • COST:    Free. All welcome

Andy serves ThoughtWorks principally as the Perth and Melbourne Technical Lead in the design and implementation of enterprise applications. He also has considerable experience in coaching and mentoring development teams adopting Agile practices.

Optional Requirements: Laptop with internet connectivity (for the hands on section of the talk).

Perth .NET User Group Meeting, Thurs 6th Oct: C#/Mono with Ben Last

Join us at the Perth .NET user group, Thurs Oct 6th 5:30pm, where Ben Last will discuss a real world application using C# and Mono. nearmap.com make heavy use of C#, but in a very non-Windows environment. Plenty of people have played with mono as a .NET platform, but there are not that many who have used it in a large-scale, high-traffic, n-tier environment. Hear our story, and find out if mono delivers what it promises.

  • TOPIC:  C#/Mono with Ben Last
  • DATE:   Thursday, Oct 6th, 5:30pm – 7:00pm
  • VENUE: Enex 100 Seminar Room, Level 3, 100 St Georges Terrace, Perth
  • COST:   Free. All welcome

Ben is a Software Engineer and Architect with more than twenty years’ experience in the design and implementation of large-scale software systems. He joined NearMap in April 2009 and is the Development Manager for HyperWeb, which delivers very high volumes of image data via the nearmap.com website and over the Internet. Before joining NearMap, Ben was R&D Manager at EMCC Software in the UK, leading product development teams for mobile enterprise and consumer applications and consulting on mobile and networked software development.

TSQL: An Efficient Dynamic Numbers Table

A numbers table is simply a table containing sequential integer values. The size of the required table will vary depending upon its use, but it is not uncommon to find permanent tables containing 1,000,000 rows. A numbers (or tally) table forms the basis of solving problems in a set-based way, and is a powerful technique for finding gaps in sequences, string manipulation (which if done purely with TSQL’s built-in functions can run very slowly), etc. It is also often used in the form of a date table, enabling some very efficient set based join constructs to be used on date range calculations.

While it is usual to create a fixed table in the database, there is the occasional need for a dynamic version. There are several ways not to do this! Such as the recursive CTE or a while loop inserting values one after another. A better option is the CROSS join against system tables method, and better still is Itzik’s often cited, cross joined CTE method:

--===== Itzik's CROSS JOINED CTE method 
WITH E00(N) AS (SELECT 1 UNION ALL SELECT 1),
E02(N) AS (SELECT 1 FROM E00 a, E00 b),
E04(N) AS (SELECT 1 FROM E02 a, E02 b),
E08(N) AS (SELECT 1 FROM E04 a, E04 b),
E16(N) AS (SELECT 1 FROM E08 a, E08 b),
E32(N) AS (SELECT 1 FROM E16 a, E16 b),
cteTally(N) AS (SELECT ROW_NUMBER() OVER (ORDER BY N) FROM E32)
SELECT N
FROM cteTally
WHERE N <= 1000000;
GO

After a little experimentation, I found that reducing the number of cross joins by increasing the size of the first table results in a more efficient query plan. I wrapped this up in an inline table valued function with the option of a start and end value for the sequence:

IF OBJECT_ID (N'dbo.tvf_DynamicNumbersTable') IS NOT NULL
DROP FUNCTION dbo.tvf_DynamicNumbersTable
GO

CREATE function dbo.tvf_DynamicNumbersTable
(
@pStartValue int = 1,
@pEndValue int = 1000000
)
returns table
as
return
(
with rows16(N) as
(
select 1 union all
select 1 union all
select 1 union all
select 1 union all
select 1 union all
select 1 union all
select 1 union all
select 1 union all
select 1 union all
select 1 union all
select 1 union all
select 1 union all
select 1 union all
select 1 union all
select 1 union all
select 1
),
rows256(N) as
(
select t1.N from rows16 t1 cross join rows16 t2
),
rows65536(N) as
(
select t1.N from rows256 t1 cross join rows256 t2
),
rows2pow32(N) as
(
select t1.N from rows65536 t1 cross join rows65536 t2
),
Numbers(N) as
(
select row_number() over (order by N) as N from rows2pow32 t1
)
select N from Numbers
where N between @pStartValue AND @pEndValue
);

Windows 7: Fast and Flexible File Copy with RoboCopy

Did you know that RoboCopy is included with all editions of Windows 7? I didn’t until very recently, when a colleague (Mike Minutillo) mentioned it.

Robocopy (short for Robust File Copy) can do so much more than the standard Copy and Xcopy commands.

The basic syntax is as follows:

robocopy source destination [file [file]…] [options]

The source and destination parameters are specified as drive:\path or \\server\share\path. The file parameter can contain one or more literal file names, or it can use ? and * wildcards.

For instance, this command copies the contents of one folder and all its subfolders from a local drive E to a shared folder:

robocopy “E:\test” \\server\public\test\ /MIR /W:30 /R:10 /MT:8 /LOG:\\server\public\logs

The /MIR switch mirrors the two folders, copying all folders (even empty ones) from the source directory and removing folders from the destination if they no longer exist on the source. The /W and /R switches set the wait and retry options; in this case, Robocopy will retry each copy up to 10 times, waiting 30 seconds between attempts. The /MT[:n] switch performs a multi-threaded copy, where n indicates the number of threads to be used (n is 8, by default) and can range from 1 to 128. The /LOG: switch logs output to the specified location.

To see the full list of options, type robocopy /? at a command prompt.

There’s even a GUI!

TSQL: Generate Missing Foreign Key Indexes

It’s good practice to ensure all foreign key columns are indexed (I’ve often wondered why SQL Server Management Studio doesn’t have a built-in option to perform this). I can’t remember where I saw this code originally (despite trying to search for a reference to it), but it is a useful addition to a TSQL code snippet toolbox:

--
-- Create non-clustered indexes for all foreign keys in the current database
--
DECLARE @sql varchar(4000)

CREATE TABLE #sqlfkindexes
(
id int not null identity(1,1),
sql varchar(4000) not null
)

INSERT INTO #sqlfkindexes
SELECT 'CREATE NONCLUSTERED INDEX [NC_' + tablename + '_' + columnname +'] ON [' +
schemaname + '].[' + tablename + '] ([' + columnname + ']);' as [sql]
FROM
(
-- All foreign key columns
SELECT
o.name AS tablename,
col.name AS columnName,
sch.name AS schemaname
FROM
sys.foreign_key_columns fkc
INNER JOIN sys.objects o ON fkc.parent_object_id = o.object_id
INNER JOIN sys.columns col ON col.object_id = o.object_id and fkc.parent_column_id = col.column_id
INNER JOIN sys.schemas sch ON sch.schema_id = o.schema_id

EXCEPT

-- All the already indexed columns
SELECT
o.name AS tablename,
col.name AS columnName,
sch.name AS schemaname
FROM
sys.index_columns ixc
INNER JOIN sys.objects o ON ixc.object_Id = o.object_id
INNER JOIN sys.columns col ON col.object_id = o.object_id and ixc.column_id = col.column_id
INNER JOIN sys.schemas sch ON sch.schema_id = o.schema_id
) FK
ORDER BY
schemaname,
tablename,
columnname

DECLARE @count int
SELECT @count = COUNT(*) FROM #sqlfkindexes
WHILE @count > 0
BEGIN
SELECT @sql = [sql] from #sqlfkindexes where [id] = @count
SET @count = @count - 1
PRINT @sql
-- Uncomment to execute directly
-- EXEC sp_executesql @sql
END

drop table #sqlfkindexes
GO

As is, this script prints out the missing index definitions but does not run them into the database. Simply copy and paste into another SSMS query window and run. (You could also uncomment the execute line, but I prefer to check them before running in).