Nov
7
2011
Git // DVCS

DVCS and my usage of Git Svn

Sometime ago I moved “away” from subversion has my Version Control System (VCS) because I felt not free of my way of working with it. I found a great was to improve my work experience by using Git Svn in front of our central Subversion repository.

I started my experimentation with Mercurial and Hg Svn because I was already using Mercurial for my personal projects. I hit some much the wall with Hg Svn that I decided quite quickly to go and try Git Svn. I had no experience with Git at that time and I had the feeling that it was more complex to handle than Mercurial (which I still think).

So currently I use Git Svn to work on one of our product at Innoveo Solutions. I also made a presentation to the team during our techno pizza lunch about DVCS, Git, Git Flow and Git Svn.

And here is the list of what I personally gained as a developer:

  1. 2 steps commit
    1. Stage/commit, Push
  2. Local history / branching
    1. No connection to central repository needed to branch/to look at history
  3. Experiment / Refactoring / Spikes
    1. Commit changes on one path, if wrong rollback
  4. Smarter Merging
    1. Git’s focus on content rather file location
    2. Better at resolving merge conflicts for you (e.g. renames)
    3. Branching/Merging is daily workflow not anymore an ‘exceptional case’
  5. Stash changes
  6. Rebase / Rewriting history
    1. Until push you can use interactive rebase

Due to my 4h daily commute (more than 2h in the train), I very much appreciate the offline capabilities of DVCS. It lets me branch, watch the history without having a connection to the central repository. So that a really convenience thing in my day to day job.

But what I even prefer is working in local branches for experiment, refactoring. With that capability I am able again to commit small steps of code change. I particularly appreciate the possibility to experiment some refactoring and to rollback wrong changes when I feel that I went the wrong way with the change. In the past this was not possible and often you would not commit to SVN because that code would be shared with the others or t would break the build. Ok, I know I could do that with Svn working in a feature branch, but we all know the pain it is with the merging back, especially when you refactor and rename files. During refactoring it is important to be able to save/commit small chunk of code change and even more important is to be able to rollback those changes. So in that case DVCS is a perfect match to that problem.

What I currently don’t like in my current way of working with Git in front of Svn is that I have local branches which I don’t sync back to the central server. I don’t like it because if I have an issue with my local machine then those changes might be lost. I will investigate in the coming weeks about possible solutions even if the best one would be a migration of the central repository to Git. But his is another story because it means a wider change in the team.

Nov
6
2011

Unlock your Windows Phone 7 with ChevronWP7 Labs

ChevronWP7 Labs just realized their Windows Phone unlocking tool. This software will let you developer unlock your device for $9.

This is not a Jailbreaking tool, it let you upload your own homebrew applications on your Windows Phone 7 device without going through Microsoft's expensive ($99/year) developer program.

You might read more about it on their blog : ChevronWP7 Labs Availability

Still waiting that the 295 people in front of me get their phones unlocked… !

Update: And here is the result after unlocking !

I also quickly deployed successfully an application to the phone directly from Visual Studio 2010 !

Congrats to the ChevronWP7 team !

Oct
30
2011

Cleaning BlogEngine.NET spam

Martinique 2011

I just migrated my blog to the latest version of BlogEngine.NET 2.5.0.6.

I had a shock when I saw the number of spam that I had on the blog!

447883 Spam! Wow. So I started the cleaning by using BlogEngine tools but it was damn slow, and no way to stop it when you started the delete all.

So I stopped the web site which was a bad idea because then one XML file was damaged. As I always do a backup before doing something like that I was on the safe side, and just reverted the files.

Then I used 7zip to zip the posts folder which is located in the App_Data which was 338 MB, again wow.

Downloaded the zip file on my local machine, installed BlogEngine and imported the post.

I thought it would be faster on my machine because it is a recent one. But still to slow to treat 447833 spam messages.

So as a developer I went on and wrote a little application to do it. And after cleanup the spam which took less than 10 seconds I went to this folder size of the posts

Quite a difference ! And BlogEngine showing me the results

And here is the code, it is using .NET Framework 4 and the parallelization of queries to treat files:

#region using

using System;
using System.IO;
using System.Linq;
using System.Xml;
using System.Xml.Linq;

#endregion

namespace BlogEngineSpamDelete
{
    internal class Program
    {
        private static void Main(string[] args)
        {
            var files = Directory.GetFiles(@"C:\Temp\blogengine\posts", "*.xml");
            foreach (var file in files.AsParallel())
            {
                FixPost(file);
            }
        }

        private static void FixPost(string file)
        {
            XDocument doc;
            using (var stream = File.OpenRead(file))
            {
                doc = XDocument.Load(stream);
            }

            var comments = from comment in doc.Descendants(XName.Get("comment", String.Empty))
                           select comment;

            var spamComments = from comment in comments.ToArray()
                               let data = new CommentState(comment.Attribute("spam").Value,
                                                           comment.Attribute("approved").Value,
                                                           comment.Attribute("deleted").Value) 
                               where ShouldDeleteSpamAndUnApproved(data)
                               select comment;

            foreach (var spamComment in spamComments)
            {
                spamComment.Remove();
            }

            using (var writer = XmlWriter.Create(file, new XmlWriterSettings {Indent = true}))
            {
                doc.WriteTo(writer);
            }
        }

        private static bool ShouldDeleteSpam(CommentState commentState)
        {
            return !commentState.Approved && 
                   (commentState.Spam || commentState.Deleted);
        }
        
        private static bool ShouldDeleteSpamAndUnApproved(CommentState commentState)
        {
            return !commentState.Approved || 
                   commentState.Spam ||
                   commentState.Deleted;
        }

        private class CommentState
        {
            public CommentState(String spam, String approved, String deleted)
            {
                Approved = bool.Parse(approved);
                Spam = bool.Parse(spam);
                Deleted = bool.Parse(deleted);
            }

            public bool Approved { get; private set; }
            public bool Spam { get; private set; }
            public bool Deleted { get; private set; }
        }
    }
}

Update: I also posted the code on bitbucket: https://bitbucket.org/lkempe/blogenginespamdelete

Apr
13
2011

Starting IIS Express from a right click in explorer

After publishing this for Starting ASP.NET Development Server from a right click in explorer it is time to do it for IIS Express.

Tonight trying out Orchard 1.1 I just wanted to start by right clicking and getting IIS Express fired so that I can test the 1.1 version.

So I just modified my old Windows Registry .reg file and adapted it to IIS Express:

Windows Registry Editor Version 5.00

[HKEY_LOCAL_MACHINE\SOFTWARE\Classes\Folder\shell\VS2005 WebServer]
@="IIS Express Here"

[HKEY_LOCAL_MACHINE\SOFTWARE\Classes\Folder\shell\VS2005 WebServer\command]
@="C:\\Program Files (x86)\\IIS Express\\iisexpress.exe /path:\"%1\""

Take care that this is a file for 64 bits Windows OS, adapt to your path. Then you can double click on the .reg file to save the settings in the registry.

Now you will have access to the IIS Express Here right click menu in explorer and you can browse your site without running Visual Studio!

You might also read more for example on the other start param on Running a Site using IIS Express from the Command Line

Apr
9
2011

Disabling Silverlight addon in IE9 is not such a good idea

The other day I disabled Silverlight add-on in IE9. Don’t ask me why I don’t really remember, and I prefer not.

Several days after that I started an out of the browser application, ClickTime which we use to report our hours. And I got a weird JavaScript error a la IE with a white window and the picture asking me to install Silverlight. I checked that it was still installed and it was, no problem.

Then I uninstalled it and reinstalled it! Same issue.

It took me time to remember that I disabled the Silverlight add-on in IE9 and for sure when I enabled it, then the out of browser applications were working again and I didn’t get anymore this install Silverlight picture.

Nov
27
2010

Mounting a remote Linux folder as a Windows drive through SSH

There are some times in which you need to come to some extreme solutions. Having two days of trials without success to have a portlet running in a local Tomcat with Day portal I came to the following solution.

Shortly why I came to such a solution? I needed to work on some CSS on a portal solution, and the development cycle was taking too long. I had to commit to svn, run a teamcity build which deployed a war to weblogic to finally be able to test my CSS changes. Far too long.

So first idea was to have our portlet working locally in Day portal deployed on Tomcat. After many attempt to have this running, I have stopped with this idea.

Next idea was to work directly on the Linux file system, and modifying the CSS files which would be reloaded automatically by weblogic. Good idea, it was working but I needed more, I needed my development environment.

So I searched a solution to be able to mount a remote Linux folder as Windows drive through SSH. And I quickly found a solution! Thanks to Dokan SSHFS

I finally could fire JetBrains WebStorm on my Windows notebook, edit CSS files which are located on a remote Linux server, save the file and refresh my page on the browser. Straight solution, certainly not the best but at least I could work.

Dokan SSHFS is a great tool! It took me 10 minutes to install it and configure it.

You must take care of:

  • Dokan SSHFS supports only OpenSSH key format. So I used puttygen to convert my key.
  • Dokan SSHFS doesn’t work with Dokan 0.5, you have to use the updated files found on the web page

The rest was just easy! Well done.

Nov
23
2010

“Unable to evaluate the expression” error in Visual Studio 2010 debugger

Last week I had an issue in Visual Studio 2010 debugger in some projects only! When I was looking at the value of variables I was getting an error message saying “Unable to evaluate the expression”!

Searching on Connect I have found that someone else had the same issue! Not really a good sign, “Debuging (Evalutation) stops working at times - Unable to evaluate the expression”. I have the same configuration, same issue and can reproduce what is described:

I'm on Windows 7 64bit and am using VS.NET 2010 Ultimate
Never had a problem with VS.NET 2010 until recently. And the problem I am having is that when I create a new console app and am not able to:
1. Evalutate any variable values
2. Hover over any variables and see their values
3. Use the immidiate window to get any values. I see a message -"Unable to evaluate the expression"
The debugger stops and the break points as expected but the above does not work.
If I switch the Project Build platofrm target property from x86 to Any CPU, then everything works as expected. Switching it back to x86 gives to the same behavior as explained above.
Other project types exhibit the same behavior sometimes. I have a new ASP.NET MVC project that are created and it exhibits the same behaviour. In fact with this project I am unable ot debug no matter what the build settings are.
Older console app projects have this problem as well (they used ot work just fine earlier).

On last Friday, I re-installed two times Visual Studio 2010 without any success, uninstalled all tooling… Still the same issue. I tried several other things over the weekend which didn’t helped.

I finally found that I had installed ASP.NET MVC 3 RC and I remember reading the documentation saying that it had an issue with Async CTP, which cannot be installed together on the same machine.

So I un-installed ASP.NET MVC 3 RC and searched Async CTP which wasn’t listed. Something I did already when installing ASP.NET MVC 3 RC.

This morning I realized why I didn’t found the Async CTP when I installed ASP.NET MVC 3 RC! It is installed as an update! What’s the hell!

So from Control Panel you have to click on “View installed updates” to see it

And now you can see it and un-install the Async CTP

Then I followed the instruction of Drew Miller of the ASP.NET Team to uninstall all pieces of ASP.NET MVC 3 RC, “How to Uninstall Microsoft ASP.NET MVC 3 RC

Now my Visual Studio 2010 debugger is working like before!

Nov
19
2010

Using Resharper Search with Pattern to protect you from your code

Today I faced a nasty bug, a null pointer exception in a property databound to our WPF application. This had some nasty side effects, and for sure this part of the code didn’t had any unit test, too bad! For sure now it has.

The line of code was really simple

Values.Where(model => model.IsSelected).FirstOrDefault().Refresh();

I guess you see the issue! If not here is the MSDN documentation:

public static TSource FirstOrDefault< TSource >(this [NotNull] IEnumerable<TSource> source)
in class Enumerable

Summary:

Returns the first element of a sequence, or a default value if the sequence contains no elements.

Parameters:

source:
The IEnumerable<out T> to return the first element of.

Type Parameters:

TSource:
The type of the elements of source.

Returns:

default(TSource) if source is empty; otherwise, the first element in source.

Exceptions:

ArgumentNullException:
source is null.

Yeah, FirstOrDefault might returns null, so if you chain a call to another method it just crash!

For sure we know that! We use this method for that purpose, but an error can happen that fast!

So I decided that I wanted to be protected by my tooling. So I went back to read the post “Introducing ReSharper 5.0: Structural Search and Replace

After several trial and some help from Ilya (Thanks!) I finally found the correct way to express what I wanted. My goal was to find all code which uses FirstOrDefault() method followed by a call to another method. Exactly like my issue.

$enumerable$.FirstOrDefault().$method$()

enumerable is an Expression of type System.Collections.IEnumerable or derived type

method is a identifier placeholder with an empty indentifier name regexp

I then verified that this error was found. And also luckily that this was the only error of that kind in our application.

Then I finally added it to the Resharper Pattern Catalog, to show a warning.

Now when ever I will type this stupid thing, I will have my preferred tool Resharper, telling me how stupid I am to even try this!

BY the way you might download a sample Pattern Catalog from this blog post “Sample SSR Pattern Catalog Available for Download”. There are some cool stuff in there and it might help writing your owns.

Nov
9
2010

Sample BDD web test using easyb and sahi

I blogged yesterday about “BDD web application testing using easyB and Sahi

I was asked to provide a sample, so here it is!

Click the picture to see full size

Nov
8
2010

BDD web application testing using easyB and Sahi

I already talked about the way we are testing our web application at Jobping in the following posts “ASP.NET MVC 2, MSpec and Watin ” and ”Automated functional tests using Watin and MSpec”.

The other day I landed on the DZone page “Automated Browser Testing: What's in Your Toolkit?” In the list of around 10 tools I knew some of them but there were 3 I didn’t knew. So I decided to go on and read about those 3. In this list there were Sahi which got me with those three sentences:

  • Powerful Recorder works on any Browser
  • Robust object identification without brittle XPaths
  • Implicit waits - even for complex AJAX applications

This is supposed to solve the issue we currently have with Selenium, even if we use Screen Objects to encapsulate our Selenium tests. It is just a pain to work in our highly AJAX application and for sure the XPath are brittle. 

So I decided to try it. I started by watching the video in the “Get Started” section and in less than 10 minutes I had my first test running.

WOW ! Impressive.

Going further I wanted to know if it could be used with a BDD framework. We currently are using JBehave, but reading about it, it was clear that it would be more effort for me to try it. So I went back to easyb  which I tried out a couple month ago.

I used Sahi Java Driver to output some Java code which I used directly in my easyb story.

I was surprised and impressed about the easiness I went through the implementation.

Looking forward for the next steps and where we will end with this.

About Laurent

Laurent Kempé

Laurent Kempé is the editor, founder, and primary contributor of Tech Head Brothers, a French portal about Microsoft .NET technologies.

He is currently employed by Innoveo Solutions since 10/2007 as a Senior Solution Architect and certified Scrum Master.

Founder, owner and Managing Partner of Jobping, which provides a unique and efficient platform for connecting Microsoft skilled job seekers with employers using Microsoft technologies.

Laurent was awarded Most Valuable Professional (MVP) by Microsoft from April 2002 to April 2012.

JetBrains Academy Member
Certified ScrumMaster
My status

Twitter

Flickr

www.flickr.com
This is a Flickr badge showing public photos and videos from Laurent Kempé. Make your own badge here.

Month List

Page List