<?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>blog.dervalp.com &#187; .NET</title>
	<atom:link href="http://blog.dervalp.com/tag/net/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.dervalp.com</link>
	<description>Think before Programming (Public learning)</description>
	<lastBuildDate>Sat, 20 Mar 2010 22:22:42 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Kiwi MVC.NET : Prepare your data access Part3</title>
		<link>http://blog.dervalp.com/2009/05/26/kiwi-mvc-prepare-your-data-access/</link>
		<comments>http://blog.dervalp.com/2009/05/26/kiwi-mvc-prepare-your-data-access/#comments</comments>
		<pubDate>Tue, 26 May 2009 20:03:45 +0000</pubDate>
		<dc:creator>dervalp</dc:creator>
				<category><![CDATA[Kiwi MVC]]></category>
		<category><![CDATA[.NET]]></category>
		<category><![CDATA[ASP.NET]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[C#.NET]]></category>
		<category><![CDATA[DB]]></category>
		<category><![CDATA[Localized]]></category>
		<category><![CDATA[MVC.NET]]></category>
		<category><![CDATA[TDD]]></category>

		<guid isPermaLink="false">http://blog.dervalp.com/?p=196</guid>
		<description><![CDATA[So, I decide to rebuild a new solution. I will carry on the membership layer later cause I want a system who could use Sql, Active Directory or OpenID for the login and only use Sql for the membership role. I have an idea to do that but as I told you in a previous [...]]]></description>
			<content:encoded><![CDATA[<p>So, I decide to rebuild a new solution. I will carry on the membership layer later cause I want a system who could use Sql, Active Directory or OpenID for the login and only use Sql for the membership role. I have an idea to do that but as I told you in a previous post, a security layer is a kind of plugin. Therefore, we could add it later.</p>
<p>Today, I will show you how I am going to create the models and prepare my data access with the help of LinqToSql class.</p>
<p>I choose to make Kiwi multilingual.</p>
<h2><span id="more-196"></span></h2>
<h2>1) The DB</h2>
<p>I am not a dba, you are welcome with your feedback.</p>
<p>Here is the design I choose :</p>
<p><img class="alignnone size-full wp-image-206" title="kiwi_db" src="http://blog.dervalp.com/wp-content/uploads/2009/05/kiwi_db.jpg" alt="kiwi_db" width="833" height="780" /></p>
<h2>2) The models</h2>
<p>I decided to create five objects to begin the project. An object Post, Page, Comment, Tag and Category.</p>
<ul>
<li>The object Post : It is a content of a news (for the moment). A post must be in a category. There are status for this type. A post cannot have subposts. This object is localized</li>
</ul>
<ul>
<li>The object Page : It cannot be a part of a category, the page can have subpages. This object is localized and have the same status (puslihed, offline,&#8230;) than a post object.</li>
</ul>
<ul>
<li>The object Comment : A classic comment object, with the author name, the ip address,&#8230; A comment can have child (qutoes). This object is not localized (for the moment, we could think of an automatic translation but KISS).</li>
</ul>
<ul>
<li>The object Category :  This object contains the post. It is localized by the name.</li>
</ul>
<p>Example for Page:</p>
<p>I use the LazyList pattern (<a href="http://blog.wekeroad.com/blog/lazy-loading-with-the-lazylist/">more info here</a>). I will put the project on codeplex, like this, you will able to browse and download the code.</p>
<pre class="brush: c;">

namespace KIWI.MVC.Data
{
class Page
{
public int PageID { get; set; }
public string Author { get; set; }
public string Status { get; set; }
public DateTime Date { get; set; }
public DateTime ModifiedDate { get; set; }
public string Version { get; set; }
public string Permalink { get; set; }
public string Password { get; set; }
public LazyList&lt;Page&gt; PageChild{ get;set;}
public LazyList&lt;Page&gt; PageLozalized { get; set; }
}
public class PageLocalized
{
public string Title { get; set; }
public string Text { get; set; }
public string Excerpt { get; set; }
public string LanguageCode { get; set; }
}
}
</pre>
<h2>3) The SqlCMSRepository</h2>
<p>This repository will be the link between my object and my db. It will contain all the main method I need. I will always return an IQueryable type.  It will allow you to use the <a href="http://en.wikipedia.org/wiki/Pipes_and_filters">pipeline pattern</a> to create some filter functions.</p>
<ul>
<li>Create a LinqToSql class.</li>
</ul>
<p><img class="alignnone size-full wp-image-212" title="kiwi_linq_to_sql" src="http://blog.dervalp.com/wp-content/uploads/2009/05/kiwi_linq_to_sql.jpg" alt="kiwi_linq_to_sql" width="683" height="414" /></p>
<p>After creating the linq to sql class, drop the table you need from the server explorer of visual studio to the dml file.</p>
<p><img class="alignnone size-full wp-image-215" title="kiwi_class_cms" src="http://blog.dervalp.com/wp-content/uploads/2009/05/kiwi_class_cms.jpg" alt="kiwi_class_cms" width="253" height="323" /></p>
<p>You will have the representation of you db (like the first page of this post). After, change some properties of you LinqCMSRespository class. Double clik on the LinqCMDRespository.dbml and right click on the screen where your tables appear. Here change the Name to &#8220;DB&#8221;. It is only to use the same name for you future dbml and improve the visibilty of your code.</p>
<p><img class="alignnone size-full wp-image-216" title="kiwi_class_linq_properties" src="http://blog.dervalp.com/wp-content/uploads/2009/05/kiwi_class_linq_properties.jpg" alt="kiwi_class_linq_properties" width="311" height="253" /></p>
<p>Build you solution to see if everything goes well.</p>
<p>If you have built successfully, then create you SqlCMSRespository class.</p>
<p>Here is the code :</p>
<pre class="brush: c;">
using CMS.MVC.Data.SqlRepository;

namespace CMS.MVC.Data
{
class SqlCMSRespository
{
//the name we changed in the properties of our Linq to Sql class
private DB _db;

//constructor
#region .ctor

//we instanciate the db when we instantciate the SqlCMSRespository
//default constructor
public SqlCMSRespository()
{
_db = new DB();
}

public SqlCMSRespository(DB dataContext)
{
//override the current context with the on passed in
//for TDD
_db = dataContext;
}

#endregion

#region Post
//there we will put our main functions like GetPost(),...
//But before, let's go to TDD !!!!
//TEST DRIVEN DESIGN
#endregion
}
}
</pre>
<p>Now we are able to begin all our data access method but before writing some code in your repository, we&#8217;ll go with the TDD approach.<br />
And by creating our tests, we will see what we need in our application.</p>
<p>So this is the end for today, as usual, feedback and comments are very appreciated.</p>
<!-- Social Bookmarks BEGIN -->
<div class="social_bookmark">
<a title="Click me to see the sites." href="#" onclick="$$('div.d196').each( function(e) { e.visualEffect('slide_down',{duration:2.5}) }); return false;"><strong><em>Bookmark It</em></strong></a>
<br />
<div class="d196" style="overflow:hidden">
<br />
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://del.icio.us/post?url=http://blog.dervalp.com/2009/05/26/kiwi-mvc-prepare-your-data-access/&amp;title=Kiwi+MVC.NET+%3A+Prepare+your+data+access+Part3" rel="nofollow" title="Add to&nbsp;Del.icio.us"><img class="social_img" src="http://blog.dervalp.com/wp-content/plugins/social-bookmarks/images/delicious.png" title="Add to&nbsp;Del.icio.us" alt="Add to&nbsp;Del.icio.us" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://digg.com/submit?phase=2&amp;url=http://blog.dervalp.com/2009/05/26/kiwi-mvc-prepare-your-data-access/&amp;title=Kiwi+MVC.NET+%3A+Prepare+your+data+access+Part3" rel="nofollow" title="Add to&nbsp;digg"><img class="social_img" src="http://blog.dervalp.com/wp-content/plugins/social-bookmarks/images/digg.png" title="Add to&nbsp;digg" alt="Add to&nbsp;digg" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.facebook.com/sharer.php?u=http://blog.dervalp.com/2009/05/26/kiwi-mvc-prepare-your-data-access/" rel="nofollow" title="Add to&nbsp;Facebook"><img class="social_img" src="http://blog.dervalp.com/wp-content/plugins/social-bookmarks/images/facebook.png" title="Add to&nbsp;Facebook" alt="Add to&nbsp;Facebook" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.google.com/bookmarks/mark?op=edit&amp;output=popup&amp;bkmk=http://blog.dervalp.com/2009/05/26/kiwi-mvc-prepare-your-data-access/&amp;title=Kiwi+MVC.NET+%3A+Prepare+your+data+access+Part3" rel="nofollow" title="Add to&nbsp;Google Bookmarks"><img class="social_img" src="http://blog.dervalp.com/wp-content/plugins/social-bookmarks/images/google.png" title="Add to&nbsp;Google Bookmarks" alt="Add to&nbsp;Google Bookmarks" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://reddit.com/submit?url=http://blog.dervalp.com/2009/05/26/kiwi-mvc-prepare-your-data-access/&amp;title=Kiwi+MVC.NET+%3A+Prepare+your+data+access+Part3" rel="nofollow" title="Add to&nbsp;reddit"><img class="social_img" src="http://blog.dervalp.com/wp-content/plugins/social-bookmarks/images/reddit.png" title="Add to&nbsp;reddit" alt="Add to&nbsp;reddit" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.stumbleupon.com/submit.php?url=http://blog.dervalp.com/2009/05/26/kiwi-mvc-prepare-your-data-access/&amp;title=Kiwi+MVC.NET+%3A+Prepare+your+data+access+Part3" rel="nofollow" title="Add to&nbsp;Stumble Upon"><img class="social_img" src="http://blog.dervalp.com/wp-content/plugins/social-bookmarks/images/stumbleupon.png" title="Add to&nbsp;Stumble Upon" alt="Add to&nbsp;Stumble Upon" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://twitter.com/home/?status=Check+out+Kiwi+MVC.NET+%3A+Prepare+your+data+access+Part3+@+http://blog.dervalp.com/2009/05/26/kiwi-mvc-prepare-your-data-access/" rel="nofollow" title="Add to&nbsp;Twitter"><img class="social_img" src="http://blog.dervalp.com/wp-content/plugins/social-bookmarks/images/twitter.png" title="Add to&nbsp;Twitter" alt="Add to&nbsp;Twitter" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://myweb2.search.yahoo.com/myresults/bookmarklet?u=http://blog.dervalp.com/2009/05/26/kiwi-mvc-prepare-your-data-access/&amp;t=Kiwi+MVC.NET+%3A+Prepare+your+data+access+Part3" rel="nofollow" title="Add to&nbsp;Yahoo My Web"><img class="social_img" src="http://blog.dervalp.com/wp-content/plugins/social-bookmarks/images/yahoo.png" title="Add to&nbsp;Yahoo My Web" alt="Add to&nbsp;Yahoo My Web" /></a>
<br />
<a style="font-size:90%;text-align: right; " title="Click me to hide the sites." href="#" onclick="$$('div.d196').each( function(e) { e.visualEffect('slide_up',{duration:0.5}) }); return false;">Hide Sites</a>
</div>
</div>
<!-- Social Bookmarks END -->
<script type="text/javascript">$$('div.d196').each( function(e) { e.visualEffect('slide_up',{duration:0.5}) }); </script>]]></content:encoded>
			<wfw:commentRss>http://blog.dervalp.com/2009/05/26/kiwi-mvc-prepare-your-data-access/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>C#.NET Create users in Active Directory</title>
		<link>http://blog.dervalp.com/2009/05/22/cnet-create-users-in-active-directory/</link>
		<comments>http://blog.dervalp.com/2009/05/22/cnet-create-users-in-active-directory/#comments</comments>
		<pubDate>Sat, 23 May 2009 02:26:16 +0000</pubDate>
		<dc:creator>dervalp</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[Active Directory]]></category>
		<category><![CDATA[Adsiedit]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[create]]></category>
		<category><![CDATA[user]]></category>

		<guid isPermaLink="false">http://blog.dervalp.com/?p=122</guid>
		<description><![CDATA[I am currently working for a project in my job where I have to write an application which manage the active directory by a website application. I know that is not the best way to manage users in Active Directory but, well,&#8230;.
First, I decided to use the linq for Active Directory of Bart Desmet, I [...]]]></description>
			<content:encoded><![CDATA[<p>I am currently working for a project in my job where I have to write an application which manage the active directory by a website application. I know that is not the best way to manage users in Active Directory but, well,&#8230;.</p>
<p>First, I decided to use the linq for Active Directory of <a href="http://community.bartdesmet.net/blogs/bart/Default.aspx">Bart Desmet</a>, I know it&#8217;s a pre-alpha version but we do not have a lot of time and I really want to use all the facilities you have when you developed with linq. <a href="http://www.codeplex.com/LINQtoAD">Here is the link</a>. If you used linq to Active Directory, you should have saw that you do not have method to create. Therefore, I decided to use linq to AD for the &#8220;get&#8221; method and the &#8220;classic&#8221; method for creating users.</p>
<p>If you want to create a user in Active Directory, you should follow theses steps :</p>
<p>1) Create the user</p>
<p>2) Set the user&#8217;s password</p>
<p>3) Activate the user</p>
<h2><span id="more-122"></span>1) Create the user in active directory :</h2>
<p>I work with the respository pattern for all the data access.  So I created an ActiveDirectoryRepository where I put all the main &#8220;get&#8221; method and the create, update and delete method.</p>
<p>Here bellow, you can see my code. I create a CreateUser function in which I pass an object ActiveDirectoryUser (custom object).</p>
<p>First I set the directory entry where I want to add my user. It is quite like a connection string. With this link, the application know where he has to make his job.</p>
<p>After, I set all the properties to make a User with some basic information (name, firstname, city, country,&#8230;). When everything is set, I commit the change to active directory.</p>
<p>When it&#8217;s done, I call the ActivePassword function and the ActiveUser function. If everything goes well and if you have not received an exception error, your user in now created in the active directory and can login with the password you set during the creation. Here &#8220;newpassword&#8221;. Of course it is only to show a basic example <img src='http://blog.dervalp.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> .</p>
<p><img class="alignnone size-full wp-image-126" title="create_user_ad_1" src="http://blog.dervalp.com/wp-content/uploads/2009/05/create_user_ad_1.png" alt="create_user_ad_1" width="801" height="585" /></p>
<p>Here under, the code for activate a user and set his password :</p>
<p><img class="alignnone size-full wp-image-127" title="create_user_ad_2" src="http://blog.dervalp.com/wp-content/uploads/2009/05/create_user_ad_2.png" alt="create_user_ad_2" width="806" height="452" /></p>
<p>Why 512 for the userAccountControl ? 512 is the value for a normal account in the active directory. I hardcoded it in the function but of course you can easily make some function to manage the type of user you want to create. To know more about the different possible type of user account, click <a href="http://support.microsoft.com/kb/305144">here</a>.</p>
<p>For example, if you want to have an active user with a password which expires never. You have to know the value for an active user, 512 and the value for the option &#8220;DONT_EXPIRE_PASSWORD&#8221; 65536. You add the number 512 and 65536. So, 66048 is the right number for the properties userAccountControl in this case.</p>
<p>NOTE : If you read my post about managing adam or azam account, I spoke about the support tools for Windows 2003. In these tools, there is one very usefull for developers to know where they have to put the data in. The snap in Adsiedit.msc. It shows you if the thing you are searching is a OU, a CN,&#8230; I will post more details about this tool in another post.</p>
<p>This is the end for today, if you have questions or comments, do not hesitate to leave a comment.</p>
<!-- Social Bookmarks BEGIN -->
<div class="social_bookmark">
<a title="Click me to see the sites." href="#" onclick="$$('div.d122').each( function(e) { e.visualEffect('slide_down',{duration:2.5}) }); return false;"><strong><em>Bookmark It</em></strong></a>
<br />
<div class="d122" style="overflow:hidden">
<br />
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://del.icio.us/post?url=http://blog.dervalp.com/2009/05/22/cnet-create-users-in-active-directory/&amp;title=C%23.NET+Create+users+in+Active+Directory" rel="nofollow" title="Add to&nbsp;Del.icio.us"><img class="social_img" src="http://blog.dervalp.com/wp-content/plugins/social-bookmarks/images/delicious.png" title="Add to&nbsp;Del.icio.us" alt="Add to&nbsp;Del.icio.us" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://digg.com/submit?phase=2&amp;url=http://blog.dervalp.com/2009/05/22/cnet-create-users-in-active-directory/&amp;title=C%23.NET+Create+users+in+Active+Directory" rel="nofollow" title="Add to&nbsp;digg"><img class="social_img" src="http://blog.dervalp.com/wp-content/plugins/social-bookmarks/images/digg.png" title="Add to&nbsp;digg" alt="Add to&nbsp;digg" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.facebook.com/sharer.php?u=http://blog.dervalp.com/2009/05/22/cnet-create-users-in-active-directory/" rel="nofollow" title="Add to&nbsp;Facebook"><img class="social_img" src="http://blog.dervalp.com/wp-content/plugins/social-bookmarks/images/facebook.png" title="Add to&nbsp;Facebook" alt="Add to&nbsp;Facebook" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.google.com/bookmarks/mark?op=edit&amp;output=popup&amp;bkmk=http://blog.dervalp.com/2009/05/22/cnet-create-users-in-active-directory/&amp;title=C%23.NET+Create+users+in+Active+Directory" rel="nofollow" title="Add to&nbsp;Google Bookmarks"><img class="social_img" src="http://blog.dervalp.com/wp-content/plugins/social-bookmarks/images/google.png" title="Add to&nbsp;Google Bookmarks" alt="Add to&nbsp;Google Bookmarks" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://reddit.com/submit?url=http://blog.dervalp.com/2009/05/22/cnet-create-users-in-active-directory/&amp;title=C%23.NET+Create+users+in+Active+Directory" rel="nofollow" title="Add to&nbsp;reddit"><img class="social_img" src="http://blog.dervalp.com/wp-content/plugins/social-bookmarks/images/reddit.png" title="Add to&nbsp;reddit" alt="Add to&nbsp;reddit" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.stumbleupon.com/submit.php?url=http://blog.dervalp.com/2009/05/22/cnet-create-users-in-active-directory/&amp;title=C%23.NET+Create+users+in+Active+Directory" rel="nofollow" title="Add to&nbsp;Stumble Upon"><img class="social_img" src="http://blog.dervalp.com/wp-content/plugins/social-bookmarks/images/stumbleupon.png" title="Add to&nbsp;Stumble Upon" alt="Add to&nbsp;Stumble Upon" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://twitter.com/home/?status=Check+out+C%23.NET+Create+users+in+Active+Directory+@+http://blog.dervalp.com/2009/05/22/cnet-create-users-in-active-directory/" rel="nofollow" title="Add to&nbsp;Twitter"><img class="social_img" src="http://blog.dervalp.com/wp-content/plugins/social-bookmarks/images/twitter.png" title="Add to&nbsp;Twitter" alt="Add to&nbsp;Twitter" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://myweb2.search.yahoo.com/myresults/bookmarklet?u=http://blog.dervalp.com/2009/05/22/cnet-create-users-in-active-directory/&amp;t=C%23.NET+Create+users+in+Active+Directory" rel="nofollow" title="Add to&nbsp;Yahoo My Web"><img class="social_img" src="http://blog.dervalp.com/wp-content/plugins/social-bookmarks/images/yahoo.png" title="Add to&nbsp;Yahoo My Web" alt="Add to&nbsp;Yahoo My Web" /></a>
<br />
<a style="font-size:90%;text-align: right; " title="Click me to hide the sites." href="#" onclick="$$('div.d122').each( function(e) { e.visualEffect('slide_up',{duration:0.5}) }); return false;">Hide Sites</a>
</div>
</div>
<!-- Social Bookmarks END -->
<script type="text/javascript">$$('div.d122').each( function(e) { e.visualEffect('slide_up',{duration:0.5}) }); </script>]]></content:encoded>
			<wfw:commentRss>http://blog.dervalp.com/2009/05/22/cnet-create-users-in-active-directory/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
