Monday 30 July 2012

Google search calculator




As you probably already know, you can search math formula into Google and let it compute for you.

Today i was doing some maths into Google and a calculator appeared.

Another great addition to the search functions is the conversion user control. It was possible to search for a sentence like "10 ft in meters" but you will now get a control displayed with from an to units.



Very nice features Google!

Friday 20 July 2012

Slow toolbox in silverlight using VS2010

The problem

If you install the RIA SDK from microsoft you may experience a very slow toolbox with the following message in visutal studio stauts bar :
Loading toolbox content from package 'Microsoft.VisualStudio.IDE.ToolBoxControlsInstaller.ToolboxInstallerPackage' {2C298B35-07DA-45F1-96A3-BE55D91C8D7}

The solution

  1. Open the registry editor (regedit from the run menu).
  2. Type the GUID in the registry editor search dialog.
  3. Find every folder with that key and remove them.
This should not load the problematic items from your toolbox anymore and your VS will be fast again.

Add text template to an edmx file

The edmx designer let's you customize your entities and sync the changes for your schema with the database and generates static entities from your edmx. What if you want to add a base class to these entities?

The solution is to attach a text template (TT) to your EDMX file. This will allow you to add features and change the entities common behavior allowing you to write less redundant code in your partial classes implementation.

 Add the text template

Follow these steps to add code generation item :
  1. Open your EDMX designer
  2. Right click in the designer and select Add code generation item.
  3. Select ADO.NET EntityObject Generator
  4. Click ok 
You will see the TT file appears and a corresponding .cs generated file. Now it is possible to add a base class and additional features to your entities.

Sample

Download the demo project


Shared code from business logic with RIA Services


RIA Does a lot of automation to simplify the data access from your UI when using the entity framework. This is great but in certain situations it is very useful to have some features available in both the UI and the DAL.

This is where the shared classes are useful. When renaming any of you classes to *.shared.cs from any projects of your solution, the RIA will generate a corresponding class in your RIA client.

When building the RIA Enabled project , a Generated_Code folder will add the corresponding folder hierarchy and generate copies of your shared classes making the code available to your UI.

Keep in mind

You cannot modify these files from the UI as they are clones of the ones hosted in your parent projects.

Any project that is referenced by the ASP.NET hosting project will see their *.shared classes generated in the Silverlight UI project.

The classes renamed to *.shared will use Silverlight as a target framework, even if they are present in a project that target another framework profile.

You can call your code from both the business logic and UI layer.

Sample

From a standard class library , DemoClass.shared.cs

    public class DemoClass
    {
        public string SayHello()
        {
            return "Hello!";
        }
    }

From the silverlight project

 DemoClass dc = new DemoClass();
 TextBlock tb = new TextBlock();
 tb.Text = dc.SayHello();

 LayoutRoot.Children.Add(tb);>

Download the demo project