First contact with Amazon Simple Storage Service (S3)

Few days ago I had my first contact with Amazon Simple Storage Service web service (aka S3). I needed to use it in a project. Just some information about the structure of this project: it was an Asp.net Mvc 2 project and I needed to integrate Amazon S3 as storage system. Immediately after the registration I started to look for something that could make Amazon S3 usage as simple as possible. Immediately I found a wonderful SDK in the Developers section of the Amazon Web Service website. Consider that the S3 storage is composed by two elements: bucket and object. A bucket is approximately like a directory and an object is file. If you want to have more information read this.
At this point I had to decide where to put Amazon S3 web service in my architecture. I decided that the "service" folder was the right place to host S3. So I created a new service, with some basic method(retrieve the bucket/object list, and create and delete).


The Amazon SDK contains the AmazonS3 class that allows you to do whatever you want with your S3 service. Here you have some example of the most common operations with S3 (remember to set your preferred programming language). My first impression of S3 was good, easy to add to my project and easy to use in production.

Map SQL server 2008 Geography Type with Fluent-NHibernate

Recently I started a new project in a company involving Geo-Localization. I needed to integrate in my project GPS coordinate and to calculate the distance between them. In this project I decided to use SQL Server 2008 and Fluent-Nhibernate. Sql server 2008 has a great set of data types related to Geo-Localization known as Geography Data Type. With this fantaboulus data type you can represent point, line even polygon ad make a wide variety of manipulation with them, included calculate the distance between two point. All I needed was to store and retrieve my GPS coordinate into and from the db. I decided to use the SQL Server POINT structure. The structure of a data table was like this:

CREATE TABLE [Content](
    [Id] [int] IDENTITY(1,1) NOT NULL,
    [Lat] [varchar](50) NOT NULL,
    [Lon] [varchar](50) NOT  NULL,   
    [Location] [geography] NULL,
    [Messgage] [varchar](400) NULL
)
go

In this project I decided to use NHibernate as O/RM mapper and in particular I decieded to use Fluent NHibernate. For every field of the above table , except for Location,   was quite easy do a mapping with Fluent because they're all basic type . But in order to map the Location field I needed to create an ad-hoc type class which I called SqlGeographyUserType. This class implemented the IUserType interface that allows you to create your own custom type.

class SqlGeographyUserType : IUserType

    {

        public bool Equals(object x, object y)

        {

            if (ReferenceEquals(x, y))

                return true;

            if (x == null || y == null)

                return false;

            return x.Equals(y);

        }

        public int GetHashCode(object x)

        {

            return x.GetHashCode();

        }

        public object NullSafeGet(IDataReader rs, string[] names, object owner)

        {

            object prop1 = NHibernateUtil.String.NullSafeGet(rs, names[0]);

            if (prop1 == null)

                return null;

            SqlGeography geo = SqlGeography.Parse(new SqlString(prop1.ToString()));

 

            return geo;

        }

        public void NullSafeSet(IDbCommand cmd, object value, int index)

        {

            if (value == null)

                ((IDataParameter)cmd.Parameters[index]).Value = DBNull.Value;

            else

                ((IDataParameter)cmd.Parameters[index]).Value = ((SqlGeography)value).STAsText().Value;

        }

        public object DeepCopy(object value)

        {

            if (value == null)

                return null;

            var sourceTarget = (SqlGeography)value;

            SqlGeography targetGeography = SqlGeography.Point(sourceTarget.Lat.Value, sourceTarget.Long.Value,

                                                              sourceTarget.STSrid.Value);

            return targetGeography;

        }

        public object Replace(object original, object target, object owner)

        {

            return DeepCopy(original);

        }

        public object Assemble(object cached, object owner)

        {

            return DeepCopy(cached);

        }

        public object Disassemble(object value)

        {

            return DeepCopy(value);

        }

        public SqlType[] SqlTypes

        {

            get { return new[] { NHibernateUtil.String.SqlType }; }

        }

        public Type ReturnedType

        {

            get { return typeof(SqlGeography); }

        }

        public bool IsMutable

        {

            get { return true; }

        }

    }

In this way I have been able to map SQL Server Geography data type with Fluent Nhibernate:

    public class ContentMap : BaseMap<Content>

    {

        public ContentMap()

        {

            Map(m => m.Location).CustomType(typeof (SqlGeographyUserType));

            Map(m => m.Lat);

            Map(m => m.Lon);

            Map(m => m.Message);

        }

    }

Next time I would like to show how to get the distance between two Geography point from SQL Server & Fluent-NHibernate . But who knows when will be? ;-)

V UgiAlt.Net Conference

Sabato scorso ho avuto il piacere di poter partecipare alla V UgiALT.net Conference . E' stato veramente un bel momento in cui ho avuto l'opportunità di potermi confrontare con persone veramente di alto livello. E' stata una grandissima opportunita di poter avere una buona visuale sulle più recenti e significative tecnologie e metodologie a disposizione degli sviluppatori (senza che per forza fossero targate Zio Bill). Una delle sessioni che mi è piaciuta di più è stata quella tenuta da Alberto Brandolini in cui ho potute vedere come gli strumenti che il DDD mette a disposizione  per dominare la complessità in grossi progetti. Un'altra sessione che ha attirato la mia curiosità è stata quella tenuta da Gabriele Lana sui database documentali, ne avevo sentito parlare ma ho avuto l'opportunità di averne un esempio concreto di utilizzo.

In generale sono stato molto soddisfatto della conferenza per il clima che si è creato di  scambio di esperienze e conoscenze. Un grazie vero a tutti gli speaker e agli organizzatori.

Che dire, porto a casa molti spunti e pensieri per il futuro, e arrivederci alla prossima!

ReMix 09

Ebbene sì, ieri sono stato al ReMix a Milano ed è stata un'esperienza veramente entusiasmante. La mattina ho seguito  la  sessione su Silverlight 3  per Web Designer, mentre nel pomeriggio mi sono potuto concentrare su "What's new..". Molto interesssante e utile per il tipo di applicazioni che sviluppo è stata la sessione di Pietro Brembati su Silverlight 3 usato in un contesto di Business Application. Anzi colgo l'occassione di ringraziarlo dei preziosi consigli che mi ha dato ieri.

Bene ora non resta che mettere in pratica ciò che ho visto..

Start -> New Porject -> Silverlight 3 Business Application Template

Yeppa!
«aprile»
domlunmarmergiovensab
31123456
78910111213
14151617181920
21222324252627
2829301234
567891011