84% of people reading this will not find the the mistake in this A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z.
Visual Studio asks for Team Foundation Server (TFS) credentials on start up
10 SepMy latest freelance project uses TFS for source control. I’d never used it before, having sworn off MS source control following an unpleasant incident with Source-Safe.
Amazingly TFS seems fine. It’s very much part of the VS toolset, but I was surprised to find that VS would display a TFS login prompt every time on start-up, not just when I opened a project that used TFS.
This got annoying pretty quickly so I looked around for a solution.
Here it is for my reference (this is copied from the blog of ‘Subhash Dike – thank you):
Steps (Windows 7)
- Control Panel, User Accounts
- Click “Manage your credentials” (on the left);
- In the “Stored Credentials for Automatic logon” page, click “Add a windows credential”;
-
On the resultant page Type in your following details -Plex (or any other TFS server for that matter)
- Add only the host name in the “Network details” field (tfs server full name);
- Type username in the “Domain\FirstName.LastName” format;
- Type Password
AppHarbor and nUnit
16 Apr
One of the reasons I moved from SVN to Git is that I wanted to have a play with AppHarbor, a reasonably new PaaS offering which (used to) boast the great slogan of ”Azure Done Right“.
Two things I really like about AppHarbor are:
- The developer plan (Canoe) is free! Which means you can have a hosted version of your development site available for clients to look at – for nothing
- If you have unit tests, AppHarbor will run the tests, only updating the deployed version if all the tests pass. This is GREAT. If you have ever watched TeamCity burn up CPU on a dev server you will know how wonderful it is to offload that to somebody lse (and then sell the dev server – yay)
There are loads of great resources on getting started with AppHarbor, which make the process look fool proof, and to be fair the first app I deployed (a simple MVC3 app with no tests) was pulled from Git and just worked.
My next test was a Web app with tests. I commited to Git, pushed to GitHub and……AppHarbor couldn’t find any tests and deployed the new version. Hmmm.
After a little digging I found out that AppHarbor uses Gallio to run the tests and Gallio only supports nUnit up to version 2.5.3 – whereas I am running nUnit 2.6.0.
So one NuGet un-install later I copied the older nunit.framework.dll across and Hey Presto – it now all works.
Hopefully this little tip will save someone the time I burnt on this!
At last, we get to Simple.Data
18 OctSo far in this coding adventure we have created a project with NancyFX as the front end.
A Nancy GET request for a specified route renders a Razor webpage. The razor view provides inital values for various Knockout.js view models in the page and it’s partial pages. The page has various jQuery modals for CRUD and reporting which use JSON data on demand via jQuery REST calls to NancyFx.
So far, the app has been developed using hard-coded dummy data within repositories – but now that our domain model design has settled, it’s time to make some database tables and connect to them. For this we are going to have a go with Simple.Data.
Simple.Data is easily installed with NuGet.
I updated the web.config to provide Simple.Data.Properties.Settings.DefaultConnectionString and created the repository that implemented this interface
public interface ILocationStatusRepository
{
ILocationStatus SelectById(int locationStatusId);
IEnumerable<ILocationStatus> SelectAll();
void Update(ILocationStatus locationStatus);
void Insert(ILocationStatus locationStatus);
void Delete(ILocationStatus locationStatus);
}
So here’s the first part of SelectById method (pardon the line breaks)
public ILocationStatus SelectById(int locationStatusId)
{
var dbObject = Database.Default
.LocationStatus.FindByLocationStatusId(locationStatusId);
Now we can see Simple.Data working it’s magic. With ONLY the web.config connection string setting Simple.Data has opened a connection to the database, looked at the LocationStatus table and understood that I want to FindBy the LocationStatusId (a column that exists in my database table). The database returns the data and Simple.Data creates a dynamic object, then maps the database table to the object and closes the connection. All in one line. Wow.
In a smaller application to the one I am on, I might have a single tier where I quickly reach in and use the dynamic object directly – but in this instance I want to map Simple.Data’s dynamic object to a domain object. I started with the wonderful ObjectMapper
Mapper.CreateMap<dynamic, ILocationStatus>();
ILocationStatus domainObject = Mapper
.Map<dynamic, ILocationStatus>(dbObject);
return domainObject;
Unfortunately, it doesn’t seem to work with dynamic objects. ValueInjecter is supposed to work with dynamic objects, I tried
domainObject.InjectFrom((object)dbObject);
But from some reason that wasn’t happening.
Out of interest I tried a cast
(LocationStatus)dbObject
which worked! Is this duck casting in action? I suppose it must be (tsk, something else I’d missed). Cool. So anyway, our repositories have Simple.Data actions like those below
public IAssetHolder SelectById(int assetHolderId)
{
var db = Database.Open();
var dbObject = db.AssetHolder
.FindAll(db.AssetHolder.AssetHolderId == assetHolderId
&& db.AssetHolder.Deleted == false)
.FirstOrDefault();
return dbObject != null ? (AssetHolder)dbObject : null;
}
public IEnumerable<IAssetHolder> SelectAll()
{
var db = Database.Open();
var dbObject = db.AssetHolder
.FindAll(db.AssetHolder.Deleted == false)
.OrderByAssetHolderName();
return dbObject != null ? dbObject.ToList<AssetHolder>() : null;
}
Remember that we have only added a connection string in web.config and the NuGet package for this to work. Genius.
This blog is not about repeating what exists in the documentation. If I find anything new or interesting, be sure I’ll post it here.
If I ever meet Mark Rendle, be sure I’ll buy him a beer. Thanks Mark.
Making mistakes with Nancy
28 Sep<< Getting to know Nancy & Simple.Data
Of course there is documentation for Nancy (which I won’t repeat here) – but that didn’t stop us experiencing a few hiccups on the way.
In ‘Creating your first Nancy application’ The documentation clearly states “1. Create a new ASP.NET Empty Web Project”. I don’t have that template. The closest I get is an ‘ASP.NET Empty Website’. “No problem” I say. “Those VS templates don’t actually do anything – they just setup some folders (bin) and files like web.config and pre-populate some configuration values. Onwards.” So onwards. I added my first NancyModule:
Get["/"] = parameters => "Hello World";

Compiled and ran and ? Oh. That’s just a directory listing = not the droid I’m looking for.
Maybe there is a difference between WebSites and WebApplication? Bloody Microsoft and their stupid names for everything..and, ah yes. WebSites are compiled into lots of little assemblies (oh yes, it’s all coming back to me now) whereas a WebApplication is precompiled into a single Dll. KK. That doesn’t explain Nancy not listening for my GET “/” and returning a string like it should. My intuition tells me it has something to do with the Nancy HttpHandlers defined in web.config – but I’m not sure why or what and being practical I actually want a WebApplication, not a WebSite anyway, so lets start again.
[starts again, this time with an 'Empty ASP.NET Web Application' (from the Projects menu)].]
Bish, bash, bosh. Compile. Run. Yay! “Hello World”. Cool.
Let’s add a view:
Get["/TestView"] = parameters => View["hello",null];
Ah, why is that not working…? It’s just an empty page. It doesn’t seem to understand Razor. Why would that be? The reason, of coure is that I forgotten to add a View Engine. I really should read the documentation…
PM> Install-Package Nancy.Viewengines.Razor
Yay! That works! Let’s change the view. I said, let’s change the view. Change the view? anyone? Ah. The View is not changing.
It must be cached. Clear the cache. It’s still not changing. Hmnn. Where is it cached then?
At this point I was a bit baffled. Why was the view not changing? Time to ask on StackOverflow. Within ten minutes Steven Robbins (aka GrumpyDev) had answered my query. A quick compile and bin plop later* and caching is disabled in debug mode. Rock on. I think we’ll be OK from here – but if we hit anything unexpected I will post the solution. Hopefully these Nancy posts will help someone. Ciao.
*Compile the CustomBootStrapper into it’s own assembly and drop it into the WebApplications /bin directory where it is (somehow) auto-discovered by Nancy.
Getting to know Nancy & Simple.Data
28 Sep
After many many months working on a large Enterprise application, my development team were offered a small, fun, greenfield project. We jumped at the chance. The project was small enough to be able to take risks and still be able to recover the situation if it all went wrong. So Risk? What risks were we thinking of?
- NancyFX is “a Sinatra inspired web framework for the .NET platform” available from GitHub.
- Simple.Data is “a light-weight, dynamic data access component for C# 4.0″, written by Mark Rendle.
Neither project is ‘risky’ in themselves. The code is well written and the authors extremely helpful. For us, the risky part – the unknown part – lies in using both as relatively early adopters in a commercial project with a set deadline. Even so, we’ve considered the risk vs benefit and we’re giving it a go. We’ve talked about risk. What’s the benefit, you ask?
As a team, we have been a bit stuck in ‘legacy’ ASP.NET forms applications and often kept too busy to move on. We are moving towards MVC (+TDD, SOLID DRY code etc), but after years of WebForms it can sometimes be hard to make the paradigm shift needed to think in terms of Model, Views and Routes. Enter Nancy. Nancy is small. Really small. Really really really small. In fact there is hardly anything there at all, which means very little to learn – at least for the basic bits.
When we said “Hello Nancy” we said “Goodbye horrible WebForms”. When someone asked me “Will GridView work in the View?” I happily answered “No. We’re going back to school. We have Modules, Views, Knockout.js and some REST services. Let’s float this boat and see how she sails.”
Samsung Galaxy – Too Many Pattern Attempts
21 Sep
My eldest daughter has a Samsung Galaxy Europa GT-15500. One day the other kids were mashing keys as small kids do. The next I know, nobody can get into the phone; It’s locked with the message “too many pattern attempts”. Onoz!
A quick Google later and we are trying various key pounding exercises, none of which work.
Now what? Phones aren’t my bag baby. I work from home in a super-insulated house with 4 foot think granite walls = not very cell phone friendly.
To cut a long and very tedious story short – I backed up most of the phone, reset it to factory defaults, then imported the data back. If you want to do this, ‘ere be they steps:
1. Download Kies from the Samsung site and install on a computer (a pc in my case).
2. Plug in the USB, connect everything up and Backup / Sync as much of the phone as possible.
3. Download the Android SDK
4. In the SDK ‘platform-tools’ folder there is a little file called adb.exe = The Android Debug Bridge.
5. Open up a command prompt and type adb to view the inline documentation.
6. Using the bridge we can issue commands to the phone. I issued a command to restart the phone in recovery mode: adb.exe reboot recovery
This rebooted the phone and finally got me to the recovery menu. From there I could choose the option to ‘wipe / factory reset’. When the phone came back to life we were in!
7. Fire up Kies again and re-import your contacts, files etc.
I think my daughter had to re-download her apps – but I had passed the buck by then, no longer cared and was glad to get back to work.