Combining changesets in TortoiseHg (Mercurial GUI)

June 30th, 2011

Here is how to merge/combine/fold multiple changesets to one. For instance when you commit some changes, then refactor, then apply review comments, . and at the end you have a set of changesets, and you want to get rid on the whole history, so there is only one left.

In the example below, I created two fake changesets: Foo and Bar

clip_image001

I want to merge them to one changeset. The idea in Mercurial is to :

  • 1- update to a specific revision (5384) which will
       a. revert the files' contents to this revision
       b. mark this revision as the parent of next commits

2- revert the changes to the tip revision (5386), which will recreate the content, without changing the parent of commits

3- commit changes

4- delete old changeset

Complete story with screenshots

1- Right click on the revision 5384 and click Update, nothing hard here

clip_image002

2- Select the tip revision,
then in the files list,
right click on a file,
click on Revert to Revision
check 'all files'
ok, ok, ok, .

clip_image003

3- Go to Working Directory, and you'll see the file system is like at the tip, but the parent revision is the one you wanted, so the diff contains all the changes.

4- To delete the old changesets, you can use the 'mq' extensions from settings, then 'strip' them like this :

clip_image004

See you at MIX11

April 1st, 2011

Placement.info hidden features

April 1st, 2011

The placement.info file contains information on how to customize the rendering for shapes in a theme. Recently we made some changes to enhance its functionalities, and it's great. However no one is using them, not because it's useless, but because I never documented them. And to be honest, I had to dive into the code to remember it.

Path

The first thing we added was to be able to alter the Match clause with the current Path. Thus you can disable the rendering or change the location of a specific shape for a set of pages only.

<Match Path="/About" DisplayType="Summary">
    <Place Parts_RoutableTitle_Summary="-"/>
</Match>

This example would simply hide the summary on the /About page only. You can also use trailing stars to define it for a container, like /myblog/*.

Switching Shape Type

Using the current dev version you can also do crazy stuff, like changing the shape type dynamically. For instance, you are about to render a shape A, but is some cases, it should render B instead. You can do it like this:

<Place Parts_RoutableTitle="Header:5;shape=Foo"/>

This will substitute the Parts_RoutableTitle by the shape Foo. By doing it, you will also clear all alternates and wrappers associated to the current shape. This can be useful when combined with next presented feature.

Adding Alternates and Wrappers

Using the same technique as shown previously, you can add new alternates and wrappers to a shape based on the current Match.

<Place Parts_RoutableTitle="Header:5;alternate=foo;alternate=bar;wrapper=baz"/>

You can repeat alternate and wrapper verbs as you need.

Placement.info is really a simple and powerful way to solve Theming puzzles, and those new features should help even more in this.

Update

Those features are only available as of version 1.1. The official documentation can be found at http://orchardproject.net/docs/Understanding-placement-info.ashx

Orchard Indexing

February 17th, 2011

There is already an existing documentation section on this exact topic in the official Orchard website, at http://www.orchardproject.net/docs/Search-and-indexing.ashx. Though, this only covers the site administrator and user experience, to setup and use the search engine. What it doesn't cover is how it works internally and how developers can reuse it, or customize the search experience. And believe me, it's great!

This post provides details on the Indexing implementation and usage. Next one will focus on querying the index, and customizing the search experience.

Anatomy

In order to have a search box in your website, you need to enable the Indexing module, then the Search module and finally the Lucene module.

Indexing is responsible for adding content to an IIndexProvider implementation as soon as a content item has been modified. There is a background task which is running on a separate thread and consumes IndexingTask records, created by a specific content handler event which creates the indexed document information. This point will be cover in detail later.

Search is providing a Search Form widget, and also a Search Settings to select what indexed fields should be part of the search.

Lucene is providing a default implementation of IIndexProvider and is used as a dependency of the Index module to save the indexed documents information in a physical storage. It's also providing an ISearchBuilder implementation which is called to build a search query.

Customizing Indexed Content

The Indexing module doesn't know anything about the content in Orchard. Though it has to be able to index anything inside a website, even from new modules, like Products, News, or anything else. For that to happen, modules can create implementations of ContentHandler and explicitly define OnIndexing<T>() in order to provide some information of a specific content part. It it defined as this:

image

This means you have to provide a lambda which takes exactly two parameters: an IndexContentContext instance, and the content part you should extract indexed information from. IndexContentContext inherits from ContentContextBase, and provide common information about the current content item:

image

It also contains a DocumentIndex property of type IDocumentIndex which looks like this:

image

This interface is used to directly provide all the information which has to be indexed. The Add() methods are used to add a named field to the index document, Analyze() just tell the concrete index implementation that the text should be tokenized (to differentiate text content like a title from metadata like an Id or an integral value). For instance, when OnIndexing() is called on the BodyPart (which is what is containing the body of a Page for instance) the following handler is executed:

image

The text of the body and its inner format are indexed. The text calls RemoveTags() which is used to remove all HTML or XML tags of a content. As our BodyPart will mostly contain HTML, and we don't want a search query on "div" to return all documents, then this method is used on this field. Finally Analyze() is called to be able to search on each different word of the content. The format is save in a separate field, and as it should only contain a mime type like text/html or so, we don't need to analyze its content or to remove tags. Though, we mark this field with a call to Store() in order to be able to retrieve the exact value from a search result, as indexing will generally break the original content. This should be done for any metadata added in the index.

NB: You can add several values to the same field name, even from different handlers. An example will be provided later.

This should be enough to understand that any module can provide information about the indexed information of a specific content item. For more examples just take a look at how Tags, Comments or Routable add their own properties in the index.

Rewrite Module

February 16th, 2011

Recently, after the release of the first public version of Orchard, I have created a bunch of modules as external contributions, even though I am in the core team. And actually the whole team has released some contributed modules.

So far, I have released 12 modules on the gallery, some of them being co-authored with other team members. But the issue is that apart from a link to the source code and a simple name, you don’t have any hint on what it is supposed to do. There is a documentation page though on www.codeplex.com</a> for each of them, but I am lazy, so I figured it could be easier to provide at least a blog post to explain the overall goals and usage for those modules.

Origins

Let’s talk a little bit about the Rewrite Module. As for most of the modules I have created, it started on an existing problem that needed a solution. In this case we were about to launch the Orchard Contest website (www.orchardproject.net/omc</a>), and we had a SSL certificate for the www.orchardproject.net domain. The SSL was working great and it was a breeze to configure IIS in order to use it. But Bradley, a PM on Orchard responsible for this site, discovered that when users were coming using the orchardproject.net domain, without the www subdomain, then the HTTPS security alert was shown in browsers. Normal as the certificate was for a single domain. Too late to order another one, or even better a wildcard one as going through the Verisign process would have been too long for us. So I suggested Bradley we could hack a specific MVC Filter in this application to automatically redirect users to the correct domain, but one idea coming after the other, I ended up creating a more complete module … typically me!

The Orchard Contest website is built on Orchard itself. Thus we could leverage the users management, a theme that Jon, a web/UX designer in our team, had already created, and also have another case study for Orchard. So instead of creating a simple hard coded MVC filter, let’s create a reusable Orchard module. What could have be reused was the simple one rule redirect stuff. And it reminded me how it is done in PHP applications running on Apache with .htaccess files. IIS has simple and yet very powerful tools to handle url rewriting, and it can even parse Apache .htaccess files, but the goal of a CMS is also to have a single configuration point for the whole application, so having a module makes sense as you might not have access to IIS manager when using a shared hosting provider.

And that’s it! The Rewrite Module is a .htaccess file handler, which enables a lot of possibilities in you Orchard hosting story. Once installed and enabled, a new settings section is created and looks like this:

image

How to use it

You might have noticed the little text under the rule editing zone, linking to the current Apache documentation. Why bother creating some documentation that already exists! Another link that I like a lot is http://corz.org/serv/tricks/htaccess2.php, because it provides a lot of interesting scenarios that can be done with this module, like:

  • preventing hot linking
  • blocking specific IP ranges
  • blocking specific browser agents or crawlers
  • forcing SSL
  • domain redirections

For instance, in the Orchard Contest website we use this rule to redirect users to the correct domain:

RewriteCond %{HTTP_HOST} ^orchardproject.net$ [NC]
RewriteRule ^(.*)$ http://www.orchardproject.net/$1 [R=301,NC,L]

Implementation details

The implementation is quite simple. First there is a RedirectSettingsPart and the associated record class to store the settings.

public class RedirectSettingsPart : ContentPart<RedirectSettingsPartRecord> {

    public string Rules {

        get { return Record.Rules; }

        set { Record.Rules = value; }

    }

 

    public bool Enabled {

        get { return Record.Enabled; }

        set { Record.Enabled = value; }

    }

}

Like other settings parts, there is also a driver, handler, migration and template file. But that’s a common and well documented implementation.

The most important part is to handle all requests and trigger specific actions based on the rules in these settings. This is done by implementing IActionFilter which lets us being called whenever a controller’s action is executed. In Orchard we also need to inherit from FilterProvider in order to getting registered.

public class RedirectFilter : FilterProvider, IActionFilter {

    private readonly IOrchardServices _services;

 

    public RedirectFilter(IOrchardServices services) {

        _services = services;

        Logger = NullLogger.Instance;

    }

 

    public ILogger Logger { get; set; }

 

    public void OnActionExecuted(ActionExecutedContext filterContext) { }

 

    public void OnActionExecuting(ActionExecutingContext filterContext) {

        // implementation

 

       }

}

 

This event can then return specific ActionResult objects. So after parsing the rewirte rules, and checked a condition is fulfilled, there are actually three different possible results:

  • HttpUnauthorizedResult
  • RedirectResult, when a permanent redirect is requested
  • TransferResult, for non permanents redirects, preventing for having the user to send another request

TransferResult is a simple custom ActionResult implementation:

/// <summary>

/// Transfers execution to the supplied url.

/// </summary>

private class TransferResult : RedirectResult {

    public TransferResult(string url)

        : base(url) {}

 

    public override void ExecuteResult(ControllerContext context) {

        var httpContext = HttpContext.Current;

 

        httpContext.RewritePath(Url, false);

 

        IHttpHandler httpHandler = new MvcHttpHandler();

        httpHandler.ProcessRequest(HttpContext.Current);
    }
}

I hope this little story will encourage you into creating reusable modules instead of doing one shot code. And if you happen to use this module someday, let me know.

As for most modules you can find on the gallery, there is a codeplex project for it, http://orchardrewriterules.codeplex.com, where you can submit bugs, get the source code, or read some documentation … when there will be some.

Half Orchard

August 3rd, 2010

After several months of development, the Orchard team is proud to deliver the first important release of the product. It's still an early version, namely number 0.5, though is now stable enough in terms of API and core functionalities to start relying on it to create modules, and more ...

You can get it on Codeplex, where the code is hosted and which is our main code source repository, so you can see exactly what is done and when.  

I have been on the team for almost 4 months, and I'm just very excited by the shape of it, and where it is going. There are still a lot of bugs, and you can't do much with this release as a end user. Though the target with that one is the developer, so that we can rely on a great set of community module early, and we get feedback from the .NET community.

There are already some web sites and blogs running on Orchard, and people are very happy with the switch so far. Now we will start another round of development tasks to reach the Beta version around October. The next version is targeting the designers, with a first big task for us to completely rebuild the Theme engine.

The whole team is participating the design of all the modules, though I have been personaly involved in the development of the Azure management, the Search module, and also the Data Migration story, so if you have any remark or question on these modules, feel free to enter the discussion with me. We are also very active on the Forums here and here.

 

Working at Microsoft

July 6th, 2010

I have finally found some time for this blog ;)

My first day was the 12th of April, so I suppose they had waited for me to launch Visual Studio 2010. First impression is that everything is done so that workers have the best possible environment to work. The facilities are great, people are always here to help, colleagues take time to explain stuff you need to know, you can't feel alone ! From a technical perspective it's also very interesting. People here are really clever and know their stuff. Actually they are even better than the better I had to work before, can you imagine it? :)

 Orchard Logo

For those who don't know yet I'm working for the Orchard Project, which is an Open Source Web Content Management system you can compare to Drupal or Wordpress, but built in ASP.NET MVC. The project itself is really great, and the goal is, wow, amazing ! I'm really confident the final result will be great because of the talents in the team and also because of the way we are open to the community feedback. It's not yet stable enough to be used in productive web sites, unless you want to develop the stuff it's lacking currently.

 

Don't let me be lonely tonight

April 1st, 2010
Say goodbye and say hello,
Sure enough good to see you, but it's time to go 

My adventure at Evaluant started with a song from James Taylor (Gaia) and ends with another one. I think I have done everything I could to make it successful, and now it's time to reach new objectives. In two weeks I will be working for Microsoft, first in Vancouver and later in Redmond, for the ASP.NET team. It's a completely new life as me and the whole family are moving abroad, and also professionaly because the goal is to target maybe millions of potential users.

Disabled buttons on long postbacks in ASP.NET

January 6th, 2010

Some users don't realize that when a long query is executing, they should not hit a button again. It can sometimes make an application to crash, for instance if it's a delete button.

To prevent this scenario, here is a script that you can embed with every page. It requires jQuery and ASP.NET Ajax.

var delay = 500; // milliseconds

function pageLoad() {
    Sys.WebForms.PageRequestManager.getInstance().add_endRequest( function() {
        requesting = false;
        $(":input[type=submit]").removeAttr('disabled');
    });

    Sys.WebForms.PageRequestManager.getInstance().add_beginRequest(function() {
        requesting = true;
        setTimeout(function() {
            if (!requesting) return;
            $(":input[type=submit]").attr('disabled', 'disabled');
        }, delay); 
    });
}

Microsoft China writes about NCalc

December 22nd, 2009

It happens that there is an article about NCalc on the Chinese version of Msdn. Here is the translation in English.

It can be interesting if you don't know how you could use it in your applications. Even more if you work in the banking area.

Blueprint CSS and ASP.NET

December 7th, 2009

Last Thursday with some colleagues we participated in a small contest which runs a night long to deliver a functional Web application. We used this event to try some tools we were not used to putting it place four our customers.

Blueprint CSS (http://www.blueprintcss.org/) is one of them. It's a CSS framework which defines a set of predefined CSS classes and styles. The benefits are that it resets browsers defaults to start with a common set of attributes, and also defines helper classes to arrange the content easily.

However, we faced an issue with ASP.NET as it comes to arrange form's elements. We used a Master Page where the CSS links were defined, and in order to use some forms specific designs we had to set an inline class to the form tag. This broke the overall design of our pages as in standard ASP.NET every content in inside the main form object.

The solution was simply to remove the form specific declaration on the inline class, and add another div to set the form elements boundaries like this:

.inline {line-height:3;}
.inline p {margin-bottom:0;}

Instead of :

form.inline {line-height:3;} 
form.inline p {margin-bottom:0;} 

I had almost decided to remove this CSS when I saw the issue, so I think it's an important tip, all the more so I think it's a very useful framework. If you don't know it yet, take a look at this article. And if you like it, you will need this cheat sheet, invaluable.

ECS5 – ECMAScript 5th edition released

December 5th, 2009

December 3, 2009
The 98th General Assembly held in Mountain View, December 3, 2009, approved the following documents:

ECMA-262 5th edition - ECMAScript Language Specification

The long awaited new version of ECMAScript has been approved by the committee. It means browsers editors have a common procedure for implementing new compatible JavaScript functionalities, Web developers have something new to learn, and that I have another set of tasks to add on the current Jint's one stack.

The Homer Car Syndrome

October 27th, 2009

This morning I had a new mail from a customer asking for some advice. Currently we have to develop a new system and had a few meetings to discuss about the project, it's feasibility, and also to define a plan. The next step now is to gather the business requirements. But the question which arises is : "Who has to do the business requirements".

[The_Homer_by_Carlos_Bisquertt.jpg]

The answer we had was obvious: "The business people". But it reminded me of an episode of The Simpsons. In this episode Homer discovers he has a half-brother, Herb, who is also the head of a big automobile manufacturer. During this episode Herb asks Homer to design a brand new car and that he has full power to decide. He defines the requirements, and the engineers produce it, as requested. The car was produced, as requested. Disaster.

What I want to say is that when a house is built, an architect should be in the process because he has some experience of the domain, has already faced a lot of problems and thus their solutions. When a car is designed it's the same. And for software ?

The business should not define requirements alone. Because Software Architects or Program Managers are paid for that, and because an advice is better to be given before everything is done than after. This could be to prevent from failure, but also to suggest features or behaviors that business wouldn't have imagined. And with a little chance, it can also make the difference between delivery and success.

How to create a template engine in 1 hour

October 21st, 2009

Today I needed to create a mass email sender application for a customer, in order to warn the users of their personal data. The template had some complexity like loops for multi-valued information, thus I needed a template engine.

The goal was to have a text processor which could take an external object model (actually a CSV file) and a template file like ASP.NET does:

Dear <%= firstname %> <%= lastname %>,

This is a set of squares:
<% for (var i=0; i<3; i++) { %> 
    <%= i %> * <%= i %> = <%= i * i %> 
<% } %>

Regards

And the result should look like this:

Dear Sébatien Ros,
This is a set of squares:
0 * 0 = 0
1 * 1 = 1
2 * 2 = 4

Regards

I quickly searched for this sort of tool when I wondered how they would be made. Actually ASP.NET changes the ASPX file into code files which is I suppose the best approach. The only thing I needed was a way to execute this generated code. And guess what, I already have it, it's Jint, again ;)

So the only thing to do is use a simple state machine and a regular expression to convert the previous template to this script :

write('Dear '); write( firstname ); write(' '); write( lastname ); 

write(',\r\n\r\nThis is a set of squares:\r\n');  
for (var i=0; i<3; i++) { 
    write(' \r\n    '); 
    write( i ); 
    write(' * '); 
    write( i ); 
    write(' = '); 
    write( i * i ); 
    write(' \r\n');  
} 

write('\r\n\r\nRegards'); 

I also configured Jint so that the write method appends its parameter to a local StringBuilder instance, and took all variables like firstname and lastname to declare them locally in the script. Then I ran the script using Jint and emailed the resulting string to the recipient.

I'm sure I will find even more usages for Jint in the future.

First bits of Euss 2.0

October 14th, 2009

The development of Euss 2.0 is progressing (Nicolas is working hard), and I can already show you some working stuff. Here is the use of NLinq as the primary query language, and the same one using pure LINQ. Note the differences (there aren't actually).

var context = CreateObjectContext();
context.InitializeRepository();

Person p = new Person() { Name = "Tintin" };
p.Pet = new Pet() { Name = "Milou" };

context.BeginTransaction();
context.Serialize(p);
context.CommitTransaction();

// using nlinq
Assert.AreEqual(1, context.LoadScalar<int>("(from Model.Pet pet select pet).Count()"));
Assert.AreEqual(1, context.LoadScalar<int>("(from Model.Person person select person).Count()"));

// using LINQ
Assert.AreEqual(1, (from Model.Pet pet in context select pet).Count());
Assert.AreEqual(1, (from Model.Person person in context select person).Count());

As usual, we don't care about the repository implementation.