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.





Silverlight: Performance Tuning Your Apps

17 01 2011

Application performance is one of my preferred subjects. If you are interested in this hot subjectĀ then I suggest you to watch this interesting show on Silverlight TV:Ā Performance Tuning Your Apps šŸ˜€





LocalizationLibrary 1.0 Alpha Released!

16 01 2011

Today I have released the LocalizationLibrary alpha 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





Forcing the binding expression updating

31 12 2010

If you need to force the binding expression updating, defined on a Silverlight control, you can use the following code.

public static void UpdateBindingExpressions(Control control)
{
  if (control != null)
  {
    Type controlType = control.GetType();
    FieldInfo[] fieldsInfo = controlType.GetFields(BindingFlags.Public | BindingFlags.Static);
    if (fieldsInfo != null)
    {
      foreach (FieldInfo fieldInfo in fieldsInfo)
      {
        DependencyProperty depProp = fieldInfo.GetValue(null) as DependencyProperty;
        if (depProp != null)
        {
          BindingExpression bindingExpression = control.GetBindingExpression(depProp);
          if (bindingExpression != null)
          {
            bindingExpression.UpdateSource();
          }
        }
      }
    }
  }
}