ASP.NET localization with Umbraco

Umbraco is very neat and easy to integrate with ASP.NET, probably because it was built on it. One typical scenario is to create a multi-lingual web site with Umbraco, which automatically requires the use of localization. Umbraco supports localization very well and there are two main techniques, I can think of – using a dictionary or using a special page with custom fields. I personally prefer the latter, because one can use nicer names and descriptions for the custom fields, so it is easier and more intuitive to edit the texts.

Umbraco Localization Structure It is a good idea to create a separate branch in Umbraco for each language in your website. You should keep the language-independent settings in the root node and all language-dependent ones in the branches.

The next step is to use this localization in your custom controls in ASP.NET. Umbraco has a nice control, called item, which can display the contents of a property. By default, this control tried to look up the property in the current node, however you can also specify a node by its id. So, one solution is to use this control and specify the node ID of your Texts node every time (or create some wrapper over this control). However, I find this way very clumsy in spite of the nice properties the item control provides. (more…)

Filled under ASP.NET, CMS, Umbraco. No Comments.

Manually trigger knockout validation

Knockout Validation plugin makes it extremely easy to validate your model. You can use all the standard validation rules (like required, min/max length, etc), but you can also write custom rules. The plugin uses Knockout’s natural way of binding: the validation is triggered when the value of your attribute changes and the error messages are displayed if that attribute is not valid. In my recent project however we had a scenario, which was not naturally supported by the plugin – we needed a way to trigger the validation manually instead of on value change. Looking at plugin’s configuration, we could see a promising option - messagesOnModified. Unfortunately, setting this to false caused the error messages to be always displayed, instead of (as we expected) when we needed them. To solve this issue, we built our model in the following way:

var model = new MyViewModel() {
 var self = this;
 self.validationEnabled = false;
 self.isValidationEnabled = function() {
  return self.validationEnabled;
 }
};

We introduced an attribute, stating whether the validation is enabled or not. Now, we made use of cool feature of the validation plugin, namely the possibility to provide a boolean function saying whether the rule should be checked or not. The traditional way of attaching validation rules is

var model = new MyViewModel() {
 ...
 self.myAttribute = ko.observable()
  .extend({ required: true });
};

However, there is a longer syntax giving you more options.

var model = new MyViewModel() {
 ...
 self.myAttribute = ko.observable().extend({
  required: {
   params: true,
   message: 'You must provide some value',
   onlyIf: self.isValidationEnabled
  }
 });
};

Notice the onlyIf attribute, which we add to the rule object. It expects a predicate whether the rule should be executed or not. By using our custom predicate, we can disable all rules. This will disable all the rules. Note that you must add this to every rule you attach to your model. The question now is how to trigger the validation when we want it. If we take a look at the source code of the plugin, we can see the following code, which performs the validation on value change:

var h_obsValidationTrigger = ko.computed(function () {
 var obs = observable();
 var ruleContexts = observable.rules();
 exports.validateObservable(observable);
 return true;
});

This code creates a computed variable, which always returns true. A computed variable is reevaluated when any of the observable variables used inside is changed. The more important thing here is the call to validateObservable() which  does the actual validation. Fortunately, this method is publicly available as ko.validation.validateObservable(). So, to trigger the validation manually it is enough to call this method for every attribute in our model, we wish to validate.

var model = new MyViewModel() {
 ...
 self.validate = function(observable) {
  if (ko.validation.utils.isValidatable(observable))
    ko.validation.validateObservable(observable);
 };
 self.validateMyAttr = function() {
  self.validationEnabled = true;
  self.validate(self.myAttribute);
 };
};

If you want to validate a group of attributes (or the entire model), you can use the plugin’s helper function, called ko.validation.group.

Filled under JavaScript. No Comments.

Games for Android: How to get started

Mobile phones allow easy access to thousand of on-line services. One big percentage of all mobile applications is composed by games. At the end of December 2011, there were more than 10 billion downloads of mobile applications from Android market (and still counting). Games formed 1/4 of all those applications and this tended to increase, too.


Source: TestCrunch

Games are fun, relaxing and sociable. However, to develop a game may not be an easy task. You need development experience, good designers and probably someone to take care of marketing. In this post I want to show you the possibilities when starting a game project with Android. Once you try any of them, you will feel better. (more…)

Filled under Android, Mobile. No Comments.

Strange behavior with Silverlight when showing modal dialogs in SharePoint

Recently I have been working seriously on integrating Silverlight applications in SharePoint. I already have some experience with SharePoint but with my everyday work I discover more and more “features” of that system.

The Scenario

Everything started with a scenario I had to implement within SharePoint and ended up to be related just to Silverlight. So, my scenario involves creating a small Silverlight application, which is displayed within a web part. This application requires showing a modal dialog, which hosts another application. As my web part may be placed in small space, I preferred to use SharePoint’s dialog feature instead of using ChildWindow. Those two Silverlight applications (the one in the web part and the one in the dialog) communicate via local message infrastructure, which Silverlight provides. (more…)

Filled under SharePoint, Silverlight, Uncategorized. 2 Comments.

Custom BDC Connector for SharePoint 2010 – Part 2

In my previous post I started a simple tutorial of how to create your own custom connector for Business Data Connectivity Services for SharePoint 2010. I created my own project in CodePlex where to store the code of these posts. So in this article I will show you the basics of creating your own connector.

Custom connectors are the ultimate abstraction in BDC services. Basically you have the model definition as .NET objects and you can manipulate it as you wish. Internally you can call services, read files, access databases, etc. As a result you need to provide an object which conforms to method’s return type description in the model definition.

Here are the steps when creating a custom connector:

  1. Create your model definition
  2. Write code-behind
  3. Deploy the solution

Note, that the first two steps can be interchanged. Some people prefer to start by writing the code-behind, deploy it and then start wirting their models. However I think it’s a better approach if you start with the model. Having it done in advance you can concentrate on its interpretation. So in this post I will exaplain how to create your model definition. (more…)

Filled under SharePoint. 1 Comment.