LocalizationLibrary 1.0 Beta Released!

3 05 2011

Today I have released the LocalizationLibrary beta release. 😀

LocalizationLibrary web site: localizationlibrary.codeplex.com

Overview
This release aims .net 3.5, Silverlight 3.0 and Window Phone 7. You can find all the compiled assemblies in the BIN folder, whilst if you are looking for examples about how to use the LocalizationLibrary you can find them in the Quickstart folder.

Prerequisites

  • Microsoft Visual Studio 2010 Professional, Premium, or Ultimate edition
  • Microsoft .NET Framework 4.0 (installed with Visual Studio 2010)
  • Silverlight Tools for Visual Studio 2010 (required for Silverlight development; includes the developer Silverlight runtime)
  • Windows Phone Developer Tools SDK (for development with the Windows Phone 7)
  • Optional tools:
    • Expression Blend 4





Select statement and NULL values

13 03 2011

When you are writing a Select statement (in SQL Server) and you want to equate a value to NULL you have to use the IS (IS NOT) NULL clause.

SELECT *
FROM Production.Product
WHERE Color IS NOT NULL

If you replace “IS NOT” with “<>” your query will not return any rows. This happens when the ANSI_NULLS setting is set to ON (The default setting is ON).

But if you need to replace “IS NOT” then you have to set ANSI_NULLS to OFF. In this way your Select will work fine.

SET ANSI_NULLS OFF

SELECT *
FROM Production.Product
WHERE Color <> NULL




How to configure known types dynamically

12 03 2011

Using WCF you may need to configure known types dynamically. Doing it is quite simple, you have to add your types (The types that you want to register dynamically) into the KnownTypes collection of the OperationDescription instance of your WCF service.

foreach (var operation in client.Endpoint.Contract.Operations)
{
  //_typeCollection is your known types collection that you want to register.
  foreach (Type type in _typeCollection)
  {
    operation.KnownTypes.Add(type);
    operation.KnownTypes.Add(type.MakeArrayType());
  }
}




Silverlight Spy

12 03 2011

If you need to inspect and/or debug your Silverlight applications then you can have a look to Silverlight Spy.SilverlightSPY





How to create a Unity controller factory

12 03 2011

If you are using ASP.NET MVC and you want to use DI (Dependency Injection) in your application you can create a custom controller factory.

Let’s implement a custom controller factory that uses Unity as DI Container.

First we have to create a class named UnityControllerFactory. This class has to be derived from ASP.NET MVC’s built-in DefaultControllerFactory. Next we have to override the GetControllerInstance method and return a control instance by using a unity container.

//Defines a custom control factory which uses unity to get a new  controller instance.
public class UnityControllerFactory : DefaultControllerFactory
{
    //Unity container instance.
    private IUnityContainer _unityContainer;

    //Creates a new instance of UnityControllerFactory.
    public UnityControllerFactory(IUnityContainer unityContainer)
    {
        if (unityContainer == null)
        {
            throw new ArgumentException();
        }
        this._unityContainer = unityContainer;
    }

    //Retrieves a controller instance for the specified request context and controller type by using Unity.
    protected override IController GetControllerInstance(RequestContext requestContext, Type controllerType)
    {
        if (controllerType == null)
        {
            return null;
        }
        return this._unityContainer.Resolve(controllerType) as IController;
    }
}

Finally we have to assign a new instance of UnityControllerFactory as  controller factory of our application’s ControllerBuilder.

UnityControllerFactory unityFactory = new UnityControllerFactory(new UnityContainer());
ControllerBuilder.Current.SetControllerFactory(unityFactory);

Below the implementation of our MVC application class.

//MVC Application
public class MvcApplication : System.Web.HttpApplication
{
    //Registeres global filters.
    public static void RegisterGlobalFilters(GlobalFilterCollection filters)
    {
        filters.Add(new HandleErrorAttribute());
    }

    //Registers routes.
    public static void RegisterRoutes(RouteCollection routes)
    {
        routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
        routes.MapRoute(
            "Default", // Route name
            "{controller}/{action}/{id}", // URL with parameters
            new { controller = "Home", action = "Index", id = UrlParameter.Optional } // Parameter defaults
        );
    }

    //Application startup method.
    protected void Application_Start()
    {
        AreaRegistration.RegisterAllAreas();
        RegisterGlobalFilters(GlobalFilters.Filters);
        RegisterRoutes(RouteTable.Routes);
        UnityControllerFactory unityFactory = new UnityControllerFactory(new UnityContainer());
        ControllerBuilder.Current.SetControllerFactory(unityFactory);
    }
}

Our Unity controller factory implementation is completed and you can enjoy it Winking smile





Using the SaveFileDialog: "Dialogs must be user-initiated" exception

12 03 2011

Using the SaveFileDialog in Silveright a Security Exception (“Dialogs must be user-inititated”) could be thrown.

This exception is thrown when there is a long-running operation preceding a call to ShowDialog of the SaveFileDialog instance. For example if it is preceded by either a Thread.Sleep or a break point.

In this case, you have to remove the long-running operation preceding the call and it’ll work fine.





Microsoft User Interface: A look Ahead

2 03 2011

Here two nice videos where you can take a look at what could be the user experience offered in the future by Microsoft.