Monday, 28 July 2008

PlugIns and DataFactory Event Handlers

Inspired by great post of Allan Thraen about When and Where to attach DataFactory Event Handlers I decided to keep digging into this subject. What seems really cool about it is that you can attach to DataFactory events and moreover you can do it in a pluggable way.

In this post I wanted to show how Allan's PlugInAtttibute class can be refined to read configuration from the EPiServer.

But first of all ... real life example ... to justify existence of this post ;)

Task: I want to be able to hide some pages in edit mode, tweak left side tree to not show some of my pages. And additionally I want to have it configurable so that I can change ID of the page which will be hidden without recompiling source code, changing web.config etc.

Step 1 - Create GuiPlugIn

In our case we will use it only to store data. Class can look like this:

[GuiPlugIn(Area = PlugInArea.None, DisplayName = "Settings")]
public class PluginSettings
protected string pagesToHide;

[PlugInProperty(Description = "Page ID", AdminControl = typeof(TextBox))]
public string PagesToHide
get { return pagesToHide; }
set { pagesToHide = value; }

and thanks to that in admin mode we will be able to define page ID.

Step 2 - Attach to the FinishedLoadingChildren event

In this step we will follow Allan's approach:

public class RegisterEventsPlugIn : PlugInAttribute
public static void Start()
//Attach to the right events
DataFactory.Instance.FinishedLoadingChildren += Instance_FinishedLoadingChildren;

static void Instance_FinishedLoadingChildren(object sender, ChildrenEventArgs e)
// /UI/to/edit/EditTree.aspx
if (HttpContext.Current.Request.Url.ToString().StartsWith(Settings.Instance.UIUrl.ToString()))
PluginSettings settings = new PluginSettings();

foreach (PageData child in e.Children)
if (child.PageLink.ID.ToString() == settings.PagesToHide)

One thing which might be new are those two lines:

PluginSettings settings = new PluginSettings();

Those two lines do the trick of reading the configuration. And basically that's it, everything should be working now.

I was also thinking about different scenario where this approach might be perfect -- we use SortIndex to order pages quite often, but it's a hassle for editors to remember about it. Solution might be to create plugIn which would automatically, based on some custom rules, assign correct SortIndex for newly created pages. It's definitely doable and I'm sure that editors would love it!

Monday, 14 July 2008

Missing features of EPiServer

In our everyday work we encounter from time to time missing "things" in EPiServer which would make our life easier. I think it's worth talking about this stuff to let EPiServer team know that there is something on our wish list :)
Sometimes it can be something really small and relatively easy to add. I have something like this -- I would like to be able to add my configuration options to custom properties.

Here is how the edit property page looks like at the moment:

All what I'm asking for is a possibility to define new fields on this page, maybe in the same way as we can define custom plugin properties ...

[PlugInProperty(Description = "Some nice description", AdminControl = typeof(TextBox))]
public string CustomProperty
get { return customProperty; }
set { customProperty= value; }

Why I need it?

Well, whenever you are building more sophisticated properties, usually you want to make them reusable and that's when you need to have a way to configure it. Having that possibility, you can have different configuration for each page type.

You need a real life example? Here it comes ... we all use and love multipage property. But the truth is that adding multiple pages to the selection can be very annoying. To add additional page to the list every time you have start from root and browse down. It would be so much nicer if we could configure start page for this property isn't it? Adam was writing about this issue some time ago.

Sometimes small changes make big difference, do you have more examples/requests like this?

Sunday, 13 July 2008

The One Minute Manager ... don’t miss it!

Have you ever been trying to figure out how people work best with other people? When they produce good results and are happy about their job, company and other people? If you are one of those who feel that this is important and interesting then I can highly recommend you this book: The One Minute Manager. It's a very well-written book which you can finish in one evening. The main message is that:

People who feel good about themselves produce good results.

But in the same time it's important to keep the organisation productive. Authors are trying to show that those two objectives can be achieved in the same time, moreover, the best way to achieve good productivity is through people. It all can be accomplished by applying one minute management. To understand how it works you need to be familiar with three secrets of one minute management.

The First Secret: One Minute Goals

One Minute Goal Setting is absolutely essential, it introduces philosophy of 'no surprises'. The point here is to be clear about what has to be done from the beginning. Therefore:

The One Minute Manager feels that a goal, and its performance standard, should take no more than 250 words to express. He insists that anyone be able to read it within a minute. Manager always makes sure that people know what good performance is. Performance standards are clear.

Rationale for that:

You see, in most organizations when you ask people what they do and then ask their boss, all too often you get two different lists. In fact, in some organizations I've worked in, any relationship between what I thought my job responsibilities were and what my boss thought they were, was purely coincidental. And then I would get in trouble for not doing something I didn't even think was my job.

And this is how the process should looks like step by step:

  1. Agree on your goals.
  2. See what good behavior looks like.
  3. Write out each of your goals on a single sheet of paper using less than 250 words.
  4. Read and re-read each goal, which requires only a minute or so each time you do it.
  5. Take a minute every once in a while out of your day to look at your performance, and
  6. See whether or not your behavior matches your goal.

Why does it work?

When your goals are clear you can work until your job is done. All the time you can compare your results with your goal which gives instant feedback. And a few words about the feedback:

Clearly the number one motivator of people is feedback on results. In fact, we have a saying here that's worth noting: 'Feedback is the Breakfast of Champions.' Feedback keeps us going.

The Second Secret: One Minute Praisings

Manager should strive to help people succeed and become a big help to the organization, therefore manager's main concern, especially at the beginning of a new task or responsibility, should be:

Help people reach their full potential, catch them doing something right.

Managers usualy try to catch people doing something wrong ... so why "catch them doing something right"? To help people by letting them know in no uncertain terms when they are doing well, to praise them and make them feel good.

Remember you don't have to praise someone for very long for them to know you noticed and you care. It usually takes less than a minute. And that's why it's called a One Minute Praising

This is how the process should looks like step by step:

  1. Tell people up front that you are going to let them know how they are doing.
  2. Praise people immediately.
  3. Tell people what they did right—be specific.
  4. Tell people how good you feel about what they did right, and how it helps the organization and the other people who work there.
  5. Stop for a moment of silence to let them "feel" how good you feel.
  6. Encourage them to do more of the same.
  7. Shake hands or touch people in a way that makes it clear that you support their success in the organization.

Why is it so important?

Key to training someone to do a new task is, in the beginning, to catch them doing something approximately right until they can eventually learn to do it exactly right.

but in some organisation it doesn't always work this way ...

That is what we often do with new, inexperienced people. We welcome them aboard, take them around to meet everybody, and then we leave them alone. Not only do we not catch them doing anything approximately right, but periodically we zap them just to keep them moving. This is the most popular leadership style of all. We call it the 'leave alone-zap' style. You leave a person alone, expecting good performance from them, and when you don't get it, you zap them.

The Third Secret: One Minute Reprimands

If you have been doing a job for some time and you know how to do it well, and you make a mistake, the One Minute Manager is quick to respond.

One minute reprimand has two parts and here is how it should looks like step by step:

  1. Tell people beforehand that you are going to let them know how they are doing and in no uncertain terms.

    The first half of the reprimand:
  2. Reprimand people immediately.
  3. Tell people what they did wrong—be specific.
  4. Tell people how you feel about what they did wrong—and in no uncertain terms.
  5. Stop for a few seconds of uncomfortable silence to let them feel how you feel.

    The second half of the reprimand:
  6. Shake hands, or touch them in a way that lets them know you are honestly on their side.
  7. Remind them how much you value them.
  8. Reaffirm that you think well of them but not of their performance in this situation.
  9. Realize that when the reprimand is over, it's over.

The most important is to remember this:

You will be successful with the One Minute Reprimand when you really care about the welfare of the person you are reprimanding.

What might happen if you don't use this rule in everyday life?

If managers would only intervene early, they could deal with one behavior at a time and the person receiving the discipline would not be overwhelmed. They could hear the feedback. That's why I think performance review is an ongoing process, not something you do only once a year.

That's it, those are all the secrets of the one minute management in a nutshell. Maybe I can add one last thing:

"I can see now," the young man said, "where the power of your management style comes from—you care about people."
"Sometimes," the One Minute Manager said, "you have to care enough to be tough. And I am. I am very tough on the poor performance—but only on the performance. I am never tough on the person."

Sound easy and cool isn't it? In the end we spend lots of time working, if there is something we can do to enjoy this time then I believe we should at least give it a try. So if you are asking yourself: Should I apply one-minute management? The answer for me is obvious: YES!

If you found one minute management interesting I highly recommend reading the book. It will give you much more details, examples and guidelines how to become One Minute Manager.

Wednesday, 2 July 2008

PlugInSettings - Use this class if you wish to store simple relational data ...

Recently I had to create plugin for editors (EPiServer 5) which would allow them to change some internal settings. It's of course possible to create a new page type for that but it's not always the coolest approach. If the requirement is to provide some custom user interface then you are forced to write your own plugin. It's fine because writing plugins in EPiServer is so straightforward. But in the end you have to store your settings somewhere. It can be a bit problematic unless ... you will use class called PlugInSettings. Here are some information which you can find in documentation:

Class for handling simple plugin settings as a DataSet


Use this class if you wish to store simple relational data and web.config or database is not an option.

You will also find nice, simple example how to use this class. It's very cool and everything works like a charm! But what I don't like about it is that you have to manually deal with DataSet. It's quite burdensome. Therefore, I decided to write something to make it more pleasant. Here is how it should work in my opinion:

using Cognifide.PlugInSettingsWrapper;


TestDTO data = (TestDTO) SettingsWrapper.Load(new TestDTO());

data.Value1 = "example string";
data.Value2 = "another one";
data.Value3 = 3;
data.Value4 = 4;


One line to load data and one line to save the data ... coolish?

Check how it works...

First of all you need to have data transfer object, within this, you need to have all properties which you want to store, declared in a following way:

public string Value1
get { return value1; }
set { value1 = value; }

As you can see, it's standard property with additional attribute Persistable. Thanks to this attribute you can specify which properties should be saved/loaded. SettingsWrapper will find all relevant properties, it will create DataSet for you and it will store all your data.

Two things before you go for it ...
  • I didn't check how fast it is, I presume that it's not fast, but if you take care of caching those objects then it should be fine,
  • I don't know what will happen if you decide to upgrade your EPiServer to newer version. Will EPiServer migrate all data? I hope so ...

If it still looks interesting and you want to give it a try then download the zip file containing source code and binary version and have fun!