Matt Roberts

Rails and .NET

  Home  |   Contact  |   Syndication    |   Login
  37 Posts | 0 Stories | 34 Comments | 35 Trackbacks

News




Twitter












Archives

Post Categories

BlogRoll

Entropy

Sunday, January 29, 2012 #

image

 

That there is a pic

 

]


Well this is a very dull post, I’m simply trying to post to tumblr from live writer. That is all.


Thursday, March 31, 2011 #

Well, it's been a while. I've been here on "geekswithblogs" for a good few years now, and recently not been too active.

So, to spur me on, and inspire me to write more, I've moved to a shinier newer place (no offence GWB). You can find me here:

http://mr-dev.tumblr.com

Adios.

Wednesday, August 11, 2010 #

At my current place, we’ve set up TeamCity as our build server. Previously I’ve used CruiseControl.net and never really questioned it – it works, it does the job, seemed quite nice if a little fiddly to setup.

(If you’re thinking “Hang on, Team City isn't free is it?”  - well there is a free version that is limited to a limited number of projects, configurations and agents – check the site for more details)

I was a bit sceptical about moving to TeamCity because I didn’t want to feel the pain of setting up yet another build/ci server and spending ages trying to get it working with our nant scripts – turns out I was so so wrong to worry. Team city is awesome! Let me talk you through some of the awesomeness…

 

Setting it up is a breeze

tc1

 

Its seriously easy to set a build configuration using TeamCity. Its all driven through the nice friendly web interface, so a real breeze to setup. Assuming you have an automated build script of some sort set up for your solution (like nant, nant, maven2, msbuild etc) then its really easy to plumb this into Team City. You can set up multiple build agents for your build really easily too.

Fantastic UI

So once you’ve got your build set up, you get all the usual stuff like a build history including things like which check-ins caused the build etc. You can drill into previous builds and see what happened – get the full build log, look at the tests, download the artefacts you defined for the build, all good stuff. You can also manually force a build. If a build fails you can set responsibility for fixing too. All of this is present in most (if not all) CI servers, but its just a lot more polished and feature-rich in Team City. 

Really Awesome Test and Cover Integration

This is what got me really excited (maybe I should be worried about that). You get all sorts of great reports/graphs from Team City that are really useful – like this one:

 

tc2

 

This shows a history of a swear word test we have, and how long its been taking to run and on what build agent.

If you have test coverage set up (like PartCover) then you can also integrate that and you get some really nice reports showing your coverage by class, methods and LOC – you even get an indicator of what the check-in did to improve (or reduce) that coverage – which is an awesome motivator for adding more tests!

 

So, all in all, I really like TeamCity, and I’m glad to be using it. If you’re considering getting a CI server set up for your project, or you want to try another flavour of CI server, check it out!


Thursday, June 4, 2009 #

I own a mac, I'm a fan of macs, but I'm not a mac-fanboy. I think they're bloody great machines, and that OSX is by far the best OS out there, but I appreciate they're not for everyone. Even osx has (cue dramatic pause) .. flaws. Copy a folder somewhere in OSX, and if the folder already exists on the destination it will prompt you to entirely replace that folder - WOT NO MERGE?! Anyway, apart from that minor niggle, OSX is awesome, especially for web development (in rails).

So where am I going with this? Recently a colleague at work has also taken the mac plunge and joined the collective, and so I thought it would be good for me to list the top (free) tools and applications that I couldn't live without on the mac. So, here they are:-

1) Firefox 3 and Safari 4
http://www.apple.com/safari/
http://www.mozilla.com/en-US/
I can't decide between these, so I use both. Firefox rules for its extensions, while Safari is very fast and slick.
 
2) Adium
http://adium.im/
Adium is a very nice IM client for the mac. Its light, simple, free of crappy adverts and other such bilge, and best of all, its a green duck. Nuff said.

3) iStat Menus
http://www.islayer.com/apps/istatmenus/
This is a really good system monitoring tool, that sits un-obtrusively in the apple menu, um, thing. Its seriously useful and very configurable, and gives me a reasuring insight into whats happening in the mac

4) Google notifier for mac
http://toolbar.google.com/gmail-helper/notifier_mac.html
Its a mail / calendar notifier for the mac. From google. Nice.

5) Quicksilver
http://thenextweb.com/2009/05/04/quicksilver-mac-greatest-app-time/
Ah, the swiss army knife of the mac world. This tool rocks. The blog above is a great write up on Quicksilver, and how to use it.

6) VLC
http://www.videolan.org/vlc/
Quicktime player is OK, pretty good for .MOV files, but well not that good for other formats. VLC on the other hand is one of those "just works" apps. it plays videos of most formats. It plays them well, and rarely complains. Nice.

7) Tweetie
http://www.atebits.com/tweetie-mac/
My mac twitter client of choice. Its a shame is ad-supported, but it really is a nice client, does everything I need, and has a good clean UI.

8) Growl.
http://growl.info/
I can't believe growl isn't actually built into OSX. Its a simple un-obtrusive notification system, that I first heard of when doing automated testing in rails. Turns out a lot of apps support growl notifications. Or maybe growl is just hooking into some central osx notifcation event broker. I dunno, but its very nice, and must be installed.

9) TextMate (or MacVim)
http://macromates.com/
Damn it. This one isn't free. But, its very cheap, and for your money you get a very very nice text editor. If you know about rails, you already know about this. If you don't want to pay, I also recommend macvim (http://code.google.com/p/macvim/). Its a mac port of VIM, done very nicely, and VIM is very nice, as long as you're prepared to master it. And theres some good rails stuff out there for VIM (http://www.akitaonrails.com/2009/1/4/rails-on-vim-in-english)

10) Transmission
http://www.transmissionbt.com/
I used this bittorrent client while I was waiting for uTorrent to be available for the mac. I liked it so much I stayed with it. Its simple, effective, pretty much does what it says on the tin.

Thats it :) By sheer co-incidence it came to 10 applications. I hope you find this list at least marginally useful, and i

Thursday, December 18, 2008 #

Ok - no credit to me for any of this good stuff. All I'm doing here is posting on how to get database rollback working in your Nunit tests.

Roy Osherove created something called XtUnit - "An Unofficial Unit Testing Extensibility Framework - Add new attributes to NUnit or MbUnit easily" - http://weblogs.asp.net/rosherove/archive/2004/10/05/238201.aspx

His blog talks you through all the cool stuff that you can do with this framework, like implementing your own attributes to do cool things pre and post method execution. But the thing I wanted more than anything was to add rollback powers to existing NUNit tests, I didn't want to switch to MbUnit to do this, I just wanted to be able to do it with my existing tests.

It was pretty simple to get working, but the documentation is a tiny bit in-complete, so this is what you need to do.

I'm in Visual Studio 2008, using LLBLGenPro to talk to the database (obviously you don't need to use LLBLGen Pro, but why the hell not!)

  1. Download the binaries. You could download the source but you'll need to migrate it to 2008, and I didn't need the src.
  2. Reference the binary file that is downloaded in your test project.
  3. Make sure that your test fixture class derives from ExtensibleFixture
  4. Add the DataRollBack attribute to your test method

Done!

Here's the code for completion. My example as basically adding a row to a table called "GlobalSearch", in case the LLBLGen stuff looks confusing to you.

   1: [TestFixture]
   2: public class Class1 : ExtensibleFixture
   3: {
   4:     [Test, DataRollBack]
   5:     public void TestDataRollBack()
   6:     {
   7:         var adapter = new DataAccessAdapter("connection string here", false, CatalogNameUsage.ForceName, "");
   8:         // Create a new GlobalSearchEntity, save it, then rollback
   9:         var g = new GlobalSearchQueueEntity();
  10:         g.RecordId = 100;
  11:         g.ToolCode = "TOOLCODE";
  12:         adapter.SaveEntity(g);
  13:     }
  14: }

Tuesday, December 16, 2008 #

There are 2 cool things I want to share here...

Partial Mocking

This is a very cool and useful feature of RhinoMocks, which allows you to test part of a class, but have some of it act normally. Its explained very well here: http://ayende.com/Wiki/(S(gvtu2q45soph42vfyhig2j55))/Rhino+Mocks+Partial+Mocks.ashx

Making "protected" methods available for mocking.

Partial mocks are great, but what do you do when you need to "mock" out a method that isn't visible to your test class - i.e. its private or protected. Well, it turns out you can use a nifty little attribute called InternalsVisibleTo to make any internal methods visible to other assemblies (i.e. your testing assembly). So, in my code, I had a method called GetRecord, which was protected. I changed this to make it protected internal virtual, and added this to my AssemblyInfo.cs file:

   1: [assembly: InternalsVisibleTo("NUnitTests")] 
   2: [assembly: InternalsVisibleTo(RhinoMocks.NormalName)] 
   3: [assembly: InternalsVisibleTo(RhinoMocks.StrongName)] 

NUnitTests is the name of my assembly that contains the tests for my project. Once this is done and compiled, intellisense lets me mock that protected method. Just for completeness, here is the code that sets up my partial mock:

   1: var mocks = new MockRepository(); 
   2: var globalSearchServiceBase = mocks.PartialMock<ClassToMock>(); 
   3: Expect.Call(globalSearchServiceBase.GetRecord(1)).IgnoreArguments().Return(GetFakeData()); 
   4: mocks.ReplayAll(); 

Thats it. Hope that was at least marginally useful to someone :)


Saturday, October 4, 2008 #

I've been playing with CouchDB a little recently. Its a "schema-free document-oriented database", which sounds pretty weird when all you've ever known is relational databases. At work, we're considering what architecture we want to go with for a new product that needs to be very flexible - the users need to be able to add fields, remove fields, and do all sorts of crazy things with the application.

One of the options we have, is to use something like CouchDB to be able to create an uber-flexible database that can evolve over time, and be very scalable. because our new product will be a SaaS one. Its pretty clear to see why CouchDB fits the bill.

Anyway, its pretty cool, and I wanted to see if I could get started creating a little application in Rails using CouchDB on the back end... It was pretty slow going until I came across this fantastic PeepCode Screencast This screencast goes through the basics of CouchDB, and then goes on to build a nifty notes-esque web application using a CouchDB gem called CouchRest.

Its a quality peepcode, and the CouchRest gem looks like its really going to help me :)

It'll be interesting to see what kind of take up CouchDB or other schema-free cloud computing databases get in the .NET world, I don't see much happening out there at the moment.

Anyway, watch out for my killer CouchDB-based rails application, coming soon (yeah right!)

Friday, April 11, 2008 #

AKA: "Why am I getting 'ActiveX can't create component' when I try to access my COM DLL's"
AKA: "Why am I getting 'Service Unavailable' when I've set IIS to run in 32 bit compatibility mode.
AKA "Why do I get 404 errors when I browse to my ASPX pages"

Man that's a long title :)

So, I recently had to spend some time looking into getting my companies web application working in 64 Bit Windows (2003 R2 to be exact). I eventually got this working, but found the information scattered and incomplete on the interweb, so this little guide should see you through. I hope someone out there finds it useful.

Starting Point.

You have windows 2003 R2 64 bit SP1. You have the 64bit version of the .NET framework (V2 or higher) installed. No other changes have been made to IIS - it seems to run just fine for serving .NET and HTML. You install your web application that includes COM, try to run it, and BANG...

Microsoft VBScript runtime error '800a01ad'
ActiveX component can't create object

The cause? Its because those COM objects are 32 bit components, and by default IIS won't work with 32 components. You need to tell IIS to run in 32 bit compatibility mode (WOW64). To do this, you need to configure IIS to run in 32 bit compatibility mode, as explained by this link.

But wait! Its not quite that easy! If you do this, then you're telling IIS to run in 32 bit mode, but then you've already got the 64 bit ASP.NET DLL's registered with IIS, so the first time you hit your app, you'll probably see a big fat "Service Unavailable" Error message. If you look in the event log, you'll see your application pools are crashing with this error:

A process serving application pool 'DefaultAppPool' reported a failure.
The process id was '4156'. The data field contains the error number.

So, you need to register the 32 bit ASP.NET DLL's with IIS. But wait! You can't do that before you un-register the existing 64 bit ones.

Enough waffling. Here's the step-by-step :-

  1. Un-register the 64 bit ASP.NET DLL's. In a command prompt, navigate to C:\Windows\Framework64\v2.0.50727\ and from there run "aspnet_regiis -u"
  2. Set IIS to work in 32 bit compatibility (WOW64) mode:
    cscript c:\inetpub\AdminScripts\adsutil.vbs set w3svc/AppPools/Enable32BitAppOnWin64 1
  3. Register the 32-Bit ASP.NET DLL's. Navigate to C:\Windows\Framework\v2.0.50727\ and from there run "aspnet_regiis -i"
  4. Finally, in IIS, Navigate to "Web Service Extensions", and make sure that ASP.NET is "allowed".

You're done!


Friday, December 14, 2007 #

Rails makes such a nice change from coding in .NET. I mean, I do like .NET and C#, but sometimes its very bloated and can be quite cumbersome to do things.

Rails, on the other hand, isn't big. Or cumbersome. In fact, its downright lean and to-the-point, unlike my blog posts (what there are of them!).

Anyway, today we're talking category trees, surely one of the most exciting concepts that there is to talk about. One thing that made me smile recently was the need to list all the categories that a company was tagged to. So, this happens with code that looks like this :-

<%for cat in @Categories %>
    <%= cat.name + "<br>" %>
<% end %>

.. Where @Categories is a collection of categories from the controller, and is generated like this:

@Categories = Company.find(params["id"]).Category.find(:all)

So, this noddy code just lists all cats that the company was tagged to. After deploying this, I was asked to change it so that the full hierarchy of categories was displayed. So instead of "Cat 1", the user wants to see "Root -> Services -> Cat 1". Hmmm, I thought, perhaps I need to write a little recursive method to go and get the parent nodes of each selected category... Turns out that because I was using acts_as_tree in the model (google it!), I was able to solve this with a really simple bit of code added to the category model :-

    def fullcategoryname
        self.ancestors().each() { |parent| fullname += parent.name + " / " }
        fullname += self.name
  end

Thats nice! :) Gotta like Ruby.


Tuesday, October 9, 2007 #

Our software has been around for a long time. It started life as an ASP application, with all the database logic tucked away in VB6 components, and lots and lots of ASP pages.

Because we invested so much into these VB6 components and also the ASP UI infrastructure, we're still using it today - so we have ASP pages that call VB6 components. Obviously, as we move more and more of the code into .NET, we are relying on Interop more and more to allow us to make use of "new" stuff from existing ASP pages... It was all working well until recently we needed to implement new features that rely on getting data out of the application config file... thats where it all goes bad :(

If you interop from unmanaged code to .NET, .NET will look for an app config that matches the executing process's filename + ".config".

.. which sucks for us. We implemented a cool new permissions checking infrastructure in .NET, and as part of this I wanted to use the SQL Cache Dependency to be able to auto-remove cache data when the underlying data changes. But...SQL Cache dependency relies on configuration data being set in the app config, so when we call through from a VB6 app - it aint gonna work! If called from COM like our .NET code is, the .NET assembly you execute is being executed from the process DLLHOST.exe, which lives in the System32 folder. Therefore the CLR looks for a config file called "DLLHost.Exe.Config" - try pursuading your clients to create that :)
 
This is a real shame and it stops us from using the SQL Cache Dependency stuff and some other things that are configured using the app config. We can get round it for simple settings like the connection strings, because we create our own classes to process the web.config that we actually do want to use, and that works, but for a lot of stuff that relies heavily on config setup, we can't use it... its a bummer!

Testing from Windows live writer :)


Wednesday, April 18, 2007 #

I recently decided to play around a bit with Ruby on Rails, its had so much hype so I thought it would be interesting to see how it fares up against ASP.NET programming!

Anyway, I'm only just starting out, but first impressions are very very good indeed! Ruby seems to be a very intuitive language, although I wouldn't say I preferred it to C#. However, the rails framework that deals with all the agile web framework side of things seems awesome!! Really easy to use and get a reasonably complex web site up and running.

I'm going to waffle on a bit more about this in the future, but in the meantime if you're interested in giving it a go on a windows box, its ridiculously easy - you don't even have to "install" any software!! Just do this:

1) Download "InstantRails". http://instantrails.rubyforge.org/wiki/wiki.pl
From the website: Instant Rails is a one-stop Rails runtime solution containing Ruby, Rails, Apache, and MySQL, all pre-configured and ready to run. No installer, you simply drop it into the directory of your choice and run it. It does not modify your system environment.
2) Get a "development environment setup"
If you're used to being spoilt/abused by Visual Studio and want something all nice and integrated, then you need to get RadRails. RadRails is a free plugin for the excellent-if-sometimes-a-little-too-slow-for-me Eclipse devenv from Sun. It needs the java runtime to work. Anyway, get it from www.radrails.org
Alternatively, use VIM with ruby plugins, or something else :)
3) Follow some tutorials.
Start here....
instantrails.rubyforge.org/tutorial/index.html
Then here....
www.digitalmediaminute.com/article/1816/top-ruby-on-rails-tutorials

Thursday, January 4, 2007 #

Installing the Visual Studio 2005 Service Pack and you get this.....


Tuesday, January 2, 2007 #

Well, its another new year (did I mention that?) I'm going to make a big attempt to update my blog more often than I did towards the end of last year, that was pitiful to be honest.

So, what better way to start the new year than installing some free software to make your development/computing life that bit easier.... Here's my top 5 list of "Stuff I always install when I rebuild my machine":

  1. Notepad2. Its my fave notepad replacement, with all the usual syntax highlighting and cool features. Check it out: http://www.flos-freeware.ch/notepad2.html
  2. TaskSwitchXP. Its a fantastic Alt-Tab replacement with loads of cool features. http://www.ntwind.com/software/taskswitchxp.html
  3. Firefox with extensions. The best browser gets even better when you start playing with extensions. There's so many good ones, but AdBlock and AllInOneSideBar always make my list. For web developers, check out FireBug (http://www.getfirebug.com/)
  4. Omea Reader. Its a free RSS reader and much more. I only use it for RSS feeds, and I really like it for that. I used to use SharpReader until I paid attention to the amount of memory it was consuming! http://www.jetbrains.com/omea/reader/
  5. Foxit Reader. For the love of God don't use that horrible piece of bloated tat known as Adobe Reader. There is a better way, and its here: http://www.foxitsoftware.com/pdf/rd_intro.php


I could go on for another 20 entries here, but these are probably my top ones... Oh, and "Query Express" (http://www.albahari.com/queryexpress.html)... oh and LLBLGen, but thats not free!