# Monday, February 14, 2011

My little Codeplex project has had a few updates lately, with a new release tonight. This weekend I was transferring a SqlServer database onto MySQL, so I fixed up the SQL generation capabilities and added it to the UI.

Simply, it now can read the SqlServer schema (or almost any other ADO database), and write out the DDL for a MySQL database. Or an Oracle one. It should also work from Oracle to SqlServer etc.

Of course this only works for simple databases. Mine had a couple of uniqueidentifer columns (GUIDs), which don't translate to anything other than in SqlServer, so that was fixed up manually. Check constraints can be problematic, and it doesn't touch views or, God forbid, triggers and stored procedures. It won't roundtrip accurately (say SqlServer to MySql to SqlServer) because we are generalizing datatypes each time.

It works on my database. Winking smile

posted on Monday, February 14, 2011 10:02:01 PM (Romance Standard Time, UTC+01:00)  #    Comments [0]
# Wednesday, January 26, 2011

I've updated the Database Schema Reader CodePlex project with basic code generation.

The original code (vintage 2005) did all sorts of things like generating ADO data access classes and, over I added NHibernate mapping, Castle ActiveRecord, and Enterprise Library validation block attributes. It's old code (that is, ugly and horrible), so I stole bits of code and made it just do something a lot simpler.

Now it reads the table schema and turns them into simple POCO classes that are NHibernate compatible (virtual properties, override Equals and GetHashCode, composite keys are made into Key classes). There's also (simplistic) NHibernate mapping. And finally it has .Net 3.5's DataAnnotations for validation.

For quick and simple data-driven code, it's an okay starting point. It is just a starting point- not a data driven solution. There is a UI, but it's the most basic one I could design - it's certainly not anything like the Linq2Sql or EF designers (there are NHibernate mapping designers out there). But once you've got started in NHibernate you'll prefer to continue in code-first mode anyway.

If your database is a mess (I've seen a few with no primary keys .) it won't be much help!

posted on Wednesday, January 26, 2011 9:36:04 PM (Romance Standard Time, UTC+01:00)  #    Comments [0]
# Saturday, November 13, 2010

messeberlin2010

What was hot:

Windows Phone 7. The stand where you could try the various handsets was always busy. Several people had their own sets (last year, it was iPhones everywhere). There were adverts all over Berlin too. It won't worry Apple, and Android has reached enough mass to secure second place, but Microsoft should easily beat Symbian and Blackberry especially if they keep up the momentum on updates and new features (HTML 5 browser, apps through private company portals rather than Microsoft's public marketplace).

The cloud. Lots of focus on aspects of Azure, including the announcement of private clouds (Hyper V Cloud) with hosting available. On the developer track, I was pretty interested to learn about the future of distributed LINQ, based on the Microsoft Research DryadLinq project. That project allows you to run distributed (Map/Reduce) queries over an HPC cluster. The future goal is to run it on Azure nodes. Just like in PLINQ where you can append "AsParallel" to a linq statement, you will be able to add "AsDistributed" and the linq statement will be broken up into computation units and run on different nodes (your app.config will also have configuration to help the create the job graph).

Kinect. The graphics are simple and Wii-like, but the demo stand was very popular.

Silverlight. There were quite a few technical Silverlight sessions. From talking to people, it seems Silverlight has taken off for line of business apps within intranets, at least in Microsoft environments where Windows Forms or WPF would have been used before. On the public web, it hasn't dented Flash and Flex, and the only public success is Netflix. But for .Net based IT departments it seems the obvious choice for RIA. The risk from the recent publicity is that managers won't want to invest in it because they think it's dead. Based on the number of sessions here, it's still key to Microsoft.

Berlin. It was cold and grey, and you could only get out after dark, but it's an interesting city to explore. Transport was easy too.

What was not:

Developers. There isn't a lot new this year for developers. We have no new Visual Studio/.Net version.

Although I complained earlier about the heavy "IT Pro" bias, I heard that some infrastructure guys were also disappointed by the content- too much simple introductions and marketing and not enough meat.

Internet connectivity (at the start of the week). Wireless was terrible on the first day, but it did improve - it was excellent on Thursday and Friday. There seemed to be many more power and wired connections this year. Okay, perhaps this point should also be in the "hot" category!

Crowds, It was very busy, and the huge space and confusing layout of the Messe made navigating to sessions a little tricky at times.

Loot. Crap. A stupid little swim-bag, and lots of T-shirts. The organizers and exhibitors have a major lack of imagination and, obviously, money. Where were the USB sticks and other useful give-aways from previous years?

Where's HTML 5?

There were a couple of HTML 5 sessions showing off IE 9, and pretty impressive it is too. There was a pleasing acknowledgement that other browsers exist and also target HTML 5, and IE 9 is just catching up. But there is no tooling, or apparently any due dates. In MVC you can just write the HTML and reference Modenizr etc to trigger down-level support, but there is no intellisense or code colouring yet, let alone HtmlHelpers. It wouldn't be difficult to traditional ASP.Net webcontrols for key HTML 5 tags. It's not just <video>; what I'd like is <input type="date" with an browser datepicker (and down-level detection to add jQuery UI). iPhone and Android (but not Windows Phone 7 yet) have strong HTML 5 features which we want to use. Oh, and the next version of Windows Phone needs to have HTML 5 capabilities to match the desktop IE9. Maybe longer term could Silverlight XAML be converted to SVG?

Where's Alt.Net?

As traditional, this was a Microsoft-only conference. Several presenters used Resharper,  and there was the odd passing mention of NHibernate. But when you talk to other attendees, NHibernate, log4Net and other testing frameworks such as NUnit and MbUnit are in widespread use - my impression is that Entity Framework is some way behind. With Oracle doing it's best to alienate Java developers, Microsoft could start showing a friendlier face with a few sessions for Mono, IoC, mocking, BDD, NoSQL etc.

Future

I enjoyed TechEd, but I think the moral of this year is, only go to a TechEd Europe when Microsoft are launching a new Visual Studio or other major developer tool.

posted on Saturday, November 13, 2010 5:51:23 PM (Romance Standard Time, UTC+01:00)  #    Comments [0]
# Tuesday, November 09, 2010

I'm back in Berlin for the Microsoft TechEd conference. It's huge- thousands of people, and even though the exhibition halls are like aircraft hangars they are packed with people, desperate to get free croissants, T-shirts and other baubles.

berlintechedThere's a lot of "IT pro" (windows admins) content, in the exhibitors and session schedule, and developers like me have thinner pickings (unless you just want croissants and T shirts, which evidently most do).

The only new stuff for developers is Windows Phone 7. The demo stand with various windows phones to try was always packed, and yes, they do look nice. Some cloud stuff, which is clearly a key target for Microsoft. Otherwise it's a rehash of the Visual Studio 2010 and .Net 4 introductory stuff from last year, which was fine last year when it was new but it's a little tired now. Very thin pickings on ASP, a single (introductory) session on MVC, a little on parallel. There is quite a bit on Silverlight, but everyone outside this audience now thinks Microsoft have killed it.

The goody bag is just a simple sports sack (I'm still carrying the rather nice laptop bag from last year). No free Windows 7 Ultimate disc this year (well, you do get a TechNet subscription so that's 5 licenses there, but still.) The free stuff from the vendors in the exhibition hall is showing signs of the economic downturn too. Lots of competitions though.

Only 3 more days of crowds, food, beer, and T-shirt collecting to go.

posted on Tuesday, November 09, 2010 10:26:28 PM (Romance Standard Time, UTC+01:00)  #    Comments [0]
# Monday, November 01, 2010

A long time ago I wrote my database schema reader. It was 2005, .Net 2.0 was just out and I was learning about the new features. .Net 2.0's ADO DbProviderFactory had a nice idea, GetSchema, to get database independent schema information. But the GetSchema collections were slightly different for each database, and they were data tables. So I wrote a simple facade over them to get proper classes.

Initially I used it to generate CRUD stored procedures, and then to generate data access code, even including NHibernate mappings. I even did some (simple) database conversions. All this was quite icky, and each time I did the code-gen a different way, but the core facade worked well.

After getting a couple of queries about the extracts I'd already posted, I thought I might as well put up the entire source code. So here's the codeplex project with the source code, and even some basic SQL code-gen.

I picked Codeplex just because it's more .Net-centric than Google code or github, plus I'm more familiar with TFS and Subversion source control. It was pretty easy. I don't expect many downloads (if any!), but maybe a couple of people can steal the relevant bits of source code.

Check out the database schema reader codeplex project.

posted on Monday, November 01, 2010 12:59:33 PM (Romance Standard Time, UTC+01:00)  #    Comments [0]
# Monday, September 20, 2010
Finding out all users on Team Foundation Server turns out to be pretty easy.
I found the answer at http://blogs.msdn.com/b/jmanning/archive/2006/05/02/588648.aspx

You need a reference to C:\Program Files\Microsoft Visual Studio 9.0\Common7\IDE\PrivateAssemblies\Microsoft.TeamFoundation.dll plus the Microsoft.TeamFoundation.Client.dll and Microsoft.TeamFoundation.Common.dll

var server = new TeamFoundationServer(tfsUrl);
var groupSecurityService =
    (IGroupSecurityService)server.GetService(typeof(IGroupSecurityService));

var validUserSid =
    groupSecurityService.ReadIdentity(
        SearchFactor.AccountName,
        @"[Server]\Team Foundation Valid Users",
        QueryMembership.Expanded);

Identity[] identities =
    groupSecurityService.ReadIdentities(
        SearchFactor.Sid,
        validUserSid.Members,
        QueryMembership.None);

//exclude Administrators and system accounts
foreach (Identity id in identities.Where(x=>
    x.Type == IdentityType.WindowsUser &&
    x.Deleted == false &&
    !x.Description.StartsWith("Built-in account", StringComparison.OrdinalIgnoreCase) &&
    !string.IsNullOrEmpty(x.MailAddress) &&
    !x.AccountName.StartsWith("sys_", StringComparison.OrdinalIgnoreCase)))
{
        Debug.WriteLine(id.AccountName + " " + id.DisplayName);
}


posted on Monday, September 20, 2010 3:51:34 PM (Romance Daylight Time, UTC+02:00)  #    Comments [0]
# Tuesday, August 10, 2010
Next step in my adventures in deploying to IIS 7

This time I try to access my webservice (MyService.svc).

HTTP Error 404.3 - Not Found

The page you are requesting cannot be served because of the extension of the configuration. If the page is a script, add a handler. If the file should be downloaded, add a MIME map.

The IIS handlers window shows no handler for *.svc.

Solution:
Open a command window as administrator
Go to C:\windows\Microsoft.Net\Framework\v3.0\Windows Communication Foundation
Type ServiceModelReg –i

No need to restart, it just works.


UPDATE .Net 4
Open a command window as administrator
Go to %windir%\Microsoft.NET\Framework\v4.0.30319
Type ServiceModelReg –i -c:httpnamespace

posted on Tuesday, August 10, 2010 9:44:57 AM (Romance Daylight Time, UTC+02:00)  #    Comments [0]
When installing a website built on XP/ IIS6 or the built-in Visual Studio Cassini, you put httpHandlers and httpModules in system.web.
On Windows Server 2008/ IIS7, you use system.webServer, with modules and handlers.

If you use the web.config in the standard Ajax-enabled template, this just works.

If not, it doesn't. IIS7 throws an error page.
Description: This application is running in an application pool that uses the Integrated .NET mode. This is the preferred mode for running ASP.NET applications on the current and future version of IIS.

In this mode, the application should not specify ASP.NET module components in the <system.web>/<httpModules> configuration section. Instead, it should use the <system.webServer>/<modules> configuration section to load ASP.NET module components.


The fix is in that Ajax web.config.
    <system.webServer>
        <validation validateIntegratedModeConfiguration="false"/>

It just turns off the validation, allowing system.web/httpModules etc to exist, but ignores them and uses the system.webServer/modules etc version.

Documentation is here.

Yes, this just happened to me. Doh.

posted on Tuesday, August 10, 2010 8:15:08 AM (Romance Daylight Time, UTC+02:00)  #    Comments [0]
# Monday, August 09, 2010
I had a Windows Server 2008 R2 but no IIS. So how to install it? It isn't obvious.

It's in Administrative Tools/ Server Manager / scroll to Roles then Add Roles.
In the roles wizard is a checkbox for Web Server (IIS)
There are various sub options including Common HTTP Features (static content for your images, css), ASP.Net, Security (Windows authentication), Performance (compression), Management Tools (IIS manager)

Here's the details



posted on Monday, August 09, 2010 11:52:17 AM (Romance Daylight Time, UTC+02:00)  #    Comments [0]
# Sunday, August 01, 2010

I was looking at the mess of another programmer's code and realised how much we have individual code styles.

Actually his code wasn't a mess. I turn on code wrapping, he didn't. His nested lambda expressions were suddenly all over the place on my screen, but looked tidy on a wide scrolled screen. I would have introduced more line breaks, splitting parameters onto different lines, but creating more vertical scrolling.

Most colleagues don't write unit tests. That's changing. I've been writing unit tests since .net 1. While I still see people exercising their code by writing console projects or winforms, I've always written unit tests. It's a primitive sort of TDD, at least the part about creating the API in a test. My code is generally old style Asserts against classes and methods, having used vintage NUnit and now MsTest. Lately I try to break up the test into arrange/act/assert sections, and sometimes the BDD language of "Given"/"When"/"Then". Recently company style is to use a custom BDD-type framework on MsTest, but I think the underscores in naming are just plain ugly (the Ruby RSpec style with quoted strings is much nicer and more natural).

I mostly use manual mocks, and whenever I've tried to use a mocking framework I've ripped it out after a while- if you have to write a manual mock it simplifies your API, and that seems neater to me. Recently I've been using Moq for stitching together some components that need use services, and it makes quite heavyweight tests (mostly because we're not allowed to use a DI framework).

Resharper, and more recently CodeRush, are hugely influential in code style- getting the right margin to go green is pretty satisfying, even for very minor things like deleting unused "using" statements. When Resharper 3 suggested using "var" instead of explicit types, I followed them, even though many developers dislike it intensely. The majority opinion seems to be to use "var" with constructors ("var x = new Entity()") but to specify the type returned from methods ("Entity x = Create();"). For the last 2 years or so (when I moved to CodeRush), my code has mostly followed the latter style. When quickly sketching together code, I use var, because I'll be changing methods to use interfaces or base classes, and you don't even have to do rename refactoring.

Resharper has got quite good at suggesting variable names, and usually I take the suggestions. Otherwise some of my variable names can be short - I'm particularly like to use "x" in Linq expressions because brevity makes them much easier to read (as long as methods are short enough):

var result = list.Where(x => x.IsValid); //simple variable names work fine in short methods & linq

ICommonCustomerEntity commonCustomerEntity = commonCustomerEntityCollection.Where(commonCustomerEntity => commonCustomerEntity.IsValid); //ugh

One thing that is characteristic of my code are chunks of specs/user stories (or emails/ work items/ bug reports as applicable) pasted in as internal comments. It doesn't always stay there after I've finished, but it's the first thing I do before coding. It can be nice to see the business logic text immediately above the code (much better than in a Word document, TFS or some task management tracker). It's particularly useful to quote emails when tracking the changing business requirements as you go through acceptance.

posted on Sunday, August 01, 2010 7:48:52 AM (Romance Daylight Time, UTC+02:00)  #    Comments [0]