Tuesday, July 24, 2012

Automapper upper and lower case properties mapping

Yesterday I face some sort of common problem: mapping an class to another one (a DTO).
The first class was a generated entity using Entity Framework 4.
The database is a legacy one, and of course untouchable and the name of the columns are are all upper case.
To map these entities to a DTO class, I'm using best tool for .NET on the way: I'm talking about AutoMapper of course.
As you probably know, AutoMapper is a convention-based object-object mapping library.
In a basic usage, AutoMapper maps your property automatically to another one, if the property have the same name.
In my case this convection (the default one) doesn't work because of the upper-case properties, different by the properties of the DTO.

The solution.

AutoMapper, as said is convention based, so you have simply to say to it, to consider one said of the mapping with upper-case property.

How to do it?
First of all write your Naming Convention class:
public class UppercaseNamingConvenction : INamingConvention
{
   private static readonly Regex _splittingExpression
         = new Regex("(\\p{Lu}0-9]+)");

   #region Implementation of INamingConvention

   public Regex SplittingExpression
   {
      get { return _splittingExpression; }
   }

   public string SeparatorCharacter
   {
      get { return string.Empty; }
   }

   #endregion
} 
As you can see, we use a splitting regular expression with a upper case specification.

The next is to define an Automapper profile to specify a different configuration usage.
Write the code below where you configure your application at startup.


Mapper.CreateProfile("first_profile"
   , expression =>
   {
      expression.SourceMemberNamingConvention
         = new UppercaseNamingConvenction();
   });

Mapper.CreateProfile("second_profile"
   , expression =>
   {
      expression.SourceMemberNamingConvention
         = new UppercaseNamingConvenction();
   });

So you will have two profiles: "first_profile" and "second_profile".
To use this configuration, simple specific the profile when you define a mapping strategy:

Mapper.CreateMap<DtoClass, MyDbEntity>().WithProfile("first_profile");

Of course the strategy is the same if you have lower case properties: you have only to change the regular expression.

Have a nice mapping ;)

Saturday, July 7, 2012

Android - Mobile clouds @ Exchange program seminars on cloud computing


Wednesday 07/07/2012 I and Emanuele Palazzetticonducted a workshop in "Università degli studi di Perugia, dipartimento di Matematica/Informatica".

Was a long and funny day and this workshop, was one of the six for the "Exchange programme summer 2012",  between University of Perugia (IT) and Hong Kong Baptist University (HK).
Thanks to all the italy and hong kong studets was there, thanks to Professor Alfredo Milani and Valentina Franzoni.

The link of the page of the cloud computing events is here.

In the second part of the workshop, we did a full android application!
This application is a simple browser, with some nice features like a "Splash screen" and "Bookmarks save/delete" in a SQLite database.

Here the abstract of the seminar.
You can see the slide of first part here.
You can download the project resource (installation guide, a source tarball and the images) here.
Here you can find the full source code of the project on github to make your own fork.

I hope all the students (and professors :-) ) had fun building this app from scratch.

See you next seminar!

Friday, May 11, 2012

Videogiocare nell'universo FLOSS - i migliori videogame free e open source - le slide..


Sono online le slide del mio intervento all'IPSIA FLOSS 2011, dal titolo "Videogiocare nell'universo FLOSS".
Con l'occasione mi è stato fatto onore di una maglietta con su scritto "I videogiochi mi hanno rovinato la vita: per fortuna ne avevo altre 2", con questa immagine stampata sopra:

Gli argomenti trattati sono ovviamente i videogiochi, e cosa offre il mondo open source, e in particolare i sistemi GNU/Linux, oggi.

Buona visione =)

Tuesday, May 8, 2012

Android Error generating final archive: Debug Certificate expired on ..

If you are trying to build your android application using Eclipse ad you are getting an error like "Error generating final archive: Debug Certificate expired on dd/MM/yyyy" is because your signing debug certificate was created more than one year ago: the certificate auto-expires after 365 days.

The solution is to delete your debug.keystore in your android directory.

The exact location is  ~/.android/debug.keystore on Linux and Mac OS X and  %USERPROFILE%/.android on Windows.

After deleted it, the Eclipse plugin will generate a new certificate when you next try to build a debug package.

You may need first to clean the project.

More information about application signing here.

Happy coding =)

Monday, May 7, 2012

Android Workshop GTUG - Sabato 19 Maggio

Il Perugia GTUG con la collaborazione di Evonove Srl organizza un workshop di 4 ore finalizzato a fornire ai partecipanti gli strumenti di base per avvicinarsi alla programmazione di applicazioni mobili su piattaforma Android.

Il workshop si terrà Sabato 19 Maggio alle ore 9:00 nella nuova sede del coworking space di Evonove a Magione, situato al piano superiore dell'edificio sede dell'esposizione di Mobili Veracchi, a fianco del Mercatone UNO.
La partecipazione è gratuita previa registrazione all'indirizzo http://android-workshop.eventbrite.com e limitata a 6 partecipanti che verranno seguiti dai 2 tutor Michele Lepri ed Emanuele Palazzettisviluppatori freelance.

Per poter seguire le attività del workshop tutti i partecipanti dovranno avere a disposizione un laptop appositamente configurato secondo le linee guida presenti al seguente indirizzo: http://goo.gl/vEEXS.

Per qualsiasi richiesta di informazioni potrete contattare gli organizzatori in mailing list (http://groups.google.com/group/perugia-gtug) oppure all'indirizzo email pippi@gtugs.org.

Ci vediamo Sabato 19 ;)

Link originale.