<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	>

<channel>
	<title>Roberto Ramírez</title>
	<atom:link href="http://www.ramirezroberto.com/blog/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.ramirezroberto.com/blog</link>
	<description>Ignorar para preguntar y preguntar para saber, eso es aprender</description>
	<pubDate>Thu, 21 Aug 2008 15:34:09 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.6.1</generator>
	<language>en</language>
			<item>
		<title>IE 6.0</title>
		<link>http://www.ramirezroberto.com/blog/2008/08/21/ie-60/</link>
		<comments>http://www.ramirezroberto.com/blog/2008/08/21/ie-60/#comments</comments>
		<pubDate>Thu, 21 Aug 2008 15:33:16 +0000</pubDate>
		<dc:creator>bobbher</dc:creator>
		
		<category><![CDATA[Blog]]></category>

		<guid isPermaLink="false">http://www.ramirezroberto.com/blog/?p=354</guid>
		<description><![CDATA[Éste blog no funciona en Internet Explorer 6.0&#8230; ¡y qué!
]]></description>
			<content:encoded><![CDATA[<p>Éste blog no funciona en Internet Explorer 6.0&#8230; ¡y qué!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.ramirezroberto.com/blog/2008/08/21/ie-60/feed/</wfw:commentRss>
		</item>
		<item>
		<title>10 Puntos, gana un dominio, un año de hosting y mas!</title>
		<link>http://www.ramirezroberto.com/blog/2008/08/19/10-puntos-gana-un-dominio-un-ano-de-hosting-y-mas/</link>
		<comments>http://www.ramirezroberto.com/blog/2008/08/19/10-puntos-gana-un-dominio-un-ano-de-hosting-y-mas/#comments</comments>
		<pubDate>Tue, 19 Aug 2008 16:28:33 +0000</pubDate>
		<dc:creator>bobbher</dc:creator>
		
		<category><![CDATA[Internet]]></category>

		<guid isPermaLink="false">http://www.ramirezroberto.com/blog/?p=347</guid>
		<description><![CDATA[
Nunca he participado en un concurso como este, pero es un buen chance, no habría porque no intentarlo.
10puntos.info es un blog que desde mi punto de vista es muy original. Su contenido hace referencia a 10 puntos en forma de lista, acerca de diferentes temas que van desde curiosos, hasta interesantes. Desde que lo leí [...]]]></description>
			<content:encoded><![CDATA[<p><img class="aligncenter" title="10puntos" src="http://img520.imageshack.us/img520/8374/10puntos1217472197390wx6.png" alt="" width="500" height="252" /></p>
<p>Nunca he participado en un concurso como este, pero es un buen chance, no habría porque no intentarlo.</p>
<p><a href="http://www.10puntos.info/">10puntos.info</a> es un blog que desde mi punto de vista es muy original. Su contenido hace referencia a 10 puntos en forma de lista, acerca de diferentes temas que van desde curiosos, hasta interesantes. Desde que lo leí por primera vez, me llamo la atención y lo coloque en mi Blogroll para leerlo más seguido (claro, siempre y cuando el trabajo y el tiempo libre lo permita).</p>
<p>Como una forma de fortalecer la imagen del blog, su dueño a lanzado una convocatoria para participar en un <a href="http://www.10puntos.info/2008/07/31/primer-concurso-en-10-puntos-gana-un-dominioun-ano-de-hosting-y-mas/">concurso</a> y poder ganar un servicio de hosting (para el primer lugar) y un dominio (para el segundo lugar) como premios importantes, gratis por un año (muy interesante)</p>
<p>Y bueno, aquí me ven participando en él, una vez que nunca de los nunca, ni siquiera en las canicas he ganado algo jojo.</p>
<p>Suerte a todos!</p>
<p>Nota: el concurso termina el 31 de agosto.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.ramirezroberto.com/blog/2008/08/19/10-puntos-gana-un-dominio-un-ano-de-hosting-y-mas/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Casi maestro</title>
		<link>http://www.ramirezroberto.com/blog/2008/08/16/casi-maestro/</link>
		<comments>http://www.ramirezroberto.com/blog/2008/08/16/casi-maestro/#comments</comments>
		<pubDate>Sat, 16 Aug 2008 18:38:27 +0000</pubDate>
		<dc:creator>bobbher</dc:creator>
		
		<category><![CDATA[Maestría]]></category>

		<guid isPermaLink="false">http://www.ramirezroberto.com/blog/?p=308</guid>
		<description><![CDATA[Según el CIA:
Nombre: Ramírez Leyva, José Roberto.
Grado: Maestría.
Programa: MATI - Mtro. en Administración de Tecnologías de Información.



Nombre
Calificación
Créditos


Entorno Empresarial
9
5.25


Negocios y las Tecnologías Información
10
5.25


Situación Organizacional
10
5.25


Evaluación Financiera de Tecnologías de Información
10
5.25


Planeación Estratégica Informática
10
5.25


Procesos de Negocios
10
5.25


Administración de Proyectos Informáticos
9
5.25


Dirección de Equipos de TI
10
5.25


Topico I
10
5.25


Gestión de Proyectos Informáticos
10
5.25


Topico II
9
5.25


Topico II
8
5.25


Formación Metodológica
10
5.25


Topico IV
10
5.25


Seminario de Tesis
10
5.25


Topico V
10
5.25



Una vez terminado mi programa academico, [...]]]></description>
			<content:encoded><![CDATA[<p>Según el <a href="http://www.itson.mx/cia">CIA</a>:</p>
<p>Nombre: Ramírez Leyva, José Roberto.<br />
Grado: Maestría.<br />
Programa: MATI - Mtro. en Administración de Tecnologías de Información.</p>
<table style="width: 100%;" border="0">
<tbody>
<tr style="margin:5px;" bgcolor="#2f2f2f">
<td align="center">Nombre</td>
<td align="center">Calificación</td>
<td align="center">Créditos</td>
</tr>
<tr>
<td>Entorno Empresarial</td>
<td align="center">9</td>
<td align="center">5.25</td>
</tr>
<tr>
<td>Negocios y las Tecnologías Información</td>
<td align="center">10</td>
<td align="center">5.25</td>
</tr>
<tr>
<td>Situación Organizacional</td>
<td align="center">10</td>
<td align="center">5.25</td>
</tr>
<tr>
<td>Evaluación Financiera de Tecnologías de Información</td>
<td align="center">10</td>
<td align="center">5.25</td>
</tr>
<tr>
<td>Planeación Estratégica Informática</td>
<td align="center">10</td>
<td align="center">5.25</td>
</tr>
<tr>
<td>Procesos de Negocios</td>
<td align="center">10</td>
<td align="center">5.25</td>
</tr>
<tr>
<td>Administración de Proyectos Informáticos</td>
<td align="center">9</td>
<td align="center">5.25</td>
</tr>
<tr>
<td>Dirección de Equipos de TI</td>
<td align="center">10</td>
<td align="center">5.25</td>
</tr>
<tr>
<td>Topico I</td>
<td align="center">10</td>
<td align="center">5.25</td>
</tr>
<tr>
<td>Gestión de Proyectos Informáticos</td>
<td align="center">10</td>
<td align="center">5.25</td>
</tr>
<tr>
<td>Topico II</td>
<td align="center">9</td>
<td align="center">5.25</td>
</tr>
<tr>
<td>Topico II</td>
<td align="center">8</td>
<td align="center">5.25</td>
</tr>
<tr>
<td>Formación Metodológica</td>
<td align="center">10</td>
<td align="center">5.25</td>
</tr>
<tr>
<td>Topico IV</td>
<td align="center">10</td>
<td align="center">5.25</td>
</tr>
<tr>
<td>Seminario de Tesis</td>
<td align="center">10</td>
<td align="center">5.25</td>
</tr>
<tr>
<td>Topico V</td>
<td align="center">10</td>
<td align="center">5.25</td>
</tr>
</tbody>
</table>
<p>Una vez terminado mi programa academico, solo queda la tesis =)</p>
]]></content:encoded>
			<wfw:commentRss>http://www.ramirezroberto.com/blog/2008/08/16/casi-maestro/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Jack Johnson - Hope ♫</title>
		<link>http://www.ramirezroberto.com/blog/2008/08/16/jack-johnson-hope-%e2%99%ab/</link>
		<comments>http://www.ramirezroberto.com/blog/2008/08/16/jack-johnson-hope-%e2%99%ab/#comments</comments>
		<pubDate>Sat, 16 Aug 2008 16:01:26 +0000</pubDate>
		<dc:creator>bobbher</dc:creator>
		
		<category><![CDATA[Música]]></category>

		<guid isPermaLink="false">http://www.ramirezroberto.com/blog/?p=303</guid>
		<description><![CDATA[
Your shadow walks faster than you
You don’t really know what to do
Do you think that you’re not alone?
You really think that you&#8217;re immune to it
Its going get that the best of you
Its going lift you up and let you down
Hmm hmm humm
It will defeat you then teach you to get back up
After it takes away [...]]]></description>
			<content:encoded><![CDATA[<p style="text-align: center;"></p>
<p style="text-align: center;">Your shadow walks faster than you<br />
You don’t really know what to do<br />
Do you think that you’re not alone?<br />
You really think that you&#8217;re immune to it<br />
Its going get that the best of you<br />
Its going lift you up and let you down<br />
Hmm hmm humm</p>
<p style="text-align: center;">It will defeat you then teach you to get back up<br />
After it takes away all that you learn to love</p>
<p style="text-align: center;">Your reflection is a blur<br />
Out of focus but in confusion<br />
The frames the sun did burn<br />
At the end of a roll of delusions<br />
A ghost waiting its turn<br />
And now I can see right through it<br />
It’s a warning that nobody heard</p>
<p style="text-align: center;">It will teach you to love what you&#8217;re afraid of<br />
After it takes away all that you&#8217;ve learn to love</p>
<p style="text-align: center;">But you don’t, always<br />
Have to hold your head<br />
Higher than your heart</p>
<p style="text-align: center;">You better hope you’re not alone<br />
You better hope you’re not alone<br />
You better hope you’re not alone<br />
You better hope you’re not alone<br />
You better hope you’re not alone<br />
You better hope you’re not alone<br />
You better hope you’re not alone<br />
You better be hoping you’re not so…</p>
<p style="text-align: center;">Du du rut<br />
Hope you’re not alone<br />
Hmm hmm humm</p>
<p style="text-align: center;">Your echo comes back out of tune<br />
Now you can&#8217;t quite get used to it<br />
Reverb is just a room<br />
The problem is that there’s no truth to it<br />
It&#8217;s fading away too soon<br />
Your shadow is on the move<br />
And maybe you should be moving too</p>
<p style="text-align: center;">Before it takes away all that you learned to love<br />
It will defeat you and then teach you to get back up</p>
<p style="text-align: center;">&#8216;Cause you don’t, always<br />
Have to hold your head<br />
Higher than your heart</p>
<p style="text-align: center;">You better hope you’re not alone<br />
You better hope you’re not alone<br />
You better hope you’re not alone<br />
You better be hoping you’re alone<br />
You better hope you’re not alone<br />
You better hope you’re not alone<br />
You better hope you’re not alone<br />
You better hope you’re not so…</p>
<p style="text-align: center;">Du ru ru ru ru<br />
Hope you’re not alone<br />
Hmm hmmm hmmmm<br />
Better hooope<br />
Huuu huuu hmmm<br />
Better hope you’re not alone<br />
Huuu huuu hmmm<br />
hooope</p>
]]></content:encoded>
			<wfw:commentRss>http://www.ramirezroberto.com/blog/2008/08/16/jack-johnson-hope-%e2%99%ab/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Crónicas de un choque anunciado VII</title>
		<link>http://www.ramirezroberto.com/blog/2008/08/16/cronicas-de-un-choque-anunciado-vii/</link>
		<comments>http://www.ramirezroberto.com/blog/2008/08/16/cronicas-de-un-choque-anunciado-vii/#comments</comments>
		<pubDate>Sat, 16 Aug 2008 15:49:17 +0000</pubDate>
		<dc:creator>bobbher</dc:creator>
		
		<category><![CDATA[Traumas]]></category>

		<guid isPermaLink="false">http://www.ramirezroberto.com/blog/?p=295</guid>
		<description><![CDATA[A veces siento que vivo en una burbujita de aire y todo lo que existe dentro de ella es bueno, pero que tan equivocado estoy o lo he estado.
Pareciera que fue ayer el día que un desgraciado de la manera más cobarde, después de casi matarme, después de llevarlo a él y a su acompañante [...]]]></description>
			<content:encoded><![CDATA[<p>A veces siento que vivo en una burbujita de aire y todo lo que existe dentro de ella es bueno, pero que tan equivocado estoy o lo he estado.</p>
<p>Pareciera que fue <a href="http://www.ramirezroberto.com/blog/2007/02/23/carro-off/">ayer</a> el día que un desgraciado de la manera más cobarde, después de casi matarme, después de llevarlo a él y a su acompañante a su casa y de pensar de manera más positiva en que todo se arreglaría, este no se hiciera responsable de sus estupideces. Pues véanme ahora, ya paso más del año y medio y después de una infinidad de vueltas con el ministerio público (MP), estiras y aflojes, depresiones por observar el estado tan deplorable en el que se encuentran nuestras instalaciones de seguridad pública, esto aun no termina.</p>
<p>Hay algo positivo, esta semana me dieron una buena noticia los señores agentes del MP. Espero de una vez poder terminar con esto y ver al fulano tras-las-rejas o bien reponiéndome el daño.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.ramirezroberto.com/blog/2008/08/16/cronicas-de-un-choque-anunciado-vii/feed/</wfw:commentRss>
		</item>
		<item>
		<title>10 tablas con CSS</title>
		<link>http://www.ramirezroberto.com/blog/2008/08/14/10-tablas-con-css/</link>
		<comments>http://www.ramirezroberto.com/blog/2008/08/14/10-tablas-con-css/#comments</comments>
		<pubDate>Thu, 14 Aug 2008 15:05:23 +0000</pubDate>
		<dc:creator>bobbher</dc:creator>
		
		<category><![CDATA[Miniblog]]></category>

		<guid isPermaLink="false">http://www.ramirezroberto.com/blog/?p=296</guid>
		<description><![CDATA[Sin duda, algún día me deberán de servir en algún diseño web: http://tinyurl.com/6277ks
]]></description>
			<content:encoded><![CDATA[<p>Sin duda, algún día me deberán de servir en algún diseño web: <a href="http://tinyurl.com/6277ks">http://tinyurl.com/6277ks</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.ramirezroberto.com/blog/2008/08/14/10-tablas-con-css/feed/</wfw:commentRss>
		</item>
		<item>
		<title>NHibernate for dummies</title>
		<link>http://www.ramirezroberto.com/blog/2008/08/07/nhibernate-for-dummies/</link>
		<comments>http://www.ramirezroberto.com/blog/2008/08/07/nhibernate-for-dummies/#comments</comments>
		<pubDate>Thu, 07 Aug 2008 20:34:00 +0000</pubDate>
		<dc:creator>bobbher</dc:creator>
		
		<category><![CDATA[NHibernate]]></category>

		<category><![CDATA[Programación]]></category>

		<guid isPermaLink="false">http://www.ramirezroberto.com/blog/?p=275</guid>
		<description><![CDATA[Sabemos hoy en día que la mayoría de las empresas basan sus aplicaciones en software analizado, diseñado y programado orientado a objetos. La empresa donde trabajo, los últimos meses se ha preocupado porque que cada vez en los desarrollos que se venden se utilicen objetos para crear modelos de negocio, que con esto, sin duda [...]]]></description>
			<content:encoded><![CDATA[<p>Sabemos hoy en día que la mayoría de las empresas basan sus aplicaciones en software analizado, diseñado y programado orientado a objetos. La empresa donde trabajo, los últimos meses se ha preocupado porque que cada vez en los desarrollos que se venden se utilicen objetos para crear modelos de negocio, que con esto, sin duda si creamos un modelo de dominio orientado a objetos será más claro el negocio para que el que lo necesite entender y código fácil mucho mas mantenible para los programadores que lo vayan a modificar.</p>
<p>Por otro lado tenemos la información, los datos, y probablemente todos nosotros en nuestros desarrollos hemos trabajado con bases de datos relacionales tales como SQL Server, MySQL, entre otras. Esta información seguramente necesitara cambiar e irse modificando, así como también necesitaremos tener esta información disponible cuando queramos, esto en al área de desarrollo de sistemas se le conoce como persistencia. Como se relaciona esto? el modelo relacional de datos es la representación más clara de los objetos de negocio que existen en nuestro dominio de sistema y este necesitara almacenar información de cada una de sus entidades dentro del mismo dominio (Clientes, Productos, Usuarios, etc) y al conjuntarse nace un concepto conocido como Object Relational Mapping (ORM).</p>
<p>NHibernate (NH) es un marco de trabajo ORM para ambientes en los que utilizamos .NET que nace de un port de Hibernate de Java y la gran utilidad es que ayuda a mapear los objetos de negocio que creamos en nuestras aplicaciones de .NET a bases de datos relacionales.</p>
<p>A partir de ahora intentaremos explicar cómo funciona a grandes rasgos NH y como podríamos aplicarlo a los nuevos desarrollos en la empresa. Para la práctica estaremos utilizando la versión 2008 del Visual Studio Team System (VSTS 2008) como IDE de desarrollo y la versión express del SQL Server 2005.</p>
<h3>1. Crear un proyecto biblioteca de clases</h3>
<p>Este proyecto deberá de contener nuestros objetos de negocio, y por lo tanto aquellos objetos que deseamos persistir. Como ya hemos mencionado en otros tutoriales, se recomienda como buena práctica crear un archivo de solución (sln) y en este agregar tantos proyectos vayamos a necesitar.</p>
<p><img class="alignnone size-full wp-image-277" title="paso1" src="http://www.ramirezroberto.com/blog/wp-content/uploads/2008/08/paso1.jpg" alt="" width="438" height="288" /></p>
<p>Para este tutorial he creado un proyecto llamado Tutorial.NH.BOL que es la biblioteca de clases que contendrá las entidades que representaran la base de datos.</p>
<h3>2. Crear modelo de dominio</h3>
<p>Nuestro modelo de dominio estará basado en usuarios (crearemos una carpeta con nombre Entidades en nuestro proyecto para depositar nuestras clases) y las diversas tareas que puede tener un usuario, sabemos que nuestras aplicaciones empresariales son más complejas, pero creo que bastará con explicar lo esencial para entender lo que es NH. La idea de esto es poder persistir estas entidades en nuestra base de datos relacional. Para hacer más sencillo el entendimiento de NH imagínense que una instancia de cada una de nuestras entidades en una fila de una tabla de la base de datos, pero no se casen con este concepto.</p>
<p>Es una buena práctica usar el diagramador de clases que por defecto cuenta el VSTS 2008, el trabajo es más limpio, mas controlado y lo mejor de todo en la mayoría de los casos ¡no tenemos que escribir código! =).</p>
<p><img src="http://www.ramirezroberto.com/blog/wp-content/uploads/2008/08/paso3.jpg" alt="" title="paso3" width="462" height="365" class="alignnone size-full wp-image-279" /></p>
<h3>3. Crear modelo relacional</h3>
<p>El modelo relacional estará representado por aquellas tablas de base de datos las cuales deberán de representar las entidades del modelo de dominio que queremos persistir. Ya sea en el IDE de VSTS 2008 o en la consola de Microsoft SQL Server deberemos de obtener algo como esto (algo ideal sería utilizar NH para generar el esquema de nuestra base de datos acorde a nuestro modelo de dominio, este método queda fuera del alcance del tutorial):</p>
<p><img src="http://www.ramirezroberto.com/blog/wp-content/uploads/2008/08/paso2.jpg" alt="" title="paso2" width="498" height="202" class="alignnone size-full wp-image-278" /></p>
<h3>4. Mapeo ORM</h3>
<p>La manera en cómo se mapeara el modelo de dominio con nuestro modelo relacional es a través de documentos XML, esto se hace con el fin de documentar la relación que existe entre nuestro objeto y la tabla que lo representa en la base de datos, es decir, el documento de configuración define que campos en la base de datos corresponden a los atributos en nuestro objeto y viceversa. La relación puede hacerse mediante código (con ayuda de la librería NHibernate.Mapping.Attributes.dll) en los atributos de la clase ó a través de archivos como los que acabo de comentar, archivos XML que tienen la extensión .hbm.xml, es por esto que nuestros archivos mapping deberan llamarse Usuario.hbm.xml y Tarea.hbm.xml. No hay que perder de vista que el .hbm es parte del nombre del archivo y es una convención que utiliza NH para identificar los archivos como mapping</p>
<p>Antes de empezar a trabajar con nuestro mapeo ORM debemos de descargar la versión 1.02 de NHibernate para .NET, la cual está disponible en la siguiente dirección: <a href="http://downloads.sourceforge.net/nhibernate/NHibernate-1.2.0.GA-bin.zip?modtime=1178204756&#038;big_mirror=0">http://downloads.sourceforge.net/nhibernate/NHibernate-1.2.0.GA-bin.zip?modtime=1178204756&#038;big_mirror=0<br />
</a></p>
<p>Se recomienza habilitar el Intellisense para el mapeo y la creación de estos archivos de configuración, para esto debemos de copiar los archivos nhibernate-configuration.xsd (para la configuración de las sesiones, algo que veremos más adelante en este tutorial) y nhibernate-mapping.xsd (para los mappings) a las carpetas de instalación de Visual Studio, <VS .NET directorio de instalación>\Common7\Packages\schemas\xml\ si usamos VS.NET 2003 y <VS 2005 installation directory>\Xml\Schemas\ para VS.NET 2005 y 2008.</p>
<p>Dentro de nuestra librería de clases Tutorial.NH.BOL vamos a crear una carpeta llamada Mapping -esto con el fin de tener mas orden- la cual contendrá todos nuestros archivos de configuración y la implementación de estos la muestro a continuación:</p>
<p>4.1. Usuario.hbm.xml</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
</pre></td><td class="code"><pre class="xml"><span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;?xml</span> <span style="color: #000066;">version</span>=<span style="color: #ff0000;">&quot;1.0&quot;</span> <span style="color: #000066;">encoding</span>=<span style="color: #ff0000;">&quot;utf-8&quot;</span> <span style="font-weight: bold; color: black;">?&gt;</span></span>
<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;hibernate-mapping</span> <span style="color: #000066;">xmlns</span>=<span style="color: #ff0000;">&quot;urn:nhibernate-mapping-2.2&quot;</span> <span style="color: #000066;">assembly</span>=<span style="color: #ff0000;">&quot;Tutorial.NH.BOL&quot;</span> <span style="color: #000066;">namespace</span>=<span style="color: #ff0000;">&quot;Tutorial.NH.BOL&quot;</span><span style="font-weight: bold; color: black;">&gt;</span></span>
    <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;class</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;Usuario&quot;</span> <span style="color: #000066;">table</span>=<span style="color: #ff0000;">&quot;usuarios&quot;</span><span style="font-weight: bold; color: black;">&gt;</span></span>
        <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;id</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;Id&quot;</span> <span style="color: #000066;">column</span>=<span style="color: #ff0000;">&quot;IdUsuario&quot;</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">&quot;int&quot;</span> <span style="color: #000066;">unsaved-value</span>=<span style="color: #ff0000;">&quot;0&quot;</span><span style="font-weight: bold; color: black;">&gt;</span></span>
            <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;generator</span> <span style="color: #000066;">class</span>=<span style="color: #ff0000;">&quot;identity&quot;</span> <span style="font-weight: bold; color: black;">/&gt;</span></span>
        <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/id<span style="font-weight: bold; color: black;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;property</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;Nombre&quot;</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">&quot;String&quot;</span> <span style="color: #000066;">length</span>=<span style="color: #ff0000;">&quot;50&quot;</span><span style="font-weight: bold; color: black;">&gt;</span></span><span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/property<span style="font-weight: bold; color: black;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;property</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;ApellidoMaterno&quot;</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">&quot;String&quot;</span> <span style="color: #000066;">length</span>=<span style="color: #ff0000;">&quot;50&quot;</span><span style="font-weight: bold; color: black;">&gt;</span></span><span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/property<span style="font-weight: bold; color: black;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;property</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;ApellidoPaterno&quot;</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">&quot;String&quot;</span> <span style="color: #000066;">length</span>=<span style="color: #ff0000;">&quot;50&quot;</span><span style="font-weight: bold; color: black;">&gt;</span></span><span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/property<span style="font-weight: bold; color: black;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;property</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;CorreoElectronico&quot;</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">&quot;String&quot;</span> <span style="color: #000066;">length</span>=<span style="color: #ff0000;">&quot;50&quot;</span><span style="font-weight: bold; color: black;">&gt;</span></span><span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/property<span style="font-weight: bold; color: black;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;property</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;Telefono&quot;</span> <span style="color: #000066;">column</span>=<span style="color: #ff0000;">&quot;TelefonoParticular&quot;</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">&quot;String&quot;</span> <span style="color: #000066;">length</span>=<span style="color: #ff0000;">&quot;50&quot;</span><span style="font-weight: bold; color: black;">&gt;</span></span><span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/property<span style="font-weight: bold; color: black;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;bag</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;Tarea&quot;</span> <span style="color: #000066;">cascade</span>=<span style="color: #ff0000;">&quot;all-delete-orphan&quot;</span><span style="font-weight: bold; color: black;">&gt;</span></span>
            <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;key</span> <span style="color: #000066;">column</span>=<span style="color: #ff0000;">&quot;IdUsuario&quot;</span> <span style="font-weight: bold; color: black;">/&gt;</span></span>
            <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;one-to-many</span> <span style="color: #000066;">class</span>=<span style="color: #ff0000;">&quot;Tarea&quot;</span> <span style="font-weight: bold; color: black;">/&gt;</span></span>
        <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/bag<span style="font-weight: bold; color: black;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/class<span style="font-weight: bold; color: black;">&gt;</span></span></span>
<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/hibernate-mapping<span style="font-weight: bold; color: black;">&gt;</span></span></span></pre></td></tr></table></div>

<p>Ahora podemos hablar un poco sobre el contenido del archivo XML. Todos los documentos para mapear XML deberán de declarar el espacio de nombre urn:nhibernate-mapping-2.2 (depende de la versión distribuida), así como de manera opcional los atributos assembly para indicar el ensamblado de nuestras clases y el namespace de nuestras clases en el proyecto. Existen otros atributos aplicables a nuestro archivo como el schema, que representa el nombre del esquema de la base de datos, entre otros que están fuera del alcance de este tutorial. Una vez hecho esto debemos de comenzar a tratar los atributos y elementos para la clase que deseamos mapear. Dentro de las etiquetas <class name="Usuario"></class> estarán todas aquellas configuraciones para la clase. El atributo name corresponde al nombre de la clase incluyendo el nombre del assembly. El atributo table corresponde al nombre de la tabla en la base de datos.</p>
<p>Con la etiqueta <id> representamos la llave primaria de la tabla de la base de datos. Este elemento define el mapeo entre la propiedad de la clase y la llave primaria de la base de datos. Entre sus atributos se encuentra el name, que indica el nombre del identificador de la propiedad; columna, que representa la columna en la tabla; type, el tipo de dato y el unsaved-value indica que el objeto es nuevo y que no existe en la base de datos.</p>
<p>Debemos de continuar con todas las propiedades, entonces Nombre, Apellido Paterno, Apellido Materno, Correo Electronico y Telefono deberán de estar dentro de las etiquetas
<property/> y representan propiedades persistentes de la clase.</p>
<p>Y como habíamos dicho al inicio del tutorial, lo complicaremos creando una relación one-to-many con la clase Tarea y de esta forma representaremos la relación en la base de datos, es decir, que a un usuario se le pueden asignar varias tareas.</p>
<p>4.2. Tarea.hbm.xml</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
</pre></td><td class="code"><pre class="xml"><span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;?xml</span> <span style="color: #000066;">version</span>=<span style="color: #ff0000;">&quot;1.0&quot;</span> <span style="color: #000066;">encoding</span>=<span style="color: #ff0000;">&quot;utf-8&quot;</span> <span style="font-weight: bold; color: black;">?&gt;</span></span>
<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;hibernate-mapping</span> <span style="color: #000066;">xmlns</span>=<span style="color: #ff0000;">&quot;urn:nhibernate-mapping-2.2&quot;</span> <span style="color: #000066;">assembly</span>=<span style="color: #ff0000;">&quot;Tutorial.NH.BOL&quot;</span> <span style="color: #000066;">namespace</span>=<span style="color: #ff0000;">&quot;Tutorial.NH.BOL&quot;</span><span style="font-weight: bold; color: black;">&gt;</span></span>
    <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;class</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;Tarea&quot;</span> <span style="color: #000066;">table</span>=<span style="color: #ff0000;">&quot;tareas&quot;</span><span style="font-weight: bold; color: black;">&gt;</span></span>
        <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;id</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;Id&quot;</span> <span style="color: #000066;">column</span>=<span style="color: #ff0000;">&quot;IdTarea&quot;</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">&quot;int&quot;</span> <span style="color: #000066;">unsaved-value</span>=<span style="color: #ff0000;">&quot;0&quot;</span><span style="font-weight: bold; color: black;">&gt;</span></span>
            <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;generator</span> <span style="color: #000066;">class</span>=<span style="color: #ff0000;">&quot;identity&quot;</span> <span style="font-weight: bold; color: black;">/&gt;</span></span>
        <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/id<span style="font-weight: bold; color: black;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;property</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;NombreTarea&quot;</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">&quot;String&quot;</span><span style="font-weight: bold; color: black;">&gt;</span></span><span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/property<span style="font-weight: bold; color: black;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;many-to-one</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;Usuario&quot;</span> <span style="color: #000066;">column</span>=<span style="color: #ff0000;">&quot;IdUsuario&quot;</span> <span style="color: #000066;">cascade</span>=<span style="color: #ff0000;">&quot;all&quot;</span> <span style="font-weight: bold; color: black;">/&gt;</span></span>
    <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/class<span style="font-weight: bold; color: black;">&gt;</span></span></span>
<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/hibernate-mapping<span style="font-weight: bold; color: black;">&gt;</span></span></span></pre></td></tr></table></div>

<p>Lo único representativo es el elemento <many-to-one> para la propiedad Usuario de nuestra clase. Esta representa una ordinaria asociación a otra clase persistente, en este caso la que tenemos en la base de datos.</p>
<p>Algo que debemos de saber es que en primera instancia NH está configurado de modo perezoso (lazy load) para todas las entidades creadas. Esto se recomienda dejarse así y no moverse. Debido a esto la regla es que todas las propiedades definidas en nuestras entidades deberán ser virtuales.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
</pre></td><td class="code"><pre class="csharp"><span style="color: #0600FF;">public</span> <span style="color: #0600FF;">virtual</span> <span style="color: #FF0000;">int</span> Id
<span style="color: #000000;">&#123;</span>
    get <span style="color: #000000;">&#123;</span> <span style="color: #0600FF;">return</span> _id<span style="color: #008000;">;</span> <span style="color: #000000;">&#125;</span>
    set <span style="color: #000000;">&#123;</span> _id <span style="color: #008000;">=</span> value<span style="color: #008000;">;</span> <span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span></pre></td></tr></table></div>

<p>Hay mucha más información relacionada a estos archivos mapping, pero sería algo complicado tratar de explicárselos paso a paso, además de que este tutorial perdería sentido, para ello, recomiendo consultar la referencia en línea sobre este mapeo de clases en <a href="http://www.hibernate.org/hib_docs/nhibernate/1.2/reference/en/html/mapping.html">http://www.hibernate.org/hib_docs/nhibernate/1.2/reference/en/html/mapping.html</a>.</p>
<p>Hasta aquí nuestro explorador de soluciones deberá verse así:</p>
<p><img src="http://www.ramirezroberto.com/blog/wp-content/uploads/2008/08/paso4.jpg" alt="" title="paso4" width="227" height="274" class="alignnone size-full wp-image-280" /></p>
<h3>5. Configurando NHibernate en VSTS 2008 .NET</h3>
<p>Bueno hasta ahora, no hemos hecho mucho, pero ya empieza lo bueno =). Hay que decirle a NH con que proveedor de base de datos vamos a trabajar. Por fortuna NH soporta el más querido por nosotros en la oficina SQL Server.</p>
<p>Para hacer mas modular la aplicación, vamos a agregar una aplicación de consola a nuestra solución con el fin de consumir nuestro ORM. El nombre que yo le he puesto al proyecto es Tutorial.NH.App, tu puedes ponerle el que gustes. Importante agregar dentro de las referencias nuestro ensamblado de nombre Tutorial.NH.BOL. Pudimos haber utilizado Unit Test para probar nuestro proyecto en lugar de la aplicación de Consola, pero mejor eso veámoslo después.</p>
<p>5.1. Configuración en App.config</p>
<p>Agregaremos un archivo de configuración donde indicaremos las llaves necesarias para establecer la comunicación con nuestra base de datos.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
</pre></td><td class="code"><pre class="xml"><span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;?xml</span> <span style="color: #000066;">version</span>=<span style="color: #ff0000;">&quot;1.0&quot;</span> <span style="color: #000066;">encoding</span>=<span style="color: #ff0000;">&quot;utf-8&quot;</span> <span style="font-weight: bold; color: black;">?&gt;</span></span>
<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;configuration<span style="font-weight: bold; color: black;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;configSections<span style="font-weight: bold; color: black;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;section</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;nhibernate&quot;</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">&quot;System.Configuration.NameValueSectionHandler, System, Version=1.0.3300.0,Culture=neutral, PublicKeyToken=b77a5c561934e089&quot;</span> <span style="font-weight: bold; color: black;">/&gt;</span></span>
    <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/configSections<span style="font-weight: bold; color: black;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;nhibernate<span style="font-weight: bold; color: black;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;add</span> <span style="color: #000066;">key</span>=<span style="color: #ff0000;">&quot;hibernate.show_sql&quot;</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;false&quot;</span> <span style="font-weight: bold; color: black;">/&gt;</span></span>
        <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;add</span> <span style="color: #000066;">key</span>=<span style="color: #ff0000;">&quot;hibernate.connection.provider&quot;</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;NHibernate.Connection.DriverConnectionProvider&quot;</span> <span style="font-weight: bold; color: black;">/&gt;</span></span>
        <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;add</span> <span style="color: #000066;">key</span>=<span style="color: #ff0000;">&quot;hibernate.dialect&quot;</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;NHibernate.Dialect.MsSql2000Dialect&quot;</span> <span style="font-weight: bold; color: black;">/&gt;</span></span>
        <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;add</span> <span style="color: #000066;">key</span>=<span style="color: #ff0000;">&quot;hibernate.connection.driver_class&quot;</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;NHibernate.Driver.SqlClientDriver&quot;</span> <span style="font-weight: bold; color: black;">/&gt;</span></span>
        <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;add</span> <span style="color: #000066;">key</span>=<span style="color: #ff0000;">&quot;hibernate.connection.connection_string&quot;</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;Data Source=ROBERTO\SQLEXPRESS;Initial Catalog=NHibernate;Integrated Security=SSPI;&quot;</span> <span style="font-weight: bold; color: black;">/&gt;</span></span>
    <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/nhibernate<span style="font-weight: bold; color: black;">&gt;</span></span></span>
<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/configuration<span style="font-weight: bold; color: black;">&gt;</span></span></span></pre></td></tr></table></div>

<p>5.2 Configuración en hibernate.cfg.xml</p>
<p>Este es otra manera de realizar nuestra configuración de NH y consiste en agregar un archivo XML a nuestro proyecto con la siguiente estructura: hibernate.cfg.xml.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
</pre></td><td class="code"><pre class="xml"><span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;?xml</span> <span style="color: #000066;">version</span>=<span style="color: #ff0000;">&quot;1.0&quot;</span> <span style="color: #000066;">encoding</span>=<span style="color: #ff0000;">&quot;utf-8&quot;</span> <span style="font-weight: bold; color: black;">?&gt;</span></span>
<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;hibernate-configuration</span>  <span style="color: #000066;">xmlns</span>=<span style="color: #ff0000;">&quot;urn:nhibernate-configuration-2.2&quot;</span> <span style="font-weight: bold; color: black;">&gt;</span></span>
    <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;session-factory</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;NH01&quot;</span><span style="font-weight: bold; color: black;">&gt;</span></span>
        <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;property</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;connection.provider&quot;</span><span style="font-weight: bold; color: black;">&gt;</span></span>NHibernate.Connection.DriverConnectionProvider<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/property<span style="font-weight: bold; color: black;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;property</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;connection.driver_class&quot;</span><span style="font-weight: bold; color: black;">&gt;</span></span>NHibernate.Driver.SqlClientDriver<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/property<span style="font-weight: bold; color: black;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;property</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;dialect&quot;</span><span style="font-weight: bold; color: black;">&gt;</span></span>NHibernate.Dialect.MsSql2005Dialect<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/property<span style="font-weight: bold; color: black;">&gt;</span></span></span>   
        <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;property</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;connection.connection_string&quot;</span><span style="font-weight: bold; color: black;">&gt;</span></span>Data Source=ROBERTO\SQLEXPRESS;Initial Catalog=NHibernate;Integrated Security=SSPI;<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/property<span style="font-weight: bold; color: black;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;property</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;show_sql&quot;</span><span style="font-weight: bold; color: black;">&gt;</span></span>false<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/property<span style="font-weight: bold; color: black;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;mapping</span> <span style="color: #000066;">assembly</span>=<span style="color: #ff0000;">&quot;Tutorial.NH.BOL&quot;</span> <span style="font-weight: bold; color: black;">/&gt;</span></span>
    <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/session-factory<span style="font-weight: bold; color: black;">&gt;</span></span></span>
<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/hibernate-configuration<span style="font-weight: bold; color: black;">&gt;</span></span></span></pre></td></tr></table></div>

<p>Podemos utilizar cualquiera de los dos. Con este archivo de configuración le decimos a NH que queremos trabajar con Microsoft SQL Server como base de datos. Para nuestro ejemplo usaremos la segunda opción.</p>
<p>Y bien ya estamos listos para iniciar con nuestras operaciones <a href="http://es.wikipedia.org/wiki/CRUD">CRUD</a>.</p>
<h3>6. Operaciones CRUD</h3>
<p>Nuestro sistema hasta este punto ha sido preparado con lo esencial. Se han implementado características necesarias para el funcionamiento de NH, se ha creado el modelo de dominio se han definido los archivos mapping y se ha establecido la configuración a NH. Vamos poco a poco y ya llevamos algo recorrido =).</p>
<p>Empezaremos a darle uso y funcionalidad a nuestro dominio.</p>
<p>Ahora, vamos a agregar una carpeta a nuestro proyecto Tutorial.NH.BOL llamado Repositorio (esto lo especifica Domain Driven Design) y en el agregaremos una clase llamada IRepositorioUsuario.cs y la definimos de la siguiente manera:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
</pre></td><td class="code"><pre class="csharp"><span style="color: #0600FF;">using</span> <span style="color: #008080;">System</span><span style="color: #008000;">;</span>
<span style="color: #0600FF;">using</span> <span style="color: #008080;">System.Collections.Generic</span><span style="color: #008000;">;</span>
<span style="color: #0600FF;">using</span> <span style="color: #008080;">System.Text</span><span style="color: #008000;">;</span>
<span style="color: #0600FF;">using</span> <span style="color: #008080;">Tutorial.NH.BOL.Entidades</span><span style="color: #008000;">;</span>
&nbsp;
<span style="color: #0600FF;">namespace</span> Tutorial.<span style="color: #0000FF;">NH</span>.<span style="color: #0000FF;">BOL</span>.<span style="color: #0000FF;">Repositorio</span>
<span style="color: #000000;">&#123;</span>
    <span style="color: #0600FF;">public</span> <span style="color: #FF0000;">interface</span> IRepositorioUsuario
    <span style="color: #000000;">&#123;</span>
        <span style="color: #0600FF;">void</span> Agregar<span style="color: #000000;">&#40;</span>Usuario usuario<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
        <span style="color: #0600FF;">void</span> Actualizar<span style="color: #000000;">&#40;</span>Usuario usuario<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
        <span style="color: #0600FF;">void</span> Eliminar<span style="color: #000000;">&#40;</span>Usuario usuario<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
        Usuario ObtenerUsuarioPorId<span style="color: #000000;">&#40;</span><span style="color: #FF0000;">int</span> IdUsuario<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
        IList<span style="color: #008000;">&lt;</span>Usuario<span style="color: #008000;">&gt;</span> ObtenerUsuarios<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
    <span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span></pre></td></tr></table></div>

<p>Ahora, lo que sigue es implementar cada uno de los métodos definidos por la Interface IRepositorioUsuario.cs. Comenzaremos con el primer método Agregar() que nos va a permitir agregar una instancia de un Usuario en nuestra base de datos.</p>
<p>Dentro de la misma carpeta (Repositorio) vamos a agregar una clase llamada RepositorioUsuario.cs y vamos a hacer que herede de la interfase IRepositorioUsuario.cs, con esto haremos que la clase implemente cada uno de los métodos de la interface.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
</pre></td><td class="code"><pre class="csharp"><span style="color: #0600FF;">using</span> <span style="color: #008080;">System</span><span style="color: #008000;">;</span>
<span style="color: #0600FF;">using</span> <span style="color: #008080;">System.Collections.Generic</span><span style="color: #008000;">;</span>
<span style="color: #0600FF;">using</span> <span style="color: #008080;">System.Text</span><span style="color: #008000;">;</span>
<span style="color: #0600FF;">using</span> <span style="color: #008080;">NHibernate</span><span style="color: #008000;">;</span>
<span style="color: #0600FF;">using</span> <span style="color: #008080;">Tutorial.NH.BOL.Entidades</span><span style="color: #008000;">;</span>
<span style="color: #0600FF;">using</span> <span style="color: #008080;">Tutorial.NH.BOL.Genericos</span><span style="color: #008000;">;</span>
&nbsp;
<span style="color: #0600FF;">namespace</span> Tutorial.<span style="color: #0000FF;">NH</span>.<span style="color: #0000FF;">BOL</span>.<span style="color: #0000FF;">Repositorio</span>
<span style="color: #000000;">&#123;</span>
    <span style="color: #0600FF;">public</span> <span style="color: #FF0000;">class</span> RepositorioUsuario <span style="color: #008000;">:</span> IRepositorioUsuario
    <span style="color: #000000;">&#123;</span>
        <span style="color: #0600FF;">public</span> <span style="color: #0600FF;">void</span> Agregar<span style="color: #000000;">&#40;</span>Usuario usuario<span style="color: #000000;">&#41;</span>
        <span style="color: #000000;">&#123;</span>
            <span style="color: #0600FF;">throw</span> <span style="color: #008000;">new</span> NotImplementedException<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
        <span style="color: #000000;">&#125;</span>
&nbsp;
        <span style="color: #0600FF;">public</span> <span style="color: #0600FF;">void</span> Actualizar<span style="color: #000000;">&#40;</span>Usuario usuario<span style="color: #000000;">&#41;</span>
        <span style="color: #000000;">&#123;</span>
            <span style="color: #0600FF;">throw</span> <span style="color: #008000;">new</span> NotImplementedException<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
        <span style="color: #000000;">&#125;</span>
&nbsp;
        <span style="color: #0600FF;">public</span> <span style="color: #0600FF;">void</span> Eliminar<span style="color: #000000;">&#40;</span>Usuario usuario<span style="color: #000000;">&#41;</span>
        <span style="color: #000000;">&#123;</span>
            <span style="color: #0600FF;">throw</span> <span style="color: #008000;">new</span> NotImplementedException<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
        <span style="color: #000000;">&#125;</span>
&nbsp;
        <span style="color: #0600FF;">public</span> Usuario ObtenerUsuarioPorId<span style="color: #000000;">&#40;</span><span style="color: #FF0000;">int</span> IdUsuario<span style="color: #000000;">&#41;</span>
        <span style="color: #000000;">&#123;</span>
            <span style="color: #0600FF;">throw</span> <span style="color: #008000;">new</span> NotImplementedException<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
        <span style="color: #000000;">&#125;</span>
&nbsp;
&nbsp;
        <span style="color: #0600FF;">public</span> IList<span style="color: #008000;">&lt;</span>Usuario<span style="color: #008000;">&gt;</span> ObtenerUsuarios<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>
        <span style="color: #000000;">&#123;</span>
            <span style="color: #0600FF;">throw</span> <span style="color: #008000;">new</span> NotImplementedException<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
        <span style="color: #000000;">&#125;</span>
    <span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span></pre></td></tr></table></div>

<p>Ahora, lo que sigue es crear el mecanismo para crear las sesiones que se van a comunicar con nuestra base de datos. Dentro del mismo proyecto, nos crearemos una Carpeta que nombraremos Genericos y agregamos una clase de nombre NHibernateClass.cs.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
</pre></td><td class="code"><pre class="csharp"><span style="color: #0600FF;">using</span> <span style="color: #008080;">System</span><span style="color: #008000;">;</span>
<span style="color: #0600FF;">using</span> <span style="color: #008080;">System.Collections.Generic</span><span style="color: #008000;">;</span>
<span style="color: #0600FF;">using</span> <span style="color: #008080;">System.Linq</span><span style="color: #008000;">;</span>
<span style="color: #0600FF;">using</span> <span style="color: #008080;">System.Text</span><span style="color: #008000;">;</span>
<span style="color: #0600FF;">using</span> <span style="color: #008080;">NHibernate</span><span style="color: #008000;">;</span>
<span style="color: #0600FF;">using</span> <span style="color: #008080;">NHibernate.Cfg</span><span style="color: #008000;">;</span>
&nbsp;
<span style="color: #0600FF;">namespace</span> Tutorial.<span style="color: #0000FF;">NH</span>.<span style="color: #0000FF;">BOL</span>.<span style="color: #0000FF;">Genericos</span>
<span style="color: #000000;">&#123;</span>
    <span style="color: #0600FF;">public</span> <span style="color: #FF0000;">class</span> NHibernateClass
    <span style="color: #000000;">&#123;</span>
        <span style="color: #0600FF;">private</span> <span style="color: #0600FF;">static</span> ISessionFactory _sessionFactory<span style="color: #008000;">;</span>
        <span style="color: #0600FF;">private</span> <span style="color: #0600FF;">static</span> ISessionFactory SessionFactory
        <span style="color: #000000;">&#123;</span>
            get
            <span style="color: #000000;">&#123;</span>
                <span style="color: #0600FF;">if</span> <span style="color: #000000;">&#40;</span>_sessionFactory <span style="color: #008000;">==</span> <span style="color: #0600FF;">null</span><span style="color: #000000;">&#41;</span>
                <span style="color: #000000;">&#123;</span>
                    var configuration <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> Configuration<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
                    configuration.<span style="color: #0000FF;">Configure</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
                    _sessionFactory <span style="color: #008000;">=</span> configuration.<span style="color: #0000FF;">BuildSessionFactory</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
                <span style="color: #000000;">&#125;</span>
                <span style="color: #0600FF;">return</span> _sessionFactory<span style="color: #008000;">;</span>
            <span style="color: #000000;">&#125;</span>
        <span style="color: #000000;">&#125;</span>
&nbsp;
        <span style="color: #0600FF;">public</span> <span style="color: #0600FF;">static</span> ISession OpenSession<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>
        <span style="color: #000000;">&#123;</span>
            <span style="color: #0600FF;">return</span> SessionFactory.<span style="color: #0000FF;">OpenSession</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
        <span style="color: #000000;">&#125;</span>
    <span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span></pre></td></tr></table></div>

<p>Esta clase lo que hará por nosotros es crear una SessionFactory solo la primera vez que el cliente necesita una sesión. Que contiene este Singleton? Contiene un objeto del tipo Configuración que utiliza la configuración de nuestro hibernate.cfg.xml que creamos en la aplicación se escritorio y que se encarga de cargar el objeto ISessionFactory gracias al método BuildSessionFactory() y de esta forma poder comenzar a crear sesiones de tipo ISessionFactory.</p>
<p>Volvamos a nuestra clase RepositorioUsuario.cs e implementemos el método Agregar() de la siguiente manera:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
</pre></td><td class="code"><pre class="csharp"><span style="color: #0600FF;">public</span> <span style="color: #0600FF;">void</span> Agregar<span style="color: #000000;">&#40;</span>Usuario usuario<span style="color: #000000;">&#41;</span>
<span style="color: #000000;">&#123;</span>
    <span style="color: #0600FF;">using</span> <span style="color: #000000;">&#40;</span>ISession sesion <span style="color: #008000;">=</span> NHibernateClass.<span style="color: #0000FF;">OpenSession</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>
    <span style="color: #0600FF;">using</span> <span style="color: #000000;">&#40;</span>ITransaction trans <span style="color: #008000;">=</span> sesion.<span style="color: #0000FF;">BeginTransaction</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>
    <span style="color: #000000;">&#123;</span>
        sesion.<span style="color: #0000FF;">Save</span><span style="color: #000000;">&#40;</span>usuario<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
        trans.<span style="color: #0000FF;">Commit</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
    <span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span></pre></td></tr></table></div>

<p>En el método Actualizar() escribiremos lo siguiente:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
</pre></td><td class="code"><pre class="csharp"><span style="color: #0600FF;">public</span> <span style="color: #0600FF;">void</span> Agregar<span style="color: #000000;">&#40;</span>Usuario usuario<span style="color: #000000;">&#41;</span>
<span style="color: #000000;">&#123;</span>
    <span style="color: #0600FF;">using</span> <span style="color: #000000;">&#40;</span>ISession sesion <span style="color: #008000;">=</span> NHibernateClass.<span style="color: #0000FF;">OpenSession</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>
    <span style="color: #0600FF;">using</span> <span style="color: #000000;">&#40;</span>ITransaction trans <span style="color: #008000;">=</span> sesion.<span style="color: #0000FF;">BeginTransaction</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>
    <span style="color: #000000;">&#123;</span>
        sesion.<span style="color: #0000FF;">Update</span><span style="color: #000000;">&#40;</span>usuario<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
        trans.<span style="color: #0000FF;">Commit</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
    <span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span></pre></td></tr></table></div>

<p>En el método Eliminar() escribiremos lo siguiente:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
</pre></td><td class="code"><pre class="csharp"><span style="color: #0600FF;">public</span> <span style="color: #0600FF;">void</span> Agregar<span style="color: #000000;">&#40;</span>Usuario usuario<span style="color: #000000;">&#41;</span>
<span style="color: #000000;">&#123;</span>
    <span style="color: #0600FF;">using</span> <span style="color: #000000;">&#40;</span>ISession sesion <span style="color: #008000;">=</span> NHibernateClass.<span style="color: #0000FF;">OpenSession</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>
    <span style="color: #0600FF;">using</span> <span style="color: #000000;">&#40;</span>ITransaction trans <span style="color: #008000;">=</span> sesion.<span style="color: #0000FF;">BeginTransaction</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>
    <span style="color: #000000;">&#123;</span>
        sesion.<span style="color: #0000FF;">Delete</span><span style="color: #000000;">&#40;</span>usuario<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
        trans.<span style="color: #0000FF;">Commit</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
    <span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span></pre></td></tr></table></div>

<p>Para el método ObtenerUsuarioPorId() haremos esto:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
</pre></td><td class="code"><pre class="csharp"><span style="color: #0600FF;">public</span> Usuario ObtenerUsuarioPorId<span style="color: #000000;">&#40;</span><span style="color: #FF0000;">int</span> IdUsuario<span style="color: #000000;">&#41;</span>
<span style="color: #000000;">&#123;</span>
    <span style="color: #0600FF;">using</span> <span style="color: #000000;">&#40;</span>ISession sesion <span style="color: #008000;">=</span> NHibernateClass.<span style="color: #0000FF;">OpenSession</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>
        <span style="color: #0600FF;">return</span> sesion.<span style="color: #0000FF;">Get</span><span style="color: #008000;">&lt;</span>Usuario<span style="color: #008000;">&gt;</span><span style="color: #000000;">&#40;</span>IdUsuario<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
<span style="color: #000000;">&#125;</span></pre></td></tr></table></div>

<p>Y para obtener todos los usuarios:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
</pre></td><td class="code"><pre class="csharp"><span style="color: #0600FF;">public</span> IList<span style="color: #008000;">&lt;</span>Usuario<span style="color: #008000;">&gt;</span> ObtenerUsuarios<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>
<span style="color: #000000;">&#123;</span>
    <span style="color: #0600FF;">using</span> <span style="color: #000000;">&#40;</span>ISession sesion <span style="color: #008000;">=</span> NHibernateClass.<span style="color: #0000FF;">OpenSession</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>
    <span style="color: #000000;">&#123;</span>
        var usuarios <span style="color: #008000;">=</span> sesion.<span style="color: #0000FF;">CreateCriteria</span><span style="color: #000000;">&#40;</span><span style="color: #008000;">typeof</span><span style="color: #000000;">&#40;</span>Usuario<span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>.<span style="color: #0000FF;">List</span><span style="color: #008000;">&lt;</span>Usuario<span style="color: #008000;">&gt;</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
        <span style="color: #0600FF;">return</span> usuarios<span style="color: #008000;">;</span>
    <span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span></pre></td></tr></table></div>

<p>Nota la creación del objeto sesión desde nuestra clase NHibernateClass.cs y tambien el uso de una transacción.</p>
<p>¡Y listo! podemos empezar a trabajar con nuestro modelo de NH para la persistencia de nuestras entidades de dominio.</p>
<p>Para guardar la información de un usuario y sus tareas una posible implementación es que desde nuestra aplicación de consola incluyamos esta implementación:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
</pre></td><td class="code"><pre class="csharp"><span style="color: #0600FF;">using</span> <span style="color: #008080;">System</span><span style="color: #008000;">;</span>
<span style="color: #0600FF;">using</span> <span style="color: #008080;">System.Collections.Generic</span><span style="color: #008000;">;</span>
<span style="color: #0600FF;">using</span> <span style="color: #008080;">System.Linq</span><span style="color: #008000;">;</span>
<span style="color: #0600FF;">using</span> <span style="color: #008080;">System.Text</span><span style="color: #008000;">;</span>
<span style="color: #0600FF;">using</span> <span style="color: #008080;">Tutorial.NH.BOL.Entidades</span><span style="color: #008000;">;</span>
<span style="color: #0600FF;">using</span> <span style="color: #008080;">Tutorial.NH.BOL.Repositorio</span><span style="color: #008000;">;</span>
&nbsp;
<span style="color: #0600FF;">namespace</span> Tutorial.<span style="color: #0000FF;">NH</span>.<span style="color: #0000FF;">App</span>
<span style="color: #000000;">&#123;</span>
    <span style="color: #FF0000;">class</span> Program
    <span style="color: #000000;">&#123;</span>
        <span style="color: #0600FF;">static</span> <span style="color: #0600FF;">void</span> Main<span style="color: #000000;">&#40;</span><span style="color: #FF0000;">string</span><span style="color: #000000;">&#91;</span><span style="color: #000000;">&#93;</span> args<span style="color: #000000;">&#41;</span>
        <span style="color: #000000;">&#123;</span>
            Usuario usr <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> Usuario<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
            usr.<span style="color: #0000FF;">Nombre</span> <span style="color: #008000;">=</span> <span style="color: #666666;">&quot;Roberto&quot;</span><span style="color: #008000;">;</span>
            usr.<span style="color: #0000FF;">ApellidoPaterno</span> <span style="color: #008000;">=</span> <span style="color: #666666;">&quot;Ramirez&quot;</span><span style="color: #008000;">;</span>
            usr.<span style="color: #0000FF;">ApellidoMaterno</span> <span style="color: #008000;">=</span> <span style="color: #666666;">&quot;Leyva&quot;</span><span style="color: #008000;">;</span>
            usr.<span style="color: #0000FF;">CorreoElectronico</span> <span style="color: #008000;">=</span> <span style="color: #666666;">&quot;jramirezleyva@gmail.com&quot;</span><span style="color: #008000;">;</span>
            usr.<span style="color: #0000FF;">Telefono</span> <span style="color: #008000;">=</span> <span style="color: #666666;">&quot;410-00-00&quot;</span><span style="color: #008000;">;</span>
&nbsp;
            Tarea task <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> Tarea<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
            task.<span style="color: #0000FF;">NombreTarea</span> <span style="color: #008000;">=</span> <span style="color: #666666;">&quot;Tutorial de NHibernate&quot;</span><span style="color: #008000;">;</span>
            task.<span style="color: #0000FF;">Usuario</span> <span style="color: #008000;">=</span> usr<span style="color: #008000;">;</span>
            usr.<span style="color: #0000FF;">Tarea</span>.<span style="color: #0000FF;">Add</span><span style="color: #000000;">&#40;</span>task<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
            IRepositorioUsuario rUsr <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> RepositorioUsuario<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
            rUsr.<span style="color: #0000FF;">Agregar</span><span style="color: #000000;">&#40;</span>usr<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>                      
        <span style="color: #000000;">&#125;</span>
    <span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span></pre></td></tr></table></div>

<p>Si bien recordamos cuando hicimos el modelo de dominio y las mapeamos con la base de datos, creamos unas propiedades que permitían las relaciones <many-to-one />, <one-to-many />. Esta es la verdadera magia, se dieron cuenta que nunca utilizamos procedimientos almacenados? o que nunca nos creamos rutinas de conexión y de creación de DataAdapters? o DataSets? mucho menos DataReaders? Gracias a NH podemos persistir nuestros objetos de una manera limpia y orientada a objetos que es lo más importante.</p>
<h3>Conclusión</h3>
<p>En este sencillo ejemplo, pudimos observar cómo manejar un modelo de dominio y como cerrar el &#8220;gap&#8221; con nuestra base de datos relacional. Sabemos que este es un ejemplo básico y hay mucho más que explicar y que probar, pero por lo pronto espero que esto les haya servido como una introducción (al menos a mí si me ayudo jeje).</p>
<p>El código de ejemplo lo pueden descargar de <a href="http://www.ramirezroberto.com/blog/wp-content/uploads/2008/08/Tutorial.zip">aqui</a>.</p>
<p>Mas información:</p>
<p><a href="http://www.hibernate.org/hib_docs/nhibernate/1.2/reference/en/html/">http://www.hibernate.org/hib_docs/nhibernate/1.2/reference/en/html/</a><br />
<a href="http://darioquintana.com.ar/articles/tutorial-de-nhibernate-primeros-pasos ">http://darioquintana.com.ar/articles/tutorial-de-nhibernate-primeros-pasos</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.ramirezroberto.com/blog/2008/08/07/nhibernate-for-dummies/feed/</wfw:commentRss>
		</item>
		<item>
		<title>La maestría casi se acaba</title>
		<link>http://www.ramirezroberto.com/blog/2008/08/06/la-maestria-casi-se-acaba/</link>
		<comments>http://www.ramirezroberto.com/blog/2008/08/06/la-maestria-casi-se-acaba/#comments</comments>
		<pubDate>Wed, 06 Aug 2008 17:51:03 +0000</pubDate>
		<dc:creator>bobbher</dc:creator>
		
		<category><![CDATA[Maestría]]></category>

		<guid isPermaLink="false">http://www.ramirezroberto.com/blog/?p=264</guid>
		<description><![CDATA[Inspirado en un post del Guamu no quise dejar de comentar acerca de lo que represento en su momento la maestría en mi vida, y es que no es para menos, fueron ¡dos años! y si no fueron intensos, si ayudaron para reflexionar sobre el rumbo de mi vida, en donde me encuentro actualmente y [...]]]></description>
			<content:encoded><![CDATA[<p>Inspirado en un post del <a href="http://gatitoteam.blogspot.com/2008/08/se-acaba-la-mati.html">Guamu</a> no quise dejar de comentar acerca de lo que represento en su momento la maestría en mi vida, y es que no es para menos, fueron ¡dos años! y si no fueron intensos, si ayudaron para reflexionar sobre el rumbo de mi vida, en donde me encuentro actualmente y hacia donde me dirijo.</p>
<p>Una vez fui de los que pensé que esta serie de programas académicos dirigidos a formar profesionales que propongan proyectos de TI y así satisfacer necesidades, no era para mí, no era lo que yo buscaba, pero es de sabios rectificar y ahora puedo decir que me siento orgulloso de pertenecer a este grupo de profesionales. Fueron mis maestros (agradecimiento especial a cada uno), las experiencias de todos y cada uno de los que alguna vez levantamos la mano para hacer una pregunta en alguna clase y qué decir de las tareas, lo que me ayudo a cambiar de parecer.</p>
<p>Lo último que puedo decir es que aun tengo mucho que mejorar y esto no se acaba aquí, hay mucho aprendizaje de por medio, muchas más ramas del área que explorar y algo mucho más importante, aplicar todo lo que he aprendido.</p>
<p>Aun tengo algunos pendientes. Uno de ellos es la clase de este jueves y por ultimo pero no menos importante, terminar el documento que me acredite como Maestro en Administración de TI (la famosa tesis), que va en buen camino por cierto.</p>
<p>Agradecimiento a la niña que contribuyó en todo momento en apoyar a su servidor en este reto, sin duda fuiste una parte muy importante en este proyecto de maestría, muchas gracias Alejandra ♥</p>
]]></content:encoded>
			<wfw:commentRss>http://www.ramirezroberto.com/blog/2008/08/06/la-maestria-casi-se-acaba/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Escribiendo una regla de análisis de código para VSTS 2008</title>
		<link>http://www.ramirezroberto.com/blog/2008/07/30/escribiendo-una-regla-de-analisis-de-codigo-para-vsts-2008/</link>
		<comments>http://www.ramirezroberto.com/blog/2008/07/30/escribiendo-una-regla-de-analisis-de-codigo-para-vsts-2008/#comments</comments>
		<pubDate>Wed, 30 Jul 2008 23:23:51 +0000</pubDate>
		<dc:creator>bobbher</dc:creator>
		
		<category><![CDATA[Code Analysis]]></category>

		<category><![CDATA[Programación]]></category>

		<guid isPermaLink="false">http://www.ramirezroberto.com/blog/?p=215</guid>
		<description><![CDATA[FxCop es una herramienta Open Source que ayuda al análisis de ensamblados de código mediante reglas y reporta información relacionada de esos ensamblados, la cual puede referirse a rubros como el de seguridad, diseño, rendimiento, todo aquello relacionado a reglas aplicables a los ensamblados (para mas información).
Después de conocer que esta herramienta viene integrada en [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://en.wikipedia.org/wiki/FxCop">FxCop</a> es una herramienta Open Source que ayuda al análisis de ensamblados de código mediante reglas y reporta información relacionada de esos ensamblados, la cual puede referirse a rubros como el de seguridad, diseño, rendimiento, todo aquello relacionado a reglas aplicables a los ensamblados <a href="http://msdn.microsoft.com/en-us/library/czefa0ke.aspx">(para mas información)</a>.</p>
<p>Después de conocer que esta herramienta viene integrada en la versión Team System de Visual Studio .NET 2008 (en realidad ya venía integrada desde versiones anteriores) en la empresa donde laboro decidieron ajustar las reglas o estándares de codificación internas utilizadas, a todo aquel ensamblado generado en los proyectos.</p>
<p>El objetivo era generar código estandarizado y que mejor que el Code Analysis para lograrlo y usarlo para crear políticas de generación de buils, es decir, no permitir compilar el proyecto si no cumplimos con los estándares internos.</p>
<p>A partir de este párrafo verán algo de lo que pude realizar para crear una regla de análisis de código que verifique el nombramiento de los elementos de interfase grafica.</p>
<h3>1. Crear biblioteca de clases</h3>
<p>Nuestro primer paso será de los más sencillo, crear un proyecto de tipo biblioteca de clases que contendrá las clases que define la regla para verificar el nombramiento de los elementos de interfase grafica de nuestras aplicaciones (es una buena práctica definir un archivo de tipo solución de proyecto y en esta ir agregando todos los proyectos que necesitemos).</p>
<p><img class="size-full wp-image-219 aligncenter" title="step1" src="http://www.ramirezroberto.com/blog/wp-content/uploads/2008/07/step1.jpg" alt="" width="500" height="205" /></p>
<h3>2. Agregar referencias</h3>
<p>Debemos de incluir nuestras referencias a la librería de FxCop que se encuentra dentro de la ruta: Archivos de programa\Microsoft Visual Studio 9.0\Team Tools\Static Analysis Tools\FxCop (podria variar dependiendo del idioma y sistema operativo y al menos en un XP en español es la misma). Estas representan el framework que contiene las clases necesarias para poder diseñar nuestra regla.</p>
<ul style="text-align: left;">
<li>FxCopSdk.dll. Para acceder a la interfase IIntrospectionRule que permitirá identificar aquellas clases de ensamblados que son reglas de Code Analysis, que implementa la clase BaseIntrospectionRule.</li>
<li>Microsoft.Cci.dll.</li>
</ul>
<p><img class="size-full wp-image-222 aligncenter" title="step2" src="http://www.ramirezroberto.com/blog/wp-content/uploads/2008/07/step2.jpg" alt="" width="249" height="176" /></p>
<h3>3. Crear la clase base</h3>
<p>Para poder implementar los métodos de la interfase IIntrospectionRule, es necesario crearnos una clase abstracta (que nosotros llamaremos BaseRule) que herede o implemente la clase BaseIntrospectionRule. Más o menos quedaría así:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
</pre></td><td class="code"><pre class="csharp"><span style="color: #0600FF;">using</span> <span style="color: #008080;">System</span><span style="color: #008000;">;</span>
<span style="color: #0600FF;">using</span> <span style="color: #008080;">System.Collections.Generic</span><span style="color: #008000;">;</span>
<span style="color: #0600FF;">using</span> <span style="color: #008080;">System.Linq</span><span style="color: #008000;">;</span>
<span style="color: #0600FF;">using</span> <span style="color: #008080;">System.Text</span><span style="color: #008000;">;</span>
<span style="color: #0600FF;">using</span> <span style="color: #008080;">Microsoft.FxCop.Sdk</span><span style="color: #008000;">;</span>
<span style="color: #0600FF;">using</span> <span style="color: #008080;">Rules.Naming.Globales</span><span style="color: #008000;">;</span>
&nbsp;
<span style="color: #0600FF;">namespace</span> Rules.<span style="color: #0000FF;">Naming</span>
<span style="color: #000000;">&#123;</span>
    <span style="color: #0600FF;">public</span> abstract <span style="color: #FF0000;">class</span> BaseRule <span style="color: #008000;">:</span> BaseIntrospectionRule
    <span style="color: #000000;">&#123;</span>
        <span style="color: #0600FF;">protected</span> BaseRule<span style="color: #000000;">&#40;</span><span style="color: #FF0000;">string</span> name<span style="color: #000000;">&#41;</span> <span style="color: #008000;">:</span> <span style="color: #0600FF;">base</span><span style="color: #000000;">&#40;</span>name, Constantes.<span style="color: #0000FF;">Config_Rules</span>, <span style="color: #008000;">typeof</span><span style="color: #000000;">&#40;</span>BaseRule<span style="color: #000000;">&#41;</span>.<span style="color: #0000FF;">Assembly</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span> <span style="color: #000000;">&#125;</span>
    <span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span></pre></td></tr></table></div>

<p>Noten que he agregado una clase (Constantes.cs) que contendrá aquellas variables constantes para nuestra regla. Yo ahí he colocado la variable que representara nuestro archivo de recursos (un archivo xml, pero aun no te preocupes por conocerlo, mas adelante lo podrás observar).</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
</pre></td><td class="code"><pre class="csharp"><span style="color: #0600FF;">namespace</span> Rules.<span style="color: #0000FF;">Naming</span>.<span style="color: #0000FF;">Globales</span>
<span style="color: #000000;">&#123;</span>
    <span style="color: #008080; font-style: italic;">/// &lt;summary&gt;</span>
    <span style="color: #008080; font-style: italic;">/// Clase estática que contiene los valores constantes.</span>
    <span style="color: #008080; font-style: italic;">/// &lt;summary&gt;</span>
    <span style="color: #0600FF;">public</span> <span style="color: #0600FF;">static</span> <span style="color: #FF0000;">class</span> Constantes
    <span style="color: #000000;">&#123;</span>
        <span style="color: #008080; font-style: italic;">/// &lt;summary&gt;</span>
        <span style="color: #008080; font-style: italic;">/// El nombre del recurso embebido. Xml que contiene las reglas.</span>
        <span style="color: #008080; font-style: italic;">/// &lt;summary&gt;</span>
        <span style="color: #0600FF;">public</span> <span style="color: #0600FF;">const</span> <span style="color: #FF0000;">string</span> Config_Rules <span style="color: #008000;">=</span> <span style="color: #666666;">&quot;Rules.Naming.Rules&quot;</span><span style="color: #008000;">;</span>
    <span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span></pre></td></tr></table></div>

<h3>4. Crear la regla de Code Analysis</h3>
<p>Bien, ¡estamos listos para crear nuestra regla!, habíamos comentado que nuestra regla validaría el nombramiento de elementos de interfase grafica de nuestras aplicaciones, entonces como primer punto debemos de agregar una clase nueva a nuestro proyecto (es una buena práctica nombrar a la clase con un nombre que haga referencia a la regla). Nuestra clase se llamara VerifyGUINaming.cs y la definición se muestra a continuación.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
</pre></td><td class="code"><pre class="csharp"><span style="color: #0600FF;">using</span> <span style="color: #008080;">System</span><span style="color: #008000;">;</span>
<span style="color: #0600FF;">using</span> <span style="color: #008080;">System.Collections.Generic</span><span style="color: #008000;">;</span>
<span style="color: #0600FF;">using</span> <span style="color: #008080;">System.Linq</span><span style="color: #008000;">;</span>
<span style="color: #0600FF;">using</span> <span style="color: #008080;">System.Text</span><span style="color: #008000;">;</span>
<span style="color: #0600FF;">using</span> <span style="color: #008080;">Microsoft.FxCop.Sdk</span><span style="color: #008000;">;</span>
&nbsp;
<span style="color: #0600FF;">namespace</span> Rules.<span style="color: #0000FF;">Naming</span>
<span style="color: #000000;">&#123;</span>
    <span style="color: #008080; font-style: italic;">/// &lt;summary&gt;</span>
    <span style="color: #008080; font-style: italic;">/// Esta clase nos permitirá diseñar una regla para realizar análisis de código</span>
    <span style="color: #008080; font-style: italic;">/// a los elementos de interfase gráfica de la aplicación.</span>
    <span style="color: #008080; font-style: italic;">/// &lt;summary&gt;</span>
    <span style="color: #0600FF;">public</span> <span style="color: #FF0000;">class</span> VerifyGUINaming <span style="color: #008000;">:</span> BaseRule
    <span style="color: #000000;">&#123;</span>
        <span style="color: #0600FF;">public</span> VerifyGUINaming<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span> <span style="color: #008000;">:</span> <span style="color: #0600FF;">base</span><span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;VerifyGUINaming&quot;</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span> <span style="color: #000000;">&#125;</span>
    <span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span></pre></td></tr></table></div>

<p>Como se puede observar lo primero que tenemos que hacer es agregar la referencia a nuestra biblioteca de clases de FxCop y después hacer que la misma herede de la clase base (BaseRule.cs) que hemos definido (no olviden documentar todo lo que hagan). Hasta aquí ya se encuentra definida la regla, pero aun no hace nada jojojo!.</p>
<h3>5. Implementando el metodo Check()</h3>
<p>Empecemos con lo nice de esto. Debemos de implementar el método Check() que contiene la clase BaseIntrospectionRule que permitirá reportar cualquier problema (¿recuerdan al inicio del tutorial? ) referente a la definición y los deposita dentro de una clase ProblemCollection.</p>
<p>Nuestro código para verificar el nombramiento de un elemento de escritorio de tipo Button deberá de verse así:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
</pre></td><td class="code"><pre class="csharp">        <span style="color: #008080; font-style: italic;">/// &lt;summary&gt;</span>
        <span style="color: #008080; font-style: italic;">/// Método que agrega a la colección de problemas en caso de no cumplirse la regla.</span>
        <span style="color: #008080; font-style: italic;">/// &lt;summary&gt;</span>
        <span style="color: #008080; font-style: italic;">/// &lt;param name=&quot;member&quot;&gt;Elemento a comparar.&lt;/param&gt;</span>
        <span style="color: #008080; font-style: italic;">/// &lt;returns&gt;Un problema en caso de haberlo.&lt;/returns&gt;</span>
        <span style="color: #0600FF;">public</span> <span style="color: #0600FF;">override</span> ProblemCollection Check<span style="color: #000000;">&#40;</span>Member member<span style="color: #000000;">&#41;</span>
        <span style="color: #000000;">&#123;</span>
            Field campo <span style="color: #008000;">=</span> member <span style="color: #0600FF;">as</span> Field<span style="color: #008000;">;</span>
            <span style="color: #0600FF;">if</span> <span style="color: #000000;">&#40;</span>campo <span style="color: #008000;">!=</span> <span style="color: #0600FF;">null</span><span style="color: #000000;">&#41;</span>
            <span style="color: #000000;">&#123;</span>
                <span style="color: #FF0000;">string</span> nombreControl <span style="color: #008000;">=</span> campo.<span style="color: #0000FF;">Type</span>.<span style="color: #0000FF;">FullName</span><span style="color: #008000;">;</span>
                <span style="color: #0600FF;">if</span> <span style="color: #000000;">&#40;</span>nombreControl.<span style="color: #0000FF;">StartsWith</span><span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;System.Windows.Forms.Button&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>
                <span style="color: #000000;">&#123;</span>
                    <span style="color: #0600FF;">if</span> <span style="color: #000000;">&#40;</span><span style="color: #008000;">!</span>campo.<span style="color: #0000FF;">Name</span>.<span style="color: #0000FF;">Name</span>.<span style="color: #0000FF;">StartsWith</span><span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;btn_&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>
                    <span style="color: #000000;">&#123;</span>
                        Problems.<span style="color: #0000FF;">Add</span><span style="color: #000000;">&#40;</span><span style="color: #008000;">new</span> Problem<span style="color: #000000;">&#40;</span>GetResolution<span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;btn_&quot;</span>, <span style="color: #666666;">&quot;System.Windows.Forms.Button&quot;</span>, campo.<span style="color: #0000FF;">Name</span>.<span style="color: #0000FF;">Name</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
                    <span style="color: #000000;">&#125;</span>
                <span style="color: #000000;">&#125;</span>
               <span style="color: #0600FF;">else</span>
                <span style="color: #000000;">&#123;</span>
                    <span style="color: #0600FF;">return</span> null<span style="color: #008000;">;</span>
                <span style="color: #000000;">&#125;</span>
            <span style="color: #000000;">&#125;</span>
            <span style="color: #0600FF;">else</span>
            <span style="color: #000000;">&#123;</span>
                <span style="color: #0600FF;">return</span> null<span style="color: #008000;">;</span>
            <span style="color: #000000;">&#125;</span>
&nbsp;
            <span style="color: #0600FF;">return</span> Problems<span style="color: #008000;">;</span>
        <span style="color: #000000;">&#125;</span></pre></td></tr></table></div>

<p>Si aun no sabes que es lo que recibe como parámetro (member) el método Check, entonces te puedo comentar que ese tipo representa los miembros que puede tener una clase, métodos, propiedades, eventos, delegados, etc. Existen otros elementos que analiza el método Check, pero como ya he escrito mucho sobre esto, tendrás oportunidad de echar un googlazo e investigar por tu cuenta.</p>
<h3>6. Creando el esquema XML</h3>
<p>Para dejar completa nuestra regla es necesario crear nuestro archivo XML que describirá información relacionada a aquellos problemas encontrados al momento de analizar el código del ensamblado, en otras palabras, el código mostrado determina si hay un problema, el archivo XML lo describe de mejor forma.</p>
<p>Como primer paso habrá que agregar a nuestro proyecto un archivo con extensión xml y escribir lo siguiente:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
</pre></td><td class="code"><pre class="xml"><span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;?xml</span> <span style="color: #000066;">version</span>=<span style="color: #ff0000;">&quot;1.0&quot;</span> <span style="color: #000066;">encoding</span>=<span style="color: #ff0000;">&quot;utf-8&quot;</span> <span style="font-weight: bold; color: black;">?&gt;</span></span>
<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;Rules</span> <span style="color: #000066;">FriendlyName</span>=<span style="color: #ff0000;">&quot;Code Analysis Rules&quot;</span><span style="font-weight: bold; color: black;">&gt;</span></span>
  <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;Rule</span> <span style="color: #000066;">TypeName</span>=<span style="color: #ff0000;">&quot;VerifyGUINaming&quot;</span> <span style="color: #000066;">Category</span>=<span style="color: #ff0000;">&quot;Rules.Naming&quot;</span> <span style="color: #000066;">CheckId</span>=<span style="color: #ff0000;">&quot;NR0001&quot;</span><span style="font-weight: bold; color: black;">&gt;</span></span>
    <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;Name<span style="font-weight: bold; color: black;">&gt;</span></span></span>Nombramiento de elementos de interfase gráfica<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/Name<span style="font-weight: bold; color: black;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;Description<span style="font-weight: bold; color: black;">&gt;</span></span></span>Para el nombramiento de los elementos de interfase gráfica el identificador del control se deberá escribir en minúscula anteponiendo al identificador un prefijo que indique el tipo de elemento grafico que es separado por un guión bajo. Esto ayudara a distinguir los elementos de interfase grafica.<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/Description<span style="font-weight: bold; color: black;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;Url<span style="font-weight: bold; color: black;">&gt;</span></span></span><span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/Url<span style="font-weight: bold; color: black;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;Resolution<span style="font-weight: bold; color: black;">&gt;</span></span></span>Reemplazar el identificador del control &quot;{2}&quot; por su correcto nombramiento de interfase gráfica: &quot;{0}&quot;.<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/Resolution<span style="font-weight: bold; color: black;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;MessageLevel</span> <span style="color: #000066;">Certainty</span>=<span style="color: #ff0000;">&quot;95&quot;</span><span style="font-weight: bold; color: black;">&gt;</span></span>Error<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/MessageLevel<span style="font-weight: bold; color: black;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;FixCategories<span style="font-weight: bold; color: black;">&gt;</span></span></span>Breaking<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/FixCategories<span style="font-weight: bold; color: black;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;Email<span style="font-weight: bold; color: black;">&gt;</span></span></span>jramirezleyva@gmail.com<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/Email<span style="font-weight: bold; color: black;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;Owner<span style="font-weight: bold; color: black;">&gt;</span></span></span>Roberto Ramírez<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/Owner<span style="font-weight: bold; color: black;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/Rule<span style="font-weight: bold; color: black;">&gt;</span></span></span>
<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/Rules<span style="font-weight: bold; color: black;">&gt;</span></span></span></pre></td></tr></table></div>

<p>El nombre del recurso si bien recuerdan lo definimos en nuestra clase Constantes.cs y se indica en la clase base BaseRule.cs</p>
<p>Algo muy importante es decirle a nuestro proyecto que este archivo de reglas XML deberá de comportarse como un recurso embebido a nuestro ensamblado.</p>
<p style="text-align: center;"><img class="size-medium wp-image-236 aligncenter" title="step3" src="http://www.ramirezroberto.com/blog/wp-content/uploads/2008/07/step3-300x180.jpg" alt="" width="300" height="180" /></p>
<h3>7. Usando nuestra regla de análisis de código</h3>
<p>Hasta este paso lo que obtenemos como resultado es un ensamblado que contiene la definición de nuestra regla, y lo que debemos de hacer es probarla.</p>
<p>Para que esto sea posible debemos manualmente copiar nuestra regla (ensamblado) al folder de nuestra versión de Visual Studio, como el titulo dice que es para la versión VSTS 2008 nuestro folder se encuentra en esta dirección: C:\Archivos de programa\Microsoft Visual Studio 9.0\Team Tools\Static Analysis Tools\FxCop\Rules, normalmente lo único que cambia es la versión del Visual Studio.</p>
<p>Una vez finalizado esto, cerramos y abrimos nuestro Visual Studio. Tu puedes crear un nuevo proyecto a agregarlo a la solución para hacer la prueba de análisis de código, en este caso puedes agregar un proyecto de escritorio para revisar el elemento de interfase grafica Button.</p>
<p>Ya que tengamos nuestro proyecto veremos sus propiedades y en la pestaña de análisis de código (Code Analysis) veremos algo muy similar a esto:</p>
<p style="text-align: center;"><img class="size-full wp-image-238 aligncenter" title="step4" src="http://www.ramirezroberto.com/blog/wp-content/uploads/2008/07/step4.jpg" alt="" width="491" height="343" /></p>
<p>Dando por hecho que en nuestra aplicación de escritorio de prueba tenemos un botón sin el prefijo &#8220;btn_&#8221; en la forma y corriendo el Code Analysis en nuestra aplicación podemos ver lo siguiente:</p>
<p style="text-align: center;"><img class="size-full wp-image-239 aligncenter" title="step5" src="http://www.ramirezroberto.com/blog/wp-content/uploads/2008/07/step5.jpg" alt="" width="500" height="126" /></p>
<p>Nota que lo que nos arroja el análisis de código en un problema de tipo Warning, dejando que nuestro proyecto compile, si al inicio hablamos de código estandarizado entonces deberemos de configurar nuestra aplicación para que no compile en caso de no cumplirse las reglas. Para esto lo único que debemos de hacer es darle a la regla un trato de error en nuestro archivo XML y en la configuración de las propiedades del proyecto habilitar las opciones de &#8220;Manejar la regla como error&#8221; y &#8220;Habilitar Code Analysis en el Build&#8221; como se muestra en la imagen:</p>
<p style="text-align: center;"><img class="size-full wp-image-241 aligncenter" title="step6" src="http://www.ramirezroberto.com/blog/wp-content/uploads/2008/07/step6.jpg" alt="" width="491" height="343" /></p>
<p>Con esto no permitiremos compilar código si antes no cumplimos con nuestras reglas.</p>
<p>Espero que esto los ayude.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.ramirezroberto.com/blog/2008/07/30/escribiendo-una-regla-de-analisis-de-codigo-para-vsts-2008/feed/</wfw:commentRss>
		</item>
		<item>
		<title>¡Que demonios&#8230;!</title>
		<link>http://www.ramirezroberto.com/blog/2008/07/29/%c2%a1que-demonios/</link>
		<comments>http://www.ramirezroberto.com/blog/2008/07/29/%c2%a1que-demonios/#comments</comments>
		<pubDate>Tue, 29 Jul 2008 16:48:57 +0000</pubDate>
		<dc:creator>bobbher</dc:creator>
		
		<category><![CDATA[Plop]]></category>

		<guid isPermaLink="false">http://www.ramirezroberto.com/blog/?p=210</guid>
		<description><![CDATA[
]]></description>
			<content:encoded><![CDATA[<p style="text-align: center;"><img class="aligncenter size-full wp-image-211" title="sp1" src="http://www.ramirezroberto.com/blog/wp-content/uploads/2008/07/sp1.jpg" alt="" width="500" height="471" /></p>
]]></content:encoded>
			<wfw:commentRss>http://www.ramirezroberto.com/blog/2008/07/29/%c2%a1que-demonios/feed/</wfw:commentRss>
		</item>
	</channel>
</rss>
