Ajden Towfeek

Towfeek Solutions AB

Moving blog to towfeek.se

This blog is moving to my company page, http://www.towfeek.se/blog, so if you're subscribing to this feed just update the URL. This site will remain up and running for links not to break and indexed search engine result purposes but no new content will be posted here.

Peace! ;-)

Customize your TFS build process to run StyleCop

This will be a short guide on how to get StyleCop to run for every check-in as a part of your build process in TFS or VisualStudio Online. You may also integrate stylecop with the project's MSBuild file, see StyleCop docs for how to do so.

Start off by downloading and installing StyleCop and TFS build extensions.

Build controller changes

First you'll need to set the custom assemblies path for your build controller. I created a new folder Custom Assemblies in the BuildProcessTemplate folder directly under the team project root folder. Also download a copy of the default template.

Add the following assemblies to Custom Assemblies:
  • StyleCop.dll
  • StyleCop.CSharp.dll
  • StyleCop.CSharp.Rules.dll
  • TFSBuildExtensions.Activites.dll
  • TFSBuildExtensions.Activites.StyleCop.dll
Next Manage Build Controllers and set Version control path to custom assemblies to your Custom Assemblies folder from Build Controller Properties.

Custom Build Templates

Create a custom build process solution with a Workflow Activity Library project. I created a BuildProcess solution in the BuildProcessTemplates folder and named the workflow project Templates

Next rename the DefaultTemplate.11.1.xaml template you downloaded earlier to CustomTemplate.xaml and add it to the project. Make sure you set the Build Action to Content.

Now let's add the StyleCop activity to the Toolbox window. Add a new tab TFS Build Extensions, right-click and select Choose items. Browse to the assembly TfsBuildExtensions.Activites.Stylecop.dll and click OK.

We want to run StyleCop early in the build process for the build to fail quickly if there are any violations, the first place where StyleCop can be executed is after the Initialize Workspace sequence within the Run on Agent sequence.

Add a new sequence activity right after Initialize Workspace and name it Run StyleCop. Add the following variables with a scope of the Run StyleCop sequence.
  • StyleCopFiles - IEnumerable<string>
  • StyleCopSettingsFile - string
  • StyleCopResults - bool
  • StyleCopViolations - Int32
Now add the following activities:
  1. FindMatchingFiles - Set the result to StyleCopFiles and the MatchPattern to String.Format("{0}\**\*.cs", BuildDirectory)
  2. Assign - Set the StyleCopSettingsFile variable to String.Format("{0}\Settings.StyleCop", SourcesDirectory)
  3. StyleCop - Set the following properties
    • SettingsFile to StyleCopSettingsFile
    • SourceFiles to SyleCopFiles.ToArray()
    • Succeeded to StyleCopResults
    • ViolationCount to StyleCopViolations.
  4. WriteBuildMessage - Change the Importance level to High and format the message to something like String.Format("StyleCop was completed with {0} violations", StyleCopViolations)

My final sequence activity looks like this:
Commit the solution if you haven't done so already.

Running the Build

Now edit the build definition you want to run StyleCop for and use the custom template.

Trigger a new build and viol√°, you'll probably have an unsuccessful build.

Personally I prefer using TeamCity with NAnt for the build process and JIRA for issue tracking, TFS is way behind imho, but the choice isn't always up to me. ;-)


AngularJS Loading Indicator / Splash screen

How do we prevent the flash of unrendered content (FOUC)? We don't want to simply hide the unrendered content from the user since the user may think that the app is broken, especially if they're on a slow connection. The browser will start to render elements as soon as it encounters them, we can use this to our advantage to display a full-screen block of HTML while the page is loading, i.e. a splash screen.

Full working sample can be found at http://jsfiddle.net/45EfF/.

Let's start with the markup, I've added a splash div at the top of the body-tag and the css is loaded inline in the head-tag. This way, when the browser starts parsing the body-tag it will lay out the splash screen elements and style them before it starts to load any other files.

We want to make sure that the splash screen goes away after the page is loaded, we can do this using the ngCloak directive. The ngCloak directive will add a CSS class that sets a display: none !important on the element and then remove the display: none once the page has been loaded. We can hijack this ngCloak directive for the splash screen and invert the style for the splash element only.

Finally, I've manually bootstrapped angular to simulate slow loading.

It's as simple as that, hope it helped, cheers!

Mobile Angular UI with Bootstrap 3

I've been looking for a nice mobile UI framework that plays well together with angular for quite some time now. When I started developing golf-caddie.se jQuery Mobile was pretty much the only competent framework out there and it was quite cumbersome to get it to play nice with angular. So every now and then I try out new UI frameworks, hoping to find a replacement for jqm. By the way, did I mention that I want it to work well on WP8? Yup, proud owner of a lumia 920.

A couple of months ago I gave ionicframework a go, don't remember the details but it was awful on WP8. Yesterday I came across an open source project, mobile-angular-ui, seemed to be exactly what I've been looking for.

You may wonder, why not just use bootstrap? Simple answer - because it doesn't give the same look and feel as a native app, my web app is intended to be used on the golf course and on mobile devices only, plain bootstrap just doesn't cut it. The user controls isn't designed with mobile first in mind even if the layouting mechanism is.

Anyways, before I started a massive refactoring to replace jqm I put together a little "hello world"-app with a simple slide in menu and some page navigations. I've hosted it on http://mobile-angular-ui-test.towfeek.se/.

Really simple stuff, a sidebar and two partials. Seemed to work fine until I added an animation when navigating between pages. Boom, page doesn't render! Ok that's fine, not a deal breaker, who needs animations anyways? I just reported a bug and went on with it.

The ultimate test - how does it look on my WP8? 

  • Page renders a bit slow, I can see the default title before the partial updates it.
  • Slide menu actually slides in, sweet!
  • Navigation works fine without animations.
  • Page only renders the content that fits the screen initially, scrolling doesn't work. Deal breaker!

The project is still in an early stage, and it definitely gots potential. I'll try to contribute to the project if time allows but I wont refactor golf-caddie to use it just yet.


Live coding 4th session - Implementing backend with WebApi2 and EF Code First

Implemented the backend as a RESTful service using WebApi2 and persistent storage to a SQL database with Entity Framework Code First. In the next session I'll implement support for multiple users and authentication with facebook.  

Live demo @ http://meetometer.azurewebsites.net/

Source code @ https://github.com/ajtowf/meetometer/


Forgot to setup automatic upgrading on application startup since I was using the package manager console in the screencast to setup the database. I added the following piece of code in commit 8be3b31:

Until next time, have a nice day!


Keywords : VS2013, Azure, HTML5, JavaScript, AngularJS, jQuery Mobile, AmplifyJS, WebApi, EntityFramework