<?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/"
	>

<channel>
	<title>Sam Beauvois</title>
	<atom:link href="http://www.sambeauvois.be/blog/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.sambeauvois.be/blog</link>
	<description>general dev, .net and other stuff</description>
	<lastBuildDate>Tue, 27 Jul 2010 07:23:57 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.6</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>SqlServer : Saving changes is not permitted</title>
		<link>http://www.sambeauvois.be/blog/2010/07/sqlserver-saving-changes-is-not-permitted/</link>
		<comments>http://www.sambeauvois.be/blog/2010/07/sqlserver-saving-changes-is-not-permitted/#comments</comments>
		<pubDate>Tue, 27 Jul 2010 07:22:51 +0000</pubDate>
		<dc:creator>Sam Beauvois</dc:creator>
				<category><![CDATA[Reminders]]></category>
		<category><![CDATA[Sql Server]]></category>

		<guid isPermaLink="false">http://www.sambeauvois.be/blog/?p=491</guid>
		<description><![CDATA[With SqlServer, when you want to change the structure of a table, you may encounter the following warning message :
&#8220;Saving changes is not permitted. The changes you have made require the following tables to be dropped and re-created. You have either made changes to a table that can&#8217;t be re-created or enabled the option Prevent [...]]]></description>
			<content:encoded><![CDATA[<p>With SqlServer, when you want to change the structure of a table, you may encounter the following warning message :</p>
<blockquote><p>&#8220;Saving changes is not permitted. The changes you have made require the following tables to be dropped and re-created. You have either made changes to a table that can&#8217;t be re-created or enabled the option Prevent saving changes that require the table to be re-created.&#8221;</p></blockquote>
<p><a href="http://www.sambeauvois.be/blog/wp-content/uploads/2010/07/warn1.png"><img class="aligncenter size-full wp-image-492" title="warn1" src="http://www.sambeauvois.be/blog/wp-content/uploads/2010/07/warn1.png" alt="warn1" width="456" height="367" /></a></p>
<p>To avoid this warning message, go to the &#8220;tools&#8221; menu, then click &#8220;Options&#8221;</p>
<p><a href="http://www.sambeauvois.be/blog/wp-content/uploads/2010/07/toolsoptions.png"><img class="aligncenter size-full wp-image-493" title="toolsoptions" src="http://www.sambeauvois.be/blog/wp-content/uploads/2010/07/toolsoptions.png" alt="toolsoptions" width="307" height="266" /></a>Click on the &#8220;Designer&#8221; node</p>
<p style="text-align: center;"><a href="http://www.sambeauvois.be/blog/wp-content/uploads/2010/07/Designers.png"><img class="aligncenter size-full wp-image-494" title="Designers" src="http://www.sambeauvois.be/blog/wp-content/uploads/2010/07/Designers.png" alt="Designers" width="386" height="221" /></a></p>
<p>Then  <strong>uncheck </strong>the &#8220;Prevent saving changes that require table re-creation&#8221; checkbox</p>
<p style="text-align: center;"><a href="http://www.sambeauvois.be/blog/wp-content/uploads/2010/07/uncheck.png"><img class="aligncenter size-full wp-image-495" title="uncheck" src="http://www.sambeauvois.be/blog/wp-content/uploads/2010/07/uncheck.png" alt="uncheck" width="386" height="223" /></a><br />
And you are done, the message box will not appears anymore</p>
]]></content:encoded>
			<wfw:commentRss>http://www.sambeauvois.be/blog/2010/07/sqlserver-saving-changes-is-not-permitted/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>I want my foreign key to be mapped to a single object and not a collection</title>
		<link>http://www.sambeauvois.be/blog/2010/06/i-want-my-foreign-key-to-be-mapped-to-a-single-object-and-not-a-collection/</link>
		<comments>http://www.sambeauvois.be/blog/2010/06/i-want-my-foreign-key-to-be-mapped-to-a-single-object-and-not-a-collection/#comments</comments>
		<pubDate>Tue, 15 Jun 2010 09:57:16 +0000</pubDate>
		<dc:creator>Sam Beauvois</dc:creator>
				<category><![CDATA[SubSonic]]></category>
		<category><![CDATA[Code generation]]></category>
		<category><![CDATA[T4]]></category>

		<guid isPermaLink="false">http://www.sambeauvois.be/blog/?p=470</guid>
		<description><![CDATA[Say you have two tables:  Teams and Registrations
Registration has a foreign key for Teams :

In Subsonic 3, the Registration class will have a property called “Beach_Teams” which returns a IQueryable&#60;Beach_Team&#62; collection.
If we look at the generate class in the activerecord.cs file, there is a “Foreign Keys” region which contains the Beach_Teams property:


 #region ' Foreign [...]]]></description>
			<content:encoded><![CDATA[<p>Say you have two tables:  Teams and Registrations</p>
<p>Registration has a foreign key for Teams :</p>
<p><a href="http://www.sambeauvois.be/blog/wp-content/uploads/2010/06/image.png" target="_blank"><img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="image" src="http://www.sambeauvois.be/blog/wp-content/uploads/2010/06/image_thumb.png" border="0" alt="image" width="484" height="218" /></a></p>
<p>In Subsonic 3, the Registration class will have a property called “Beach_Teams” which returns a IQueryable&lt;Beach_Team&gt; collection.</p>
<p>If we look at the generate class in the activerecord.cs file, there is a “Foreign Keys” region which contains the Beach_Teams property:</p>
<pre class="brush: csharp;">

 #region ' Foreign Keys '
 public IQueryable&lt;Beach_Team&gt; Beach_Teams
 {
   get
   {
     var repo=LJR.DAL.Activities.Beach.Beach_Team.GetRepo();
     return from items in repo.GetAll()
          where items.TeamID == _TeamIDfk
          select items;
   }
 }

#endregion
</pre>
<p>It’s not ok for my use, I want a property returning only one &#8220;Beach_Team” object, so I can use it in my presentation layer with databound controls with no efforts</p>
<pre class="brush: xml;">
&lt;asp:ListView runat=&quot;server&quot; ID=&quot;LastTeams&quot; DataSourceID=&quot;registrationsOds&quot;&gt;
   &lt;ItemTemplate&gt;
     &lt;%# Eval(&quot;Beach_Team.Name&quot;)%&gt;
   &lt;/ItemTemplate&gt;
 &lt;/asp:ListView&gt;
</pre>
<p>So, what can I do ?</p>
<p>I can edit the ActiveRecord.cs file and add a property called “Beach_Team” and returning a Beach_Team object</p>
<pre class="brush: csharp;">
 public Beach_Team Beach_Team
 {
   get
   {
     var repo = LJR.DAL.Activities.Beach.Beach_Team.GetRepo();
    return repo.GetByKey(_TeamIDfk);
   }
 }
</pre>
<p>It do the job !</p>
<p>But if I want to regenerate the ActiveRecord.cs file, my modification will be lost !</p>
<p>So the good solution is to modify the T4 template to generate this property.</p>
<p>Let’s do this :</p>
<p>Go to the ActiveRecord.tt file and search for &#8216; Foreign Keys &#8216;.</p>
<p>Once you have find it look how it works:</p>
<pre class="brush: csharp;">

#region ' Foreign Keys '
&lt;#
 List&lt;string&gt; fkCreated = new List&lt;string&gt;();
 foreach(FKTable fk in tbl.FKTables)
 {
   if(IsTableOkToBeIncluded(fk.OtherTable))
   {
    string propName=fk.OtherQueryable;
    if(fkCreated.Contains(propName))
    {
      propName=fk.OtherQueryable+fkCreated.Count.ToString();
    }
    fkCreated.Add(fk.OtherQueryable);
#&gt;
   public IQueryable&lt;&lt;#=fk.OtherClass #&gt;&gt; &lt;#=propName #&gt;
  {
  get
  {
     var repo=&lt;#=Namespace #&gt;.&lt;#=fk.OtherClass#&gt;.GetRepo();
     return from items in repo.GetAll()
         where items.&lt;#=CleanUp(fk.OtherColumn)#&gt; == _&lt;#=CleanUp(fk.ThisColumn)#&gt;
         select items;
   }
 }

&lt;#
 }
 }
#&gt;
 #endregion
</pre>
<p>In a nutshell, for each tables linked to the table we are on, we check if the access code to the table has to be generated (see my previous article : <a href="http://www.sambeauvois.be/blog/2010/06/subsonic-specify-the-tables-you-really-need/" target="_blank">Subsonic : Specify the tables you really need !</a> ).</p>
<p>If the code has to be generated, we create a string variable named “propName” which will be the name of the property.</p>
<p>If this property already exists, we suffix the name to be sure we don&#8217;t have the same property twice.</p>
<p>Then we generate the IQueryable property.</p>
<p>Now, the first thing we want is to have the property name equals to the object name.</p>
<p>We could think that we don’t have to twist our minds because  we already have it with “fk.OtherClass” and i could be like that</p>
<pre class="brush: csharp;">
 public &lt;#=fk.OtherClass #&gt; &lt;#=fk.OtherClass #&gt;
 {
  get
  {
   var repo=&lt;#=Namespace #&gt;.&lt;#=fk.OtherClass#&gt;.GetRepo();
   return repo.GetByKey(_&lt;#=CleanUp(fk.ThisColumn)#&gt;);
  }
 }
</pre>
<p>But what if we have two foreign keys to the same table ? We will have the same property twice! and we have to avoid it!</p>
<p>So, we have to check if this property isn’t already generated.</p>
<p>To do this, we can use the list “fkCreated” already present in the code, and create a “secondPropName” string variable, assign it the value of the OtherClass and check if it’s not already created :</p>
<pre class="brush: csharp;">
 string secondPropName=fk.OtherClass;
 if(fkCreated.Contains(secondPropName))
 {
   secondPropName+=fkCreated.Count.ToString();
 }
 fkCreated.Add(secondPropName);
</pre>
<p>There is the final code</p>
<pre class="brush: csharp;">

#region ' Foreign Keys '
&lt;#
 List&lt;string&gt; fkCreated = new List&lt;string&gt;();
 foreach(FKTable fk in tbl.FKTables)
 {
   if(IsTableOkToBeIncluded(fk.OtherTable))
   {
    string propName=fk.OtherQueryable;
    if(fkCreated.Contains(propName))
    {
     propName=fk.OtherQueryable+fkCreated.Count.ToString();
    }
   fkCreated.Add(fk.OtherQueryable);

   string secondPropName=fk.OtherClass;
   if(fkCreated.Contains(secondPropName))
   {
     secondPropName+=fkCreated.Count.ToString();
   }
   fkCreated.Add(secondPropName);
#&gt;
  public IQueryable&lt;&lt;#=fk.OtherClass #&gt;&gt; &lt;#=propName #&gt;
  {
    get
    {
      var repo=&lt;#=Namespace #&gt;.&lt;#=fk.OtherClass#&gt;.GetRepo();
      return from items in repo.GetAll()
        where items.&lt;#=CleanUp(fk.OtherColumn)#&gt; == _&lt;#=CleanUp(fk.ThisColumn)#&gt;
        select items;
    }
  }

  public &lt;#=fk.OtherClass #&gt; &lt;#=secondPropName #&gt;
  {
    get
    {
      var repo=&lt;#=Namespace #&gt;.&lt;#=fk.OtherClass#&gt;.GetRepo();
      return repo.GetByKey(_&lt;#=CleanUp(fk.ThisColumn)#&gt;);
    }
  }

&lt;#
 }
 }
#&gt;
 #endregion
</pre>
<p>Now I can use the linked object directly !</p>
<p>You can donwload my T4 templates <a href="http://www.sambeauvois.be/Demos/SubSonic/FKasSingleObject/20100615ActiveRecord.zip" target="_blank">here</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.sambeauvois.be/blog/2010/06/i-want-my-foreign-key-to-be-mapped-to-a-single-object-and-not-a-collection/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Subsonic : Specify the tables you really need !</title>
		<link>http://www.sambeauvois.be/blog/2010/06/subsonic-specify-the-tables-you-really-need/</link>
		<comments>http://www.sambeauvois.be/blog/2010/06/subsonic-specify-the-tables-you-really-need/#comments</comments>
		<pubDate>Mon, 14 Jun 2010 13:11:02 +0000</pubDate>
		<dc:creator>Sam Beauvois</dc:creator>
				<category><![CDATA[SubSonic]]></category>
		<category><![CDATA[Code generation]]></category>
		<category><![CDATA[T4]]></category>

		<guid isPermaLink="false">http://www.sambeauvois.be/blog/?p=435</guid>
		<description><![CDATA[With the Subsonic&#8217;s T4 Templates you can specify the tables you don&#8217;t want the access code to be generated.
But what if you want to choose the tables for which the mapping classes will be created ?
Actually you can have many reasons to do that : having an application using only specific tables from a big [...]]]></description>
			<content:encoded><![CDATA[<p>With the Subsonic&#8217;s T4 Templates you can specify the tables you don&#8217;t want the access code to be generated.</p>
<p>But what if you want to choose the tables for which the mapping classes will be created ?</p>
<p>Actually you can have many reasons to do that : having an application using only specific tables from a big system or having the ability to separate distinct parts of a system by example.</p>
<p>In my case I wanted to use only three tables from my database to build an ASP.NET membership provider. This is the example I&#8217;ll use for this article.</p>
<p style="text-align: left;">So, in my database I have at least three tables :</p>
<ul>
<li>Users</li>
<li>Roles</li>
<li>UsersInRoles</li>
</ul>
<p>Now I want to generate the DAL layer only for these tables, so I create a new code library project, a add an app.config file containing the connection string and add the Subsonic.Core reference.</p>
<p>The I have to add my T4 template, but they are not ready. I have to modify them to allow the selection of my tables.</p>
<p>To do that, I go to the T4 template directory and edit the &#8220;Settings.ttinclude&#8221; and the &#8220;Context.tt&#8221; files :</p>
<p style="text-align: left;"><a href="http://www.sambeauvois.be/blog/wp-content/uploads/2010/06/T4TemplatesDirectory.png"><img class="aligncenter size-medium wp-image-442" title="T4TemplatesDirectory" src="http://www.sambeauvois.be/blog/wp-content/uploads/2010/06/T4TemplatesDirectory-480x249.png" alt="T4TemplatesDirectory" width="480" height="249" /></a></p>
<p>First, check how it works</p>
<p>In the &#8220;Settings.ttinclude&#8221; file, line #30 we see the definition of the tables to be excluded:</p>
<pre class="brush: csharp;">

//this is a list of tables you don't want generated
string[] ExcludeTables = new string[]{
&quot;sysdiagrams&quot;,
&quot;BuildVersion&quot;
};
</pre>
<p>In the &#8220;Context.tt&#8221; file, il we search for &#8220;ExcludeTables&#8221;, we find three part of code using it in the same way:</p>
<pre class="brush: csharp;">
// line 135

&lt;#  foreach(Table tbl in tables){
if(!ExcludeTables.Contains(tbl.Name))
{

// ...

// line 251

foreach(Table tbl in tables)
{
if(!ExcludeTables.Contains(tbl.Name))
{

// ...

// line 271

foreach(Table tbl in tables)
{
if(!ExcludeTables.Contains(tbl.Name))
{

// ....
</pre>
<p>Now that we know how it&#8217;s working, we can modify the T4 templates to add the ability to choose the tables we want</p>
<p>The simplest option would be to replace the &#8220;ExcludeTables&#8221; array by &#8220;IncludeTables&#8221; and to remove the logical NOT operator (!) in the conditions and the job will be done.</p>
<p>But if we think a bit, we realize that there is many ways to choose the tables we want.<br />
We can decide to choose :</p>
<ul>
<li>All tables</li>
<li>All tables except the specified ones</li>
<li>Only the specified tables</li>
<li>All tables matching a pattern (example : starting by &#8220;MyApplication_&#8221;)</li>
<li>An other choice method</li>
</ul>
<h3>My solution :</h3>
<h4>In the &#8220;Settings.ttinclude&#8221; file:</h4>
<p>Add a string array named &#8220;IncludeTables&#8221; containing the tables you want :</p>
<pre class="brush: csharp;">

// this is the list of the tables you want to be generated
string[] IncludeTables = new string[]{
&quot;Users&quot;,
&quot;Roles&quot;,
&quot;UsersInRoles&quot;
};
</pre>
<p>Add a string variable named TablePrefix</p>
<pre class="brush: csharp;">
 // the prefix of the table you want to be generated
 string TablePrefix=&quot;&quot;;
</pre>
<p>Add an enumeration named &#8220;TableChoiceMethod&#8221; and containing the different ways to choose the tables:</p>
<pre class="brush: csharp;">

enum TableChoiceMethod
 {
SpecifiedExcludes,
SpecifiedIncludes,
SpecifiedPrefix,
All
 }
</pre>
<p>Add a variable for this enum, set to the value you want</p>
<pre class="brush: csharp;">

// define the table choice method
 TableChoiceMethod tableChoiceMethod = TableChoiceMethod.SpecifiedIncludes;
</pre>
<p>Create  a &#8220;“IsTableOkToBeIncluded&#8221; method taking care of the choice we made in the activerecord file and returning whether or not the table is ok to be generated.</p>
<pre class="brush: csharp;">

bool IsTableOkToBeIncluded(string tableName)
{
 switch(tableChoiceMethod)
 {
  case TableChoiceMethod.SpecifiedIncludes:
  {
   return IncludeTables.Contains(tableName);
  }
  case TableChoiceMethod.SpecifiedExcludes:
  {
   return !ExcludeTables.Contains(tableName);
  }
  case TableChoiceMethod.SpecifiedPrefix:
  {
  return tableName.StartsWith(TablePrefix, StringComparison.InvariantCultureIgnoreCase);
  }
  default: // assume TableChoiceMethod.All
  {
   return true;
  }
 }
}
</pre>
<h4>In the Context.tt, ActiveRecord.tt and Struct.tt files :</h4>
<p>Replace the condition&#8221;if(!ExcludeTables.Contains(tbl.Name))&#8221; by this method</p>
<pre class="brush: csharp;">

&lt;#  foreach(Table tbl in tables){
if(IsTableOkToBeIncluded(tbl.Name))
{

// ...
</pre>
<p>Now specify the Namespace, ConnectionStringName and DatabaseName in the Settings.ttinclude file.</p>
<p>Add the template to your DAL project,</p>
<p>Generate</p>
<p>You are done !</p>
<p>You can download my templates <a href="http://www.sambeauvois.be/Demos/SubSonic/ChooseTables/20100614ActiveRecord.zip" target="_blank">here</a>.</p>
<h4>Remarks :</h4>
<ul>
<li>The Subsonic version I use is 3.0.0.4.</li>
<li>I&#8217;m running Windows 7 64 bits and I had  unblock the files in windows explorer.</li>
<li>I had to run Visual Studio as an administrator.</li>
<li>If you are not familiar with subsonic, I invite you to watch the <a href="http://subsonicproject.com/docs/The_5_Minute_Demo" target="_blank" onclick="pageTracker._trackPageview('/outgoing/subsonicproject.com/docs/The_5_Minute_Demo?referer=');">5 minute demo</a> and read the <a href="http://subsonicproject.com/docs/Using_ActiveRecord" target="_blank" onclick="pageTracker._trackPageview('/outgoing/subsonicproject.com/docs/Using_ActiveRecord?referer=');">startup  tutorial</a> from the <a href="http://subsonicproject.com/" target="_blank" onclick="pageTracker._trackPageview('/outgoing/subsonicproject.com/?referer=');">subsonicproject </a>website.</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://www.sambeauvois.be/blog/2010/06/subsonic-specify-the-tables-you-really-need/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>How to set two background images for an HTML page ?</title>
		<link>http://www.sambeauvois.be/blog/2010/06/how-to-set-two-background-images-for-an-html-page/</link>
		<comments>http://www.sambeauvois.be/blog/2010/06/how-to-set-two-background-images-for-an-html-page/#comments</comments>
		<pubDate>Mon, 07 Jun 2010 07:50:26 +0000</pubDate>
		<dc:creator>Sam Beauvois</dc:creator>
				<category><![CDATA[CSS]]></category>
		<category><![CDATA[Tips and Tricks]]></category>
		<category><![CDATA[Web design]]></category>
		<category><![CDATA[HowTo]]></category>
		<category><![CDATA[HTML]]></category>
		<category><![CDATA[Images]]></category>

		<guid isPermaLink="false">http://www.sambeauvois.be/blog/?p=414</guid>
		<description><![CDATA[The other day I was wondering how could I set two background images for an HTML page and I came with one solution.
I don&#8217;t know if it&#8217;s the best way to do that but it worked as I wanted.
To explain the solution, here is the complete steps I made
First I had an HTML page without [...]]]></description>
			<content:encoded><![CDATA[<p>The other day I was wondering how could I set two background images for an HTML page and I came with one solution.<br />
I don&#8217;t know if it&#8217;s the best way to do that but it worked as I wanted.</p>
<p>To explain the solution, here is the complete steps I made</p>
<p>First I had an HTML page without any background:</p>
<p style="text-align: center;"><a href="http://www.sambeauvois.be/blog/wp-content/uploads/2010/06/Beach_withoutBackground1.jpg" target="_blank"><img class="aligncenter size-medium wp-image-420" title="Beach_withoutBackground" src="http://www.sambeauvois.be/blog/wp-content/uploads/2010/06/Beach_withoutBackground1-480x263.jpg" alt="Beach_withoutBackground" width="480" height="263" /></a></p>
<p>Then I added some CSS to set a background image :</p>
<p style="text-align: center;"><a href="http://www.sambeauvois.be/blog/wp-content/uploads/2010/06/bg.gif" target="_blank"><img class="aligncenter size-medium wp-image-421" title="bg" src="http://www.sambeauvois.be/blog/wp-content/uploads/2010/06/bg-480x385.gif" alt="bg" width="480" height="385" /></a></p>
<pre class="brush: css;">
body
{
   background:url(&quot;img/bg.gif&quot;) no-repeat fixed left top #9AE4E8;
}
</pre>
<p style="text-align: left;">The result was good :<br />
<a href="http://www.sambeauvois.be/blog/wp-content/uploads/2010/06/Beach_OneBackground.jpg" target="_blank"><img class="aligncenter size-medium wp-image-422" title="Beach_OneBackground" src="http://www.sambeauvois.be/blog/wp-content/uploads/2010/06/Beach_OneBackground-480x266.jpg" alt="Beach_OneBackground" width="480" height="266" /></a><br />
But I wanted to add a second background image on the right bottom :<br />
<a href="http://www.sambeauvois.be/blog/wp-content/uploads/2010/06/logobeachrahier_medium.png" target="_blank"><img class="aligncenter size-medium wp-image-423" title="logobeachrahier_medium" src="http://www.sambeauvois.be/blog/wp-content/uploads/2010/06/logobeachrahier_medium-480x580.png" alt="logobeachrahier_medium" width="480" height="580" /></a><br />
So I moved my background declaration for the head part of the html file</p>
<pre class="brush: css;">
html
{
 background:url(&quot;img/bg.gif&quot;) no-repeat fixed left top #9AE4E8;
}
</pre>
<p>and I added an other background declaration for the body part</p>
<pre class="brush: css;">
body
{
 background:url(&quot;img/logobeachrahier_medium.png&quot;) no-repeat fixed right bottom ;
}
</pre>
<p>The background declared for the body is applied over the html one:</p>
<p style="text-align: left;"><a href="http://www.sambeauvois.be/blog/wp-content/uploads/2010/06/Beach_TwoBackground.jpg" target="_blank"><img class="aligncenter size-medium wp-image-424" title="Beach_TwoBackground" src="http://www.sambeauvois.be/blog/wp-content/uploads/2010/06/Beach_TwoBackground-480x264.jpg" alt="Beach_TwoBackground" width="480" height="264" /></a><br />
I think it&#8217;s Pretty good now.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.sambeauvois.be/blog/2010/06/how-to-set-two-background-images-for-an-html-page/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Debugging ADO.NET Datatables</title>
		<link>http://www.sambeauvois.be/blog/2010/05/debugging-ado-net-datatables/</link>
		<comments>http://www.sambeauvois.be/blog/2010/05/debugging-ado-net-datatables/#comments</comments>
		<pubDate>Fri, 14 May 2010 13:32:54 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[ADO.NET]]></category>
		<category><![CDATA[Debug]]></category>
		<category><![CDATA[Development]]></category>

		<guid isPermaLink="false">http://www.sambeauvois.be/blog/?p=246</guid>
		<description><![CDATA[Do you ever had the famous error message :
&#8220;Failed to enable constraints. One or more rows  contain values violating non-null, unique, or foreign-key  constraints.&#8221;
when using ADO.NET Datasets ?
Tthis is an incredibly useful message isn&#8217;t it ?
So what can you do to spare you some headaches ? Retrieve a more useful message sure !
You have to [...]]]></description>
			<content:encoded><![CDATA[<p>Do you ever had the famous error message :</p>
<blockquote><p>&#8220;Failed to enable constraints. One or more rows  contain values violating non-null, unique, or foreign-key  constraints.&#8221;</p></blockquote>
<p>when using ADO.NET Datasets ?</p>
<p>Tthis is an incredibly useful message isn&#8217;t it ?</p>
<p>So what can you do to spare you some headaches ? Retrieve a more useful message sure !</p>
<p>You have to know that a Datatable object have a &#8220;HasError&#8221; property, this property allows you to know if the datatable has one ore more rows in error.</p>
<p>When HasError is true, you can retrieve the rows havin an error with the DataTable&#8217;s &#8220;GetErrors()&#8221; method wich return an array with all datarow having an error.</p>
<p>The &#8220;in errror&#8221; rows can inform you about errors with the &#8220;RowError&#8221; property.</p>
<p>Here is a simple helper class which can be used to debug a single DataTable or an entire DataSet:</p>
<pre class="brush: csharp;">
using System;
using System.Data;

public class DataSetErrorRevealer
{

   /// &lt;summary&gt;
   /// Get errors on rows of a DataTable
   /// &lt;/summary&gt;
   /// &lt;param name=&quot;errorDataTable&quot;&gt;The DataTable to be checked&lt;/param&gt;
   public static void RevealTableErrors(DataTable errorDataTable)
   {
      if (errorDataTable == null)
      {
         Console.WriteLine(&quot;The provided DataTable object is null&quot;);
         return;
      }

      if (errorDataTable.HasErrors)
      {
         DataRow[] rowsInError = errorDataTable.GetErrors();
         if (rowsInError.Length &lt;= 0)
         {
            Console.WriteLine(&quot;There is no problem with table {0}&quot;, errorDataTable.TableName);
         }
         else
         {
            foreach (DataRow errorRow in rowsInError)
            {
               Console.WriteLine(errorRow.RowError);
            }
         }
      }
   }

   /// &lt;summary&gt;
   /// Get errors on row for all tables of a DataSet
   /// &lt;/summary&gt;
   /// &lt;param name=&quot;errorDataSet&quot;&gt;The Dataset to be checked&lt;/param&gt;
   public static void RevealDataSetErrors(DataSet errorDataSet)
   {
         if (errorDataSet == null)
         {
            Console.WriteLine(&quot;The provided DataSet is null&quot;);
            return;
         }

         foreach (DataTable errorTable in errorDataSet.Tables)
         {
            RevealTableErrors(errorTable);
         }
      }
   }
</pre>
<p>Use it this way :</p>
<pre class="brush: csharp;">

   TestDataSet dataset = new TestDataSet();
   try
   {
      using (SqlConnection sqlCon = new SqlConnection(&quot;MyConnectionString&quot;))
      {
         SqlCommand sqlComm = sqlCon.CreateCommand();
         sqlComm.CommandType = CommandType.StoredProcedure;
         sqlComm.CommandText = &quot;Select Stored procedure&quot;;
         SqlDataAdapter sqlDa = new SqlDataAdapter(sqlComm);
         sqlDa.Fill(dataset);
      }
   }
   catch (Exception ex)
   {
   // Will provide the error message :
   // &quot;Failed to enable constraints. One or more rows
   // contain values violating non-null, unique,
   // or foreign-key  constraints.&quot;
   Console.WriteLine(&quot;Error : {0}&quot;, ex);

   // will provide a more helpful message
   DataSetErrorRevealer.RevealDataSetErrors(dataset);
   }
</pre>
<p>If you prefer, you can use an extension method :</p>
<pre class="brush: csharp;">

using System.Data;
using System;

public static class DataSetExtensions
{
   public static void RevealErrors(this DataSet errorDataSet)
   {
      if (errorDataSet == null)
      {
         Console.WriteLine(&quot;The provided DataSet is null&quot;);
         return;
      }

      foreach (DataTable errorTable in errorDataSet.Tables)
      {
         errorTable.RevealErrors();
      }
   }

   public static void RevealErrors(this DataTable errorDataTable)
   {
      if (errorDataTable == null)
      {
         Console.WriteLine(&quot;The provided DataTable object is null&quot;);
         return;
      }

      if (errorDataTable.HasErrors)
      {
         DataRow[] rowsInError = errorDataTable.GetErrors();
         if (rowsInError.Length &lt;= 0)
         {
            Console.WriteLine(&quot;There is no problem with table {0}&quot;, errorDataTable.TableName);
         }
         else
         {
            foreach (DataRow errorRow in rowsInError)
            {
               Console.WriteLine(errorRow.RowError);
            }
         }
      }
   }
}
</pre>
<p>use :</p>
<pre class="brush: csharp;">

catch (Exception ex)
{
   // will provide an helpful message
   dataset.RevealErrors();
}
</pre>
<p>Hope this helps !</p>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 211px; width: 1px; height: 1px; overflow: hidden;">using System;<br />
using System.Data;public class DataSetErrorRevealer<br />
{</p>
<p>/// &lt;summary&gt;<br />
/// Get errors on rows of a DataTable<br />
/// &lt;/summary&gt;<br />
/// &lt;param name=&#8221;errorDataTable&#8221;&gt;The DataTable to be checked&lt;/param&gt;<br />
public static void RevealTableErrors(DataTable errorDataTable)<br />
{<br />
if (errorDataTable == null)<br />
{<br />
Console.WriteLine(&#8221;The provided DataTable object is null&#8221;);<br />
return;<br />
}</p>
<p>if (errorDataTable.HasErrors)<br />
{<br />
DataRow[] rowsInError = errorDataTable.GetErrors();<br />
if (rowsInError.Length &lt;= 0)<br />
{<br />
Console.WriteLine(&#8221;There is no problem with table {0}&#8221;, errorDataTable.TableName);<br />
}<br />
else<br />
{<br />
foreach (DataRow errorRow in rowsInError)<br />
{<br />
Console.WriteLine(errorRow.RowError);<br />
}<br />
}<br />
}<br />
}</p>
<p>/// &lt;summary&gt;<br />
/// Get errors on row for all tables of a DataSet<br />
/// &lt;/summary&gt;<br />
/// &lt;param name=&#8221;errorDataSet&#8221;&gt;The Dataset to be checked&lt;/param&gt;<br />
public static void RevealDataSetErrors(DataSet errorDataSet)<br />
{<br />
if (errorDataSet == null)<br />
{<br />
Console.WriteLine(&#8221;The provided DataSet is null&#8221;);<br />
return;<br />
}</p>
<p>foreach (DataTable errorTable in errorDataSet.Tables)<br />
{<br />
RevealTableErrors(errorTable);<br />
}<br />
}<br />
}</p>
</div>
]]></content:encoded>
			<wfw:commentRss>http://www.sambeauvois.be/blog/2010/05/debugging-ado-net-datatables/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>FreeImage and x64 projects : Yes you can !</title>
		<link>http://www.sambeauvois.be/blog/2010/05/freeimage-and-x64-projects-yes-you-can/</link>
		<comments>http://www.sambeauvois.be/blog/2010/05/freeimage-and-x64-projects-yes-you-can/#comments</comments>
		<pubDate>Fri, 14 May 2010 07:02:23 +0000</pubDate>
		<dc:creator>Sam Beauvois</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[CPP]]></category>
		<category><![CDATA[Libs]]></category>

		<guid isPermaLink="false">http://www.sambeauvois.be/blog/2010/05/freeimage-and-x64-projects-yes-you-can/</guid>
		<description><![CDATA[A few words about FreeImage
According to the website, FreeImage (http://freeimage.sourceforge.net) is an Open Source library project for developers who would like to support popular graphics image formats like PNG, BMP, JPEG, TIFF and others as needed by today&#8217;s multimedia applications.
FreeImage is easy to use, fast, multithreading safe, compatible with all 32-bit versions of Windows, and [...]]]></description>
			<content:encoded><![CDATA[<h3>A few words about FreeImage</h3>
<p>According to the website, FreeImage (<a href="http://freeimage.sourceforge.net" target="_blank" onclick="pageTracker._trackPageview('/outgoing/freeimage.sourceforge.net?referer=');">http://freeimage.sourceforge.net</a>) is an Open Source library project for developers who would like to support popular graphics image formats like PNG, BMP, JPEG, TIFF and others as needed by today&#8217;s multimedia applications.</p>
<p>FreeImage is easy to use, fast, multithreading safe, compatible with all <strong><span style="color: #ff0000; font-size: medium;">32-bit</span></strong> versions of Windows, and cross-platform (works both with Linux and Mac OS X).</p>
<p>FreeImage is written in C++ but can be used in .NET by using a wrapper (which is provided on the site in the download section)</p>
<h3>Using FreeImage in a .NET project</h3>
<p>To use FreeImage with a .NET project, you have to include the native C++ library (<span style="text-decoration: underline;"><strong>FreeImage.dll</strong></span>) in the same folder as the executable or in a folder contained in the PATH variable (“%WINDIR%\System32” can be a good choice).<br />
A good way to include the FreeImage dll in the executable’s folder is to add it to your visual studio projet, and set the Build Action property to “none” and the Copy to Output Directory property to “Copy always”</p>
<p><a href="http://www.sambeauvois.be/blog/wp-content/uploads/2010/05/image.png" target="_blank"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" src="http://www.sambeauvois.be/blog/wp-content/uploads/2010/05/image_thumb.png" border="0" alt="image" width="484" height="216" /></a></p>
<p>You have to add a reference to the wrapper library too, which is “<strong>FreeImageNET.dll</strong>”.</p>
<p>Now, using the library is easy.</p>
<p>Add an using directive:</p>
<pre class="brush: csharp;">using FreeImageAPI;</pre>
<p>Check if the library is available :</p>
<pre class="brush: csharp;">
if (!FreeImage.IsAvailable())
{
   Console.WriteLine(&quot;FreeImage.dll seems to be missing. Aborting&quot;);
   return;
}
</pre>
<p>Do something with your pictures:</p>
<pre class="brush: csharp;">

FIBITMAP myImage= new FIBITMAP();
myImage= FreeImage.Load( [parameters] );

// some smart actions
</pre>
<p>Don’t forget to dispose your images when finished to use them</p>
<pre class="brush: csharp;">
if (!myImage.IsNull
{
   FreeImage.Unload(myImage);
}
myImage.SetNull();
</pre>
<p>Well, this is nice but it still has a problem with that library (there is always one):</p>
<h3>And with a x64 project ?</h3>
<p>The executable you build has to be the same architecture as the library. The library is x86 so you can use it for win32 applications. What if you have (for some reasons) to build an x64 application?</p>
<p>In that case, you have to rebuild the library to target X64 architectures.</p>
<p>Here is how to do that with Visual Studio 2010 (I assume that it’s more or less the same procedure with other visual studio versions).</p>
<p>Grab the latest FreeImage sources on  the download site (go to the <a href="http://freeimage.sourceforge.net/download.html" target="_blank" onclick="pageTracker._trackPageview('/outgoing/freeimage.sourceforge.net/download.html?referer=');">http://freeimage.sourceforge.net/download.html</a> page and click to the link in the Source Distribution section. Once you have the sources, unzip the archive (obvious but&#8230;)</p>
<p>In the FreeImage folder there is a visual studio 2005 and a visual studio 2003 solutions, pick the 2005.</p>
<p><a href="http://www.sambeauvois.be/blog/wp-content/uploads/2010/05/image1.png" target="_blank"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" src="http://www.sambeauvois.be/blog/wp-content/uploads/2010/05/image_thumb1.png" border="0" alt="image" width="484" height="337" /></a></p>
<p>Convert the solution</p>
<p><a href="http://www.sambeauvois.be/blog/wp-content/uploads/2010/05/image2.png" target="_blank"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" src="http://www.sambeauvois.be/blog/wp-content/uploads/2010/05/image_thumb2.png" border="0" alt="image" width="484" height="465" /></a><br />
<a href="http://www.sambeauvois.be/blog/wp-content/uploads/2010/05/image3.png" target="_blank"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" src="http://www.sambeauvois.be/blog/wp-content/uploads/2010/05/image_thumb3.png" border="0" alt="image" width="484" height="465" /></a><br />
<a href="http://www.sambeauvois.be/blog/wp-content/uploads/2010/05/image4.png" target="_blank"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" src="http://www.sambeauvois.be/blog/wp-content/uploads/2010/05/image_thumb4.png" border="0" alt="image" width="484" height="465" /></a><br />
<a href="http://www.sambeauvois.be/blog/wp-content/uploads/2010/05/image5.png" target="_blank"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" src="http://www.sambeauvois.be/blog/wp-content/uploads/2010/05/image_thumb5.png" border="0" alt="image" width="484" height="465" /></a><br />
<a href="http://www.sambeauvois.be/blog/wp-content/uploads/2010/05/image6.png" target="_blank"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" src="http://www.sambeauvois.be/blog/wp-content/uploads/2010/05/image_thumb6.png" border="0" alt="image" width="484" height="290" /></a></p>
<p>Notice the compilation configuration</p>
<p><a href="http://www.sambeauvois.be/blog/wp-content/uploads/2010/05/image7.png" target="_blank"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" src="http://www.sambeauvois.be/blog/wp-content/uploads/2010/05/image_thumb7.png" border="0" alt="image" width="484" height="68" /></a></p>
<p>By default, Win32 is set : we don’t want that !</p>
<p>Go to the Configuration Manager</p>
<p><a href="http://www.sambeauvois.be/blog/wp-content/uploads/2010/05/image8.png" target="_blank"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" src="http://www.sambeauvois.be/blog/wp-content/uploads/2010/05/image_thumb8.png" border="0" alt="image" width="484" height="124" /></a><br />
<a href="http://www.sambeauvois.be/blog/wp-content/uploads/2010/05/image9.png" target="_blank"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" src="http://www.sambeauvois.be/blog/wp-content/uploads/2010/05/image_thumb9.png" border="0" alt="image" width="484" height="352" /></a></p>
<p>As you can see, all FreeImage libs are set to target the Win32 platform, we want 64 bits !</p>
<p>Add a new solution platform</p>
<p><a href="http://www.sambeauvois.be/blog/wp-content/uploads/2010/05/image10.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" src="http://www.sambeauvois.be/blog/wp-content/uploads/2010/05/image_thumb10.png" border="0" alt="image" width="484" height="352" /></a></p>
<p>Choose to target the x64 platform</p>
<p><a href="http://www.sambeauvois.be/blog/wp-content/uploads/2010/05/image11.png" target="_blank"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" src="http://www.sambeauvois.be/blog/wp-content/uploads/2010/05/image_thumb11.png" border="0" alt="image" width="484" height="363" /></a></p>
<p>Just select x64 then click OK</p>
<p><a href="http://www.sambeauvois.be/blog/wp-content/uploads/2010/05/image12.png" target="_blank"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" src="http://www.sambeauvois.be/blog/wp-content/uploads/2010/05/image_thumb12.png" border="0" alt="image" width="484" height="352" /></a></p>
<p>Close the manager</p>
<p>Build the solution (keyboard shortcut : ctrl-shift-B).</p>
<p><a href="http://www.sambeauvois.be/blog/wp-content/uploads/2010/05/image13.png" target="_blank"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" src="http://www.sambeauvois.be/blog/wp-content/uploads/2010/05/image_thumb13.png" border="0" alt="image" width="484" height="176" /></a></p>
<p>And at this point you will see that there is a problem, yes, you don’t really think it would be that easy <img src='http://www.sambeauvois.be/blog/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' /> </p>
<p><a href="http://www.sambeauvois.be/blog/wp-content/uploads/2010/05/image14.png" target="_blank"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" src="http://www.sambeauvois.be/blog/wp-content/uploads/2010/05/image_thumb14.png" border="0" alt="image" width="484" height="103" /></a></p>
<p>It seems that the compilation encounters a problem especially with the “LibOpenJpeg” project</p>
<p>So, to be sure, try to compile the library one at the same time</p>
<p><a href="http://www.sambeauvois.be/blog/wp-content/uploads/2010/05/image15.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" src="http://www.sambeauvois.be/blog/wp-content/uploads/2010/05/image_thumb15.png" border="0" alt="image" width="437" height="484" /></a></p>
<p>We see that it is the LibOpenJPEG the big source of problems :</p>
<p><a href="http://www.sambeauvois.be/blog/wp-content/uploads/2010/05/image16.png" target="_blank"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" src="http://www.sambeauvois.be/blog/wp-content/uploads/2010/05/image_thumb16.png" border="0" alt="image" width="484" height="95" /></a></p>
<p>A quick Google search allows to find a post on the Google user group for OpenJPEG that helps:<br />
<a href="http://groups.google.com/group/openjpeg/browse_thread/thread/64b89cdb1a44bb3b/fd4db2f74c76db87?lnk=gst&amp;q=x64#fd4db2f74c76db87" target="_blank" onclick="pageTracker._trackPageview('/outgoing/groups.google.com/group/openjpeg/browse_thread/thread/64b89cdb1a44bb3b/fd4db2f74c76db87?lnk=gst_amp_q=x64_fd4db2f74c76db87&amp;referer=');">http://groups.google.com/group/openjpeg/browse_thread/thread/64b89cdb1a44bb3b/fd4db2f74c76db87?lnk=gst&amp;q=x64#fd4db2f74c76db87</a></p>
<p>The problematic file is the “opj_include.h” wich use a keyword non supported by the x64 architecture (the &#8220;_asm” keyword if you want to know. It’s because the c++ compiler does not support inline x64 assembly)</p>
<p><a href="http://www.sambeauvois.be/blog/wp-content/uploads/2010/05/image17.png" target="_blank"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" src="http://www.sambeauvois.be/blog/wp-content/uploads/2010/05/image_thumb17.png" border="0" alt="image" width="170" height="484" /></a></p>
<p>We have to change :</p>
<pre class="brush: cpp;">
/* MSVC does not have lrintf */
#ifdef _MSC_VER
static INLINE long lrintf(float f){
 int i;

 _asm{
 fld f
 fistp i
 };

 return i;
}
#endif
</pre>
<p>to</p>
<pre class="brush: cpp;">
/* MSVC does not have lrintf */
#ifdef _MSC_VER
static INLINE long lrintf(float f){
#ifdef _M_X64
	return (long)((f&gt;0.0f) ? (f + 0.5f):(f -0.5f));
#else
	int i;

	_asm{
		fld f
		fistp i
	};

	return i;
#endif
}
#endif
</pre>
<p>Now compile</p>
<p><a href="http://www.sambeauvois.be/blog/wp-content/uploads/2010/05/image18.png" target="_blank"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" src="http://www.sambeauvois.be/blog/wp-content/uploads/2010/05/image_thumb18.png" border="0" alt="image" width="484" height="385" /></a></p>
<p>The project compiles pretty well, there is some remaining warnings . . . but it works.</p>
<p>Now you can use that library (mine can be downloaded at  <a href="http://www.sambeauvois.be/Demos/FreeImage/x64/FreeImageX64.zip" target="_blank">http://www.sambeauvois.be/Demos/FreeImage/x64/FreeImageX64.zip</a>) in your x64 applications</p>
<p>Attention anyway : the library will be slower !</p>
<h4>Additional links :</h4>
<p>FreeImage download page : <a title="http://freeimage.sourceforge.net/download.html" href="http://freeimage.sourceforge.net/download.html" target="_blank" onclick="pageTracker._trackPageview('/outgoing/freeimage.sourceforge.net/download.html?referer=');">http://freeimage.sourceforge.net/download.html</a><br />
FreeImage API documentation: <a href="http://freeimage.sourceforge.net/fnet/Index.html" target="_blank" onclick="pageTracker._trackPageview('/outgoing/freeimage.sourceforge.net/fnet/Index.html?referer=');">http://freeimage.sourceforge.net/fnet/Index.html</a></p>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 8091px; width: 1px; height: 1px; overflow: hidden;"><!--[if gte mso 9]><xml> <o:OfficeDocumentSettings> <o:AllowPNG /> </o:OfficeDocumentSettings> </xml><![endif]--><!--[if gte mso 9]><xml> <w:WordDocument> <w:View>Normal</w:View> <w:Zoom>0</w:Zoom> <w:TrackMoves /> <w:TrackFormatting /> <w:HyphenationZone>21</w:HyphenationZone> <w:PunctuationKerning /> <w:ValidateAgainstSchemas /> <w:SaveIfXMLInvalid>false</w:SaveIfXMLInvalid> <w:IgnoreMixedContent>false</w:IgnoreMixedContent> <w:AlwaysShowPlaceholderText>false</w:AlwaysShowPlaceholderText> <w:DoNotPromoteQF /> <w:LidThemeOther>FR-BE</w:LidThemeOther> <w:LidThemeAsian>X-NONE</w:LidThemeAsian> <w:LidThemeComplexScript>X-NONE</w:LidThemeComplexScript> <w:Compatibility> <w:BreakWrappedTables /> <w:SnapToGridInCell /> <w:WrapTextWithPunct /> <w:UseAsianBreakRules /> <w:DontGrowAutofit /> <w:SplitPgBreakAndParaMark /> <w:EnableOpenTypeKerning /> <w:DontFlipMirrorIndents /> <w:OverrideTableStyleHps /> </w:Compatibility> <m:mathPr> <m:mathFont m:val="Cambria Math" /> <m:brkBin m:val="before" /> <m:brkBinSub m:val="&#45;-" /> <m:smallFrac m:val="off" /> <m:dispDef /> <m:lMargin m:val="0" /> <m:rMargin m:val="0" /> <m:defJc m:val="centerGroup" /> <m:wrapIndent m:val="1440" /> <m:intLim m:val="subSup" /> <m:naryLim m:val="undOvr" /> </m:mathPr></w:WordDocument> </xml><![endif]--><!--[if gte mso 9]><xml> <w:LatentStyles DefLockedState="false" DefUnhideWhenUsed="true"   DefSemiHidden="true" DefQFormat="false" DefPriority="99"   LatentStyleCount="267"> <w:LsdException Locked="false" Priority="0" SemiHidden="false"    UnhideWhenUsed="false" QFormat="true" Name="Normal" /> <w:LsdException Locked="false" Priority="9" SemiHidden="false"    UnhideWhenUsed="false" QFormat="true" Name="heading 1" /> <w:LsdException Locked="false" Priority="9" QFormat="true" Name="heading 2" /> <w:LsdException Locked="false" Priority="9" QFormat="true" Name="heading 3" /> <w:LsdException Locked="false" Priority="9" QFormat="true" Name="heading 4" /> <w:LsdException Locked="false" Priority="9" QFormat="true" Name="heading 5" /> <w:LsdException Locked="false" Priority="9" QFormat="true" Name="heading 6" /> <w:LsdException Locked="false" Priority="9" QFormat="true" Name="heading 7" /> <w:LsdException Locked="false" Priority="9" QFormat="true" Name="heading 8" /> <w:LsdException Locked="false" Priority="9" QFormat="true" Name="heading 9" /> <w:LsdException Locked="false" Priority="39" Name="toc 1" /> <w:LsdException Locked="false" Priority="39" Name="toc 2" /> <w:LsdException Locked="false" Priority="39" Name="toc 3" /> <w:LsdException Locked="false" Priority="39" Name="toc 4" /> <w:LsdException Locked="false" Priority="39" Name="toc 5" /> <w:LsdException Locked="false" Priority="39" Name="toc 6" /> <w:LsdException Locked="false" Priority="39" Name="toc 7" /> <w:LsdException Locked="false" Priority="39" Name="toc 8" /> <w:LsdException Locked="false" Priority="39" Name="toc 9" /> <w:LsdException Locked="false" Priority="35" QFormat="true" Name="caption" /> <w:LsdException Locked="false" Priority="10" SemiHidden="false"    UnhideWhenUsed="false" QFormat="true" Name="Title" /> <w:LsdException Locked="false" Priority="1" Name="Default Paragraph Font" /> <w:LsdException Locked="false" Priority="11" SemiHidden="false"    UnhideWhenUsed="false" QFormat="true" Name="Subtitle" /> <w:LsdException Locked="false" Priority="22" SemiHidden="false"    UnhideWhenUsed="false" QFormat="true" Name="Strong" /> <w:LsdException Locked="false" Priority="20" SemiHidden="false"    UnhideWhenUsed="false" QFormat="true" Name="Emphasis" /> <w:LsdException Locked="false" Priority="59" SemiHidden="false"    UnhideWhenUsed="false" Name="Table Grid" /> <w:LsdException Locked="false" UnhideWhenUsed="false" Name="Placeholder Text" /> <w:LsdException Locked="false" Priority="1" SemiHidden="false"    UnhideWhenUsed="false" QFormat="true" Name="No Spacing" /> <w:LsdException Locked="false" Priority="60" SemiHidden="false"    UnhideWhenUsed="false" Name="Light Shading" /> <w:LsdException Locked="false" Priority="61" SemiHidden="false"    UnhideWhenUsed="false" Name="Light List" /> <w:LsdException Locked="false" Priority="62" SemiHidden="false"    UnhideWhenUsed="false" Name="Light Grid" /> <w:LsdException Locked="false" Priority="63" SemiHidden="false"    UnhideWhenUsed="false" Name="Medium Shading 1" /> <w:LsdException Locked="false" Priority="64" SemiHidden="false"    UnhideWhenUsed="false" Name="Medium Shading 2" /> <w:LsdException Locked="false" Priority="65" SemiHidden="false"    UnhideWhenUsed="false" Name="Medium List 1" /> <w:LsdException Locked="false" Priority="66" SemiHidden="false"    UnhideWhenUsed="false" Name="Medium List 2" /> <w:LsdException Locked="false" Priority="67" SemiHidden="false"    UnhideWhenUsed="false" Name="Medium Grid 1" /> <w:LsdException Locked="false" Priority="68" SemiHidden="false"    UnhideWhenUsed="false" Name="Medium Grid 2" /> <w:LsdException Locked="false" Priority="69" SemiHidden="false"    UnhideWhenUsed="false" Name="Medium Grid 3" /> <w:LsdException Locked="false" Priority="70" SemiHidden="false"    UnhideWhenUsed="false" Name="Dark List" /> <w:LsdException Locked="false" Priority="71" SemiHidden="false"    UnhideWhenUsed="false" Name="Colorful Shading" /> <w:LsdException Locked="false" Priority="72" SemiHidden="false"    UnhideWhenUsed="false" Name="Colorful List" /> <w:LsdException Locked="false" Priority="73" SemiHidden="false"    UnhideWhenUsed="false" Name="Colorful Grid" /> <w:LsdException Locked="false" Priority="60" SemiHidden="false"    UnhideWhenUsed="false" Name="Light Shading Accent 1" /> <w:LsdException Locked="false" Priority="61" SemiHidden="false"    UnhideWhenUsed="false" Name="Light List Accent 1" /> <w:LsdException Locked="false" Priority="62" SemiHidden="false"    UnhideWhenUsed="false" Name="Light Grid Accent 1" /> <w:LsdException Locked="false" Priority="63" SemiHidden="false"    UnhideWhenUsed="false" Name="Medium Shading 1 Accent 1" /> <w:LsdException Locked="false" Priority="64" SemiHidden="false"    UnhideWhenUsed="false" Name="Medium Shading 2 Accent 1" /> <w:LsdException Locked="false" Priority="65" SemiHidden="false"    UnhideWhenUsed="false" Name="Medium List 1 Accent 1" /> <w:LsdException Locked="false" UnhideWhenUsed="false" Name="Revision" /> <w:LsdException Locked="false" Priority="34" SemiHidden="false"    UnhideWhenUsed="false" QFormat="true" Name="List Paragraph" /> <w:LsdException Locked="false" Priority="29" SemiHidden="false"    UnhideWhenUsed="false" QFormat="true" Name="Quote" /> <w:LsdException Locked="false" Priority="30" SemiHidden="false"    UnhideWhenUsed="false" QFormat="true" Name="Intense Quote" /> <w:LsdException Locked="false" Priority="66" SemiHidden="false"    UnhideWhenUsed="false" Name="Medium List 2 Accent 1" /> <w:LsdException Locked="false" Priority="67" SemiHidden="false"    UnhideWhenUsed="false" Name="Medium Grid 1 Accent 1" /> <w:LsdException Locked="false" Priority="68" SemiHidden="false"    UnhideWhenUsed="false" Name="Medium Grid 2 Accent 1" /> <w:LsdException Locked="false" Priority="69" SemiHidden="false"    UnhideWhenUsed="false" Name="Medium Grid 3 Accent 1" /> <w:LsdException Locked="false" Priority="70" SemiHidden="false"    UnhideWhenUsed="false" Name="Dark List Accent 1" /> <w:LsdException Locked="false" Priority="71" SemiHidden="false"    UnhideWhenUsed="false" Name="Colorful Shading Accent 1" /> <w:LsdException Locked="false" Priority="72" SemiHidden="false"    UnhideWhenUsed="false" Name="Colorful List Accent 1" /> <w:LsdException Locked="false" Priority="73" SemiHidden="false"    UnhideWhenUsed="false" Name="Colorful Grid Accent 1" /> <w:LsdException Locked="false" Priority="60" SemiHidden="false"    UnhideWhenUsed="false" Name="Light Shading Accent 2" /> <w:LsdException Locked="false" Priority="61" SemiHidden="false"    UnhideWhenUsed="false" Name="Light List Accent 2" /> <w:LsdException Locked="false" Priority="62" SemiHidden="false"    UnhideWhenUsed="false" Name="Light Grid Accent 2" /> <w:LsdException Locked="false" Priority="63" SemiHidden="false"    UnhideWhenUsed="false" Name="Medium Shading 1 Accent 2" /> <w:LsdException Locked="false" Priority="64" SemiHidden="false"    UnhideWhenUsed="false" Name="Medium Shading 2 Accent 2" /> <w:LsdException Locked="false" Priority="65" SemiHidden="false"    UnhideWhenUsed="false" Name="Medium List 1 Accent 2" /> <w:LsdException Locked="false" Priority="66" SemiHidden="false"    UnhideWhenUsed="false" Name="Medium List 2 Accent 2" /> <w:LsdException Locked="false" Priority="67" SemiHidden="false"    UnhideWhenUsed="false" Name="Medium Grid 1 Accent 2" /> <w:LsdException Locked="false" Priority="68" SemiHidden="false"    UnhideWhenUsed="false" Name="Medium Grid 2 Accent 2" /> <w:LsdException Locked="false" Priority="69" SemiHidden="false"    UnhideWhenUsed="false" Name="Medium Grid 3 Accent 2" /> <w:LsdException Locked="false" Priority="70" SemiHidden="false"    UnhideWhenUsed="false" Name="Dark List Accent 2" /> <w:LsdException Locked="false" Priority="71" SemiHidden="false"    UnhideWhenUsed="false" Name="Colorful Shading Accent 2" /> <w:LsdException Locked="false" Priority="72" SemiHidden="false"    UnhideWhenUsed="false" Name="Colorful List Accent 2" /> <w:LsdException Locked="false" Priority="73" SemiHidden="false"    UnhideWhenUsed="false" Name="Colorful Grid Accent 2" /> <w:LsdException Locked="false" Priority="60" SemiHidden="false"    UnhideWhenUsed="false" Name="Light Shading Accent 3" /> <w:LsdException Locked="false" Priority="61" SemiHidden="false"    UnhideWhenUsed="false" Name="Light List Accent 3" /> <w:LsdException Locked="false" Priority="62" SemiHidden="false"    UnhideWhenUsed="false" Name="Light Grid Accent 3" /> <w:LsdException Locked="false" Priority="63" SemiHidden="false"    UnhideWhenUsed="false" Name="Medium Shading 1 Accent 3" /> <w:LsdException Locked="false" Priority="64" SemiHidden="false"    UnhideWhenUsed="false" Name="Medium Shading 2 Accent 3" /> <w:LsdException Locked="false" Priority="65" SemiHidden="false"    UnhideWhenUsed="false" Name="Medium List 1 Accent 3" /> <w:LsdException Locked="false" Priority="66" SemiHidden="false"    UnhideWhenUsed="false" Name="Medium List 2 Accent 3" /> <w:LsdException Locked="false" Priority="67" SemiHidden="false"    UnhideWhenUsed="false" Name="Medium Grid 1 Accent 3" /> <w:LsdException Locked="false" Priority="68" SemiHidden="false"    UnhideWhenUsed="false" Name="Medium Grid 2 Accent 3" /> <w:LsdException Locked="false" Priority="69" SemiHidden="false"    UnhideWhenUsed="false" Name="Medium Grid 3 Accent 3" /> <w:LsdException Locked="false" Priority="70" SemiHidden="false"    UnhideWhenUsed="false" Name="Dark List Accent 3" /> <w:LsdException Locked="false" Priority="71" SemiHidden="false"    UnhideWhenUsed="false" Name="Colorful Shading Accent 3" /> <w:LsdException Locked="false" Priority="72" SemiHidden="false"    UnhideWhenUsed="false" Name="Colorful List Accent 3" /> <w:LsdException Locked="false" Priority="73" SemiHidden="false"    UnhideWhenUsed="false" Name="Colorful Grid Accent 3" /> <w:LsdException Locked="false" Priority="60" SemiHidden="false"    UnhideWhenUsed="false" Name="Light Shading Accent 4" /> <w:LsdException Locked="false" Priority="61" SemiHidden="false"    UnhideWhenUsed="false" Name="Light List Accent 4" /> <w:LsdException Locked="false" Priority="62" SemiHidden="false"    UnhideWhenUsed="false" Name="Light Grid Accent 4" /> <w:LsdException Locked="false" Priority="63" SemiHidden="false"    UnhideWhenUsed="false" Name="Medium Shading 1 Accent 4" /> <w:LsdException Locked="false" Priority="64" SemiHidden="false"    UnhideWhenUsed="false" Name="Medium Shading 2 Accent 4" /> <w:LsdException Locked="false" Priority="65" SemiHidden="false"    UnhideWhenUsed="false" Name="Medium List 1 Accent 4" /> <w:LsdException Locked="false" Priority="66" SemiHidden="false"    UnhideWhenUsed="false" Name="Medium List 2 Accent 4" /> <w:LsdException Locked="false" Priority="67" SemiHidden="false"    UnhideWhenUsed="false" Name="Medium Grid 1 Accent 4" /> <w:LsdException Locked="false" Priority="68" SemiHidden="false"    UnhideWhenUsed="false" Name="Medium Grid 2 Accent 4" /> <w:LsdException Locked="false" Priority="69" SemiHidden="false"    UnhideWhenUsed="false" Name="Medium Grid 3 Accent 4" /> <w:LsdException Locked="false" Priority="70" SemiHidden="false"    UnhideWhenUsed="false" Name="Dark List Accent 4" /> <w:LsdException Locked="false" Priority="71" SemiHidden="false"    UnhideWhenUsed="false" Name="Colorful Shading Accent 4" /> <w:LsdException Locked="false" Priority="72" SemiHidden="false"    UnhideWhenUsed="false" Name="Colorful List Accent 4" /> <w:LsdException Locked="false" Priority="73" SemiHidden="false"    UnhideWhenUsed="false" Name="Colorful Grid Accent 4" /> <w:LsdException Locked="false" Priority="60" SemiHidden="false"    UnhideWhenUsed="false" Name="Light Shading Accent 5" /> <w:LsdException Locked="false" Priority="61" SemiHidden="false"    UnhideWhenUsed="false" Name="Light List Accent 5" /> <w:LsdException Locked="false" Priority="62" SemiHidden="false"    UnhideWhenUsed="false" Name="Light Grid Accent 5" /> <w:LsdException Locked="false" Priority="63" SemiHidden="false"    UnhideWhenUsed="false" Name="Medium Shading 1 Accent 5" /> <w:LsdException Locked="false" Priority="64" SemiHidden="false"    UnhideWhenUsed="false" Name="Medium Shading 2 Accent 5" /> <w:LsdException Locked="false" Priority="65" SemiHidden="false"    UnhideWhenUsed="false" Name="Medium List 1 Accent 5" /> <w:LsdException Locked="false" Priority="66" SemiHidden="false"    UnhideWhenUsed="false" Name="Medium List 2 Accent 5" /> <w:LsdException Locked="false" Priority="67" SemiHidden="false"    UnhideWhenUsed="false" Name="Medium Grid 1 Accent 5" /> <w:LsdException Locked="false" Priority="68" SemiHidden="false"    UnhideWhenUsed="false" Name="Medium Grid 2 Accent 5" /> <w:LsdException Locked="false" Priority="69" SemiHidden="false"    UnhideWhenUsed="false" Name="Medium Grid 3 Accent 5" /> <w:LsdException Locked="false" Priority="70" SemiHidden="false"    UnhideWhenUsed="false" Name="Dark List Accent 5" /> <w:LsdException Locked="false" Priority="71" SemiHidden="false"    UnhideWhenUsed="false" Name="Colorful Shading Accent 5" /> <w:LsdException Locked="false" Priority="72" SemiHidden="false"    UnhideWhenUsed="false" Name="Colorful List Accent 5" /> <w:LsdException Locked="false" Priority="73" SemiHidden="false"    UnhideWhenUsed="false" Name="Colorful Grid Accent 5" /> <w:LsdException Locked="false" Priority="60" SemiHidden="false"    UnhideWhenUsed="false" Name="Light Shading Accent 6" /> <w:LsdException Locked="false" Priority="61" SemiHidden="false"    UnhideWhenUsed="false" Name="Light List Accent 6" /> <w:LsdException Locked="false" Priority="62" SemiHidden="false"    UnhideWhenUsed="false" Name="Light Grid Accent 6" /> <w:LsdException Locked="false" Priority="63" SemiHidden="false"    UnhideWhenUsed="false" Name="Medium Shading 1 Accent 6" /> <w:LsdException Locked="false" Priority="64" SemiHidden="false"    UnhideWhenUsed="false" Name="Medium Shading 2 Accent 6" /> <w:LsdException Locked="false" Priority="65" SemiHidden="false"    UnhideWhenUsed="false" Name="Medium List 1 Accent 6" /> <w:LsdException Locked="false" Priority="66" SemiHidden="false"    UnhideWhenUsed="false" Name="Medium List 2 Accent 6" /> <w:LsdException Locked="false" Priority="67" SemiHidden="false"    UnhideWhenUsed="false" Name="Medium Grid 1 Accent 6" /> <w:LsdException Locked="false" Priority="68" SemiHidden="false"    UnhideWhenUsed="false" Name="Medium Grid 2 Accent 6" /> <w:LsdException Locked="false" Priority="69" SemiHidden="false"    UnhideWhenUsed="false" Name="Medium Grid 3 Accent 6" /> <w:LsdException Locked="false" Priority="70" SemiHidden="false"    UnhideWhenUsed="false" Name="Dark List Accent 6" /> <w:LsdException Locked="false" Priority="71" SemiHidden="false"    UnhideWhenUsed="false" Name="Colorful Shading Accent 6" /> <w:LsdException Locked="false" Priority="72" SemiHidden="false"    UnhideWhenUsed="false" Name="Colorful List Accent 6" /> <w:LsdException Locked="false" Priority="73" SemiHidden="false"    UnhideWhenUsed="false" Name="Colorful Grid Accent 6" /> <w:LsdException Locked="false" Priority="19" SemiHidden="false"    UnhideWhenUsed="false" QFormat="true" Name="Subtle Emphasis" /> <w:LsdException Locked="false" Priority="21" SemiHidden="false"    UnhideWhenUsed="false" QFormat="true" Name="Intense Emphasis" /> <w:LsdException Locked="false" Priority="31" SemiHidden="false"    UnhideWhenUsed="false" QFormat="true" Name="Subtle Reference" /> <w:LsdException Locked="false" Priority="32" SemiHidden="false"    UnhideWhenUsed="false" QFormat="true" Name="Intense Reference" /> <w:LsdException Locked="false" Priority="33" SemiHidden="false"    UnhideWhenUsed="false" QFormat="true" Name="Book Title" /> <w:LsdException Locked="false" Priority="37" Name="Bibliography" /> <w:LsdException Locked="false" Priority="39" QFormat="true" Name="TOC Heading" /> </w:LatentStyles> </xml><![endif]--><!--  /* Font Definitions */  @font-face 	{font-family:Calibri; 	panose-1:2 15 5 2 2 2 4 3 2 4; 	mso-font-charset:0; 	mso-generic-font-family:swiss; 	mso-font-pitch:variable; 	mso-font-signature:-520092929 1073786111 9 0 415 0;} @font-face 	{font-family:Consolas; 	panose-1:2 11 6 9 2 2 4 3 2 4; 	mso-font-charset:0; 	mso-generic-font-family:modern; 	mso-font-pitch:fixed; 	mso-font-signature:-520092929 1073806591 9 0 415 0;}  /* Style Definitions */  p.MsoNormal, li.MsoNormal, div.MsoNormal 	{mso-style-unhide:no; 	mso-style-qformat:yes; 	mso-style-parent:""; 	margin-top:0cm; 	margin-right:0cm; 	margin-bottom:10.0pt; 	margin-left:0cm; 	line-height:115%; 	mso-pagination:widow-orphan; 	font-size:11.0pt; 	font-family:"Calibri","sans-serif"; 	mso-ascii-font-family:Calibri; 	mso-ascii-theme-font:minor-latin; 	mso-fareast-font-family:Calibri; 	mso-fareast-theme-font:minor-latin; 	mso-hansi-font-family:Calibri; 	mso-hansi-theme-font:minor-latin; 	mso-bidi-font-family:"Times New Roman"; 	mso-bidi-theme-font:minor-bidi; 	mso-fareast-language:EN-US;} .MsoChpDefault 	{mso-style-type:export-only; 	mso-default-props:yes; 	font-family:"Calibri","sans-serif"; 	mso-ascii-font-family:Calibri; 	mso-ascii-theme-font:minor-latin; 	mso-fareast-font-family:Calibri; 	mso-fareast-theme-font:minor-latin; 	mso-hansi-font-family:Calibri; 	mso-hansi-theme-font:minor-latin; 	mso-bidi-font-family:"Times New Roman"; 	mso-bidi-theme-font:minor-bidi; 	mso-fareast-language:EN-US;} .MsoPapDefault 	{mso-style-type:export-only; 	margin-bottom:10.0pt; 	line-height:115%;} @page WordSection1 	{size:612.0pt 792.0pt; 	margin:70.85pt 70.85pt 70.85pt 70.85pt; 	mso-header-margin:36.0pt; 	mso-footer-margin:36.0pt; 	mso-paper-source:0;} div.WordSection1 	{page:WordSection1;} --><!--[if gte mso 10]> <mce:style><!   /* Style Definitions */  table.MsoNormalTable 	{mso-style-name:"Table Normal"; 	mso-tstyle-rowband-size:0; 	mso-tstyle-colband-size:0; 	mso-style-noshow:yes; 	mso-style-priority:99; 	mso-style-parent:""; 	mso-padding-alt:0cm 5.4pt 0cm 5.4pt; 	mso-para-margin-top:0cm; 	mso-para-margin-right:0cm; 	mso-para-margin-bottom:10.0pt; 	mso-para-margin-left:0cm; 	line-height:115%; 	mso-pagination:widow-orphan; 	font-size:11.0pt; 	font-family:"Calibri","sans-serif"; 	mso-ascii-font-family:Calibri; 	mso-ascii-theme-font:minor-latin; 	mso-hansi-font-family:Calibri; 	mso-hansi-theme-font:minor-latin; 	mso-bidi-font-family:"Times New Roman"; 	mso-bidi-theme-font:minor-bidi; 	mso-fareast-language:EN-US;} --> <!--[endif]--></p>
<p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;"><span style="font-size: 9.5pt; font-family: Consolas; color: green;" lang="EN-US">/* MSVC does not have lrintf */</span><span style="font-size: 9.5pt; font-family: Consolas;" lang="EN-US"> </span></p>
<p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;"><span style="font-size: 9.5pt; font-family: Consolas; color: blue;" lang="EN-US">#ifdef</span><span style="font-size: 9.5pt; font-family: Consolas;" lang="EN-US"> _MSC_VER</span></p>
<p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;"><span style="font-size: 9.5pt; font-family: Consolas; color: blue;" lang="EN-US">static</span><span style="font-size: 9.5pt; font-family: Consolas;" lang="EN-US"> INLINE <span style="color: blue;">long</span> lrintf(<span style="color: blue;">float</span> f){</span></p>
<p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;"><span style="font-size: 9.5pt; font-family: Consolas; color: blue;" lang="EN-US">#ifdef</span><span style="font-size: 9.5pt; font-family: Consolas;" lang="EN-US"> _M_X64</span></p>
<p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;"><span style="font-size: 9.5pt; font-family: Consolas;" lang="EN-US"><span> </span><span style="color: blue;">return</span> (<span style="color: blue;">long</span>)((f&gt;0.0f) ? (f + 0.5f):(f -0.5f));</span></p>
<p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;"><span style="font-size: 9.5pt; font-family: Consolas; color: blue;" lang="EN-US">#else</span><span style="font-size: 9.5pt; font-family: Consolas;" lang="EN-US"> </span></p>
<p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;"><span style="font-size: 9.5pt; font-family: Consolas;" lang="EN-US"><span> </span><span style="color: blue;">int</span> i;</span></p>
<p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;"><span style="font-size: 9.5pt; font-family: Consolas;" lang="EN-US"> </span></p>
<p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;"><span style="font-size: 9.5pt; font-family: Consolas;" lang="EN-US"><span> </span><span style="color: blue;">_asm</span>{</span></p>
<p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;"><span style="font-size: 9.5pt; font-family: Consolas;" lang="EN-US"><span> </span>fld f</span></p>
<p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;"><span style="font-size: 9.5pt; font-family: Consolas;" lang="EN-US"><span> </span>fistp i</span></p>
<p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;"><span style="font-size: 9.5pt; font-family: Consolas;" lang="EN-US"><span> </span>};</span></p>
<p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;"><span style="font-size: 9.5pt; font-family: Consolas;" lang="EN-US"> </span></p>
<p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;"><span style="font-size: 9.5pt; font-family: Consolas;" lang="EN-US"><span> </span><span style="color: blue;">return</span> i;</span></p>
<p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;"><span style="font-size: 9.5pt; font-family: Consolas; color: blue;" lang="EN-US">#endif</span><span style="font-size: 9.5pt; font-family: Consolas;" lang="EN-US"> </span></p>
<p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;"><span style="font-size: 9.5pt; font-family: Consolas;" lang="EN-US">}</span></p>
<p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;"><span style="font-size: 9.5pt; font-family: Consolas; color: blue;" lang="EN-US">#endif</span></p>
</div>
]]></content:encoded>
			<wfw:commentRss>http://www.sambeauvois.be/blog/2010/05/freeimage-and-x64-projects-yes-you-can/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Change the Office 2010 product key</title>
		<link>http://www.sambeauvois.be/blog/2010/04/change-the-office-2010-product-key/</link>
		<comments>http://www.sambeauvois.be/blog/2010/04/change-the-office-2010-product-key/#comments</comments>
		<pubDate>Fri, 30 Apr 2010 12:39:02 +0000</pubDate>
		<dc:creator>Sam Beauvois</dc:creator>
				<category><![CDATA[Office]]></category>
		<category><![CDATA[Tips and Tricks]]></category>
		<category><![CDATA[Activation]]></category>
		<category><![CDATA[Product Key]]></category>

		<guid isPermaLink="false">http://www.sambeauvois.be/blog/2010/04/change-the-office-2010-product-key/</guid>
		<description><![CDATA[A few days ago I received Office 2010 from work.
I installed it with the provided product key, and tried to activate it:


Unfortunately, the product key has been already activated for the maximum number of times permitted.

So I asked for a new key, I received it and I tried to change the key

After several researches, I [...]]]></description>
			<content:encoded><![CDATA[<p>A few days ago I received Office 2010 from work.</p>
<p>I installed it with the provided product key, and tried to activate it:</p>
<p><a href="http://www.sambeauvois.be/blog/wp-content/uploads/2010/04/image17.png" target="_blank"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" src="http://www.sambeauvois.be/blog/wp-content/uploads/2010/04/image_thumb17.png" border="0" alt="image" width="484" height="418" /></a></p>
<p><a href="http://www.sambeauvois.be/blog/wp-content/uploads/2010/04/image31.png" target="_blank"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" src="http://www.sambeauvois.be/blog/wp-content/uploads/2010/04/image31_thumb.png" border="0" alt="image" width="484" height="418" /></a></p>
<p>Unfortunately, the product key has been already activated for the maximum number of times permitted.</p>
<p><a href="http://www.sambeauvois.be/blog/wp-content/uploads/2010/04/image61.png" target="_blank"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" src="http://www.sambeauvois.be/blog/wp-content/uploads/2010/04/image6_thumb.png" border="0" alt="image" width="484" height="418" /></a></p>
<p>So I asked for a new key, I received it and I tried to change the key</p>
<p><a href="http://www.sambeauvois.be/blog/wp-content/uploads/2010/04/image121.png" target="_blank"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" src="http://www.sambeauvois.be/blog/wp-content/uploads/2010/04/image12_thumb.png" border="0" alt="image" width="484" height="388" /></a></p>
<p>After several researches, I couldn&#8217;t find an option to change this key.</p>
<p>I finally tried to repair the installation, so I start the office installer</p>
<p>and  the wanted option was here :</p>
<p><a href="http://www.sambeauvois.be/blog/wp-content/uploads/2010/04/image151.png" target="_blank"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" src="http://www.sambeauvois.be/blog/wp-content/uploads/2010/04/image15_thumb.png" border="0" alt="image" width="484" height="395" /></a></p>
<p>Choose “Enter a product key” then click on Continue</p>
<p><a href="http://www.sambeauvois.be/blog/wp-content/uploads/2010/04/image18.png" target="_blank"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" src="http://www.sambeauvois.be/blog/wp-content/uploads/2010/04/image18_thumb.png" border="0" alt="image" width="484" height="395" /></a></p>
<p>Enter your product key and click on &#8220;Continue&#8221;.</p>
<p>Then you cant choose if you want to install additional office options</p>
<p>Now it’s activated !</p>
<p><a href="http://www.sambeauvois.be/blog/wp-content/uploads/2010/04/image19.png" target="_blank"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" src="http://www.sambeauvois.be/blog/wp-content/uploads/2010/04/image1_thumb.png" border="0" alt="image" width="484" height="388" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.sambeauvois.be/blog/2010/04/change-the-office-2010-product-key/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>The IX509CertificateRequestPkcs10 InitializeFromTemplateName adventure</title>
		<link>http://www.sambeauvois.be/blog/2010/04/the-ix509certificaterequestpkcs10-initializefromtemplatename-adventure/</link>
		<comments>http://www.sambeauvois.be/blog/2010/04/the-ix509certificaterequestpkcs10-initializefromtemplatename-adventure/#comments</comments>
		<pubDate>Wed, 28 Apr 2010 16:54:31 +0000</pubDate>
		<dc:creator>Sam Beauvois</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[Security]]></category>
		<category><![CDATA[Source Code]]></category>
		<category><![CDATA[Certificate]]></category>

		<guid isPermaLink="false">http://www.sambeauvois.be/blog/2010/04/the-ix509certificaterequestpkcs10-initializefromtemplatename-adventure/</guid>
		<description><![CDATA[This week has been researches, tests and headaches to be able to make request on a Certificate Authority server from a web application.
My client has a Win server 2008 CA server for my developments
On this server I have a certificate template named “User Template”

My assignment was to request a certificate via an ASP.NET application.
After researches [...]]]></description>
			<content:encoded><![CDATA[<p>This week has been researches, tests and headaches to be able to make request on a Certificate Authority server from a web application.</p>
<p>My client has a Win server 2008 CA server for my developments</p>
<p>On this server I have a certificate template named “User Template”</p>
<p><a href="http://www.sambeauvois.be/blog/wp-content/uploads/2010/04/Certificate_server_templates.png" target="_blank"><img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="Certificate_server_templates" src="http://www.sambeauvois.be/blog/wp-content/uploads/2010/04/Certificate_server_templates_thumb.png" border="0" alt="Certificate_server_templates" width="484" height="297" /></a></p>
<p>My assignment was to request a certificate via an ASP.NET application.</p>
<p>After researches on how to do that, I found this blog post that helped me a lot : <a title="http://blogs.msdn.com/alejacma/archive/2008/09/05/how-to-create-a-certificate-request-with-certenroll-and-net-c.aspx" href="http://blogs.msdn.com/alejacma/archive/2008/09/05/how-to-create-a-certificate-request-with-certenroll-and-net-c.aspx" target="_blank" onclick="pageTracker._trackPageview('/outgoing/blogs.msdn.com/alejacma/archive/2008/09/05/how-to-create-a-certificate-request-with-certenroll-and-net-c.aspx?referer=');">http://blogs.msdn.com/alejacma/archive/2008/09/05/how-to-create-a-certificate-request-with-certenroll-and-net-c.aspx</a></p>
<p>In my development environment, I create a request for a certificate by using  this code</p>
<pre class="brush: csharp;">
 CERTENROLLLib.CX509CertificateRequestPkcs10Class request = new CERTENROLLLib.CX509CertificateRequestPkcs10Class();
 string templateName = &quot;User Template&quot;;
 try
 {
    request.InitializeFromTemplateName(CERTENROLLLib.X509CertificateEnrollmentContext.ContextUser, templateName);
 }
 catch (Exception ex)
 {
   log.DebugFormat(&quot;Error InitializeFromTemplateName : message {0}, inner : {1}, stack : {2}, source : {3}, target : {4} &quot;,
    ex.Message,
    ex.InnerException,
    ex.StackTrace,
    ex.Source,
    ex.TargetSite);
 }
</pre>
<p>And it worked just fine !</p>
<p>Then we moved the published solution to the staging environment, and the problems arrived . . .</p>
<p>It didn’t worked !</p>
<p>The error message said:</p>
<p>&#8220;CertEnroll::CX509CertificateRequestPkcs10::InitializeFromTemplateName: The requested certificate template is not supported by this CA. 0&#215;80094800 (-2146875392)&#8221;</p>
<p>stack :</p>
<p>&#8220;at CERTENROLLLib.CX509CertificateRequestPkcs10Class.InitializeFromTemplateName(X509CertificateEnrollmentContext Context, String strTemplateName)&#8221;</p>
<p><a href="http://www.sambeauvois.be/blog/wp-content/uploads/2010/04/cererror.png" target="_blank"><img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="cererror" src="http://www.sambeauvois.be/blog/wp-content/uploads/2010/04/cererror_thumb.png" border="0" alt="cererror" width="484" height="294" /></a></p>
<p>We checked the security everywhere ( CA server, Certificate templates, IIS Account, …), give access to everyone on the CA, on the template, … without any success</p>
<p>Then, after days and hours of search and tests, I decided to re-read the method documentation : <a title="http://msdn.microsoft.com/en-us/library/aa377533%28v=VS.85%29.aspx" href="http://msdn.microsoft.com/en-us/library/aa377533%28v=VS.85%29.aspx" target="_blank" onclick="pageTracker._trackPageview('/outgoing/msdn.microsoft.com/en-us/library/aa377533_28v=VS.85_29.aspx?referer=');">http://msdn.microsoft.com/en-us/library/aa377533%28v=VS.85%29.aspx</a></p>
<p>And I noticed the second parameter description:</p>
<blockquote>
<dt><em>strTemplateName</em> [in] </dt>
<dd>Pointer to a <strong>BSTR</strong> variable that contains the Common Name (CN) of the template as it appears in Active Directory or the dotted decimal <a href="http://msdn.microsoft.com/en-us/library/ms721599%28v=VS.85%29.aspx#_security_object_identifier_gly" target="_blank" onclick="pageTracker._trackPageview('/outgoing/msdn.microsoft.com/en-us/library/ms721599_28v=VS.85_29.aspx_security_object_identifier_gly?referer=');"><em>object identifier</em></a>.</p>
</dd>
</blockquote>
<p>I had never tried using the dotted decimal object identifier, so i give it a shot.</p>
<p>I retrieved the object identifier on a certificate previously created with the “User Template”</p>
<p>On the CA server, I had a certificate request with the template “User Template”, so I right-click on it, go to All Tasks and click on the “View attributes/Extensions. . .” menu item.</p>
<p><a href="http://www.sambeauvois.be/blog/wp-content/uploads/2010/04/image14.png" target="_blank"><img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="image" src="http://www.sambeauvois.be/blog/wp-content/uploads/2010/04/image_thumb14.png" border="0" alt="image" width="484" height="304" /></a></p>
<p><a href="http://www.sambeauvois.be/blog/wp-content/uploads/2010/04/image15.png" target="_blank"><img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="image" src="http://www.sambeauvois.be/blog/wp-content/uploads/2010/04/image_thumb15.png" border="0" alt="image" width="484" height="103" /></a></p>
<p>A property windows opened, I go to the Extensions tab and click on the “Certificate Template Information” item.</p>
<p><a href="http://www.sambeauvois.be/blog/wp-content/uploads/2010/04/image16.png"><img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="image" src="http://www.sambeauvois.be/blog/wp-content/uploads/2010/04/image_thumb16.png" border="0" alt="image" width="425" height="484" /></a></p>
<p>In the information panel, I can see the famous dotted decimal object identifier between brackets.</p>
<p>I copy-paste this identifier in my code :</p>
<pre class="brush: csharp;">
 CERTENROLLLib.CX509CertificateRequestPkcs10Class request = new CERTENROLLLib.CX509CertificateRequestPkcs10Class();
 string templateName = &quot;1.3.6.1.4.1.311.21.8.3531346.8488945.6374567.164989.5001604.52.12582268.10747996&quot;;
 try
 {
    request.InitializeFromTemplateName(CERTENROLLLib.X509CertificateEnrollmentContext.ContextUser, templateName);
 }
 catch (Exception ex)
 {
    log.DebugFormat(&quot;Error InitializeFromTemplateName : message {0}, inner : {1}, stack : {2}, source : {3}, target : {4} &quot;,
      ex.Message,
      ex.InnerException,
      ex.StackTrace,
      ex.Source,
      ex.TargetSite);
 }
</pre>
<p>I compiled, I tried in the development environment and it worked !!</p>
<p>(note: there is just a minimal change in my code since I put the “templateName” in a configuration file in order to be able to modify it)</p>
<p>So we moved the published solution to the staging environment,</p>
<p>retrieve the dotted decimal object identifier corresponding to the “User Template” on the staging CA server,</p>
<p>copy-pasted this identifier in the configuration file,</p>
<p>executed a “IISRESET” command and try to execute the application.</p>
<p>And it worked !</p>
<p>We can&#8217;t figured out why it worked in the development environment but not in the staging one while both are equals. So If anyone knows about it, please let me know.</p>
<p>So, don’t trust the template name and use the object identifier !</p>
]]></content:encoded>
			<wfw:commentRss>http://www.sambeauvois.be/blog/2010/04/the-ix509certificaterequestpkcs10-initializefromtemplatename-adventure/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Visual Studio Default Key binding posters</title>
		<link>http://www.sambeauvois.be/blog/2010/04/visual-studio-default-key-bindings-posters/</link>
		<comments>http://www.sambeauvois.be/blog/2010/04/visual-studio-default-key-bindings-posters/#comments</comments>
		<pubDate>Mon, 26 Apr 2010 07:57:59 +0000</pubDate>
		<dc:creator>Sam Beauvois</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[Visual Studio]]></category>

		<guid isPermaLink="false">http://www.sambeauvois.be/blog/?p=320</guid>
		<description><![CDATA[The visual studio 2010 keybinding poster is available since a few weeks.
Visual C# 2010 default key bindings preview :


Shortcuts are grouped by category (debuging, refactoring, editing,  navigation, &#8230;)
Here is the Visual Studio Keyboard shortcuts posters for C#:
Visual Studio 2010

Download the pdf
Go to the msdn page

Visual Studio  2008

Download the pdf
Go to the msdn page

Visual Studio [...]]]></description>
			<content:encoded><![CDATA[<p>The visual studio 2010 keybinding poster is available since a few weeks.</p>
<p>Visual C# 2010 default key bindings preview :</p>
<p style="text-align: center;"><a href="http://www.sambeauvois.be/blog/wp-content/uploads/2010/04/VS2010CsharpKeyBinding1.png" target="_blank"><img class="aligncenter" title="VS2010CsharpKeyBinding1" src="http://www.sambeauvois.be/blog/wp-content/uploads/2010/04/VS2010CsharpKeyBinding1-300x149.png" alt="VS2010CsharpKeyBinding1" width="300" height="149" /></a></p>
<h3><a href="http://www.sambeauvois.be/blog/wp-content/uploads/2010/04/VS2010CsharpKeyBinding2.png" target="_blank"><img class="aligncenter" title="VS2010CsharpKeyBinding2" src="http://www.sambeauvois.be/blog/wp-content/uploads/2010/04/VS2010CsharpKeyBinding2-300x149.png" alt="VS2010CsharpKeyBinding2" width="300" height="149" /></a></h3>
<p>Shortcuts are grouped by category (debuging, refactoring, editing,  navigation, &#8230;)</p>
<h4>Here is the Visual Studio Keyboard shortcuts posters for C#:</h4>
<h4>Visual Studio 2010</h4>
<ul>
<li>Download <a href="http://www.sambeauvois.be/Docs/Microsoft/VS2010CSharp.pdf">the pdf</a></li>
<li>Go to the <a href="http://www.microsoft.com/downloads/details.aspx?displaylang=en&amp;FamilyID=92ced922-d505-457a-8c9c-84036160639f" target="_blank" onclick="pageTracker._trackPageview('/outgoing/www.microsoft.com/downloads/details.aspx?displaylang=en_amp_FamilyID=92ced922-d505-457a-8c9c-84036160639f&amp;referer=');">msdn page</a></li>
</ul>
<h4>Visual Studio  2008</h4>
<ul>
<li>Download <a href="http://www.sambeauvois.be/Docs/Microsoft/VS2008CSharp.pdf">the pdf</a></li>
<li>Go to the <a href="http://www.microsoft.com/downloads/details.aspx?displaylang=en&amp;FamilyID=e5f902a8-5bb5-4cc6-907e-472809749973" target="_blank" onclick="pageTracker._trackPageview('/outgoing/www.microsoft.com/downloads/details.aspx?displaylang=en_amp_FamilyID=e5f902a8-5bb5-4cc6-907e-472809749973&amp;referer=');">msdn page</a></li>
</ul>
<h4>Visual Studio 2005</h4>
<ul>
<li>Download <a href="http://www.sambeauvois.be/Docs/Microsoft/VS2005CSharp.pdf">the pdf</a></li>
<li>Go to the<a href="http://www.microsoft.com/downloads/details.aspx?displaylang=en&amp;FamilyID=c15d210d-a926-46a8-a586-31f8a2e576fe" target="_blank" onclick="pageTracker._trackPageview('/outgoing/www.microsoft.com/downloads/details.aspx?displaylang=en_amp_FamilyID=c15d210d-a926-46a8-a586-31f8a2e576fe&amp;referer=');"> msdn page</a></li>
</ul>
<p><span id="result_box"><span style="background-color: #ffffff;" title="profitez en">Enjoy them !<br />
</span></span></p>
]]></content:encoded>
			<wfw:commentRss>http://www.sambeauvois.be/blog/2010/04/visual-studio-default-key-bindings-posters/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Custom paging with Subsonic 3 and ObjectDataSource in ASP.NET</title>
		<link>http://www.sambeauvois.be/blog/2010/04/custom-paging-with-subsonic-3-and-objectdatasource-in-asp-net/</link>
		<comments>http://www.sambeauvois.be/blog/2010/04/custom-paging-with-subsonic-3-and-objectdatasource-in-asp-net/#comments</comments>
		<pubDate>Thu, 22 Apr 2010 07:34:08 +0000</pubDate>
		<dc:creator>Sam Beauvois</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[ASP.NET]]></category>
		<category><![CDATA[SubSonic]]></category>

		<guid isPermaLink="false">http://www.sambeauvois.be/blog/?p=292</guid>
		<description><![CDATA[Here is how I created a paged items list in ASP.NET 3.5 using Subsonic for data access, and ASP.NET Controls for the display.
I use Subsonic 3.0.0.4 with ActiveRecord and ASP.NET 3.5 SP1 webforms.
For this example, we are creating a blog post list and that the DAL is created (the data class we use is &#8220;DAL.BlogPost&#8221;).
The [...]]]></description>
			<content:encoded><![CDATA[<p>Here is how I created a paged items list in ASP.NET 3.5 using Subsonic for data access, and ASP.NET Controls for the display.</p>
<p>I use Subsonic 3.0.0.4 with ActiveRecord and ASP.NET 3.5 SP1 webforms.</p>
<p>For this example, we are creating a blog post list and that the DAL is created (the data class we use is &#8220;DAL.BlogPost&#8221;).</p>
<p>The DAL.BlogPost object has three properties we need : CreatedOn, Subject and Body.</p>
<h4>First step : prepare your data manager class</h4>
<pre class="brush: csharp;">

namespace MyBlog.BLL
{
   public class PostManager
   {
     // ...
   }
}
</pre>
<p>(keep in mind the namespace and the class for the nexts steps)</p>
<p>In this class, two methods are required,</p>
<p>The first returns the total number of items</p>
<pre class="brush: csharp;">

public int GetPostCount()
{
  return DAL.BlogPost.All().Count(x =&gt; x.IsDeleted != true);
}
</pre>
<p>The second one returns the items contained in a defined range (start index and then nomber of elements), so this method needs to know where to start and how many items to get.</p>
<pre class="brush: csharp;">

public PagedList&lt;DAL.BlogPost&gt; GetLastestPosts(int startRowIndex, int maximumRows)
{
   if (startRowIndex != 0)
   {
     startRowIndex =(startRowIndex/maximumRows);
   }

    IOrderedQueryable&lt;DAL.BlogPost&gt; yourQuery = DAL.BlogPost.All().OrderByDescending(x =&gt; x.CreatedOn);
    return new PagedList&lt;DAL.BlogPost&gt;(yourQuery, startRowIndex, maximumRows);
}
</pre>
<p>One important part to remember when using Subsonic is</p>
<pre class="brush: csharp;">

if (startRowIndex != 0)
{
   startRowIndex = startRowIndex / maximumRows;
}
</pre>
<p>This conversion is necessary because subsonic and the ObjectDataSource doesn&#8217;t share the same opinion about the paging method.<br />
Subsonic says</p>
<blockquote><p>&#8220;I want the third page containing five elements&#8221;</p></blockquote>
<p>ObjectDataSource says</p>
<blockquote><p>&#8220;I want the five elements following the third element&#8221;</p></blockquote>
<p>So the conversion is mandatory if you want a correct paging.</p>
<h4>Second step : create the aspx page.</h4>
<p>Declare an ObjectDataSource:</p>
<pre class="brush: xml;">
&lt;asp:ObjectDataSource runat=&quot;server&quot; ID=&quot;postsDataSource&quot;
 TypeName=&quot;Example.BLL.PostManager&quot;
 SelectMethod=&quot;GetLastestPosts&quot;
 EnablePaging=&quot;true&quot;
 SelectCountMethod=&quot;GetPostCount&quot; &gt;
 &lt;/asp:ObjectDataSource&gt;
</pre>
<p>Note the TypeName attribute : the value is the namespace + the class name of our datamanager class.<br />
We set the EnablePaging attribute to true and we specify the SelectCountMethod and the SelectMethod.</p>
<p>We don&#8217;t need any parameters for the paging, by default the MaximumRowsParameterName and StartRowIndexParameterName are set to &#8220;maximumRows&#8221; and &#8220;startRowIndex&#8221;.<br />
If we want other parameters names in our datamanager class, we can define them in the ObjectDataSource with these two parameters.</p>
<p>Add an asp ListView element</p>
<pre class="brush: xml;">
&lt;asp:ListView runat=&quot;server&quot; ID=&quot;postsListview&quot;
     DataSourceID=&quot;postsDataSource&quot;&gt;
 &lt;LayoutTemplate&gt;
    &lt;asp:PlaceHolder ID=&quot;itemPlaceHolder&quot;
         runat=&quot;server&quot; /&gt;
 &lt;/LayoutTemplate&gt;
 &lt;ItemTemplate&gt;
    &lt;h2&gt;&lt;%# Eval(&quot;CreatedOn&quot;,&quot;{0:d}&quot;)%&gt; :
     &lt;%# Eval(&quot;Subject&quot;) %&gt;&lt;/h2&gt;
    &lt;br /&gt;
    &lt;p&gt;
     &lt;%# Eval(&quot;Body&quot;) %&gt;
    &lt;/p&gt;
    &lt;hr /&gt;
 &lt;/ItemTemplate&gt;
&lt;/asp:ListView&gt;
</pre>
<p>Set the DataSourceID attribute to the ObjectDataSource ID parameter.</p>
<p>Define a LayoutTemplate and an ItemTemplate with the elements we want to display.</p>
<p>Then add an asp datapager control in the LayoutTemplate</p>
<pre class="brush: xml;">

&lt;LayoutTemplate&gt;

  &lt;asp:DataPager ID=&quot;postsDataPager&quot; runat=&quot;server&quot;
       PageSize=&quot;3&quot;&gt;
    &lt;Fields&gt;
      &lt;asp:NextPreviousPagerField ButtonType=&quot;Link&quot;
           FirstPageText=&quot;&lt;&lt;&quot; PreviousPageText=&quot;&lt;&quot;
           ShowNextPageButton=&quot;false&quot;
           ShowFirstPageButton=&quot;true&quot; /&gt;
      &lt;asp:NumericPagerField PreviousPageText=&quot;...&quot;
           NextPageText=&quot;...&quot; ButtonCount=&quot;10&quot; /&gt;
      &lt;asp:NextPreviousPagerField ButtonType=&quot;Link&quot;
           LastPageText=&quot;&gt;&gt;&quot; NextPageText=&quot;&gt;&quot;
           ShowPreviousPageButton=&quot;false&quot;
           ShowLastPageButton=&quot;true&quot; /&gt;
     &lt;/Fields&gt;
   &lt;/asp:DataPager&gt;

   &lt;asp:PlaceHolder ID=&quot;itemPlaceHolder&quot; runat=&quot;server&quot; /&gt;
 &lt;/LayoutTemplate&gt;
</pre>
<p>Here is the result :<br />
<a href="http://www.sambeauvois.be/blog/wp-content/uploads/2010/04/blogposts.png" target="_blank"><img class="aligncenter size-medium wp-image-307" title="blogposts" src="http://www.sambeauvois.be/blog/wp-content/uploads/2010/04/blogposts-300x178.png" alt="blogposts" width="300" height="178" /></a></p>
<h4>Remark about the data access method</h4>
<p>It&#8217;s possible to avoid the start index value conversion !</p>
<p>Check the PagedList first constructor code (<a href="http://github.com/subsonic/SubSonic-3.0/blob/master/SubSonic.Core/Schema/PagedList.cs" target="_blank" onclick="pageTracker._trackPageview('/outgoing/github.com/subsonic/SubSonic-3.0/blob/master/SubSonic.Core/Schema/PagedList.cs?referer=');">code is available on the subsonic git repository</a>)</p>
<pre class="brush: csharp;">

public PagedList(IQueryable&lt;T&gt; source, int index, int pageSize)
{
   int total = source.Count();
   TotalCount = total;
   TotalPages = total / pageSize;

   if(total % pageSize &gt; 0)
     TotalPages++;

   PageSize = pageSize;
   PageIndex = index;
   AddRange(source.Skip(index * pageSize).Take(pageSize).ToList());
}
</pre>
<p>As you can see, Subsonic use the Skip and the Take methods from Linq</p>
<p>So, you can modify the GetLastestPosts method to return a<span id="main" style="visibility: visible;"><span id="search" style="visibility: visible;"> strongly <em> </em></span></span> typed List in place of the PagedList:</p>
<pre class="brush: csharp;">

public List&lt;DAL.BlogPost&gt; GetLastestPosts(int startRowIndex, int maximumRows)
{
   return DAL.BlogPost.All().
          Skip(startRowIndex).
          Take(maximumRows).
          OrderByDescending(x =&gt; x.CreatedOn).
          ToList&lt;DAL.BlogPost&gt;();
}
</pre>
<p>With this method, no more conversion needed</p>
]]></content:encoded>
			<wfw:commentRss>http://www.sambeauvois.be/blog/2010/04/custom-paging-with-subsonic-3-and-objectdatasource-in-asp-net/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
