<?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"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
	>

<channel>
	<title>Massimo Albertin Blog</title>
	<atom:link href="http://massimoalbertin.wordpress.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://massimoalbertin.wordpress.com</link>
	<description></description>
	<lastBuildDate>Sat, 20 Aug 2011 08:51:54 +0000</lastBuildDate>
	<language>it</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
<cloud domain='massimoalbertin.wordpress.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://s2.wp.com/i/buttonw-com.png</url>
		<title>Massimo Albertin Blog</title>
		<link>http://massimoalbertin.wordpress.com</link>
	</image>
	<atom:link rel="search" type="application/opensearchdescription+xml" href="http://massimoalbertin.wordpress.com/osd.xml" title="Massimo Albertin Blog" />
	<atom:link rel='hub' href='http://massimoalbertin.wordpress.com/?pushpress=hub'/>
		<item>
		<title>Post-Build Event: Copy files and TFS Build Service</title>
		<link>http://massimoalbertin.wordpress.com/2011/07/09/post-build-event-copy-files-and-tfs-build-service/</link>
		<comments>http://massimoalbertin.wordpress.com/2011/07/09/post-build-event-copy-files-and-tfs-build-service/#comments</comments>
		<pubDate>Sat, 09 Jul 2011 09:49:13 +0000</pubDate>
		<dc:creator>massimoalbertin</dc:creator>
				<category><![CDATA[C#]]></category>
		<category><![CDATA[Visual Studio]]></category>

		<guid isPermaLink="false">https://massimoalbertin.wordpress.com/2011/07/09/post-build-event-copy-files-and-tfs-build-service/</guid>
		<description><![CDATA[Today I’ve got a problem with a Silverlight project and a custom post-build event. I have a Silverlight project that, on post-build event, must copy the xap inside another project in my solution. Easy I have to add a post build copy command as follow…. … ehm not so easy… It works on my local [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=massimoalbertin.wordpress.com&amp;blog=2503456&amp;post=48&amp;subd=massimoalbertin&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Today I’ve got a problem with a Silverlight project and a custom post-build event. I have a Silverlight project that, on post-build event, must copy the xap inside another project in my solution. Easy I have to add a post build copy command as follow….</p>
<p><a href="http://massimoalbertin.files.wordpress.com/2011/07/image2.png"><img style="background-image:none;padding-left:0;padding-right:0;display:inline;padding-top:0;border-width:0;" title="image" src="http://massimoalbertin.files.wordpress.com/2011/07/image_thumb2.png?w=648&#038;h=452" alt="image" width="648" height="452" border="0" /></a></p>
<p>… ehm not so easy… It works on my local Visual Studio but when I commit this changes on TFS and TFS Build Service starts, a surprise…. error copy return errors… My aim is to make a copy locally on post build but not make this copy during TFS Build Service compile process. After a lot of searches on web and a lot of tries… a solution <img class="wlEmoticon wlEmoticon-lightbulb" style="border-style:none;" src="http://massimoalbertin.files.wordpress.com/2011/07/wlemoticon-lightbulb1.png?w=600" alt="Light bulb" /></p>
<ul>
<li>Open .csproj with an xml editor manually or with context menu (VSCommands 2010 Add-In for Visual Studio 2010 <a href="http://bit.ly/gnEAgb">http://bit.ly/gnEAgb</a>)</li>
</ul>
<p align="center"><a href="http://massimoalbertin.files.wordpress.com/2011/07/image3.png"><img style="background-image:none;padding-left:0;padding-right:0;display:inline;padding-top:0;border-width:0;" title="image" src="http://massimoalbertin.files.wordpress.com/2011/07/image_thumb3.png?w=349&#038;h=129" alt="image" width="349" height="129" border="0" /></a></p>
<ul>
<li>Add &lt;Target&gt; Section as follow</li>
</ul>
<pre class="csharpcode"><span class="kwrd">&lt;</span><span class="html">Target</span> <span class="attr">Name</span><span class="kwrd">="AfterBuild"</span> <span class="attr">Condition</span><span class="kwrd">="'$(BuildingInsideVisualStudio)' == 'true'"</span><span class="kwrd">&gt;</span>
    <span class="kwrd">&lt;</span><span class="html">Copy</span> <span class="attr">SourceFile</span><span class="kwrd">="$(Target)*.xap"</span>
                <span class="attr">DestinationFolder</span><span class="kwrd">="$(SolutionDir)MyProject\MyFolder"</span><span class="kwrd">/&gt;</span>
<span class="kwrd">&lt;/</span><span class="html">Target</span><span class="kwrd">&gt;</span></pre>
<p>This works because variable <strong><a href="http://msdn.microsoft.com/en-us/library/microsoft.visualstudio.package.projectfileconstants.buildinginsidevisualstudio.aspx">BuildingInsideVisualStudio</a></strong> is true only in Visual Studio Environment.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/massimoalbertin.wordpress.com/48/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/massimoalbertin.wordpress.com/48/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/massimoalbertin.wordpress.com/48/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/massimoalbertin.wordpress.com/48/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/massimoalbertin.wordpress.com/48/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/massimoalbertin.wordpress.com/48/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/massimoalbertin.wordpress.com/48/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/massimoalbertin.wordpress.com/48/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/massimoalbertin.wordpress.com/48/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/massimoalbertin.wordpress.com/48/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/massimoalbertin.wordpress.com/48/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/massimoalbertin.wordpress.com/48/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/massimoalbertin.wordpress.com/48/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/massimoalbertin.wordpress.com/48/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=massimoalbertin.wordpress.com&amp;blog=2503456&amp;post=48&amp;subd=massimoalbertin&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://massimoalbertin.wordpress.com/2011/07/09/post-build-event-copy-files-and-tfs-build-service/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/f5fa63c63e733fa55b227ca19efbb642?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">massimoalbertin</media:title>
		</media:content>

		<media:content url="http://massimoalbertin.files.wordpress.com/2011/07/image_thumb2.png" medium="image">
			<media:title type="html">image</media:title>
		</media:content>

		<media:content url="http://massimoalbertin.files.wordpress.com/2011/07/wlemoticon-lightbulb1.png" medium="image">
			<media:title type="html">Light bulb</media:title>
		</media:content>

		<media:content url="http://massimoalbertin.files.wordpress.com/2011/07/image_thumb3.png" medium="image">
			<media:title type="html">image</media:title>
		</media:content>
	</item>
		<item>
		<title>Utilizzare librerie .NET 2.0 in applicazioni .NET 4.0</title>
		<link>http://massimoalbertin.wordpress.com/2010/08/02/utilizzare-librerie-net-2-0-in-applicazioni-net-4-0/</link>
		<comments>http://massimoalbertin.wordpress.com/2010/08/02/utilizzare-librerie-net-2-0-in-applicazioni-net-4-0/#comments</comments>
		<pubDate>Mon, 02 Aug 2010 16:38:46 +0000</pubDate>
		<dc:creator>massimoalbertin</dc:creator>
				<category><![CDATA[C#]]></category>
		<category><![CDATA[Microsoft.NET]]></category>

		<guid isPermaLink="false">https://massimoalbertin.wordpress.com/2010/08/02/utilizzare-librerie-net-2-0-in-applicazioni-net-4-0/</guid>
		<description><![CDATA[In alcune situazioni capita di dover utilizzare librerie già compilate con framework 2.0 (magari perchè non abbiamo a disposizione i sorgenti) all&#8217;interno di un&#8217;applicazione realizzata con il framework .NET 4.0. A me è appena successo con la libreria System.Data.SqlLite di cui non volevo rincompilare i sorgenti per .NET 4.0. Affinchè tutto funzioni è necessario indicare [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=massimoalbertin.wordpress.com&amp;blog=2503456&amp;post=29&amp;subd=massimoalbertin&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>In alcune situazioni capita di dover utilizzare librerie già compilate con framework 2.0 (magari perchè non abbiamo a disposizione i sorgenti) all&#8217;interno di un&#8217;applicazione realizzata con il framework .NET 4.0. A me è appena successo con la libreria <a href="http://sqlite.phxsoftware.com">System.Data.SqlLite</a> di cui non volevo rincompilare i sorgenti per .NET 4.0.     <br />Affinchè tutto funzioni è necessario indicare nel file app.config (o web.config) quanto segue:</p>
<blockquote><p><font face="Courier New">&lt;?xml version=&quot;1.0&quot;?&gt;        <br />&lt;configuration&gt;         <br />&#160; <strong>&lt;startup <font>useLegacyV2RuntimeActivationPolicy=&quot;true&quot;</font>&gt;           <br /></strong>&#160;&#160;&#160; &lt;supportedRuntime version=&quot;v4.0&quot;/&gt;         <br />&#160; &lt;/startup&gt;         <br />&lt;/configuration&gt;</font></p>
</blockquote>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/massimoalbertin.wordpress.com/29/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/massimoalbertin.wordpress.com/29/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/massimoalbertin.wordpress.com/29/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/massimoalbertin.wordpress.com/29/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/massimoalbertin.wordpress.com/29/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/massimoalbertin.wordpress.com/29/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/massimoalbertin.wordpress.com/29/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/massimoalbertin.wordpress.com/29/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/massimoalbertin.wordpress.com/29/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/massimoalbertin.wordpress.com/29/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/massimoalbertin.wordpress.com/29/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/massimoalbertin.wordpress.com/29/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/massimoalbertin.wordpress.com/29/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/massimoalbertin.wordpress.com/29/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=massimoalbertin.wordpress.com&amp;blog=2503456&amp;post=29&amp;subd=massimoalbertin&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://massimoalbertin.wordpress.com/2010/08/02/utilizzare-librerie-net-2-0-in-applicazioni-net-4-0/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/f5fa63c63e733fa55b227ca19efbb642?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">massimoalbertin</media:title>
		</media:content>
	</item>
		<item>
		<title>Collezione di supporto alla Paginazione</title>
		<link>http://massimoalbertin.wordpress.com/2010/08/01/collezione-di-supporto-alla-paginazione/</link>
		<comments>http://massimoalbertin.wordpress.com/2010/08/01/collezione-di-supporto-alla-paginazione/#comments</comments>
		<pubDate>Sun, 01 Aug 2010 17:00:20 +0000</pubDate>
		<dc:creator>massimoalbertin</dc:creator>
				<category><![CDATA[C#]]></category>

		<guid isPermaLink="false">https://massimoalbertin.wordpress.com/2010/08/01/collezione-di-supporto-alla-paginazione/</guid>
		<description><![CDATA[La paginazione dei dati è uno dei problemi classici ricorrente, soprattutto in ambito web, ma non solo. Immaginiamo di voler visualizzare una lista di 10000 elementi, ovviamente non potranno essere visualizzati tutti in una sola pagina o finestra. Per questa ragione si ricorre alla paginazione, in modo da visualizzare solo un numero limitato di elementi [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=massimoalbertin.wordpress.com&amp;blog=2503456&amp;post=17&amp;subd=massimoalbertin&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>La paginazione dei dati è uno dei problemi classici ricorrente, soprattutto in ambito web, ma non solo. Immaginiamo di voler visualizzare una lista di 10000 elementi, ovviamente non potranno essere visualizzati tutti in una sola pagina o finestra. Per questa ragione si ricorre alla paginazione, in modo da visualizzare solo un numero limitato di elementi per pagina fornendo la possibilità di scorrere le pagine e quindi i dati, evitandone il caricamento massivo. Nel caso in cui i dati siano recuperati da database (come al 99% dei casi) dovranno essere effettuate query top k dove k è il numero massimo di elementi ritornati dalla query (grandezza della pagina) con indice in modo da avere gli x-esimi k elementi. (Es. Voglio i primi 10 elementi, per la prima pagina, poi i secondi 10 ecc.).</p>
<p>Prima di tutto è necessario quindi definire i parametri di paginazione, tramite la classe PagingSettings che definisce tutti le informazioni sui dati recuperati. I dati possono essere visualizzati da due punti di vista, assolutamente analoghi: </p>
<ul>
<li>Numero di Elementi per pagina – Indice di Pagina </li>
<li>Indice di Scostamento – Numero massimo di elementi visualizzati </li>
</ul>
<p>Chiramente è sempre possibile tramite calcolo passare da una visualizzazione all’altra, a patto di sapere se l’indice della prima pagina (che potrebbe essere 0 o 1). </p>
<blockquote><p><font face="Courier New">public class PagingSettings&#160;&#160;&#160; <br />{         <br />&#160;&#160; private readonly int _firstPage;&#160; <br />&#160;&#160; private readonly int _pageIndex;&#160; <br />&#160;&#160; private readonly int _pageSize;&#160;&#160;&#160; <br />}</font></p>
</blockquote>
<p>La scelta del criterio da utilizzare per la memorizzazione interna dello stato è assolutamente arbitraria, io ho scelto indice di pagine e grandezza della pagina, ma l’altro sarebbe assolutamente equivalente. La conversione nell’altra visualizzalizzazione è possibile tramite proprietà di solo get come segue:</p>
<blockquote><p><font face="Courier New">public long StartIndex        <br />{         <br />&#160;&#160; get { return (_pageIndex &#8211; _firstPage) * _pageSize; }         <br />}</font></p>
<p><font face="Courier New">public int PageIndex        <br />{         <br />&#160;&#160; get { return _pageIndex; }         <br />}&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; </font></p>
<p><font face="Courier New">public int PageSize        <br />{         <br />&#160;&#160; get { return _pageSize; }         <br />}</font></p>
</blockquote>
<p>In entrambe le viste il numero è ovviamente presente il PageSize definibile anche come MaxRowCount (sinonimi). La creazione di questa classe di impostazioni e stato è possibile sia da entrambi i punti di vista (due valori interi con diversa semantica), per questa ragione ho scelto di realizzare il costruttore privato e due metodi factory per i due differenti punti di vista:</p>
<blockquote><p><font face="Courier New">public static PagingSettings CreateByPageData(int pageSize, int pageIndex)        <br />{         <br />&#160;&#160; return new PagingSettings(pageSize, pageIndex, 1);         <br />}</font></p>
<p><font face="Courier New">public static PagingSettings CreateByPageData(int pageSize, int pageIndex, int firstPage)        <br />{         <br />&#160;&#160; return new PagingSettings(pageSize, pageIndex, firstPage);         <br />}</font></p>
<p><font face="Courier New">public static PagingSettings CreateByIndexData(long startIndex, int maxRowCount)        <br />{         <br />&#160;&#160; return CreateByIndexData(startIndex, maxRowCount, 1);         <br />}</font></p>
<p><font face="Courier New">public static PagingSettings CreateByIndexData(long startIndex, int maxRowCount, int firstPage)        <br />{         <br />&#160;&#160; if (startIndex == 0 &amp;&amp; maxRowCount == 0)         <br />&#160;&#160;&#160;&#160;&#160; return new PagingSettings(0, 0, 0);         <br />&#160;&#160; return new PagingSettings(maxRowCount, (int)Math.Ceiling((double)startIndex / maxRowCount), firstPage);         <br />}</font></p>
</blockquote>
<p>questi si appoggiano ad altri due metodi statici di creazione a cui è possibile passare anche l’indice della prima pagina (il default è ovviamente 1)</p>
<p>realizzato la classe PagingSettings manca ora la collezione vera e propria che dovrà mantenere internamente lo stato (classe PagingSettings) gli elementi della pagina corrente e il numero totale di elementi. Di seguito l’interfaccia della collezione IPaginatedList&lt;T&gt;.</p>
<blockquote><p><font face="Courier New">public interface IPaginatedList&lt;T&gt; : IList&lt;T&gt;        <br />{         <br />&#160;&#160; bool HasNextPage { get; }         <br />&#160;&#160; bool HasPreviousPage { get; }         <br />&#160;&#160; int PageIndex { get; }         <br />&#160;&#160; int PageSize { get; }         <br />&#160;&#160; long TotalDomainObjectCount { get; set; }         <br />&#160;&#160; long TotalPages { get; }         <br />}</font></p>
</blockquote>
<p>per I dettagli dell’implementazione si rimanda al codice sorgente allegato..    </p>
<p><a href="http://dl.dropbox.com/u/9648062/Paginazione%20-%20Sources.7z">Scarica Sorgente</a></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/massimoalbertin.wordpress.com/17/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/massimoalbertin.wordpress.com/17/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/massimoalbertin.wordpress.com/17/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/massimoalbertin.wordpress.com/17/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/massimoalbertin.wordpress.com/17/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/massimoalbertin.wordpress.com/17/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/massimoalbertin.wordpress.com/17/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/massimoalbertin.wordpress.com/17/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/massimoalbertin.wordpress.com/17/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/massimoalbertin.wordpress.com/17/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/massimoalbertin.wordpress.com/17/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/massimoalbertin.wordpress.com/17/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/massimoalbertin.wordpress.com/17/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/massimoalbertin.wordpress.com/17/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=massimoalbertin.wordpress.com&amp;blog=2503456&amp;post=17&amp;subd=massimoalbertin&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://massimoalbertin.wordpress.com/2010/08/01/collezione-di-supporto-alla-paginazione/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/f5fa63c63e733fa55b227ca19efbb642?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">massimoalbertin</media:title>
		</media:content>
	</item>
		<item>
		<title>Regular Expressions e C#</title>
		<link>http://massimoalbertin.wordpress.com/2010/03/31/regular-expressions-e-c/</link>
		<comments>http://massimoalbertin.wordpress.com/2010/03/31/regular-expressions-e-c/#comments</comments>
		<pubDate>Wed, 31 Mar 2010 19:14:21 +0000</pubDate>
		<dc:creator>massimoalbertin</dc:creator>
				<category><![CDATA[C#]]></category>
		<category><![CDATA[Microsoft.NET]]></category>
		<category><![CDATA[Regex]]></category>

		<guid isPermaLink="false">http://massimoalbertin.wordpress.com/2010/03/31/regular-expressions-e-c/</guid>
		<description><![CDATA[La classe base utilizzata per lavorare con le regular expression è Regex, il cui costruttore richiede la stringa di regular expression da utilizzare per l’elaborazione di stringhe. Questa classe mette a disposizione una serie di metodi che permettono di: Ricercare un particolare pattern all’interno di una stringa Effettuare delle sosituzioni testuali Isolare alcuni gruppi di [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=massimoalbertin.wordpress.com&amp;blog=2503456&amp;post=10&amp;subd=massimoalbertin&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>La classe base utilizzata per lavorare con le regular expression è <strong>Regex</strong>, il cui costruttore richiede la stringa di regular expression da utilizzare per l’elaborazione di stringhe.</p>
<p>Questa classe mette a disposizione una serie di metodi che permettono di:</p>
<ul>
<li>Ricercare un particolare pattern all’interno di una stringa </li>
<li>Effettuare delle sosituzioni testuali </li>
<li>Isolare alcuni gruppi di caratteri all’interno di una stringa </li>
</ul>
<h3>Sintassi delle Regular Expression</h3>
<p>La stringa che definisce una regular expression utilizza una sintassi particolare che verrà descritti di seguito, basata su caratteri speciali a cui è associato uno specifico significato.</p>
<p>Nel caso in cui non siano specificati caratteri speciali, la stringa inserita come regular expression farà match con qualsiasi stringa contenente quel testo, in sostanza si avrà un comportamento del tutto analogo al metodo Contains() di string.</p>
<p><em>Es. “aaa” farà match con “aaabbb”, “bbaaacc”, “bbbbaaa” ecc.</em></p>
<h5>Inizio e Fine</h5>
<p>Per limitare il match a inizio o fine string è possibile utilizzare i caratteri speciali <strong>^ </strong>per indicare l’inizio stringa e <strong>$ </strong>per indicare il fine stringa. Nel caso in cui la stringa sia composta da più righe e sia impostata l’opzione <strong>Multiline</strong> il match farà riferimento a qualsiasi riga, ovvero basterà una riga che soddisfi il criterio per avere il match della stringa nel suo complesso.</p>
<p><em>Es. “^aaa” fa match con “aaabbb”, “aaabbb(New Line)bbbccc”, “bbbaaa(New Line)aaabbb” (quest’ultima solo nel caso in cui sia specificato l’opzione multiline altrimenti non farà match)</em></p>
<p>Nel caso in cui si voglia il comportamento analogo di ^ e $ anche nel caso Multiline è possibile usare rispettivamente <strong>\A</strong> e <strong>\Z</strong> per inizio e fine di stringa, indipendentemente dalle righe</p>
<p><em>Es. “\Aaaa” fa match con “aaabbb”, “aaabbb(New Line)bbbccc”, mentre NON fa match “bbbaaa(New Line)aaabbb” </em></p>
<p>Nel caso in cui si vogliano considerare le singole parole (separate da spazi) è possibile utilizzare <strong>\b </strong>per indicare che il match è sui confini di una parola e <strong>\B </strong>per indicare che è all’interno della parola.</p>
<p><em>Es. “aa\b” fa match con “aabb cc”, “bbaa cc” ma non con “bbaabb” e “aa\B” fa match con “baab cc”, “cc caac”.</em></p>
</p>
<h5>Molteplicità e Occorrenze</h5>
<p>Nel caso in cui si vogliano ripetere alcuni caratteri 0 o più volte è possibile usare il carattere <strong>*</strong>,per una o più volte <strong>+</strong>, per un numero n specificato di volte <strong>{n}</strong> (con n numero di volte), n o più di n volte <strong>{n,}</strong>, da n a m volte <strong>{n,m}</strong>. Nel caso in cui si vogliano ripetere gruppi di caratteri è possibile utilizzare le <strong>parantesi tonde</strong>.</p>
<p><em>Es. “^a*$”&#160; farà match con “”, “a”, “aa” ecc. “^a+$” farà match con “a”, “aa” ecc ma non con “”. “^a{2}$” farà match con “aa”, “^(ab){2,3}$” farà match con “abab” e “ababab”.</em></p>
<h5>Gruppi di Caratteri e Wildcards</h5>
<p>Nel caso in cui si voglia far match con un carattere qualsiasi opzionale si può usare il carattere <strong>?</strong>, mentre con un carattere qualsiasi obbligatorio <strong>. </strong>è possibile definire un gruppo di caratteri ammissibile tramite semplice elenco [abc] o [a|b|c] (farà match con il carattere a o b o c), un range [a-c] (farà match con i caratteri a o b o c) </p>
<p><em>Es. “^a?c$” farà match con “ac”,”aac”,”abc”, “a.c$” farà match con “abc”,”aac” ma non con “ac”, “^[ab]c$” farà match con “ac” e “bc”, “^[a-c]d$” farà match con “ad”, “bd”, “cd”</em></p>
<p>Di seguito altre wildcards utilizzabili</p>
<table border="0" cellspacing="0" cellpadding="2" width="502">
<tbody>
<tr>
<td valign="top" width="76">\d</td>
<td valign="top" width="424">qualsiasi numero equivalente a [0-9]</td>
</tr>
<tr>
<td valign="top" width="76">\D</td>
<td valign="top" width="424">qualsiasi carattere NON numerico equivalente a [^0-9]</td>
</tr>
<tr>
<td valign="top" width="76">\s</td>
<td valign="top" width="424">qualsiasi carattere equivalente allo spazio</td>
</tr>
<tr>
<td valign="top" width="76">\S</td>
<td valign="top" width="424">qualsiasi carattere NON equivalente ad uno spazio</td>
</tr>
<tr>
<td valign="top" width="76">\w</td>
<td valign="top" width="424">qualsiasi carattere [a-zA-Z0-9]</td>
</tr>
<tr>
<td valign="top" width="76">\W</td>
<td valign="top" width="424">l’opposto del precedente [^a-zA-Z0-9]</td>
<h5></h5>
</tr>
</tbody>
</table>
<table border="0" cellspacing="0" cellpadding="2" width="502">
<tbody>
<tr></tr>
</tbody>
</table>
</table>
</tr>
</tbody>
</table>
<h5>Gruppi</h5>
<p>E’ possibile definire dei gruppi che è possibile ripetere e richiamare all’interno di una espressione regolare. La definizione di un gruppo avviene tramite caratteri <strong>^(?&lt;groupname&gt;regex)</strong> in cui groupname è il nome del gruppo e regex è la regular expression che definisce quel gruppo. Per richiamare il gruppo è necessario usare <strong>\k&lt;groupname&gt;, </strong>in alternativa è possibile richiamare i gruppi con <strong>\n</strong> dove n è l’indice del gruppo in ordine di apparizione (da sinistra verso destra). I gruppi sono numerati a partire da 1 poichè il gruppo 0 è sempre il match completo dell’intera regular expression</p>
<p><em>Es.&quot;^(?&lt;first&gt;aa)bb\k&lt;first&gt;$” fa match con “aabbaa” così come &quot;^(?&lt;first&gt;aa)(?&lt;second&gt;bb)\1$&quot;”</em></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/massimoalbertin.wordpress.com/10/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/massimoalbertin.wordpress.com/10/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/massimoalbertin.wordpress.com/10/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/massimoalbertin.wordpress.com/10/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/massimoalbertin.wordpress.com/10/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/massimoalbertin.wordpress.com/10/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/massimoalbertin.wordpress.com/10/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/massimoalbertin.wordpress.com/10/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/massimoalbertin.wordpress.com/10/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/massimoalbertin.wordpress.com/10/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/massimoalbertin.wordpress.com/10/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/massimoalbertin.wordpress.com/10/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/massimoalbertin.wordpress.com/10/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/massimoalbertin.wordpress.com/10/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=massimoalbertin.wordpress.com&amp;blog=2503456&amp;post=10&amp;subd=massimoalbertin&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://massimoalbertin.wordpress.com/2010/03/31/regular-expressions-e-c/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/f5fa63c63e733fa55b227ca19efbb642?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">massimoalbertin</media:title>
		</media:content>
	</item>
		<item>
		<title>WCF Sicurezza con Doppio Certificato</title>
		<link>http://massimoalbertin.wordpress.com/2010/03/10/wcf-sicurezza-con-doppio-certificato/</link>
		<comments>http://massimoalbertin.wordpress.com/2010/03/10/wcf-sicurezza-con-doppio-certificato/#comments</comments>
		<pubDate>Wed, 10 Mar 2010 20:20:48 +0000</pubDate>
		<dc:creator>massimoalbertin</dc:creator>
				<category><![CDATA[Microsoft.NET]]></category>
		<category><![CDATA[Security]]></category>
		<category><![CDATA[WCF]]></category>

		<guid isPermaLink="false">http://massimoalbertin.wordpress.com/2010/03/10/wcf-sicurezza-con-doppio-certificato/</guid>
		<description><![CDATA[Vediamo un po’ come configurare un servizio WCF (Web Service) con sicurezza a livello di messagio: solo il cotenuto dell’envelope soap sarà cifrato. Con questo sistema varrà garantita oltre alla sicurezza anche l’autenticità di client e server: il client avendo a disposizione il certificato pubblico del server potrà verificarne l’autenticità oltre ad utilizzarlo per cifrare [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=massimoalbertin.wordpress.com&amp;blog=2503456&amp;post=7&amp;subd=massimoalbertin&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[</p>
<p>Vediamo un po’ come configurare un servizio WCF (Web Service) con sicurezza a livello di messagio: solo il cotenuto dell’envelope soap sarà cifrato. Con questo sistema varrà garantita oltre alla sicurezza anche l’autenticità di client e server: il client avendo a disposizione il certificato pubblico del server potrà verificarne l’autenticità oltre ad utilizzarlo per cifrare i messaggi verso il servizio. In modo duale anche il servizio potrà controllare autenticità del client e cifrare il conenuto a lui destinato. </p>
<p>Tralasciamo la creazione del servizio e veniamo subito alla configurazione….</p>
<h3>Creazione dei Certificati</h3>
<p>Iniziamo con la generazione dei certificati che ci serviranno per cifrare il contenuto dei messaggi e autenticare client e server. Per la generazione utilizziamo l’utility da linea di comando disponibile con visual studio <font face="Courier New">makecert per la generazione del certificato e chiave private e <font face="Courier New">pvk2pfx</font> per l’esportazione in formato pfx (in cui è possibile esportare anche la chiave privata per il deploy). </font>Tali utility a linea di comando sono disponibili utilizzando il prompt dei comandi di visual studio (che ha già il path correttamente configurato).</p>
<p><strong>Generazione Certificato Server</strong></p>
<p><font face="Courier New">makecert.exe -n &quot;CN=Service&quot; -sky exchange -sv Service.pvk Service.cer</font></p>
<p><font face="Courier New">pvk2pfx.exe -pvk Service.pvk -spc Service.cer</font></p>
<p><strong>Generazione Certificato Client</strong></p>
<p><font face="Courier New">makecert.exe&#160; -n &quot;CN=Client&quot; -sky exchange -sv Client.pvk Client.cer      <br />pvk2pfx.exe -pvk Client.pvk -spc Client.cer</font></p>
<h3><font face="ta">Configurazione dei Servizi</font></h3>
<p><font face="TAho">Generati i certificato procediamo con la configurazione del nostro servizio WCF e del client in modo da utilizzare i certificati per autenticare mutuamente client e server e cifrare i messaggi.</font></p>
<p><strong><font face="TAho">Configurazione del Servizio</font></strong></p>
<pre class="code"><span style="color:blue;">&lt;</span><span style="color:#a31515;">system.serviceModel</span><span style="color:blue;">&gt;

    &lt;</span><span style="color:#a31515;">services</span><span style="color:blue;">&gt;
      &lt;</span><span style="color:#a31515;">service </span><span style="color:red;">name</span><span style="color:blue;">=</span>&quot;<span style="color:blue;">ServiceName</span>&quot;
               <span style="color:red;">behaviorConfiguration</span><span style="color:blue;">=</span>&quot;<span style="color:blue;">CustomServiceBehaviour</span>&quot;<span style="color:blue;">&gt;
        &lt;</span><span style="color:#a31515;">endpoint </span><span style="color:red;">address</span><span style="color:blue;">=</span>&quot;&quot;
                  <span style="color:red;">binding</span><span style="color:blue;">=</span>&quot;<span style="color:blue;">wsHttpBinding</span>&quot;
                  <span style="color:red;">bindingConfiguration</span><span style="color:blue;">=</span>&quot;<span style="color:blue;">CustomBinding</span>&quot;
                  <span style="color:red;">contract</span><span style="color:blue;">=</span>&quot;<span style="color:blue;">MyNamespace.IServiceContract</span>&quot;<span style="color:blue;">&gt;
          &lt;</span><span style="color:#a31515;">identity</span><span style="color:blue;">&gt;
            &lt;</span><span style="color:#a31515;">certificateReference </span><span style="color:red;">storeName</span><span style="color:blue;">=</span>&quot;<span style="color:blue;">My</span>&quot; <span style="color:red;">storeLocation</span><span style="color:blue;">=</span>&quot;<span style="color:blue;">CurrentUser</span>&quot; <span style="color:red;">x509FindType</span><span style="color:blue;">=</span>&quot;<span style="color:blue;">FindBySubjectName</span>&quot; <span style="color:red;">findValue</span><span style="color:blue;">=</span>&quot;<span style="color:blue;">Service</span>&quot; <span style="color:blue;">/&gt;
          &lt;/</span><span style="color:#a31515;">identity</span><span style="color:blue;">&gt;
        &lt;/</span><span style="color:#a31515;">endpoint</span><span style="color:blue;">&gt;
        &lt;</span><span style="color:#a31515;">endpoint </span><span style="color:red;">address</span><span style="color:blue;">=</span>&quot;<span style="color:blue;">mex</span>&quot; <span style="color:red;">binding</span><span style="color:blue;">=</span>&quot;<span style="color:blue;">mexHttpBinding</span>&quot; <span style="color:red;">contract</span><span style="color:blue;">=</span>&quot;<span style="color:blue;">IMetadataExchange</span>&quot; <span style="color:blue;">/&gt;
      &lt;/</span><span style="color:#a31515;">service</span><span style="color:blue;">&gt;
    &lt;/</span><span style="color:#a31515;">services</span><span style="color:blue;">&gt;

    &lt;</span><span style="color:#a31515;">bindings</span><span style="color:blue;">&gt;
      &lt;</span><span style="color:#a31515;">wsHttpBinding</span><span style="color:blue;">&gt;
        &lt;</span><span style="color:#a31515;">binding </span><span style="color:red;">name</span><span style="color:blue;">=</span>&quot;<span style="color:blue;">CustomBinding</span>&quot;<span style="color:blue;">&gt;
          &lt;</span><span style="color:#a31515;">security </span><span style="color:red;">mode </span><span style="color:blue;">=</span>&quot;<span style="color:blue;">Message</span>&quot;<span style="color:blue;">&gt;
            &lt;</span><span style="color:#a31515;">message </span><span style="color:red;">clientCredentialType</span><span style="color:blue;">=</span>&quot;<span style="color:blue;">Certificate</span>&quot; <span style="color:blue;">/&gt;
          &lt;/</span><span style="color:#a31515;">security</span><span style="color:blue;">&gt;
        &lt;/</span><span style="color:#a31515;">binding</span><span style="color:blue;">&gt;
</span><span style="color:blue;">      &lt;/</span><span style="color:#a31515;">wsHttpBinding</span><span style="color:blue;">&gt;
    &lt;/</span><span style="color:#a31515;">bindings</span><span style="color:blue;">&gt;

    &lt;</span><span style="color:#a31515;">behaviors</span><span style="color:blue;">&gt;
      &lt;</span><span style="color:#a31515;">serviceBehaviors</span><span style="color:blue;">&gt;
        &lt;</span><span style="color:#a31515;">behavior </span><span style="color:red;">name</span><span style="color:blue;">=</span>&quot;<span style="color:blue;">CustomBehaviour</span>&quot;<span style="color:blue;">&gt;
          &lt;</span><span style="color:#a31515;">serviceMetadata </span><span style="color:red;">httpGetEnabled</span><span style="color:blue;">=</span>&quot;<span style="color:blue;">true</span>&quot; <span style="color:blue;">/&gt;
          &lt;</span><span style="color:#a31515;">serviceDebug </span><span style="color:red;">includeExceptionDetailInFaults</span><span style="color:blue;">=</span>&quot;<span style="color:blue;">False</span>&quot; <span style="color:blue;">/&gt;
          &lt;</span><span style="color:#a31515;">serviceCredentials</span><span style="color:blue;">&gt;
            &lt;</span><span style="color:#a31515;">serviceCertificate </span><span style="color:red;">findValue</span><span style="color:blue;">=</span>&quot;<span style="color:blue;">AuthService</span>&quot; <span style="color:red;">storeLocation</span><span style="color:blue;">=</span>&quot;<span style="color:blue;">CurrentUser</span>&quot; <span style="color:red;">storeName</span><span style="color:blue;">=</span>&quot;<span style="color:blue;">My</span>&quot; <span style="color:red;">x509FindType</span><span style="color:blue;">=</span>&quot;<span style="color:blue;">FindBySubjectName</span>&quot; <span style="color:blue;">/&gt;
            &lt;</span><span style="color:#a31515;">clientCertificate</span><span style="color:blue;">&gt;
              &lt;</span><span style="color:#a31515;">authentication </span><span style="color:red;">certificateValidationMode</span><span style="color:blue;">=</span>&quot;<span style="color:blue;">PeerOrChainTrust</span>&quot; <span style="color:blue;">/&gt;
            &lt;/</span><span style="color:#a31515;">clientCertificate</span><span style="color:blue;">&gt;
          &lt;/</span><span style="color:#a31515;">serviceCredentials</span><span style="color:blue;">&gt;
        &lt;/</span><span style="color:#a31515;">behavior</span><span style="color:blue;">&gt;
      &lt;/</span><span style="color:#a31515;">serviceBehaviors</span><span style="color:blue;">&gt;
    &lt;/</span><span style="color:#a31515;">behaviors</span><span style="color:blue;">&gt;

  &lt;/</span><span style="color:#a31515;">system.serviceModel</span><span style="color:blue;">&gt;
</span></pre>
<p><strong>Configurazione Del Client</strong></p>
<pre class="code">  <span style="color:blue;">&lt;</span><span style="color:#a31515;">system.serviceModel</span><span style="color:blue;">&gt;

    &lt;</span><span style="color:#a31515;">client</span><span style="color:blue;">&gt;
      &lt;</span><span style="color:#a31515;">endpoint </span><span style="color:red;">address</span><span style="color:blue;">=</span>&quot;<span style="color:blue;">http://address/MyService.svc</span>&quot;
                <span style="color:red;">behaviorConfiguration</span><span style="color:blue;">=</span>&quot;<span style="color:blue;">CustomBehaviour</span>&quot;
                <span style="color:red;">binding</span><span style="color:blue;">=</span>&quot;<span style="color:blue;">wsHttpBinding</span>&quot;
                <span style="color:red;">bindingConfiguration</span><span style="color:blue;">=</span>&quot;<span style="color:blue;">ClientBinding</span>&quot;
                <span style="color:red;">contract</span><span style="color:blue;">=</span>&quot;<span style="color:blue;">AdhocWs.IAdhocServices</span>&quot;
                <span style="color:red;">name</span><span style="color:blue;">=</span>&quot;&quot;<span style="color:blue;">&gt;
        &lt;</span><span style="color:#a31515;">identity</span><span style="color:blue;">&gt;
          &lt;</span><span style="color:#a31515;">certificateReference </span><span style="color:red;">storeName</span><span style="color:blue;">=</span>&quot;<span style="color:blue;">TrustedPeople</span>&quot;
                                <span style="color:red;">storeLocation</span><span style="color:blue;">=</span>&quot;<span style="color:blue;">CurrentUser</span>&quot;
                                <span style="color:red;">x509FindType</span><span style="color:blue;">=</span>&quot;<span style="color:blue;">FindBySubjectName</span>&quot;
                                <span style="color:red;">findValue</span><span style="color:blue;">=</span>&quot;<span style="color:blue;">AdhocBridgeService</span>&quot; <span style="color:blue;">/&gt;
        &lt;/</span><span style="color:#a31515;">identity</span><span style="color:blue;">&gt;
      &lt;/</span><span style="color:#a31515;">endpoint</span><span style="color:blue;">&gt;
    &lt;/</span><span style="color:#a31515;">client</span><span style="color:blue;">&gt;

    &lt;</span><span style="color:#a31515;">bindings</span><span style="color:blue;">&gt;
      &lt;</span><span style="color:#a31515;">wsHttpBinding</span><span style="color:blue;">&gt;
        &lt;</span><span style="color:#a31515;">binding </span><span style="color:red;">name</span><span style="color:blue;">=</span>&quot;<span style="color:blue;">ClientBinding</span>&quot;<span style="color:blue;">&gt;
          &lt;</span><span style="color:#a31515;">security </span><span style="color:red;">mode</span><span style="color:blue;">=</span>&quot;<span style="color:blue;">Message</span>&quot; <span style="color:blue;">&gt;
            &lt;</span><span style="color:#a31515;">message </span><span style="color:red;">clientCredentialType</span><span style="color:blue;">=</span>&quot;<span style="color:blue;">Certificate</span>&quot; <span style="color:blue;">/&gt;
          &lt;/</span><span style="color:#a31515;">security</span><span style="color:blue;">&gt;
        &lt;/</span><span style="color:#a31515;">binding</span><span style="color:blue;">&gt;
      &lt;/</span><span style="color:#a31515;">wsHttpBinding</span><span style="color:blue;">&gt;
    &lt;/</span><span style="color:#a31515;">bindings</span><span style="color:blue;">&gt;

    &lt;</span><span style="color:#a31515;">behaviors</span><span style="color:blue;">&gt;

      &lt;</span><span style="color:#a31515;">endpointBehaviors</span><span style="color:blue;">&gt;
        &lt;</span><span style="color:#a31515;">behavior </span><span style="color:red;">name</span><span style="color:blue;">=</span>&quot;<span style="color:blue;">CustomBehaviour</span>&quot;<span style="color:blue;">&gt;
          &lt;</span><span style="color:#a31515;">dataContractSerializer </span><span style="color:red;">maxItemsInObjectGraph</span><span style="color:blue;">=</span>&quot;<span style="color:blue;">2147483646</span>&quot; <span style="color:blue;">/&gt;
          &lt;</span><span style="color:#a31515;">clientCredentials</span><span style="color:blue;">&gt;
            &lt;</span><span style="color:#a31515;">clientCertificate </span><span style="color:red;">findValue</span><span style="color:blue;">=</span>&quot;<span style="color:blue;">Client</span>&quot; <span style="color:red;">storeLocation</span><span style="color:blue;">=</span>&quot;<span style="color:blue;">CurrentUser</span>&quot; <span style="color:red;">storeName</span><span style="color:blue;">=</span>&quot;<span style="color:blue;">My</span>&quot; <span style="color:red;">x509FindType</span><span style="color:blue;">=</span>&quot;<span style="color:blue;">FindBySubjectName</span>&quot; <span style="color:blue;">/&gt;
            &lt;</span><span style="color:#a31515;">serviceCertificate</span><span style="color:blue;">&gt;
              &lt;</span><span style="color:#a31515;">authentication </span><span style="color:red;">certificateValidationMode</span><span style="color:blue;">=</span>&quot;<span style="color:blue;">PeerOrChainTrust</span>&quot; <span style="color:blue;">/&gt;
            &lt;/</span><span style="color:#a31515;">serviceCertificate</span><span style="color:blue;">&gt;
          &lt;/</span><span style="color:#a31515;">clientCredentials</span><span style="color:blue;">&gt;
        &lt;/</span><span style="color:#a31515;">behavior</span><span style="color:blue;">&gt;
      &lt;/</span><span style="color:#a31515;">endpointBehaviors</span><span style="color:blue;">&gt;
    &lt;/</span><span style="color:#a31515;">behaviors</span><span style="color:blue;">&gt;

  &lt;/</span><span style="color:#a31515;">system.serviceModel</span><span style="color:blue;">&gt;
</span></pre>
<p><a href="http://11011.net/software/vspaste"></a></p>
<p>Con questa configurazione i certificati dovranno trovarsi nel Certificate Store dell’utente che esegue l’applicazione in particolare il <strong>Client</strong> deve avere il certificato Client <strong>con</strong> chiave privata e il certificato del server <strong>senza </strong>chiave privata. L’utente che esegue il <strong>Servizio</strong> dovrà avere il certificato <strong>Service</strong> <strong>con </strong>chiave privata e il certificato client <strong>senza </strong>privata. I certificati con chiave privata dovranno trovarsi in <strong>Personal</strong> mentre i certificati senza chiave privata in <strong>Trusted People</strong>. </p>
<h3>Configurazione con IIS</h3>
<p>Nel caso in cui il server, ma anche il client, siano ospitati da IIS l’application Pool dovrà essere configurato in modo da utilizzare un utente con i corretti certificati nel relativo Certificate Store. </p>
<p><strong>Attenzione!</strong> Affinche il certificate store sia caricato e accessibile per l’utente dovrà essere caricato il profilo dell’utente.</p>
<p><div style="display:inline;float:none;margin:0;padding:0;" id="scid:0767317B-992E-4b12-91E0-4F059A8CECA8:9a197313-c44e-45d4-9a07-b4f8cb5e7b75" class="wlWriterEditableSmartContent">Technorati Tags: <a href="http://technorati.com/tags/Microsoft+.NET" rel="tag">Microsoft .NET</a>,<a href="http://technorati.com/tags/Security" rel="tag">Security</a>,<a href="http://technorati.com/tags/WCF" rel="tag">WCF</a></div>
</p>
<p><div style="display:inline;float:none;margin:0;padding:0;" id="scid:0767317B-992E-4b12-91E0-4F059A8CECA8:ee60f8d4-4aa7-45d3-9f83-f34dc912558c" class="wlWriterEditableSmartContent">del.icio.us Tags: <a href="http://del.icio.us/popular/Microsoft+.NET" rel="tag">Microsoft .NET</a>,<a href="http://del.icio.us/popular/Security" rel="tag">Security</a>,<a href="http://del.icio.us/popular/WCF" rel="tag">WCF</a></div></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/massimoalbertin.wordpress.com/7/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/massimoalbertin.wordpress.com/7/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/massimoalbertin.wordpress.com/7/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/massimoalbertin.wordpress.com/7/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/massimoalbertin.wordpress.com/7/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/massimoalbertin.wordpress.com/7/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/massimoalbertin.wordpress.com/7/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/massimoalbertin.wordpress.com/7/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/massimoalbertin.wordpress.com/7/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/massimoalbertin.wordpress.com/7/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/massimoalbertin.wordpress.com/7/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/massimoalbertin.wordpress.com/7/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/massimoalbertin.wordpress.com/7/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/massimoalbertin.wordpress.com/7/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=massimoalbertin.wordpress.com&amp;blog=2503456&amp;post=7&amp;subd=massimoalbertin&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://massimoalbertin.wordpress.com/2010/03/10/wcf-sicurezza-con-doppio-certificato/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/f5fa63c63e733fa55b227ca19efbb642?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">massimoalbertin</media:title>
		</media:content>
	</item>
		<item>
		<title>Creazione di una Certification Authority con OpenSSL</title>
		<link>http://massimoalbertin.wordpress.com/2008/01/13/generare-certificati-self-signed-con-openssl/</link>
		<comments>http://massimoalbertin.wordpress.com/2008/01/13/generare-certificati-self-signed-con-openssl/#comments</comments>
		<pubDate>Sun, 13 Jan 2008 17:31:11 +0000</pubDate>
		<dc:creator>massimoalbertin</dc:creator>
				<category><![CDATA[OpenSSL]]></category>
		<category><![CDATA[Security]]></category>

		<guid isPermaLink="false">http://massimoalbertin.wordpress.com/2008/01/13/generare-certificati-self-signed-con-openssl/</guid>
		<description><![CDATA[Per prima cosa è necessario scaricare OpenSSL Toolkit, qui trovate la versione per Windows e qui le versioni per linux. Una volta completata l&#8217;installazione consiglio di aggiungere il percorso [OpenSSLFolder]\bin\ all&#8217;elenco dei PATH, in modo da porte richiamare le utility da linea di comando in ogni posizione dal prompt dei comandi. Di seguito verranno descritte [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=massimoalbertin.wordpress.com&amp;blog=2503456&amp;post=4&amp;subd=massimoalbertin&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Per prima cosa è necessario scaricare OpenSSL Toolkit, <a href="http://www.shininglightpro.com/products/Win32OpenSSL.html">qui</a> trovate la versione per Windows e <a href="http://www.openssl.org">qui</a> le versioni per linux. </p>
<p>Una volta completata l&#8217;installazione consiglio di aggiungere il percorso [OpenSSLFolder]\bin\ all&#8217;elenco dei PATH, in modo da porte richiamare le utility da linea di comando in ogni posizione dal prompt dei comandi.</p>
<p>Di seguito verranno descritte le procedure di generazione dei certificati passo a passo tramite linea di comando (prompt dei comandi).</p>
<p>In alternativa è possibile utilizzare un tool che si appoggia ad OpenSSL chiamato <a href="http://sourceforge.net/projects/xca">XCA</a>, che permette di effettuare tutte le operazioni tramite GUI. </p>
<p><strong><font size="4">Generarazione della Certification Authority (CA)</font></strong></p>
<p>Come prima cosa è necessario generare le chiavi per la Certification Authority, ovvero le chiavi che verrano usate per generare firmare tutte le chiavi di cui abbiamo bisogno. Siccome queste chiavi non verrano firmate da una Authority riconosciuta (Verisign, Thawte ecc.) ma da noi stessi, molte applicazioni visualizzeranno degli avvisi per notificare la cosa.</p>
<p>Vediamo ora come procedere alla generazione di una CA:</p>
<ul>
<li>Create una cartella in cui posizionare tutte le informazioni della CA (Es. \MyCA)
<li>Al suo interno consiglio di create tre cartelle (come viene consigliato anche dal <a href="http://www.dylanbeattie.net/docs/openssl_iis_ssl_howto.html">questo tutorial</a>) <strong>Keys</strong> (per le chiavi pubbliche e private generate) <strong>Requests </strong>(per le richieste di emissione dei certificati) e<strong> Certs </strong>(per i certificati veri e propri).
<li>Come prima cosa è necessario generare una chiave con algoritmo RSA e cifratura Triple DES (in alternativa è possibile utilizzare DES o IDEA). La chiave privata (da conservare in luogo sicuro e protetto) verrà salvata all&#8217;interno del file <strong>ca.key</strong> e sarà di 1024 bit (in alternativa è possibile utilizzare 512, 2048, 4076). Il comando (per maggiori informazioni consultare <a href="http://www.openssl.org/docs/apps/genrsa.html">qui</a>) da eseguire è:</li>
</ul>
<blockquote><pre><strong>openssl</strong> <strong><font color="#000080">genrsa</font></strong> <font color="#008040"><em>-des3</em> <em>-out</em></font> <font color="#ff0080">keys/ca.key 1024</font></pre>
</blockquote>
<ul>
<li>Verrà richiesta una passphrase con cui proteggere la chiave privata da generare. Tale passphrase verrà richiesta tutte le volte che si utilizzata la chiave generata per firmare o cifrare. Lasciandola bianca non verrà richiesta durante l&#8217;utilizzo. Si consiglia di utilizzare una passphrase per garantire la sicurezza della propria CA, che sfrutti tutti i canoni di <a href="http://www.microsoft.com/protect/yourself/password/create.mspx">sicurezza per le password.</a> Il file ottenuto avrà una forma simile alla seguente (chiave espressa in base64):</li>
</ul>
<blockquote>
<p><font face="Courier New" size="1">&#8212;&#8211;BEGIN RSA PRIVATE KEY&#8212;&#8211;<br />Proc-Type: 4,ENCRYPTED<br />DEK-Info: DES-EDE3-CBC,09C9FA8C5DDAE12D </font></p>
<p><font face="Courier New" size="1">I29lb68jzuR0FFbdQRS6HKaQ7NEJauH689YFRpKKmqvYCCIhDxARRIRkskI4yp9B<br />IHEGyICcBnEvNiw+Jgm+4nmJsaoJuWFYSVb4qfcrq/7MXUa7hPVHF+hFxuU/uS4q<br />/INqbcVeH74ivI+rMZr0p4KcXll8fFH/vh+JultcR/tlsN8tc6RtGmE/zrVmubrU<br />Ufxpt+XgwESnyQqOhXcFxQDwcakQ3lSBll2SQaYBLvCgblJqPGFxfFb7QVyeoQJ0<br />yaHnzm2aun+gXCuU83BXfgHQUv9uWugsVMModgO/cyDiP9xwfasiYIOdGRCkZFXV<br />pOskmdtk6s+uYQBXU+TvnUeiYir5J5Ci+yuTOqx/dxQSFvcxjhX5d53+oWlLg+2K<br />0PHU5M3rzc5ybLREoqX31MOd0f6IFGfV8C8fsyuQoKYFVeeKAUWB0Br9Sg8eBVnA<br />GyQG4NQlpI+fKrcPLV6x8G+bx8Cns2Zht0TZpMRXT0ZbaEmLRhcK718SroUx5lCo<br />SdjvLvHD3saUsdNq28Zk0wh8MWXyW60uJmgQPP7dtzMpq5VKXQVAgh8FY+z2VumM<br />5oZgQXje7YnjVN+esB1NYoMUuXbPZfYmFPTAZEEP5aueRnntjsMa8IildZz5jhWN<br />c5Yb0L0/OobZfTXa8lVEc2HfJ7dh3mimtVCF6tQzwiUecZmxXaeLmpjbshE8JLPv<br />tsxPmCPwy1r+eqLlb8nz9SkhhUZoj7wS4BIhtUXdWILWmz8lp/dHdMug/kh9MkoY<br />fswyGGbI9Z1B6t22ZsjVuAQgmPQ9Sz3Sqr/bhRJnhRtE6/i17opotQ==<br />&#8212;&#8211;END RSA PRIVATE KEY&#8212;&#8211;</font></p>
</blockquote>
<ul>
<li>Il passo successivo è di generareil certificato della nostra Certification Authority sfruttando proprio quella chiave privata generata al passo precedente per la firma. Il comando per effettuare l&#8217;operazione è</li>
</ul>
<blockquote><pre><strong>openssl</strong> <strong><font color="#000080">req</font></strong> <font color="#008040"><em>-new -x509 -days</em></font> <font color="#ff0080">1001</font> <font color="#008040"><em>-key</em></font> <font color="#ff0080">keys/ca.key</font> <font color="#008040">-out</font> <font color="#ff0080">certs/ca.cer</font></pre>
</blockquote>
<ul>
<li><font face="Courier New" color="#000000">Verrà creato in nuovo certificato X509 con validità 1001 giorni (modificabile a piacere) sfruttando la chiave <strong>ca.key</strong> memorizzandolo sul file<strong> ca.cer.</strong></font>Durante la fase di generazione del certificato verranno richieste alcune informazioni come Stato, Provincia, Città, Nome, Mail che verranno memorizzate all&#8217;interno del certificato.</li>
<li>L&#8217;ultima operazione consiste nel&#8217;estrazione del certificato della CA in formato PKCS12, in modo da poter distribuire il certificato e corrispondete chiave pubblica agli utilizzatore dei certificati generati dalla nostra nuova CA. Per evitare che alcuni software segnalino i futuri certificati da noi generati come non affidabili è necessario aggiungere tale PKCS12 alla liste delle Trusted Root Store. Il comando da eseguire sarà:</li>
</ul>
<blockquote><pre><strong>openssl</strong> <strong><font color="#000080">x509</font></strong><em><font color="#008040"> -in</font></em> <font color="#ff0080">ca.cer</font> <em><font color="#008040">-outform</font></em> <font color="#ff0080">DER</font> <em><font color="#008040">-out</font></em> <font color="#ff0080">ca.der</font></pre>
</blockquote>
<blockquote><p>Nel caso lo si voglia in formato DER.</p></blockquote>
<br /><img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/massimoalbertin.wordpress.com/4/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/massimoalbertin.wordpress.com/4/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/massimoalbertin.wordpress.com/4/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/massimoalbertin.wordpress.com/4/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/massimoalbertin.wordpress.com/4/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/massimoalbertin.wordpress.com/4/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/massimoalbertin.wordpress.com/4/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/massimoalbertin.wordpress.com/4/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/massimoalbertin.wordpress.com/4/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/massimoalbertin.wordpress.com/4/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/massimoalbertin.wordpress.com/4/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/massimoalbertin.wordpress.com/4/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/massimoalbertin.wordpress.com/4/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/massimoalbertin.wordpress.com/4/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/massimoalbertin.wordpress.com/4/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/massimoalbertin.wordpress.com/4/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=massimoalbertin.wordpress.com&amp;blog=2503456&amp;post=4&amp;subd=massimoalbertin&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://massimoalbertin.wordpress.com/2008/01/13/generare-certificati-self-signed-con-openssl/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/f5fa63c63e733fa55b227ca19efbb642?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">massimoalbertin</media:title>
		</media:content>
	</item>
		<item>
		<title>Configurazione di NHibernate 1.2</title>
		<link>http://massimoalbertin.wordpress.com/2008/01/12/configurazione-di-nhibernate/</link>
		<comments>http://massimoalbertin.wordpress.com/2008/01/12/configurazione-di-nhibernate/#comments</comments>
		<pubDate>Sat, 12 Jan 2008 11:00:41 +0000</pubDate>
		<dc:creator>massimoalbertin</dc:creator>
				<category><![CDATA[C#]]></category>
		<category><![CDATA[Microsoft.NET]]></category>
		<category><![CDATA[NHibernate]]></category>
		<category><![CDATA[.net framework]]></category>
		<category><![CDATA[configurazione]]></category>

		<guid isPermaLink="false">http://massimoalbertin.wordpress.com/2008/01/12/configurazione-di-nhibernate/</guid>
		<description><![CDATA[La configurazione di NHibernate può essere fatta principalmente in tre modi; vediamo un attimo come realizzarli con alcuni esempi: Tramite .Config: La configurazione è mantenuata all&#8217;interno di un una Section custom del file di configurazione dell&#8217;applicazione. Prima di tutto bisogna definire la section, che verrà poi utilizzata da NHibernate in questo modo: &#60;configSections&#62; &#60;section name="nhibernate" [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=massimoalbertin.wordpress.com&amp;blog=2503456&amp;post=3&amp;subd=massimoalbertin&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>La configurazione di NHibernate può essere fatta principalmente in tre modi; vediamo un attimo come realizzarli con alcuni esempi:</p>
<ul>
<li><strong>Tramite .Config:</strong></li>
</ul>
<p>La configurazione è mantenuata all&#8217;interno di un una <em>Section</em> custom del file di configurazione dell&#8217;applicazione. Prima di tutto bisogna definire la section, che verrà poi utilizzata da NHibernate in questo modo:</p>
<blockquote><pre><span style="color:blue;">&lt;</span><span style="color:#a31515;">configSections</span><span style="color:blue;">&gt;
  &lt;</span><span style="color:#a31515;">section </span><span style="color:red;">name</span><span style="color:blue;">=</span>"<span style="color:blue;">nhibernate</span>"
           <span style="color:red;">type</span><span style="color:blue;">=</span>"<span style="color:blue;">System.Configuration.NameValueSectionHandler,
           System, Version=1.0.5000.0, Culture=neutral,
           PublicKeyToken=b77a5c561934e089</span>" <span style="color:blue;">/&gt;
&lt;/</span><span style="color:#a31515;">configSections</span><span style="color:blue;">&gt;</span></pre>
</blockquote>
<p><a href="http://11011.net/software/vspaste"></a><a href="http://11011.net/software/vspaste"></a><a href="http://11011.net/software/vspaste"></a></p>
<p>Una volta impostata la definizione per la configSection è necessario inserire la sezione di configurazione vera e propria. Di seguito riporto un esempio classico di configurazione.</p>
<blockquote><pre><span style="color:blue;">&lt;</span><span style="color:#a31515;">nhibernate</span><span style="color:blue;">&gt;
  &lt;</span><span style="color:#a31515;">add </span><span style="color:red;">key</span><span style="color:blue;">=</span>"<span style="color:blue;">hibernate.connection.provider</span>"
       <span style="color:red;">value</span><span style="color:blue;">=</span>"<span style="color:blue;">NHibernate.Connection.DriverConnectionProvider</span>" <span style="color:blue;">/&gt;
  &lt;</span><span style="color:#a31515;">add </span><span style="color:red;">key</span><span style="color:blue;">=</span>"<span style="color:blue;">hibernate.connection.driver_class</span>"
       <span style="color:red;">value</span><span style="color:blue;">=</span>"<span style="color:blue;">NHibernate.Driver.SqlClientDriver</span>" <span style="color:blue;">/&gt;
  &lt;</span><span style="color:#a31515;">add </span><span style="color:red;">key</span><span style="color:blue;">=</span>"<span style="color:blue;">hibernate.dialect</span>"
       <span style="color:red;">value</span><span style="color:blue;">=</span>"<span style="color:blue;">NHibernate.Dialect.MsSql2005Dialect</span>" <span style="color:blue;">/&gt;
  &lt;</span><span style="color:#a31515;">add </span><span style="color:red;">key</span><span style="color:blue;">=</span>"<span style="color:blue;">hibernate.connection.connection_string</span>"
       <span style="color:red;">value</span><span style="color:blue;">=</span>"<span style="color:blue;">Server=.\SQLEXPRESS; Integrated Security=True;
       Database=AdventureWorks;</span>" <span style="color:blue;">/&gt;
  &lt;</span><span style="color:#a31515;">add </span><span style="color:red;">key</span><span style="color:blue;">=</span>"<span style="color:blue;">hibernate.default_schema</span>" <span style="color:red;">value</span><span style="color:blue;">=</span>"<span style="color:blue;">dbo</span>" <span style="color:blue;">/&gt;
&lt;/</span><span style="color:#a31515;">nhibernate</span><span style="color:blue;">&gt;</span></pre>
</blockquote>
<p><a href="http://11011.net/software/vspaste"></a></p>
<p>I primi tre parametri riguardano la tipologia di connessione, utilizzando un <em>DriverConnectionProvieder </em>e il Client per Sql Server (ne esistono un po&#8217; per tutti i principali motori DBMS). Il <em>Dialect </em>indica il particolare dialetto SQL (dal momento che SQL non è proprio identico per ogni DBMS), in questo caso per Sql Server 2005. La <em>ConnectionString</em> anch&#8217;essa legata al tipo di DBMS al quale ci si collega (Consultare la documentazione del Driver di connessione specifico). Ed infine nel caso si voglia definire lo schema di default da utilizzare per l&#8217;accesso al DB, in questo caso lo standard di SQL server &#8220;dbo&#8221;.</p>
<p>A livello di codice è necessario, all&#8217;avvio di NHibernate, avviare la configurazione, che recupera dal file appena descritto tutti i parametri di cui ha bisogno per effettuare le connessioni al DB.</p>
<blockquote><pre><span style="color:#2b91af;">Configuration </span>configuration = <span style="color:blue;">new </span><span style="color:#2b91af;">Configuration</span>();
configuration.AddAssembly(<span style="color:#a31515;">"Assembly.Name"</span>);
</pre>
</blockquote>
<p><a href="http://11011.net/software/vspaste"></a></p>
<p>Il metodo AddAssembly non fa altro che indicare l&#8217;assembly da cui ricavare le Entity per effettuare il mapping (classi e file .hbm.xml).</p>
<ul>
<li><strong>Tramite File hibernate.cfg.xml</strong></li>
</ul>
<p>In alternativa è possibile utilizzare un file di configurazione specifico di nhibernate chiamato hibernate.cfg.xml; tale file va copiato nella cartella di output dei file compilati e non incluso come risorsa embedded. La struttura di questo file rispecchia le caratteristiche già evidenziate in precedenza, ma con una sintassi leggermente differente.</p>
<blockquote><pre><span style="color:blue;">&lt;?</span><span style="color:#a31515;">xml </span><span style="color:red;">version</span><span style="color:blue;">=</span>"<span style="color:blue;">1.0</span>" <span style="color:red;">encoding</span><span style="color:blue;">=</span>"<span style="color:blue;">utf-8</span>" <span style="color:blue;">?&gt;
&lt;</span><span style="color:#a31515;">hibernate-configuration </span><span style="color:red;">xmlns</span><span style="color:blue;">=</span>"<span style="color:blue;">urn:nhibernate-configuration-2.2</span>"<span style="color:blue;">&gt;
  &lt;</span><span style="color:#a31515;">session-factory</span><span style="color:blue;">&gt;
    &lt;</span><span style="color:#a31515;">property </span><span style="color:red;">name</span><span style="color:blue;">=</span>"<span style="color:blue;">dialect</span>"<span style="color:blue;">&gt;
      </span>NHibernate.Dialect.MsSql2005Dialect<span style="color:blue;">&lt;/</span><span style="color:#a31515;">property</span><span style="color:blue;">&gt;
    &lt;</span><span style="color:#a31515;">property </span><span style="color:red;">name</span><span style="color:blue;">=</span>"<span style="color:blue;">connection.provider</span>"<span style="color:blue;">&gt;
      </span>NHibernate.Connection.DriverConnectionProvider<span style="color:blue;">&lt;/</span><span style="color:#a31515;">property</span><span style="color:blue;">&gt;
    &lt;</span><span style="color:#a31515;">property </span><span style="color:red;">name</span><span style="color:blue;">=</span>"<span style="color:blue;">hibernate.connection.driver_class</span>"<span style="color:blue;">&gt;
      </span>NHibernate.Driver.SqlClientDriver<span style="color:blue;">&lt;/</span><span style="color:#a31515;">property</span><span style="color:blue;">&gt;
    &lt;</span><span style="color:#a31515;">property </span><span style="color:red;">name</span><span style="color:blue;">=</span>"<span style="color:blue;">connection.connection_string</span>"<span style="color:blue;">&gt;
      </span>Server=.\SQLEXPRESS; Integrated Security=True;
      Database=AdventureWorks;<span style="color:blue;">&lt;/</span><span style="color:#a31515;">property</span><span style="color:blue;">&gt;
    &lt;</span><span style="color:#a31515;">mapping </span><span style="color:red;">assembly</span><span style="color:blue;">=</span>"<span style="color:blue;">Assembly.Name</span>" <span style="color:blue;">/&gt;
  &lt;/</span><span style="color:#a31515;">session-factory</span><span style="color:blue;">&gt;
&lt;/</span><span style="color:#a31515;">hibernate-configuration</span><span style="color:blue;">&gt;</span></pre>
</blockquote>
<p><a href="http://11011.net/software/vspaste"></a></p>
<p>In questo caso il mapping con assembly contenente le entità è stato specificato direttamente all&#8217;interno del file di configurazione; ciò eviterà di dover utilizzare il metodo AddAssembly().</p>
<p>Con questo tipo di soluzione si ha il vantaggio di poter utilizzare l&#8217;Xsd (nhibernate-configuration-2.2) fornito con la distribuzione di nhibernate e conseguentemente l&#8217;intellisense funzionante durante la scrittura del file. Affinchè venga individuato il file XSD è necessario copiarlo all&#8217;interno della cartella [VisualStudioFolder]\Xml\Schemas.</p>
<p>A Livello di implementazione è necessario aggiungere una riga di codice, così come mostrato dall&#8217;esempo sottostante:</p>
<blockquote><pre><span style="color:#2b91af;">Configuration </span>configuration = <span style="color:blue;">new </span><span style="color:#2b91af;">Configuration</span>();
configuration.Configure();</pre>
</blockquote>
<ul>
<li><strong>Tramite file xml</strong></li>
</ul>
<p>L&#8217;ultima possibilità è quella di utilizzare un file xml, con nome e percorso qualsiasi, con la stessa sintassi già vista per il file hibernate.cfg.xml. Ciò che cambia a livello di codice è che al metodo Configure in questo caso è necessario passare percorso e nome del file di configurazione utilizzato.</p>
<blockquote><pre><span style="color:#2b91af;">Configuration </span>configuration = <span style="color:blue;">new </span><span style="color:#2b91af;">Configuration</span>();
configuration.Configure(<span style="color:#a31515;">@"path\filename.xml"</span>);</pre>
</blockquote>
<p><a href="http://11011.net/software/vspaste"></a></p>
<br /><img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/massimoalbertin.wordpress.com/3/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/massimoalbertin.wordpress.com/3/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/massimoalbertin.wordpress.com/3/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/massimoalbertin.wordpress.com/3/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/massimoalbertin.wordpress.com/3/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/massimoalbertin.wordpress.com/3/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/massimoalbertin.wordpress.com/3/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/massimoalbertin.wordpress.com/3/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/massimoalbertin.wordpress.com/3/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/massimoalbertin.wordpress.com/3/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/massimoalbertin.wordpress.com/3/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/massimoalbertin.wordpress.com/3/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/massimoalbertin.wordpress.com/3/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/massimoalbertin.wordpress.com/3/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/massimoalbertin.wordpress.com/3/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/massimoalbertin.wordpress.com/3/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=massimoalbertin.wordpress.com&amp;blog=2503456&amp;post=3&amp;subd=massimoalbertin&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://massimoalbertin.wordpress.com/2008/01/12/configurazione-di-nhibernate/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/f5fa63c63e733fa55b227ca19efbb642?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">massimoalbertin</media:title>
		</media:content>
	</item>
	</channel>
</rss>
