<?xml version="1.0" encoding="UTF-8"?><!-- generator="wordpress.com" -->
<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/"
	>

<channel>
	<title>linq &amp;laquo; WordPress.com Tag Feed</title>
	<link>http://en.wordpress.com/tag/linq/</link>
	<description>Feed of posts on WordPress.com tagged "linq"</description>
	<pubDate>Tue, 01 Dec 2009 18:52:35 +0000</pubDate>

	<generator>http://en.wordpress.com/tags/</generator>
	<language>en</language>

<item>
<title><![CDATA[Tự học LINQ]]></title>
<link>http://dyelvn.wordpress.com/2009/11/30/t%e1%bb%b1-h%e1%bb%8dc-linq/</link>
<pubDate>Mon, 30 Nov 2009 07:09:23 +0000</pubDate>
<dc:creator>keithervn</dc:creator>
<guid>http://dyelvn.wordpress.com/2009/11/30/t%e1%bb%b1-h%e1%bb%8dc-linq/</guid>
<description><![CDATA[Đây là bài viết đầu tiên trong loạt bài có chủ đề “LINQ to SQL”, các bài này sẽ cho bạn một cái nhìn]]></description>
<content:encoded><![CDATA[<div class='snap_preview'><div id="post_message_12457"><span style="color:#000000;">Đây là bài viết đầu tiên trong loạt bài có chủ đề “LINQ to SQL”, các bài này sẽ cho bạn một cái nhìn khái quát, giúp bạn làm quen với LINQ, một trong những công nghệ mới có trong .NET 3.5.</span><br />
<span style="color:#000000;">Loạt bài này được dựa trên loạt Tutorial của ScottGu (</span><a href="http://weblogs.asp.net/scottgu" target="_blank"><span style="color:#0000ff;"><strong>http://weblogs.asp.net/scottgu</strong></span></a><span style="color:#000000;">).</span></p>
<p><strong><span style="text-decoration:underline;">LINQ to SQL là gì?</span></strong></p>
<p>LINQ to SQL là một phiên bản hiện thực hóa của O/RM (object relational mapping) có bên trong .NET Framework bản “Orcas” (nay là .NET 3.5), nó cho phép bạn mô hình hóa một cơ sở dữ liệu dùng các lớp .NET. Sau đó bạn có thể truy vấn cơ sở dữ liệu (CSDL) dùng LINQ, cũng như cập nhật/thêm/xóa dữ liệu từ đó.<br />
LINQ to SQL hỗ trợ đầy đủ transaction, view và các stored procedure (SP). Nó cũng cung cấp một cách dễ dàng để thêm khả năng kiểm tra tính hợp lệ của dữ liệu và các quy tắc vào trong mô hình dữ liệu của bạn.<br />
<strong><span style="text-decoration:underline;">Mô hình hóa CSDL dùng LINQ to SQL:</span></strong></p>
<p>Visual Studio “Orcas” đã tích hợp thêm một trình thiết kế LINQ to SQL như một công cụ dễ dàng cho việc mô hình hóa một cách trực quan các CSDL dùng LINQ to SQL. Bài viết sau sẽ đi sâu hơn vào cách dùng trình thiết kế này (bạn cũng có thể <a href="http://weblogs.asp.net/scottgu/archive/2007/01/28/video-using-linq-with-asp-net-in-vs-orcas-part-1.aspx" target="_blank"><strong><span style="color:#536d88;">xem đoạn video này</span></strong></a> để xem cách tôi tạo một mô hình LINQ to SQL).<br />
Bằng cách dùng trình thiết kế LINQ to SQL, tôi có thể dễ dàng tạo một mô hình cho CSDL mẫu “Northwind” giống như dưới đây:<br />
<a href="http://www.scottgu.com/blogposts/linqtosql/step1.jpg"><img src="http://www.scottgu.com/blogposts/linqtosql/step1.jpg" border="0" alt="" /></a><br />
Mô hình LINQ to SQL ở trên định nghĩa bốn lớp thực thể: Product, Category, Order và OrderDetail. Các thuộc tính của mỗi lớp ánh xạ vào các cột của bảng tương ứng trong CSDL. Mỗi instance của một lớp biểu diễn một dòng trong bảng dữ liệu.<br />
Các mũi tên giữa bốn lớp thực thể trên biểu diễn quan hệ giữa các thực thể khác nhau, chúng được tạo ra dựa trên các mối quan hệ primary-key/foreign-key trong CSDL. Hướng của mũi tên chỉ ra mối quan hệ là một &#8211; một hay một &#8211; nhiều. Các thuộc tính tương ứng sẽ được thêm vào các lớp thực thể trong các trường hợp này. Lấy ví dụ, lớp Category ở trên có một mối quan hệ một nhiều với lớp Product, điều này có nghĩa nó sẽ có một thuộc tính “Categories” là một tập hợp các đối tượng Product trong Category này. Lớp Product cũng sẽ có một thuộc tính “Category” chỉ đến đối tượng ”Category” chứa Product này bên trong.<br />
Bảng các phương thức bên tay phải bên trong trình thiết kế LINQ to SQL ở trên chứa một danh sách các SP để tương tác với mô hình dữ liệu của chúng ta. Trong ví dụ trên tôi đã thêm một thủ tục có tên “GetProductsByCategory”. Nó nhận vào một categoryID và trả về một chuỗi các Product. Chúng ta sẽ xem bằng cách nào có thể gọi được thủ tục này trong một đoạn code bên dưới.<br />
<span style="text-decoration:underline;">Tìm hiểu lớp DataContext</span><br />
Khi bạn bấm nút “Save” bên trong màn hình thiết kế LINQ to SQL, Visual Studio sẽ lưu các lớp .NET biểu diễn các thực thể và quan hệ bên trong CSDL mà chúng ta vừa mô hình hóa. Cứ mỗi một file LINQ to SQL chúng ta thêm vào solution, một lớp DataContext sẽ được tạo ra, nó sẽ được dùng khi cần truy vấn hay cập nhật lại các thay đổi. Lớp DataContext được tạo sẽ có các thuộc tính để biểu diễn mối bảng được mô hình hóa từ CSDL, cũng như các phương thức cho mỗi SP mà chúng ta đã thêm vào.<br />
Lấy ví dụ, dưới đây là lớp NorthwindDataContext được sinh ra dựa trên mô hình chúng ta tạo ra ở trên:<br />
<a href="http://www.scottgu.com/blogposts/linqtosql/step2.jpg"><img src="http://www.scottgu.com/blogposts/linqtosql/step2.jpg" border="0" alt="" /></a><br />
<strong><span style="text-decoration:underline;">Các ví dụ LINQ to SQL</span></strong></p>
<p>Một khi đã mô hình hóa CSDL dùng trình thiết kế LINQ to SQL, chúng ta có thể dễ dàng viết các đoạn lệnh để làm việc với nó. Dưới đây là một vài ví dụ về các thao tác chung khi xử lý dữ liệu:<br />
<strong><span style="text-decoration:underline;">1) Lấy các Product từ CSDL</span></strong></p>
<p>Đoạn lệnh dưới đây dùng cú pháp LINQ để lấy về một tập IEnumerable các đối tượng Product. Các sản phẩm được lấy ra phải thuộc phân loại “Beverages”:<br />
<em>C#:</em><br />
<a href="http://www.scottgu.com/blogposts/linqtosql/step3.jpg"><img src="http://www.scottgu.com/blogposts/linqtosql/step3.jpg" border="0" alt="" /></a><br />
<em>VB:</em><br />
<a href="http://www.scottgu.com/blogposts/linqtosql/step9.jpg"><img src="http://www.scottgu.com/blogposts/linqtosql/step9.jpg" border="0" alt="" /></a><br />
<strong><span style="text-decoration:underline;">2) Cập nhật một sản phẩm trong CSDL</span></strong></p>
<p>Đoạn lệnh dưới đây cho thấy cách lấy một sản phẩm, cập nhật lại giá tiền và lưu lại CSDL.<br />
<em>C#:</em><br />
<a href="http://www.scottgu.com/blogposts/linqtosql/step5.jpg"><img src="http://www.scottgu.com/blogposts/linqtosql/step5.jpg" border="0" alt="" /></a><br />
<em>VB:</em><br />
<a href="http://www.scottgu.com/blogposts/linqtosql/step11.jpg"><img src="http://www.scottgu.com/blogposts/linqtosql/step11.jpg" border="0" alt="" /></a><br />
<strong><span style="text-decoration:underline;">3) Chèn thêm một phân loại mới và hai sản phẩm vào CSDL</span></strong></p>
<p>Đoạn mã dưới đây biểu diễn cách tạo một phân loại mới, và tạo hai sản phẩm mới và đưa chúng vào trong phân loại đã tạo. Cả ba sau đó sẽ được đưa vào cơ sở dữ liệu.<br />
Chú ý rằng tôi không cần phải tự quản lý các mối quan hệ primary key/foreign key, thay vào đó, tôi chỉ đơn giản thêm các đối tượng Product vào tập hợp Products của đối tượng category, và rồi thêm đối tượng category vào tập hợp Categories của DataContext, LINQ to SQL sẽ biết cách thiết lập các giá trị primary key/foreign key một cách thích hợp.<br />
<em>C# </em><br />
<a href="http://www.scottgu.com/blogposts/linqtosql/step4.jpg"><img src="http://www.scottgu.com/blogposts/linqtosql/step4.jpg" border="0" alt="" /></a><br />
<em>VB:</em><br />
<a href="http://www.scottgu.com/blogposts/linqtosql/step12.jpg"><img src="http://www.scottgu.com/blogposts/linqtosql/step12.jpg" border="0" alt="" /></a><br />
<strong><span style="text-decoration:underline;">4) Xóa các sản phẩm</span></strong></p>
<p>Đoạn mã sau sẽ biểu diễn cách xóa tất cả các sản phẩm Toy khỏi CSDL:<br />
<em>C#:</em><br />
<a href="http://www.scottgu.com/blogposts/linqtosql/step6.jpg"><img src="http://www.scottgu.com/blogposts/linqtosql/step6.jpg" border="0" alt="" /></a><br />
<em>VB:</em><br />
<a href="http://www.scottgu.com/blogposts/linqtosql/step13.jpg"><img src="http://www.scottgu.com/blogposts/linqtosql/step13.jpg" border="0" alt="" /></a><br />
<strong><span style="text-decoration:underline;">5) Gọi một thủ tục</span></strong></p>
<p>Đoạn mã dưới đây biểu diễn cách lấy các thực thể Product mà không dùng cú pháp của LINQ, mà gọi đến thủ tục “GetProductsByCategory” chúng ta đã thêm vào trước đây. Nhớ rằng một khi đã lấy về kết quả, tôi có thể cập nhật/xóa và sau đó gọi db.SubmitChanges() để cập nhật các thay đổi trở lại CSDL.<br />
<em>C#:</em><br />
<a href="http://www.scottgu.com/blogposts/linqtosql/step7.jpg"><img src="http://www.scottgu.com/blogposts/linqtosql/step7.jpg" border="0" alt="" /></a><br />
<em>VB:</em><br />
<a href="http://www.scottgu.com/blogposts/linqtosql/step14.jpg"><img src="http://www.scottgu.com/blogposts/linqtosql/step14.jpg" border="0" alt="" /></a><br />
<strong><span style="text-decoration:underline;">6) Lấy các sản phẩm và phân trang</span></strong></p>
<p>Đoạn mã dưới đây biểu diễn cách phân trang trên server như một phần của câu truy vấn LINQ. Bằng cách dùng các toán tử Skip() và Take(), chúng ta sẽ chỉ trả về 10 dòng từ CSDL &#8211; bắt đầu từ dòng 200.<br />
<em>C#:</em><br />
<a href="http://www.scottgu.com/blogposts/linqtosql/step8.jpg"><img src="http://www.scottgu.com/blogposts/linqtosql/step8.jpg" border="0" alt="" /></a><br />
<em>VB:</em><br />
<a href="http://www.scottgu.com/blogposts/linqtosql/step10.jpg"><img src="http://www.scottgu.com/blogposts/linqtosql/step10.jpg" border="0" alt="" /></a><br />
<strong><span style="text-decoration:underline;">Tổng kết</span></strong></p>
<p>LINQ to SQL cung cấp một cách hay, rõ ràng để mô hình hóa lớp dữ liệu trong ứng dụng của bạn. Một khi đã định nghĩa mô hinh dữ liệu, bạn có thể dễ dàng thực hiện các câu truy vấn cũng như cập nhật, xóa, sửa dữ liệu một cách hiệu quả.<br />
Hi vọng những hướng dẫn và ví dụ mẫu ở trên đã giúp bạn làm quen với LINQ. Tôi sẽ tiếp tục các bài viết này để giúp bạn khám phá LINQ to SQL một cách chi tiết hơn.</p>
<p><span style="color:#ff9900;"><em>Các bạn đang xem bài viết trong loạt bài “LINQ to SQL”, loạt bài này được dịch từ blog ScottGu </em></span><a href="http://weblogs.asp.net/scottgu/" target="_blank"><span style="color:#ff9900;"><em><strong>http://weblogs.asp.net/scottgu/</strong></em></span></a></div>
</div>]]></content:encoded>
</item>
<item>
<title><![CDATA[Linq Like Operator]]></title>
<link>http://sladescross.wordpress.com/2009/11/29/linq-like-operator/</link>
<pubDate>Sun, 29 Nov 2009 19:54:35 +0000</pubDate>
<dc:creator>sladescross</dc:creator>
<guid>http://sladescross.wordpress.com/2009/11/29/linq-like-operator/</guid>
<description><![CDATA[http://www.devexpertise.com/2009/09/25/implementing-a-linq-version-of-sqls-like-operator/]]></description>
<content:encoded><![CDATA[<div class='snap_preview'><p><a href="http://www.devexpertise.com/2009/09/25/implementing-a-linq-version-of-sqls-like-operator/">http://www.devexpertise.com/2009/09/25/implementing-a-linq-version-of-sqls-like-operator/</a></p>
</div>]]></content:encoded>
</item>
<item>
<title><![CDATA[راه های دسترسی به داده در دات نت فریم ورک!]]></title>
<link>http://farasun.wordpress.com/2009/11/29/data-access-ways-in-net-framework/</link>
<pubDate>Sun, 29 Nov 2009 15:09:50 +0000</pubDate>
<dc:creator>ایمان</dc:creator>
<guid>http://farasun.wordpress.com/2009/11/29/data-access-ways-in-net-framework/</guid>
<description><![CDATA[در اکثر برنامه های کامپیوتری نیاز به ذخیره و بازیابی داده ها وجود دارد. داده هایی که بدون آن ها سیست]]></description>
<content:encoded><![CDATA[<div class='snap_preview'><blockquote>
<p style="text-align:justify;">در اکثر برنامه های کامپیوتری نیاز به ذخیره و بازیابی داده ها وجود دارد. داده هایی که بدون آن ها سیستم نرم افزاری ما معنایی ندارد. برنامه نویسان معمولاً راه های مختلفی برای این کار سراغ دارند. کسانی که با دات نت فریم ورک برنامه نویسی می کنند راه های مختلفی برای دسترسی به داده ها دارند. در این مطلب با تکنولوژی های مایکروسافت برای این کار آشنا خواهیم شد و سه ORM معروف دنیای دات نت را معرفی خواهیم کرد. مایکروسافت انتخاب های زیادی برای دسترسی به داده ها به برنامه نویسان دات نت می دهد که شما باید با بررسی آن ها و با توجه به نیازهای خودتان یکی از آن ها را انتخاب کنید.</p>
</blockquote>
<h2>ADO.NET</h2>
<p style="text-align:justify;"><strong>ADO.NET</strong> مجموعه ای از کامپوننت هاست که برنامه نویسان می توانند از آن ها برای برقراری ارتباط با دیتابیس های مختلف استفاده کنند. ADO.NET بخشی از کتابخانه کلاس های پایه دات نت فریم ورک است که توسط مایکروسافت توسعه داده می شود. برنامه نویسان به صورت گسترده از این تکنولوژی برای دسترسی و دستکاری داده های ذخیره شده در یک دیتابیس رابطه ای استفاده می کنند. ADO.NET می تواند با اکثر دیتابیس های موجود کار کند، هر چند به صورت پیش فرض در دات نت فریم ورک فقط فراهم کننده های SQL Server، OleDb و Odbc وجود دارد، افراد و شرکت های دیگر فراهم کننده های دیتابیس های دیگر را برای دات نت ایجاد کرده اند.</p>
<p style="text-align:justify;">برای هر <strong>Provider</strong> کامپوننت هایی وجود دارند که برنامه نویس با استفاده از آن ها به مقصودش می رسد. به طور مثال برای استفاده از SQL Server در روش ADO.NET کامپوننت هایی مانند <strong>SQLConnection</strong> و <strong>SQLCommand</strong> وجود دارد که با استفاده از آن ها می توانید یک دستور SQL را روی داده های موجود در یک دیتابیس SQL Server اجرا کنید. با SQLConnection به دیتابیس موجود در SQL Server وصل می شویم و با استفاده از یک SQLCommand می توانیم یک عبارت T-SQL را که می تواند دستور INSERT, UPDATE, DELETE یا SELECT باشد یا حتی یک Stored Procedure یا عبارت DDL باشد را برای مقصود خاصی روی دیتابیس اجرا کنیم. چون ADO.NET در مورد سینتاکس دیتابیس چیزی نمی داند، دستورات را به صورت یک رشته ساده به SQLCommand می دهیم و این شیء نیز به صورت مستقیم به دیتابیس دستور می دهد.</p>
<p style="text-align:left;"><code><span style="color:#0000ff;">string</span> query = <span style="color:#ff0000;">"SELECT * FROM tblCustomers"</span>;<br />
<span style="color:#33cccc;">SqlConnection</span> con = <span style="color:#0000ff;">new</span> <span style="color:#00ccff;">SqlConnection</span>(cnnString);<br />
<span style="color:#00ccff;">SqlCommand</span> command = <span style="color:#0000ff;">new</span> <span style="color:#00ccff;">SqlCommand</span>(query, con);<br />
con.Open();<br />
<span style="color:#00ccff;">SqlDataReader</span> reader = command.ExecuteReader();<br />
<span style="color:#0000ff;">while</span> (reader.Read())<br />
{<br />
Response.Write(reader.GetInt32(0) +<br />
reader.GetString(1));<br />
}</code></p>
<p style="text-align:justify;">نکته ای که باید در مورد ADO.NET بدانید این است که برای استفاده از هر سیستم دیتابیس رابطه ای، مجموعه کامپوننت های جدایی وجود دارد. در مثال بالا از آبجکت های مربوط به SQL Server استفاده کردیم. اگر بخواهید مثلاً از یک دیتابیس اوراکل در برنامه خود استفاده کنید، بایستی از کامپوننت های مربوط به اوراکل استفاده کنید. خوشبختانه تمام این کامپوننت ها بر پایه یک Interface ساخته شده اند، این یعنی شما می توانید با استفاده از کلاس DbProviderFactory برنامه ای بسیازید که با چند نوع دیتابیس مختلف کار کند.</p>
<h2>Linq to SQL</h2>
<p style="text-align:justify;">مایکروسافت با دات نت فریم ورک 3.0 و 3.5 یک <a title="Object Relational Mapping on Wikipedia" href="http://en.wikipedia.org/wiki/Object-Relational_mapping" target="_blank"><strong>ORM</strong></a> به نام <strong>Linq to SQL</strong> را به عنوان بخشی از پروژه LINQ خود عرضه کرد. این شرکت مدت ها پیش از آن قول داده بود که یک ORM برای دات نت فریم ورک طراحی کند اما تا نسخه 3.0 دات نت فریم ورک خبری از آن پروژه نشد. Linq to SQL به شما اجازه می دهد که کوئری های LINQ را روی دیتابیس های SQL Server اجرا کنید. علاوه بر این از یک Mapping Framework بهره می برد که به برنامه نویسان اجازه Map کردن جدول های یک دیتابیس را به کلاس ها و بالعکس می دهد. این کار در ویژوال استادیو می تواند به صورت ویژوال یا کدنویسی انجام گیرد. به این صورت که برای هر جدول از دیتابیس یک کلاس تعریف می شود که هر ستون از یک جدول به عنوان یک Property درون آن کلاس تعریف می شود.</p>
<p style="text-align:justify;">
<div id="attachment_1221" class="wp-caption aligncenter" style="width: 460px"><a title="برای دیدن نمای بزرگتر کلیک کنید" href="http://farasun.wordpress.com/files/2009/11/linq-to-sql-large.png" target="_blank"><img class="size-full wp-image-1221" title="linq-to-sql-thumb" src="http://farasun.wordpress.com/files/2009/11/linq-to-sql-thumb.png" alt="" width="450" height="253" /></a><p class="wp-caption-text">نمایی از ابزار طراحی ویژوال Linq to SQL</p></div>
<p style="text-align:justify;">به مثال زیر توجه کنید :<br />
<code><span style="color:#0000ff;">public</span> <span style="color:#0000ff;">class</span> Customer<br />
{<br />
[<span style="color:#00ccff;">Column</span>(Name=<span style="color:#ff0000;">"CustomerID"</span>,IsPrimaryKey = <span style="color:#0000ff;">true</span>)]<br />
<span style="color:#0000ff;">public</span> <span style="color:#0000ff;">long</span> ID<br />
{<br />
<span style="color:#0000ff;">get</span> { <span style="color:#0000ff;">return</span> _ID;}<br />
<span style="color:#0000ff;">set</span> { _ID = value;}<br />
}<br />
[<span style="color:#00ccff;">Column</span>(Name = <span style="color:#ff0000;">"CustomerName"</span>)]<br />
<span style="color:#0000ff;">public</span> <span style="color:#0000ff;">string</span> Name<br />
{<br />
<span style="color:#0000ff;">get</span> { <span style="color:#0000ff;">return</span> _name; }<br />
<span style="color:#0000ff;">set</span> { _name = value; }<br />
}<br />
}</code><br />
کلاس بالا به جدول tblCustomers که دارای دو ستون CustomerID و CustomerName است Map می شود. قبل از اینکه بخواهید از Linq to SQL استفاده کنید باید این کلاس ها را تعریف کنید. ویژوال استادیو 2008 دارای ابزاری است که به صورت ویژوال به شما امکان Map کردن جدول های یک دیتابیس SQL Server را به کلاس های دات نت می دهد. این ابزار می تواند به صورت اتوماتیک کلاس های مورد نیاز شما را از روی مدل دیتابیس بسازد، و حتی اجازه تغییرات دستی و ایجاد Viewهای مختلف از دیتابیس را به شما می دهد. عملیات Mapping با استفاده از DataContext (که یک رشته اتصال به سرور نیاز دارد) پیاده سازی می شود. سپس شما قادر خواهید بود کوئری های LINQ خود را روی دیتابیس موجود در سرور اجرا کنید، که البته این کوئری ها ابتدا به دستوارت T-SQL متناظر ترجمه و سپس روی دیتابیس مورد نظر اجرا می شوند.</p>
<h2>Entity Framework</h2>
<p style="text-align:justify;"><a href="http://www.microsoft.com/sqlserver/2008/en/us/ado-net-entity.aspx" target="_blank"><strong>Entity Framework</strong></a> یک فریم ورک ORM برای دات نت فریم ورک است که نسخه یک آن به همراه دات نت فریم ورک 3.5 سرویس پک 1 عرضه شد اما مورد استقبال توسعه دهندگان قرار نگرفت. نسخه 2 این فریم ورک به صورت بتا به عنوان بخشی از ویژوال استادیو 2010 قابل دسترس است.<strong> ADO.NET Entity Framework</strong> نام اصلی این فریم ورک است و جزئی از تکنولوژی ADO.NET است.</p>
<p style="text-align:justify;">
<div id="attachment_1225" class="wp-caption aligncenter" style="width: 460px"><img class="size-full wp-image-1225" title="SFS_EF_model" src="http://farasun.wordpress.com/files/2009/11/sfs_ef_model.jpg" alt="ابزار طراحی Entity Framework در ویژوال استادیو" width="450" height="295" /><p class="wp-caption-text">ابزار طراحی Entity Framework در ویژوال استادیو</p></div>
<p style="text-align:justify;">Entity Framework مدل رابطه ای موجود در یک دیتابیس را به مدل مفهمومی تبدیل می کند و آن را به اپلیکیشن ما تحویل می دهد. در مدل رابطه ای عناصر ترکیبی از جداول هستند، به همراه کلید های اصلی و خارجی که جدول ها را به هم مرتبط می سازند. برعکس آن، انواع موجودیت ها مدل مفهومی داده را تعریف می کنند. انواع موجودیت  اجتماعی از چند فیلد است (هر فیلد به یک ستون از دیتابیس Map می شود) و می تواند شامل اطلاعات از چند جدول فیزیکی باشد. انواع موجودیت می توانند به هم مرتبط باشند، مستقل از ارتباطاتی که در مدل فیزیکی دارند. شمای منطقی و نگاشت (mapping) آن به شمای فیزیکی به عنوان یک Entity Data Model یا EDM نمایش داده می شوند که مشخصات EDM در یک فایل XML ذخیره می شود. Entity Framework از EDM برای انجام عملیات نگاشت و دادن قابلیت کار با موجودیت ها به اپلیکیشن استفاده می کند. Entity Framework اطلاعات مورد نیاز هر موجودیت را با Join کردن چندین جدول از مدل فیزیکی (دیتابیس) بدست می آورد. هنگامی که اطلاعات یک موجودیت آپدیت می شود، Entity Framework بررسی می کند که داده ها مربوط به کدام یک از جدول های موجود در دیتابیس هستند، سپس آن ها را با دستور SQL مناسب آپدیت می کند.</p>
<p style="text-align:justify;">هر چند Entity Framework و Linq to SQL بسیار شبیه به هم به نظر می رسند، هر دو ابزارهایی برای طراحی گرافیکی و ویزاردی برای نگاشت یک دیتابیس به مدل شیء گرا دارند و هر دو می توانند از کوئری های LINQ برای مقصود خاصی استفاده کنند، اما با هم تفاوت هایی هم دارند. بیان تفاوت های این دو در این مطلب جایی ندارد.</p>
<h2>NHibernate</h2>
<p style="text-align:justify;"><img class="alignright" title="orm" src="../files/2009/11/orm.png" alt="" width="280" height="190" />نمی توان در مورد ORMها در دات نت صحبت کرد اما نام <a href="http://www.nhforge.org/" target="_blank"><strong>NHiernate</strong></a> را ذکر نکرد. NH یک فریم ورک ORM اوپن سورس برای دات نت فریم ورک است که از روی پروژه موفق Hibernate جاوا وارد دنیای دات نت شد. توضیحات بیشتر در مورد NHibernate توضیحات اضافی است، زیرا این فریم ورک هم وظیفه ORMهای دیگر را انجام می دهد. اکثر برنامه نویسانی که از NH برای نگاشت استفاده می کنند، ابتدا کلاس های خود را تعریف می کنند و سپس با استفاده از یک فایل XML آن ها را به جدول های دیتابیس Map می کنند. Linq to SQL و Entity Framework برخلاف NHibernate از روش Model-first یا مبتنی در دیتابیس استفاده می کنند، به این معنی که هر دو ORM تصور می کنند شما دیتابیسی در اختیار دارید که می خواهید آن به تعدادی آبجکت Map کنید.</p>
<p>در مورد Nhibernate بیش از این صحبت نمی کنم، آقای وحید نصیری در<a href="http://vahidnasiri.blogspot.com/search/label/NHibernate" target="_blank"><strong> اینجا</strong></a> به صورت کامل در مورد این ORM محبوب نوشته است.</p>
<p><span style="color:#ffffff;">farasun.wordpress.com</span></p>
<p>انتخاب از میان روش های بالا به عهده خود شماست. در این مطلب کوتاه نمی توان به بررسی تمام زوایا و تفاوت های میان آن ها پرداخت. در مطالب آینده سعی میکنم در مورد نحوه استفاده از هر کدام یک مثال عملی بزنم (البته به جز NHibernate).</p>
</div>]]></content:encoded>
</item>
<item>
<title><![CDATA[Using Ext JS Grid with ASP.NET MVC]]></title>
<link>http://nraykov.wordpress.com/2009/11/29/using-ext-js-grid-with-asp-net-mvc/</link>
<pubDate>Sun, 29 Nov 2009 13:51:14 +0000</pubDate>
<dc:creator>Nikolay Raykov</dc:creator>
<guid>http://nraykov.wordpress.com/2009/11/29/using-ext-js-grid-with-asp-net-mvc/</guid>
<description><![CDATA[ASP.NET MVC is the new cool kid on the block of Microsoft platforms. I have been using it for a litt]]></description>
<content:encoded><![CDATA[<div class='snap_preview'><p>ASP.NET MVC is the new cool kid on the block of Microsoft platforms. I have been using it for a little over half an year and I can say that I like it much more than ASP.NET. Why is that?</p>
<ol>
<li>No more viewstate which adds an additional overhead on your page</li>
<li>Clean separation of concerns through the MVC pattern</li>
<li>Going back to the basics (standard HTML controls) &#8211; most of the ASP.NET server controls do not work with ASP.NET MVC because there is no viewstate and the notion of postbacks</li>
</ol>
<p>This would be the first of a series of blog posts that I would write about ASP.NET MVC and some performance techniques that could get the most out of it. We will start by building a simple application that uses Ext JS Grid to display employees data that is fetched from the AdventureWorks database. Since jQuery is being shipped with Visual Studio for over a year now I will be using it as well &#8211; as an adapter to Ext JS (I am a big fan of jQuery).</p>
<p>I am going to create my app using Visual Stidio 2010 Beta 2 which ships with ASP.NET MVC 2 Beta. If you are using Visual Studio 2008 you have to download the <a href="http://www.microsoft.com/downloads/details.aspx?FamilyID=4817cdb2-88ea-4af4-a455-f06b4c90fd2c&#38;displaylang=en" target="_blank">Beta</a> and install it on your machine. First we start by creating a new ASP.NET MVC Project.</p>
<p style="text-align:center;">
<div id="attachment_65" class="wp-caption aligncenter" style="width: 610px"><a href="http://nraykov.wordpress.com/files/2009/11/step_11.png"><img class="size-full wp-image-65" title="New ASP.NET MVC Project" src="http://nraykov.wordpress.com/files/2009/11/step_11.png" alt="New ASP.NET MVC Project" width="600" height="413" /></a><p class="wp-caption-text">New ASP.NET MVC Project</p></div>
<p>Next I am copying the necessary files that are needed for Ext JS &#8211; ext-all.debug.js and ext-jquery-adapter.js to an extjs folder I created under my Scripts folder which was created for me by the ASP.NET MVC project template. I will use the latest version of the library &#8211; <a href="http://www.extjs.com/" target="_blank">Ext JS 3.0.3</a>.</p>
<p>In the next step we need to include the css and js files &#8211; I will put them in the master page (located under Views/Shared folder):</p>
<pre style="overflow:auto;"><span style="color:#0000ff;">&#60;</span><span style="color:#800000;">link</span> <span style="color:#ff0000;">href</span><span style="color:#0000ff;">="../../Content/resources/css/ext-all.css"</span> <span style="color:#ff0000;">rel</span><span style="color:#0000ff;">="stylesheet"</span> <span style="color:#ff0000;">type</span><span style="color:#0000ff;">="text/css"</span> <span style="color:#0000ff;">/&#62;</span>
<span style="color:#0000ff;">&#60;</span><span style="color:#800000;">script</span> <span style="color:#ff0000;">type</span><span style="color:#0000ff;">="text/javascript"</span> <span style="color:#ff0000;">src</span><span style="color:#0000ff;">="../../Scripts/jquery-1.3.2.js"</span><span style="color:#0000ff;">&#62;&#60;/</span><span style="color:#800000;">script</span><span style="color:#0000ff;">&#62;</span>
<span style="color:#0000ff;">&#60;</span><span style="color:#800000;">script</span> <span style="color:#ff0000;">type</span><span style="color:#0000ff;">="text/javascript"</span> <span style="color:#ff0000;">src</span><span style="color:#0000ff;">="../../Scripts/extjs/ext-jquery-adapter.js"</span><span style="color:#0000ff;">&#62;&#60;/</span><span style="color:#800000;">script</span><span style="color:#0000ff;">&#62;</span>
<span style="color:#0000ff;">&#60;</span><span style="color:#800000;">script</span> <span style="color:#ff0000;">type</span><span style="color:#0000ff;">="text/javascript"</span> <span style="color:#ff0000;">src</span><span style="color:#0000ff;">="../../Scripts/extjs/ext-all-debug.js"</span><span style="color:#0000ff;">&#62;&#60;/</span><span style="color:#800000;">script</span><span style="color:#0000ff;">&#62;</span></pre>
<p>The order in which you include the JavaScript files is important.</p>
<p><em>Note: Please remember that it is essential to put all your css files in the head section of the page &#8211; this improves the loading of your page. All js files that are needed for the page rendering should also be put in the head, otherwise they should be put at the end of your page. I will talk more about this in a future blog post.</em></p>
<p>For the purpose of this sample application I will use the AdventureWorks database alongside with the Entity Framework for my data model. First we have to add the database into the App_Data folder and then create our data model in the Models folder. The Entity Framework will generate all the necessary entities and a context class and we are ready to write our data access code &#8211; I will write my LINQ queries against the database in the controller classes though you will not do this in a real world application. You would use for example the Repository pattern, put your data access logic in a separate assembly, maybe write your own services that will abstract away the business logic and inject them with some Dependency Injection framework, etc.</p>
<div id="attachment_63" class="wp-caption aligncenter" style="width: 610px"><a href="http://nraykov.wordpress.com/files/2009/11/ef_datamodel.png"><img class="size-full wp-image-63" title="Entity Framework Data Model" src="http://nraykov.wordpress.com/files/2009/11/ef_datamodel.png" alt="Entity Framework Data Model" width="600" height="414" /></a><p class="wp-caption-text">Entity Framework Data Model</p></div>
<p>Now that we have everything in place we can write an action method which would return a subset of employees:</p>
<pre style="overflow:auto;">[AcceptVerbs(HttpVerbs.Get)]
[ActionName(<span style="color:#006080;">"Employees"</span>)]
<span style="color:#0000ff;">public</span> JsonResult GetEmployees()
{
   <span style="color:#0000ff;">int</span> start = Convert.ToInt32(Request.QueryString[<span style="color:#006080;">"start"</span>]);
   <span style="color:#0000ff;">int</span> limit = Convert.ToInt32(Request.QueryString[<span style="color:#006080;">"limit"</span>]);

   <span style="color:#0000ff;">using</span> (AdventureWorksEntities dbContext = <span style="color:#0000ff;">new</span> AdventureWorksEntities())
   {
      var query = dbContext.Employees
                              .Include(<span style="color:#006080;">"Contact"</span>)
                              .OrderBy(emp =&#62; emp.EmployeeID);
      var result = (from emp <span style="color:#0000ff;">in</span> query
                                  .Skip(start).Take(limit).ToList()
                    select <span style="color:#0000ff;">new</span>
                    {
                       ID = emp.EmployeeID,
                       FirstName = emp.Contact.FirstName,
                       LastName = emp.Contact.LastName,
                       BirthDate = emp.BirthDate.ToShortDateString(),
                       HireDate = emp.HireDate.ToShortDateString(),
                       VacationHours = emp.VacationHours,
                       SickLeaveHours = emp.SickLeaveHours,
                       Email = emp.Contact.EmailAddress,
                       Phone = emp.Contact.Phone
                    }).ToList();

      <span style="color:#0000ff;">return</span> Json(<span style="color:#0000ff;">new</span> { data = result, totalCount = query.Count() }, JsonRequestBehavior.AllowGet);
   }
}</pre>
<p>Notice the <strong>AcceptVerbs </strong>attribute that the method is decorated with &#8211; it tells the framework that only GET requests are allowed to call the method through the <strong>HttpVerbs </strong>enumeration. This was the way to constrain the requests so far but in the new version of ASP.NET MVC there are some new handy attributes that you could use as well &#8211; <strong>HttpGet</strong>, <strong>HttpPost</strong>, <strong>HttpPut </strong>and <strong>HttpDelete </strong>which do the same thing. I am using the <strong>ActionName </strong>attribute to explicitly add a name for my action method so that I could have a nice URL schema for my actions and use the same name for different CRUD operations (I just need to use different verb for the requests).</p>
<p>In the method itself I create an instance of the database context and based on the parameters received from the grid I do paging with the LINQ extension methods Skip and Take. The interesting part is when the data is returned as a JSON &#8211; in ASP.NET MVC 1 the JSON method required a single parameter while now you have to pass an additional parameter of type JsonRequestBehavior. It is introduced for security reasons and you as a developer should explicitly decide whether or not to support GET requests. The problem is that if you return a response in the form of a JSON Array for a GET request it could be easily compromised, so it is suggested to wrap it inside a JSON object or do POSTs instead of that. You could read more about this in <a title="JSON Hijacking" href="http://haacked.com/archive/2009/06/25/json-hijacking.aspx" target="_blank">Phil Haack&#8217;s post</a>.</p>
<p>Next we need to write the JavaScript code that will instantiate our grid and fetch the data from the server:</p>
<pre style="font-size:small;color:black;font-family:Consolas,;overflow:auto;"><span style="color:#0000ff;">&#60;</span><span style="color:#800000;">script</span> <span style="color:#ff0000;">type</span><span style="color:#0000ff;">="text/javascript"</span><span style="color:#0000ff;">&#62;</span>
   $(document).ready(<span style="color:#0000ff;">function</span> () {
      <span style="color:#0000ff;">var</span> store = <span style="color:#0000ff;">new</span> Ext.data.Store({
         proxy: <span style="color:#0000ff;">new</span> Ext.data.HttpProxy({
            url: <span style="color:#006080;">'Home/Employees'</span>,
            dataType: <span style="color:#006080;">'json'</span>,
            method: <span style="color:#006080;">'GET'</span>
         }),
         reader: <span style="color:#0000ff;">new</span> Ext.data.JsonReader({
            root: <span style="color:#006080;">'data'</span>,
            totalProperty: <span style="color:#006080;">'totalCount'</span>
         }, Ext.data.Record.create([
            { name: <span style="color:#006080;">'ID'</span>, mapping: <span style="color:#006080;">'ID'</span> },
            { name: <span style="color:#006080;">'FirstName'</span>, mapping: <span style="color:#006080;">'FirstName'</span> },
            { name: <span style="color:#006080;">'LastName'</span>, mapping: <span style="color:#006080;">'LastName'</span> },
            { name: <span style="color:#006080;">'BirthDate'</span>, mapping: <span style="color:#006080;">'BirthDate'</span> },
            { name: <span style="color:#006080;">'HireDate'</span>, mapping: <span style="color:#006080;">'HireDate'</span> },
            { name: <span style="color:#006080;">'VacationHours'</span>, mapping: <span style="color:#006080;">'VacationHours'</span> },
            { name: <span style="color:#006080;">'SickLeaveHours'</span>, mapping: <span style="color:#006080;">'SickLeaveHours'</span> },
            { name: <span style="color:#006080;">'Email'</span>, mapping: <span style="color:#006080;">'Email'</span> },
            { name: <span style="color:#006080;">'Phone'</span>, mapping: <span style="color:#006080;">'Phone'</span> }
         ]))
      });

      <span style="color:#0000ff;">var</span> grid = <span style="color:#0000ff;">new</span> Ext.grid.GridPanel({
         store: store,
         columns: [
            { header: <span style="color:#006080;">'ID'</span>, dataIndex: <span style="color:#006080;">'ID'</span>, hidden: <span style="color:#0000ff;">true</span> },
            { header: <span style="color:#006080;">'First Name'</span>, dataIndex: <span style="color:#006080;">'FirstName'</span>, width: 100 },
            { header: <span style="color:#006080;">'Last Name'</span>, dataIndex: <span style="color:#006080;">'LastName'</span>, width: 100 },
            { header: <span style="color:#006080;">'Birth Date'</span>, dataIndex: <span style="color:#006080;">'BirthDate'</span>, width: 100 },
            { header: <span style="color:#006080;">'Hire Date'</span>, dataIndex: <span style="color:#006080;">'HireDate'</span>, width: 100 },
            { header: <span style="color:#006080;">'Vacation Hours'</span>, dataIndex: <span style="color:#006080;">'VacationHours'</span>, width: 100 },
            { header: <span style="color:#006080;">'Sick Leave Hours'</span>, dataIndex: <span style="color:#006080;">'SickLeaveHours'</span>, width: 100 },
            { header: <span style="color:#006080;">'Email'</span>, dataIndex: <span style="color:#006080;">'Email'</span>, width: 200 },
            { header: <span style="color:#006080;">'Phone'</span>, dataIndex: <span style="color:#006080;">'Phone'</span>, width: 200 }
         ],
         renderTo: <span style="color:#006080;">'grid'</span>,
         width: 1000,
         autoHeight: <span style="color:#0000ff;">true</span>,
         bbar: <span style="color:#0000ff;">new</span> Ext.PagingToolbar({
            store: store,
            pageSize: 25,
            displayInfo: <span style="color:#0000ff;">true</span>,
            displayMsg: <span style="color:#006080;">'Displaying employees {0} - {1} of {2}'</span>,
            emptyMsg: <span style="color:#006080;">"No employees to display"</span>
         }),
         pageSize: 20,
         title: <span style="color:#006080;">'Employees'</span>
      });

      grid.getStore().load({ <span style="color:#0000ff;">params</span>: {
         start: 0,
         limit: 25
      }
   });
});
<span style="color:#0000ff;">&#60;/</span><span style="color:#800000;">script</span><span style="color:#0000ff;">&#62;</span></pre>
<p>When the DOM is ready to be manipulated I create a Store which will make the request to the server and use a JsonReader object which has all the necessary mappings in place to parse the data. Then an instance of the Grid is created with the store that was created in the previous step and columns which are mapped to the parsed JSON result object. That&#8217;s all you need to do &#8211; create these objects passing some configurations and you are ready to get your data. All the tricky parts of making an XmlHttpRequest, parsing the JSON, creating the HTML for the grid is done for you. Here is how the grid looks like when the application is run:</p>
<div id="attachment_78" class="wp-caption aligncenter" style="width: 610px"><a href="http://nraykov.wordpress.com/files/2009/11/ext_js_grid.png"><img class="size-full wp-image-78" title="Ext Js Grid" src="http://nraykov.wordpress.com/files/2009/11/ext_js_grid.png" alt="Ext Js Grid" width="600" height="382" /></a><p class="wp-caption-text">Ext Js Grid</p></div>
<p>This is a simple application in which I wanted to show you how to use Ext JS Grid to present data in a nice tabular fashion using ASP.NET MVC and Entity Framework. Here you could <a href="http://www.box.net/shared/f20o4ol724">download</a> the code for this app (I have not included the AdventureWorks database in order to keep the file size small, but you could download it from <a href="http://www.codeplex.com/MSFTDBProdSamples" target="_blank">here</a>).</p>
<p>In my next blog post I will show you how to write ASP.NET MVC HTML extension methods to include CSS and JavaScript files in your pages and how to instantiate some jQuery UI plugin widgets.</p>
</div>]]></content:encoded>
</item>
<item>
<title><![CDATA[XrmLinq]]></title>
<link>http://crmlinks.wordpress.com/2009/11/29/xrmlinq/</link>
<pubDate>Sat, 28 Nov 2009 23:09:44 +0000</pubDate>
<dc:creator>Jukka</dc:creator>
<guid>http://crmlinks.wordpress.com/2009/11/29/xrmlinq/</guid>
<description><![CDATA[Linq to Dynamics CRM .NET library http://www.xrmlinq.com/default.aspx]]></description>
<content:encoded><![CDATA[<div class='snap_preview'><p>Linq to Dynamics CRM .NET library</p>
<p><a href="http://www.xrmlinq.com/default.aspx" target="_blank">http://www.xrmlinq.com/default.aspx</a></p>
</div>]]></content:encoded>
</item>
<item>
<title><![CDATA[Using INTERSECT with LINQ to XML]]></title>
<link>http://santoshbenjamin.wordpress.com/2009/11/28/using-intersect-with-linq-to-xml/</link>
<pubDate>Sat, 28 Nov 2009 17:21:16 +0000</pubDate>
<dc:creator>santoshbenjamin</dc:creator>
<guid>http://santoshbenjamin.wordpress.com/2009/11/28/using-intersect-with-linq-to-xml/</guid>
<description><![CDATA[In terms of hands-on coding (not general awareness) I&#8217;m a bit of a newbie to the world of LINQ]]></description>
<content:encoded><![CDATA[In terms of hands-on coding (not general awareness) I&#8217;m a bit of a newbie to the world of LINQ]]></content:encoded>
</item>
<item>
<title><![CDATA[LINQ]]></title>
<link>http://miteshisheth.wordpress.com/2009/11/27/linq/</link>
<pubDate>Fri, 27 Nov 2009 08:27:18 +0000</pubDate>
<dc:creator>miteshisheth</dc:creator>
<guid>http://miteshisheth.wordpress.com/2009/11/27/linq/</guid>
<description><![CDATA[I’m going to use following class for my entire explanation of LINQ. I’ve two classes one is Employee]]></description>
<content:encoded><![CDATA[<div class='snap_preview'><p>I’m going to use following class for my entire explanation of LINQ. </p>
<p>I’ve two classes one is Employee and other one is Address. If you observe, Employee class has one property (OfficeAddress) type of Address and HomeAddresses type of list of Addresses.</p>
<div style="padding:5px;" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:770fd967-706d-44d2-a374-c864f427ae1c" class="wlWriterEditableSmartContent">
<div style="border:#000080 1px solid;font-family:'Courier New', Courier, Monospace;font-size:10pt;">
<div style="background:#000080;color:#fff;font-family:Verdana, Tahoma, Arial, sans-serif;font-weight:bold;padding:2px 5px;">Code Snippet</div>
<div style="background:#ddd;max-height:300px;overflow:auto;padding:0;">
<ol style="background:#ffffff;white-space:wrap;margin:0 0 0 35px;">
<li> <span style="color:#0000ff;">public</span> <span style="color:#0000ff;">class</span> <span style="color:#2b91af;">Employee</span></li>
<li style="background:#f3f3f3;">     {</li>
<li>         <span style="color:#0000ff;">public</span> <span style="color:#0000ff;">string</span> FirstName { <span style="color:#0000ff;">get</span>; <span style="color:#0000ff;">set</span>; }   </li>
<li style="background:#f3f3f3;">         <span style="color:#0000ff;">public</span> <span style="color:#0000ff;">string</span> LastName { <span style="color:#0000ff;">get</span>; <span style="color:#0000ff;">set</span>; }</li>
<li>         <span style="color:#0000ff;">public</span> <span style="color:#2b91af;">List</span>&#60;<span style="color:#2b91af;">Address</span>&#62; HomeAddresses { <span style="color:#0000ff;">get</span>; <span style="color:#0000ff;">set</span>; }</li>
<li style="background:#f3f3f3;">         <span style="color:#0000ff;">public</span> <span style="color:#2b91af;">Address</span> OfficeAddress { <span style="color:#0000ff;">get</span>; <span style="color:#0000ff;">set</span>; }</li>
<li>         <span style="color:#0000ff;">public</span> <span style="color:#0000ff;">int</span> Salary { <span style="color:#0000ff;">get</span>; <span style="color:#0000ff;">set</span>; }</li>
<li style="background:#f3f3f3;">         <span style="color:#0000ff;">public</span> <span style="color:#0000ff;">int</span> MyProperty { <span style="color:#0000ff;">get</span>; <span style="color:#0000ff;">set</span>; }</li>
<li> </li>
<li style="background:#f3f3f3;"> </li>
<li>         <span style="color:#0000ff;">public</span> <span style="color:#0000ff;">static</span> <span style="color:#2b91af;">List</span>&#60;<span style="color:#2b91af;">Employee</span>&#62; getEmployee()</li>
<li style="background:#f3f3f3;">         {</li>
<li> </li>
<li style="background:#f3f3f3;">             <span style="color:#2b91af;">List</span>&#60;<span style="color:#2b91af;">Employee</span>&#62; employees = <span style="color:#0000ff;">new</span> <span style="color:#2b91af;">List</span>&#60;<span style="color:#2b91af;">Employee</span>&#62;()</li>
<li>             {<span style="color:#0000ff;">new</span> <span style="color:#2b91af;">Employee</span>(){ FirstName=<span style="color:#a31515;">&#8220;Mitesh&#8221;</span>, LastName=<span style="color:#a31515;">&#8220;Sheth&#8221;</span>, Salary=50000, OfficeAddress=<span style="color:#0000ff;">new</span> <span style="color:#2b91af;">Address</span>(){ Add1=<span style="color:#a31515;">&#8220;Manyata&#8221;</span>, City=<span style="color:#a31515;">&#8220;Bangalore&#8221;</span>}, HomeAddresses=<span style="color:#0000ff;">new</span> <span style="color:#2b91af;">List</span>&#60;<span style="color:#2b91af;">Address</span>&#62;(){<span style="color:#0000ff;">new</span> <span style="color:#2b91af;">Address</span>{ Add1=<span style="color:#a31515;">&#8220;Baroda&#8221;</span>, City=<span style="color:#a31515;">&#8220;Ahd&#8221;</span>},<span style="color:#0000ff;">new</span> <span style="color:#2b91af;">Address</span>{ Add1=<span style="color:#a31515;">&#8220;Bombay&#8221;</span>, City=<span style="color:#a31515;">&#8220;Ahd&#8221;</span>}}},</li>
<li style="background:#f3f3f3;">             <span style="color:#0000ff;">new</span> <span style="color:#2b91af;">Employee</span>(){ FirstName=<span style="color:#a31515;">&#8220;Nitesh&#8221;</span>, LastName=<span style="color:#a31515;">&#8220;Shah&#8221;</span>, Salary=50000, OfficeAddress=<span style="color:#0000ff;">new</span> <span style="color:#2b91af;">Address</span>(){ Add2=<span style="color:#a31515;">&#8220;Manyata&#8221;</span>, City=<span style="color:#a31515;">&#8220;Bangalore&#8221;</span>}, HomeAddresses=<span style="color:#0000ff;">new</span> <span style="color:#2b91af;">List</span>&#60;<span style="color:#2b91af;">Address</span>&#62;(){<span style="color:#0000ff;">new</span> <span style="color:#2b91af;">Address</span>{ Add1=<span style="color:#a31515;">&#8220;Baroda&#8221;</span>, City=<span style="color:#a31515;">&#8220;BAroda&#8221;</span>},<span style="color:#0000ff;">new</span> <span style="color:#2b91af;">Address</span>{ Add1=<span style="color:#a31515;">&#8220;Bombay&#8221;</span>, City=<span style="color:#a31515;">&#8220;Bombay&#8221;</span>}}},</li>
<li>             <span style="color:#0000ff;">new</span> <span style="color:#2b91af;">Employee</span>(){ FirstName=<span style="color:#a31515;">&#8220;Hitesh&#8221;</span>, LastName=<span style="color:#a31515;">&#8220;Patel&#8221;</span>, OfficeAddress=<span style="color:#0000ff;">new</span> <span style="color:#2b91af;">Address</span>(){ Add1=<span style="color:#a31515;">&#8220;Rju&#8221;</span>, City=<span style="color:#a31515;">&#8220;Bng&#8221;</span>, Country=<span style="color:#a31515;">&#8220;India&#8221;</span>}, HomeAddresses=<span style="color:#0000ff;">new</span> <span style="color:#2b91af;">List</span>&#60;<span style="color:#2b91af;">Address</span>&#62;(){<span style="color:#0000ff;">new</span> <span style="color:#2b91af;">Address</span>{ Add1=<span style="color:#a31515;">&#8220;Baroda&#8221;</span>, City=<span style="color:#a31515;">&#8220;BAroda&#8221;</span>},<span style="color:#0000ff;">new</span> <span style="color:#2b91af;">Address</span>{ Add1=<span style="color:#a31515;">&#8220;Bombay&#8221;</span>, City=<span style="color:#a31515;">&#8220;Bombay&#8221;</span>}}},</li>
<li style="background:#f3f3f3;">             <span style="color:#0000ff;">new</span> <span style="color:#2b91af;">Employee</span>(){ FirstName=<span style="color:#a31515;">&#8220;Kitesh&#8221;</span>, LastName=<span style="color:#a31515;">&#8220;Shukla&#8221;</span>, Salary=50000, OfficeAddress=<span style="color:#0000ff;">new</span> <span style="color:#2b91af;">Address</span>(){ Add1=<span style="color:#a31515;">&#8220;EP&#8221;</span>, City=<span style="color:#a31515;">&#8220;BNG&#8221;</span>}, HomeAddresses=<span style="color:#0000ff;">new</span> <span style="color:#2b91af;">List</span>&#60;<span style="color:#2b91af;">Address</span>&#62;(){<span style="color:#0000ff;">new</span> <span style="color:#2b91af;">Address</span>{ Add1=<span style="color:#a31515;">&#8220;Baroda&#8221;</span>, City=<span style="color:#a31515;">&#8220;BAroda&#8221;</span>},<span style="color:#0000ff;">new</span> <span style="color:#2b91af;">Address</span>{ Add1=<span style="color:#a31515;">&#8220;Bombay&#8221;</span>, City=<span style="color:#a31515;">&#8220;Bombay&#8221;</span>}}},</li>
<li>             <span style="color:#0000ff;">new</span> <span style="color:#2b91af;">Employee</span>(){ FirstName=<span style="color:#a31515;">&#8220;Pitesh&#8221;</span>, LastName=<span style="color:#a31515;">&#8220;Sheth&#8221;</span>, Salary=50000, OfficeAddress=<span style="color:#0000ff;">new</span> <span style="color:#2b91af;">Address</span>(){ Add1=<span style="color:#a31515;">&#8220;EGL&#8221;</span>, City=<span style="color:#a31515;">&#8220;BNG&#8221;</span>}, HomeAddresses=<span style="color:#0000ff;">new</span> <span style="color:#2b91af;">List</span>&#60;<span style="color:#2b91af;">Address</span>&#62;(){<span style="color:#0000ff;">new</span> <span style="color:#2b91af;">Address</span>{ Add1=<span style="color:#a31515;">&#8220;Baroda&#8221;</span>, City=<span style="color:#a31515;">&#8220;Ahd&#8221;</span>},<span style="color:#0000ff;">new</span> <span style="color:#2b91af;">Address</span>{ Add1=<span style="color:#a31515;">&#8220;Bombay&#8221;</span>, City=<span style="color:#a31515;">&#8220;Bombay&#8221;</span>}}},</li>
<li style="background:#f3f3f3;">             }</li>
<li>                         ;</li>
<li style="background:#f3f3f3;"> </li>
<li>             <span style="color:#0000ff;">return</span> employees;</li>
<li style="background:#f3f3f3;"> </li>
<li>         }</li>
<li style="background:#f3f3f3;"> </li>
<li>     }</li>
<li style="background:#f3f3f3;">     <span style="color:#0000ff;">public</span> <span style="color:#0000ff;">class</span> <span style="color:#2b91af;">Address</span></li>
<li>     {</li>
<li style="background:#f3f3f3;">         <span style="color:#0000ff;">public</span> <span style="color:#0000ff;">string</span> Add1 { <span style="color:#0000ff;">get</span>; <span style="color:#0000ff;">set</span>; }</li>
<li>         <span style="color:#0000ff;">public</span> <span style="color:#0000ff;">string</span> Add2 { <span style="color:#0000ff;">get</span>; <span style="color:#0000ff;">set</span>; }</li>
<li style="background:#f3f3f3;">         <span style="color:#0000ff;">public</span> <span style="color:#0000ff;">string</span> City { <span style="color:#0000ff;">get</span>; <span style="color:#0000ff;">set</span>; }</li>
<li>         <span style="color:#0000ff;">public</span> <span style="color:#0000ff;">string</span> State { <span style="color:#0000ff;">get</span>; <span style="color:#0000ff;">set</span>; }</li>
<li style="background:#f3f3f3;">         <span style="color:#0000ff;">public</span> <span style="color:#0000ff;">string</span>  Country { <span style="color:#0000ff;">get</span>; <span style="color:#0000ff;">set</span>; }</li>
<li> </li>
<li style="background:#f3f3f3;">     }</li>
</ol>
</div>
</div>
</div>
<p>&#160;</p>
<p>Ex : 1</p>
<p>I’ve to find out the records, which HomeAddress’s city is Ahd. It means if the employee has two or three addresses and any address’s city is AHD , i want that employee.</p>
<div style="padding:5px;" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:90775fc3-5fbd-4ad9-911d-d22684ada485" class="wlWriterEditableSmartContent">
<div style="border:#000080 1px solid;font-family:'Courier New', Courier, Monospace;font-size:10pt;">
<div style="background:#000080;color:#fff;font-family:Verdana, Tahoma, Arial, sans-serif;font-weight:bold;padding:2px 5px;">Code Snippet</div>
<div style="background:#ddd;max-height:300px;overflow:auto;padding:0;">
<ol style="background:#ffffff;white-space:wrap;margin:0 0 0 25px;">
<li> <span style="color:#0000ff;">var</span> emp = <span style="color:#0000ff;">from</span> ee <span style="color:#0000ff;">in</span> <span style="color:#2b91af;">Employee</span>.getEmployee()</li>
<li style="background:#f3f3f3;">                       <span style="color:#0000ff;">where</span> ee.HomeAddresses.Exists(add =&#62; add.City == <span style="color:#a31515;">&#8220;Ahd&#8221;</span>)</li>
<li>                       <span style="color:#0000ff;">select</span> ee;</li>
</ol>
</div>
</div>
</div>
<p>I’ve used Exists to find out my condition. In Above example, EMployee.getEmployee() will give (static fn for Employee class) the list of employee. in where clause i’ve used ee (nothing but Employee object)’s HomeAddress property and use Exists and give the lemda express (add =&#62; add.City == “Ahd”)</p>
<p>&#160;</p>
<p>It gives the employee whose at least one address’s city is “Ahd”. The out is whole employee object.</p>
<p>&#160;</p>
<p>Now suppose i want that, i want the employee’s only that address which is for AHD. If employee has five address and out of five, two are for AHD than i want only this two&#160; addresses.</p>
</div>]]></content:encoded>
</item>
<item>
<title><![CDATA[Using Transaction with Linq]]></title>
<link>http://yasserzaid.wordpress.com/2009/11/27/using-transaction-with-linq/</link>
<pubDate>Fri, 27 Nov 2009 02:02:19 +0000</pubDate>
<dc:creator>yasserzaid</dc:creator>
<guid>http://yasserzaid.wordpress.com/2009/11/27/using-transaction-with-linq/</guid>
<description><![CDATA[Hi try the following example to use Transaction with Linq : &#8211; First Example :-       DataClass]]></description>
<content:encoded><![CDATA[<div class='snap_preview'><p>Hi</p>
<p>try the following example to use Transaction with Linq :</p>
<p><strong>&#8211; First Example :-</strong></p>
<p>      DataClasses1DataContext db = new DataClasses1DataContext();<br />
       // Get all customers list<br />
      IQueryable&#60;Customer&#62; list = from x in db.Customers<br />
                                  where x.Code &#62; 0<br />
                                  select x;<br />
      Customer cust1 = list.Single&#60;Customer&#62;(x =&#62; x.Code == 1);<br />
      Customer cust2 = list.Single&#60;Customer&#62;(x =&#62; x.Code == 2);<br />
      // Update the first customer object<br />
      cust1.FirstName = &#8220;yasser&#8221;;<br />
      cust1.LastName = &#8220;zaid&#8221;;<br />
      // Delete the second customer object<br />
      db.Customers.Remove(cust2);<br />
      // The update &#38; delete operation will execte<br />
      // in the same transaction       <br />
      db.Connection.Open();<br />
      db.Transaction = db.Connection.BeginTransaction();<br />
      try<br />
      {<br />
          db.SubmitChanges();<br />
          db.Transaction.Commit();<br />
      }<br />
      catch<br />
      {<br />
          db.Transaction.Rollback();<br />
          // And do some error handling&#8230;<br />
      }<br />
      finally<br />
      {<br />
          db.Connection.Close();<br />
          db.Transaction = null;<br />
      }</p>
<p><strong>&#8211; Second Example :-</strong></p>
<p>      DataClasses1DataContext db = new DataClasses1DataContext();<br />
      // Get all customers list<br />
      IQueryable&#60;Customer&#62; list = from x in db.Customers<br />
                                  select x;<br />
      Customer cust1 = list.Single&#60;Customer&#62;(x =&#62; x.Code == 1);<br />
      Customer cust2 = list.Single&#60;Customer&#62;(x =&#62; x.Code == 2);<br />
      // Update the first customer object<br />
      cust1.FirstName = &#8220;yasser&#8221;;<br />
      cust1.LastName = &#8220;zaid&#8221;;<br />
      // Delete the second customer object<br />
      db.Customers.Remove(cust2);<br />
      using (TransactionScope ts = new TransactionScope())<br />
      {<br />
          // The update &#38; delete operation will execte in<br />
          //the same transaction       <br />
          db.SubmitChanges();<br />
          ts.Complete();<br />
      }</p>
<p>Hope this helps</p>
<p>Good Luck</p>
</div>]]></content:encoded>
</item>
<item>
<title><![CDATA[Multiple Delete with Linq ]]></title>
<link>http://yasserzaid.wordpress.com/2009/11/26/multiple-delete-with-linq/</link>
<pubDate>Thu, 26 Nov 2009 18:26:59 +0000</pubDate>
<dc:creator>yasserzaid</dc:creator>
<guid>http://yasserzaid.wordpress.com/2009/11/26/multiple-delete-with-linq/</guid>
<description><![CDATA[Hi try this example for Multiple Delete with Linq :- MyAppDataContext db = new MyAppDataContext(); v]]></description>
<content:encoded><![CDATA[<div class='snap_preview'><p>Hi</p>
<p>try this example for Multiple Delete with Linq :-</p>
<p>MyAppDataContext db = new MyAppDataContext();<br />
var objCarFeature = db.CarFeatures.Where(p=&#62; p.Car_ID == CarID);<br />
Dt.DataTire.db.CarFeatures.DeleteAllOnSubmit(objCarFeature);<br />
Dt.DataTire.db.SubmitChanges();</p>
<p><strong>//&#8212; another way</strong></p>
<p>NorthwindDataContext context = new NorthwindDataContext();<br />
var products = context.Products.Where(p =&#62; p.CategoryID == 1);<br />
context.Products.DeleteAllOnSubmit(products);<br />
context.SubmitChanges();</p>
<p><strong>//&#8212; another way</strong></p>
<p>MyAppDataContext db = new MyAppDataContext();<br />
var deleteRelatedRecords = from relatedRecords in db.RelatedRecords<br />
    where relatedRecords.MyForeignKeyID == MyPrimaryKeyID<br />
    select relatedRecords;<br />
foreach (var relatedRecords in deleteRelatedRecords)<br />
{<br />
db.RelatedRecords.DeleteOnSubmit(RelatedRecords);<br />
}<br />
db.SubmitChanges();</p>
<p>Hope this helps</p>
<p>Good Luck</p>
</div>]]></content:encoded>
</item>
<item>
<title><![CDATA[Parallel programming highlights from Microsoft PDC09]]></title>
<link>http://softtalkblog.wordpress.com/2009/11/25/parallel-programming-highlights-from-microsoft-pdc09/</link>
<pubDate>Wed, 25 Nov 2009 11:10:47 +0000</pubDate>
<dc:creator>softtalkblog</dc:creator>
<guid>http://softtalkblog.wordpress.com/2009/11/25/parallel-programming-highlights-from-microsoft-pdc09/</guid>
<description><![CDATA[Microsoft’s Professional Developers Conference (PDC) took place last week in Los Angeles, giving the]]></description>
<content:encoded><![CDATA[Microsoft’s Professional Developers Conference (PDC) took place last week in Los Angeles, giving the]]></content:encoded>
</item>
<item>
<title><![CDATA[jLinq Update (2.2.1)]]></title>
<link>http://somewebguy.wordpress.com/2009/11/23/jlinq-update-2-2-1/</link>
<pubDate>Tue, 24 Nov 2009 02:03:46 +0000</pubDate>
<dc:creator>webdev_hb</dc:creator>
<guid>http://somewebguy.wordpress.com/2009/11/23/jlinq-update-2-2-1/</guid>
<description><![CDATA[I&#8217;m off from work this week so the first thing I did was get some work done on jLinq. I&#8217;]]></description>
<content:encoded><![CDATA[<div class='snap_preview'><p>I&#8217;m off from work this week so the first thing I did was get some work done on jLinq. I&#8217;ve had a few bugs I&#8217;ve needed to sort out along with a new feature I wanted to implement. I&#8217;m also going to be working on documentation this week. Previously, I had created a Wiki and was hoping that people might add to the documentation&#8230; but instead spam bots pretty much ruined it so I&#8217;ll be starting over from scratch&#8230; oh well..</p>
<h3>New Features</h3>
<p>jLinq itself doesn&#8217;t really have a new feature but instead a new way to get the jLinq library. Instead of simply downloading a standard jLinq library you can use the new <a href="http://hugoware.net/Projects/jLinq/FrameworkGenerator" target="_blank">online jLinq Framework Generator to select only the functionality that you want to include.</a> You can still download the basic pack but this option gives you a little more control what goes into your version of jLinq.</p>
<p><a href="http://somewebguy.wordpress.com/files/2009/11/framework-generator.jpg"><img src="http://somewebguy.wordpress.com/files/2009/11/framework-generator.jpg?w=300" alt="" title="framework-generator" width="300" height="252" class="aligncenter size-medium wp-image-859" /></a></p>
<h3>Changes</h3>
<p>The most notable change for jLinq is that all of the operator commands have been included as standard functions for the framework. Before, these functions were actually methods extended onto the framework. Since these functions are required for jLinq to work I&#8217;ve moved them so that they are in every jLinq framework by default.</p>
<h3>Bug Fixes</h3>
<p><strong>orderBy with joined records would return incorrect results</strong><br />
jLinq uses <code>eval</code> to figure out the values of field names since you can provide methods, array indexes or whatever. The code used to sort the values wasn&#8217;t getting the values correctly so the sorted result was always wrong.</p>
<p><strong>using 0 in certain comparisons would return incorrect results</strong><br />
Ah, this one was fun. So check out the code below&#8230;<br />
<code><br />
var values = [ 0 ];<br />
var index = 0;<br />
var a = !values[index];<br />
var b = values[index] == null;<br />
</code></p>
<p>So what is <strong>a</strong> and what is <strong>b</strong>? If you said <strong>true</strong> and <strong>false</strong> then give yourself a cookie.</p>
<p>jLinq uses the number of arguments passed to help determine if anything is being memorized (like the field name). jLinq makes a quick pass to select all values until it finds a null value&#8230; or at least that is what I meant for it to do. Unfortunately, I wasn&#8217;t thinking when I wrote that method and didn&#8217;t check explicitly for <code>null</code>.</p>
<h3>Feedback</h3>
<p>If you find any problems with jLinq or have any suggestions, please leave a comment or <a href="http://hugoware.net/contact" target="_blank">contact me directly</a>.</p>
</div>]]></content:encoded>
</item>
<item>
<title><![CDATA[Set default date parameter in Linq DataSource]]></title>
<link>http://yasserzaid.wordpress.com/2009/11/23/set-default-date-parameter-in-linq-datasource/</link>
<pubDate>Mon, 23 Nov 2009 09:23:22 +0000</pubDate>
<dc:creator>yasserzaid</dc:creator>
<guid>http://yasserzaid.wordpress.com/2009/11/23/set-default-date-parameter-in-linq-datasource/</guid>
<description><![CDATA[Hi try this example &lt;asp:LinqDataSource ID=&#8221;LinqDataSource1&#8243; runat=&#8221;server]]></description>
<content:encoded><![CDATA[<div class='snap_preview'><p>Hi</p>
<p>try this example</p>
<p>&#60;asp:LinqDataSource ID=&#8221;LinqDataSource1&#8243; runat=&#8221;server&#8221;<br />
    ContextTypeName=&#8221;newDataContext&#8221; TableName=&#8221;Lists&#8221;<br />
    Where=&#8221;startDate &#62;= DateTime.Now&#8221;&#62;<br />
&#60;/asp:LinqDataSource&#62;</p>
<p><strong><em>another way</em></strong></p>
<p>IF you wanted to do it completely in the codebehind, you can too (refer example)<br />
and IF you want a Default date on a parameter:</p>
<p>&#60;asp:LinqDataSource ID=&#8221;LinqDataSource1&#8243; runat=&#8221;server&#8221;<br />
    ContextTypeName=&#8221;newDataContext&#8221; TableName=&#8221;Lists&#8221;<br />
    Where=&#8221;startDate &#38;gt;= @startDate&#8221;&#62;<br />
    &#60;WhereParameters&#62;<br />
        &#60;asp:Parameter DefaultValue=&#8221;&#60;%# DateTime.Now %&#62;&#8221; Name=&#8221;startDate&#8221; Type=&#8221;DateTime&#8221; /&#62;<br />
    &#60;/WhereParameters&#62;<br />
&#60;/asp:LinqDataSource&#62;</p>
<p>Hope this helps</p>
<p>Good Luck</p>
</div>]]></content:encoded>
</item>
<item>
<title><![CDATA[IsNullOrEmpty]]></title>
<link>http://mypersonalfailures.wordpress.com/2009/11/22/isnullorempty/</link>
<pubDate>Sun, 22 Nov 2009 09:39:52 +0000</pubDate>
<dc:creator>Andy Grant</dc:creator>
<guid>http://mypersonalfailures.wordpress.com/2009/11/22/isnullorempty/</guid>
<description><![CDATA[I started C# coding with .NET 2. When we upgraded to 3.5 with all its improvements, such as LINQ, I ]]></description>
<content:encoded><![CDATA[<div class='snap_preview'><div id="_mcePaste"><span style="background-color:#ffffff;">I started C# coding with .NET 2. When we upgraded to 3.5 with all its improvements, such as LINQ, I went back through my old code seeing what could be tidied up. Inevitably I missed some things. This one was</span></div>
<pre>if ( something != null &#38;&#38; something.Count &#62; 0 )</pre>
<p>What I&#8217;m really trying to do here is establish whether &#8217;something&#8217; isn&#8217;t null or empty. &#8216;Something&#8217; could be a dictionary, an array or a list and it cropped up in many places in my code. &#8221;Count&#8217; is clearly overkill here as all we care about is whether an IEnumerable contains anything at all. LINQ added the &#8216;Any()&#8217; extension method to IEnumerable which takes a lambda expression and returns true or false depending on whether the enumerable contains an item satisfying the lambda. It exits early, as soon as it finds a matching criteria, the only time it&#8217;ll go through the whole enumerable is if nothing matches the lambda. If you don&#8217;t pass in a lambda then any item in the enumerable will satisfy it. So we can rewrite the above code as</p>
<pre>if ( something != null &#38;&#38; something.Any() )</pre>
<p>Better, we&#8217;re not wasting clock cycles on the count and it&#8217;s a little clearer to other developers and our future selves what our intent was but this logic is repeated all over the place and will be repeated in the future. It might only be a little bit of logic but if we&#8217;re repeating it over and over it would be better as it&#8217;s own method. And as it applies to any IEnumerable it&#8217;s an excellent candidate for pulling out to a static class and method as</p>
<pre>public static bool IsNullOrEmpty&#60;T&#62;(this IEnumerable&#60;T&#62; input) where T:class
{
    return input == null &#124;&#124; !input.Any();
}</pre>
<p>a new LINQ style extension method. I&#8217;ve inverted the logic and given the method a name which should be familiar to anyone who&#8217;s worked with strings in C# (hint: string.IsNullOrEmpty()). Now we can rewrite our starting code to end up with</p>
<pre>if ( !something.IsNullOrEmpty() )</pre>
<p>Total clarity. It will be very hard for anyone reading this code to not understand our intent even without seeing the logic behind the method.</p>
<p>I would like to thank my colleague Simon for pointing this one out to me and making me rethink something I do daily without thinking.</p>
</div>]]></content:encoded>
</item>
<item>
<title><![CDATA[WMI : Get the disk drive details of a computer]]></title>
<link>http://dotnetgeeks.wordpress.com/2009/11/19/wmi-get-the-disk-drive-details-of-a-computer/</link>
<pubDate>Thu, 19 Nov 2009 15:01:01 +0000</pubDate>
<dc:creator>dotnetgeeks</dc:creator>
<guid>http://dotnetgeeks.wordpress.com/2009/11/19/wmi-get-the-disk-drive-details-of-a-computer/</guid>
<description><![CDATA[try { ConnectionOptions connection = new ConnectionOptions(); connection.Username = userNameBox.Text]]></description>
<content:encoded><![CDATA[<div class='snap_preview'><p>try</p>
<p>{</p>
<p>ConnectionOptions connection = new ConnectionOptions();</p>
<p>connection.Username = userNameBox.Text;</p>
<p>connection.Password = passwordBox.Text;</p>
<p>connection.Authority = &#34;ntlmdomain:Finance123&#34;;</p>
<p>ManagementScope scope = new ManagementScope(</p>
<p>&#34;\\dell417\root\CIMV2&#34;, connection);</p>
<p>scope.Connect();</p>
<p>ObjectQuery query= new ObjectQuery(</p>
<p>&#34;SELECT * FROM Win32_DiskDrive&#34;);</p>
<p>ManagementObjectSearcher searcher =</p>
<p>new ManagementObjectSearcher(scope, query);</p>
<p>foreach (ManagementObject queryObj in searcher.Get())</p>
<p>{</p>
<p>Console.WriteLine(&#34;&#34;);</p>
<p>Console.WriteLine(&#34;Win32_DiskDrive instance&#34;);</p>
<p>Console.WriteLine(&#34;&#34;);</p>
<p>Console.WriteLine(&#34;Availability: {0}&#34;, queryObj[&#34;Availability&#34;]);</p>
<p>Console.WriteLine(&#34;BytesPerSector: {0}&#34;, queryObj[&#34;BytesPerSector&#34;]);</p>
<p>if(queryObj[&#34;Capabilities&#34;] == null)</p>
<p>Console.WriteLine(&#34;Capabilities: {0}&#34;, queryObj[&#34;Capabilities&#34;]);</p>
<p>else</p>
<p>{</p>
<p>UInt16[] arrCapabilities = (UInt16[])(queryObj[&#34;Capabilities&#34;]);</p>
<p>foreach (UInt16 arrValue in arrCapabilities)</p>
<p>{</p>
<p>Console.WriteLine(&#34;Capabilities: {0}&#34;, arrValue);</p>
<p>}</p>
<p>}</p>
<p>if(queryObj[&#34;CapabilityDescriptions&#34;] == null)</p>
<p>Console.WriteLine(&#34;CapabilityDescriptions: {0}&#34;, queryObj[&#34;CapabilityDescriptions&#34;]);</p>
<p>else</p>
<p>{</p>
<p>String[] arrCapabilityDescriptions = (String[])(queryObj[&#34;CapabilityDescriptions&#34;]);</p>
<p>foreach (String arrValue in arrCapabilityDescriptions)</p>
<p>{</p>
<p>Console.WriteLine(&#34;CapabilityDescriptions: {0}&#34;, arrValue);</p>
<p>}</p>
<p>}</p>
<p>Console.WriteLine(&#34;Caption: {0}&#34;, queryObj[&#34;Caption&#34;]);</p>
<p>Console.WriteLine(&#34;CompressionMethod: {0}&#34;, queryObj[&#34;CompressionMethod&#34;]);</p>
<p>Console.WriteLine(&#34;ConfigManagerErrorCode: {0}&#34;, queryObj[&#34;ConfigManagerErrorCode&#34;]);</p>
<p>Console.WriteLine(&#34;ConfigManagerUserConfig: {0}&#34;, queryObj[&#34;ConfigManagerUserConfig&#34;]);</p>
<p>Console.WriteLine(&#34;CreationClassName: {0}&#34;, queryObj[&#34;CreationClassName&#34;]);</p>
<p>Console.WriteLine(&#34;DefaultBlockSize: {0}&#34;, queryObj[&#34;DefaultBlockSize&#34;]);</p>
<p>Console.WriteLine(&#34;Description: {0}&#34;, queryObj[&#34;Description&#34;]);</p>
<p>Console.WriteLine(&#34;DeviceID: {0}&#34;, queryObj[&#34;DeviceID&#34;]);</p>
<p>Console.WriteLine(&#34;ErrorCleared: {0}&#34;, queryObj[&#34;ErrorCleared&#34;]);</p>
<p>Console.WriteLine(&#34;ErrorDescription: {0}&#34;, queryObj[&#34;ErrorDescription&#34;]);</p>
<p>Console.WriteLine(&#34;ErrorMethodology: {0}&#34;, queryObj[&#34;ErrorMethodology&#34;]);</p>
<p>Console.WriteLine(&#34;Index: {0}&#34;, queryObj[&#34;Index&#34;]);</p>
<p>Console.WriteLine(&#34;InstallDate: {0}&#34;, queryObj[&#34;InstallDate&#34;]);</p>
<p>Console.WriteLine(&#34;InterfaceType: {0}&#34;, queryObj[&#34;InterfaceType&#34;]);</p>
<p>Console.WriteLine(&#34;LastErrorCode: {0}&#34;, queryObj[&#34;LastErrorCode&#34;]);</p>
<p>Console.WriteLine(&#34;Manufacturer: {0}&#34;, queryObj[&#34;Manufacturer&#34;]);</p>
<p>Console.WriteLine(&#34;MaxBlockSize: {0}&#34;, queryObj[&#34;MaxBlockSize&#34;]);</p>
<p>Console.WriteLine(&#34;MaxMediaSize: {0}&#34;, queryObj[&#34;MaxMediaSize&#34;]);</p>
<p>Console.WriteLine(&#34;MediaLoaded: {0}&#34;, queryObj[&#34;MediaLoaded&#34;]);</p>
<p>Console.WriteLine(&#34;MediaType: {0}&#34;, queryObj[&#34;MediaType&#34;]);</p>
<p>Console.WriteLine(&#34;MinBlockSize: {0}&#34;, queryObj[&#34;MinBlockSize&#34;]);</p>
<p>Console.WriteLine(&#34;Model: {0}&#34;, queryObj[&#34;Model&#34;]);</p>
<p>Console.WriteLine(&#34;Name: {0}&#34;, queryObj[&#34;Name&#34;]);</p>
<p>Console.WriteLine(&#34;NeedsCleaning: {0}&#34;, queryObj[&#34;NeedsCleaning&#34;]);</p>
<p>Console.WriteLine(&#34;NumberOfMediaSupported: {0}&#34;, queryObj[&#34;NumberOfMediaSupported&#34;]);</p>
<p>Console.WriteLine(&#34;Partitions: {0}&#34;, queryObj[&#34;Partitions&#34;]);</p>
<p>Console.WriteLine(&#34;PNPDeviceID: {0}&#34;, queryObj[&#34;PNPDeviceID&#34;]);</p>
<p>if(queryObj[&#34;PowerManagementCapabilities&#34;] == null)</p>
<p>Console.WriteLine(&#34;PowerManagementCapabilities: {0}&#34;, queryObj[&#34;PowerManagementCapabilities&#34;]);</p>
<p>else</p>
<p>{</p>
<p>UInt16[] arrPowerManagementCapabilities = (UInt16[])(queryObj[&#34;PowerManagementCapabilities&#34;]);</p>
<p>foreach (UInt16 arrValue in arrPowerManagementCapabilities)</p>
<p>{</p>
<p>Console.WriteLine(&#34;PowerManagementCapabilities: {0}&#34;, arrValue);</p>
<p>}</p>
<p>}</p>
<p>Console.WriteLine(&#34;PowerManagementSupported: {0}&#34;, queryObj[&#34;PowerManagementSupported&#34;]);</p>
<p>Console.WriteLine(&#34;SCSIBus: {0}&#34;, queryObj[&#34;SCSIBus&#34;]);</p>
<p>Console.WriteLine(&#34;SCSILogicalUnit: {0}&#34;, queryObj[&#34;SCSILogicalUnit&#34;]);</p>
<p>Console.WriteLine(&#34;SCSIPort: {0}&#34;, queryObj[&#34;SCSIPort&#34;]);</p>
<p>Console.WriteLine(&#34;SCSITargetId: {0}&#34;, queryObj[&#34;SCSITargetId&#34;]);</p>
<p>Console.WriteLine(&#34;SectorsPerTrack: {0}&#34;, queryObj[&#34;SectorsPerTrack&#34;]);</p>
<p>Console.WriteLine(&#34;Signature: {0}&#34;, queryObj[&#34;Signature&#34;]);</p>
<p>Console.WriteLine(&#34;Size: {0}&#34;, queryObj[&#34;Size&#34;]);</p>
<p>Console.WriteLine(&#34;Status: {0}&#34;, queryObj[&#34;Status&#34;]);</p>
<p>Console.WriteLine(&#34;StatusInfo: {0}&#34;, queryObj[&#34;StatusInfo&#34;]);</p>
<p>Console.WriteLine(&#34;SystemCreationClassName: {0}&#34;, queryObj[&#34;SystemCreationClassName&#34;]);</p>
<p>Console.WriteLine(&#34;SystemName: {0}&#34;, queryObj[&#34;SystemName&#34;]);</p>
<p>Console.WriteLine(&#34;TotalCylinders: {0}&#34;, queryObj[&#34;TotalCylinders&#34;]);</p>
<p>Console.WriteLine(&#34;TotalHeads: {0}&#34;, queryObj[&#34;TotalHeads&#34;]);</p>
<p>Console.WriteLine(&#34;TotalSectors: {0}&#34;, queryObj[&#34;TotalSectors&#34;]);</p>
<p>Console.WriteLine(&#34;TotalTracks: {0}&#34;, queryObj[&#34;TotalTracks&#34;]);</p>
<p>Console.WriteLine(&#34;TracksPerCylinder: {0}&#34;, queryObj[&#34;TracksPerCylinder&#34;]);</p>
<p>}</p>
<p>Close();</p>
<p>}</p>
<p>catch(ManagementException err)</p>
<p>{</p>
<p>MessageBox.Show(&#34;An error occurred while querying for WMI data: &#34; + err.Message);</p>
<p>}</p>
<p>catch(System.UnauthorizedAccessException unauthorizedErr)</p>
<p>{</p>
<p>MessageBox.Show(&#34;Connection error (user name or password might be incorrect): &#34; + unauthorizedErr.Message);</p>
<p>}</p>
</div>]]></content:encoded>
</item>
<item>
<title><![CDATA[WMI : Get Directory specifications of a directory on a computer]]></title>
<link>http://dotnetgeeks.wordpress.com/2009/11/19/wmi-get-directory-specifications-of-a-directory-on-a-computer/</link>
<pubDate>Thu, 19 Nov 2009 15:00:11 +0000</pubDate>
<dc:creator>dotnetgeeks</dc:creator>
<guid>http://dotnetgeeks.wordpress.com/2009/11/19/wmi-get-directory-specifications-of-a-directory-on-a-computer/</guid>
<description><![CDATA[try { ConnectionOptions connection = new ConnectionOptions(); connection.Username = userNameBox.Text]]></description>
<content:encoded><![CDATA[<div class='snap_preview'><p>try</p>
<p>{</p>
<p>ConnectionOptions connection = new ConnectionOptions();</p>
<p>connection.Username = userNameBox.Text;</p>
<p>connection.Password = passwordBox.Text;</p>
<p>connection.Authority = &#34;ntlmdomain:Finance123&#34;;</p>
<p>ManagementScope scope = new ManagementScope(</p>
<p>&#34;\\dell417\root\CIMV2&#34;, connection);</p>
<p>scope.Connect();</p>
<p>ObjectQuery query= new ObjectQuery(</p>
<p>&#34;SELECT * FROM Win32_DirectorySpecification&#34;);</p>
<p>ManagementObjectSearcher searcher =</p>
<p>new ManagementObjectSearcher(scope, query);</p>
<p>foreach (ManagementObject queryObj in searcher.Get())</p>
<p>{</p>
<p>Console.WriteLine(&#34;&#34;);</p>
<p>Console.WriteLine(&#34;Win32_DirectorySpecification instance&#34;);</p>
<p>Console.WriteLine(&#34;&#34;);</p>
<p>Console.WriteLine(&#34;Caption: {0}&#34;, queryObj[&#34;Caption&#34;]);</p>
<p>Console.WriteLine(&#34;CheckID: {0}&#34;, queryObj[&#34;CheckID&#34;]);</p>
<p>Console.WriteLine(&#34;CheckMode: {0}&#34;, queryObj[&#34;CheckMode&#34;]);</p>
<p>Console.WriteLine(&#34;DefaultDir: {0}&#34;, queryObj[&#34;DefaultDir&#34;]);</p>
<p>Console.WriteLine(&#34;Description: {0}&#34;, queryObj[&#34;Description&#34;]);</p>
<p>Console.WriteLine(&#34;Directory: {0}&#34;, queryObj[&#34;Directory&#34;]);</p>
<p>Console.WriteLine(&#34;DirectoryPath: {0}&#34;, queryObj[&#34;DirectoryPath&#34;]);</p>
<p>Console.WriteLine(&#34;DirectoryType: {0}&#34;, queryObj[&#34;DirectoryType&#34;]);</p>
<p>Console.WriteLine(&#34;Name: {0}&#34;, queryObj[&#34;Name&#34;]);</p>
<p>Console.WriteLine(&#34;SoftwareElementID: {0}&#34;, queryObj[&#34;SoftwareElementID&#34;]);</p>
<p>Console.WriteLine(&#34;SoftwareElementState: {0}&#34;, queryObj[&#34;SoftwareElementState&#34;]);</p>
<p>Console.WriteLine(&#34;TargetOperatingSystem: {0}&#34;, queryObj[&#34;TargetOperatingSystem&#34;]);</p>
<p>Console.WriteLine(&#34;Version: {0}&#34;, queryObj[&#34;Version&#34;]);</p>
<p>}</p>
<p>Close();</p>
<p>}</p>
<p>catch(ManagementException err)</p>
<p>{</p>
<p>MessageBox.Show(&#34;An error occurred while querying for WMI data: &#34; + err.Message);</p>
<p>}</p>
<p>catch(System.UnauthorizedAccessException unauthorizedErr)</p>
<p>{</p>
<p>MessageBox.Show(&#34;Connection error (user name or password might be incorrect): &#34; + unauthorizedErr.Message);</p>
<p>}</p>
</div>]]></content:encoded>
</item>
<item>
<title><![CDATA[WMI : Get details of a Directory on a computer]]></title>
<link>http://dotnetgeeks.wordpress.com/2009/11/19/wmi-get-details-of-a-directory-on-a-computer/</link>
<pubDate>Thu, 19 Nov 2009 14:59:17 +0000</pubDate>
<dc:creator>dotnetgeeks</dc:creator>
<guid>http://dotnetgeeks.wordpress.com/2009/11/19/wmi-get-details-of-a-directory-on-a-computer/</guid>
<description><![CDATA[try { ConnectionOptions connection = new ConnectionOptions(); connection.Username = userNameBox.Text]]></description>
<content:encoded><![CDATA[<div class='snap_preview'><p>try</p>
<p>{</p>
<p>ConnectionOptions connection = new ConnectionOptions();</p>
<p>connection.Username = userNameBox.Text;</p>
<p>connection.Password = passwordBox.Text;</p>
<p>connection.Authority = &#34;ntlmdomain:Finance123&#34;;</p>
<p>ManagementScope scope = new ManagementScope(</p>
<p>&#34;\\dell417\root\CIMV2&#34;, connection);</p>
<p>scope.Connect();</p>
<p>ObjectQuery query= new ObjectQuery(</p>
<p>&#34;SELECT * FROM Win32_Directory&#34;);</p>
<p>ManagementObjectSearcher searcher =</p>
<p>new ManagementObjectSearcher(scope, query);</p>
<p>foreach (ManagementObject queryObj in searcher.Get())</p>
<p>{</p>
<p>Console.WriteLine(&#34;&#34;);</p>
<p>Console.WriteLine(&#34;Win32_Directory instance&#34;);</p>
<p>Console.WriteLine(&#34;&#34;);</p>
<p>Console.WriteLine(&#34;AccessMask: {0}&#34;, queryObj[&#34;AccessMask&#34;]);</p>
<p>Console.WriteLine(&#34;Archive: {0}&#34;, queryObj[&#34;Archive&#34;]);</p>
<p>Console.WriteLine(&#34;Caption: {0}&#34;, queryObj[&#34;Caption&#34;]);</p>
<p>Console.WriteLine(&#34;Compressed: {0}&#34;, queryObj[&#34;Compressed&#34;]);</p>
<p>Console.WriteLine(&#34;CompressionMethod: {0}&#34;, queryObj[&#34;CompressionMethod&#34;]);</p>
<p>Console.WriteLine(&#34;CreationClassName: {0}&#34;, queryObj[&#34;CreationClassName&#34;]);</p>
<p>Console.WriteLine(&#34;CreationDate: {0}&#34;, queryObj[&#34;CreationDate&#34;]);</p>
<p>Console.WriteLine(&#34;CSCreationClassName: {0}&#34;, queryObj[&#34;CSCreationClassName&#34;]);</p>
<p>Console.WriteLine(&#34;CSName: {0}&#34;, queryObj[&#34;CSName&#34;]);</p>
<p>Console.WriteLine(&#34;Description: {0}&#34;, queryObj[&#34;Description&#34;]);</p>
<p>Console.WriteLine(&#34;Drive: {0}&#34;, queryObj[&#34;Drive&#34;]);</p>
<p>Console.WriteLine(&#34;EightDotThreeFileName: {0}&#34;, queryObj[&#34;EightDotThreeFileName&#34;]);</p>
<p>Console.WriteLine(&#34;Encrypted: {0}&#34;, queryObj[&#34;Encrypted&#34;]);</p>
<p>Console.WriteLine(&#34;EncryptionMethod: {0}&#34;, queryObj[&#34;EncryptionMethod&#34;]);</p>
<p>Console.WriteLine(&#34;Extension: {0}&#34;, queryObj[&#34;Extension&#34;]);</p>
<p>Console.WriteLine(&#34;FileName: {0}&#34;, queryObj[&#34;FileName&#34;]);</p>
<p>Console.WriteLine(&#34;FileSize: {0}&#34;, queryObj[&#34;FileSize&#34;]);</p>
<p>Console.WriteLine(&#34;FileType: {0}&#34;, queryObj[&#34;FileType&#34;]);</p>
<p>Console.WriteLine(&#34;FSCreationClassName: {0}&#34;, queryObj[&#34;FSCreationClassName&#34;]);</p>
<p>Console.WriteLine(&#34;FSName: {0}&#34;, queryObj[&#34;FSName&#34;]);</p>
<p>Console.WriteLine(&#34;Hidden: {0}&#34;, queryObj[&#34;Hidden&#34;]);</p>
<p>Console.WriteLine(&#34;InstallDate: {0}&#34;, queryObj[&#34;InstallDate&#34;]);</p>
<p>Console.WriteLine(&#34;InUseCount: {0}&#34;, queryObj[&#34;InUseCount&#34;]);</p>
<p>Console.WriteLine(&#34;LastAccessed: {0}&#34;, queryObj[&#34;LastAccessed&#34;]);</p>
<p>Console.WriteLine(&#34;LastModified: {0}&#34;, queryObj[&#34;LastModified&#34;]);</p>
<p>Console.WriteLine(&#34;Name: {0}&#34;, queryObj[&#34;Name&#34;]);</p>
<p>Console.WriteLine(&#34;Path: {0}&#34;, queryObj[&#34;Path&#34;]);</p>
<p>Console.WriteLine(&#34;Readable: {0}&#34;, queryObj[&#34;Readable&#34;]);</p>
<p>Console.WriteLine(&#34;Status: {0}&#34;, queryObj[&#34;Status&#34;]);</p>
<p>Console.WriteLine(&#34;System: {0}&#34;, queryObj[&#34;System&#34;]);</p>
<p>Console.WriteLine(&#34;Writeable: {0}&#34;, queryObj[&#34;Writeable&#34;]);</p>
<p>}</p>
<p>Close();</p>
<p>}</p>
<p>catch(ManagementException err)</p>
<p>{</p>
<p>MessageBox.Show(&#34;An error occurred while querying for WMI data: &#34; + err.Message);</p>
<p>}</p>
<p>catch(System.UnauthorizedAccessException unauthorizedErr)</p>
<p>{</p>
<p>MessageBox.Show(&#34;Connection error (user name or password might be incorrect): &#34; + unauthorizedErr.Message);</p>
<p>}</p>
</div>]]></content:encoded>
</item>
<item>
<title><![CDATA[WMI : Get hardware details of the monitor of computer]]></title>
<link>http://dotnetgeeks.wordpress.com/2009/11/19/wmi-get-hardware-details-of-the-monitor-of-computer/</link>
<pubDate>Thu, 19 Nov 2009 14:57:57 +0000</pubDate>
<dc:creator>dotnetgeeks</dc:creator>
<guid>http://dotnetgeeks.wordpress.com/2009/11/19/wmi-get-hardware-details-of-the-monitor-of-computer/</guid>
<description><![CDATA[try { ConnectionOptions connection = new ConnectionOptions(); connection.Username = userNameBox.Text]]></description>
<content:encoded><![CDATA[<div class='snap_preview'><p>try</p>
<p>{</p>
<p>ConnectionOptions connection = new ConnectionOptions();</p>
<p>connection.Username = userNameBox.Text;</p>
<p>connection.Password = passwordBox.Text;</p>
<p>connection.Authority = &#34;ntlmdomain:Finance123&#34;;</p>
<p>ManagementScope scope = new ManagementScope(</p>
<p>&#34;\\dell417\root\CIMV2&#34;, connection);</p>
<p>scope.Connect();</p>
<p>ObjectQuery query= new ObjectQuery(</p>
<p>&#34;SELECT * FROM Win32_DesktopMonitor&#34;);</p>
<p>ManagementObjectSearcher searcher =</p>
<p>new ManagementObjectSearcher(scope, query);</p>
<p>foreach (ManagementObject queryObj in searcher.Get())</p>
<p>{</p>
<p>Console.WriteLine(&#34;&#34;);</p>
<p>Console.WriteLine(&#34;Win32_DesktopMonitor instance&#34;);</p>
<p>Console.WriteLine(&#34;&#34;);</p>
<p>Console.WriteLine(&#34;Availability: {0}&#34;, queryObj[&#34;Availability&#34;]);</p>
<p>Console.WriteLine(&#34;Bandwidth: {0}&#34;, queryObj[&#34;Bandwidth&#34;]);</p>
<p>Console.WriteLine(&#34;Caption: {0}&#34;, queryObj[&#34;Caption&#34;]);</p>
<p>Console.WriteLine(&#34;ConfigManagerErrorCode: {0}&#34;, queryObj[&#34;ConfigManagerErrorCode&#34;]);</p>
<p>Console.WriteLine(&#34;ConfigManagerUserConfig: {0}&#34;, queryObj[&#34;ConfigManagerUserConfig&#34;]);</p>
<p>Console.WriteLine(&#34;CreationClassName: {0}&#34;, queryObj[&#34;CreationClassName&#34;]);</p>
<p>Console.WriteLine(&#34;Description: {0}&#34;, queryObj[&#34;Description&#34;]);</p>
<p>Console.WriteLine(&#34;DeviceID: {0}&#34;, queryObj[&#34;DeviceID&#34;]);</p>
<p>Console.WriteLine(&#34;DisplayType: {0}&#34;, queryObj[&#34;DisplayType&#34;]);</p>
<p>Console.WriteLine(&#34;ErrorCleared: {0}&#34;, queryObj[&#34;ErrorCleared&#34;]);</p>
<p>Console.WriteLine(&#34;ErrorDescription: {0}&#34;, queryObj[&#34;ErrorDescription&#34;]);</p>
<p>Console.WriteLine(&#34;InstallDate: {0}&#34;, queryObj[&#34;InstallDate&#34;]);</p>
<p>Console.WriteLine(&#34;IsLocked: {0}&#34;, queryObj[&#34;IsLocked&#34;]);</p>
<p>Console.WriteLine(&#34;LastErrorCode: {0}&#34;, queryObj[&#34;LastErrorCode&#34;]);</p>
<p>Console.WriteLine(&#34;MonitorManufacturer: {0}&#34;, queryObj[&#34;MonitorManufacturer&#34;]);</p>
<p>Console.WriteLine(&#34;MonitorType: {0}&#34;, queryObj[&#34;MonitorType&#34;]);</p>
<p>Console.WriteLine(&#34;Name: {0}&#34;, queryObj[&#34;Name&#34;]);</p>
<p>Console.WriteLine(&#34;PixelsPerXLogicalInch: {0}&#34;, queryObj[&#34;PixelsPerXLogicalInch&#34;]);</p>
<p>Console.WriteLine(&#34;PixelsPerYLogicalInch: {0}&#34;, queryObj[&#34;PixelsPerYLogicalInch&#34;]);</p>
<p>Console.WriteLine(&#34;PNPDeviceID: {0}&#34;, queryObj[&#34;PNPDeviceID&#34;]);</p>
<p>if(queryObj[&#34;PowerManagementCapabilities&#34;] == null)</p>
<p>Console.WriteLine(&#34;PowerManagementCapabilities: {0}&#34;, queryObj[&#34;PowerManagementCapabilities&#34;]);</p>
<p>else</p>
<p>{</p>
<p>UInt16[] arrPowerManagementCapabilities = (UInt16[])(queryObj[&#34;PowerManagementCapabilities&#34;]);</p>
<p>foreach (UInt16 arrValue in arrPowerManagementCapabilities)</p>
<p>{</p>
<p>Console.WriteLine(&#34;PowerManagementCapabilities: {0}&#34;, arrValue);</p>
<p>}</p>
<p>}</p>
<p>Console.WriteLine(&#34;PowerManagementSupported: {0}&#34;, queryObj[&#34;PowerManagementSupported&#34;]);</p>
<p>Console.WriteLine(&#34;ScreenHeight: {0}&#34;, queryObj[&#34;ScreenHeight&#34;]);</p>
<p>Console.WriteLine(&#34;ScreenWidth: {0}&#34;, queryObj[&#34;ScreenWidth&#34;]);</p>
<p>Console.WriteLine(&#34;Status: {0}&#34;, queryObj[&#34;Status&#34;]);</p>
<p>Console.WriteLine(&#34;StatusInfo: {0}&#34;, queryObj[&#34;StatusInfo&#34;]);</p>
<p>Console.WriteLine(&#34;SystemCreationClassName: {0}&#34;, queryObj[&#34;SystemCreationClassName&#34;]);</p>
<p>Console.WriteLine(&#34;SystemName: {0}&#34;, queryObj[&#34;SystemName&#34;]);</p>
<p>}</p>
<p>Close();</p>
<p>}</p>
<p>catch(ManagementException err)</p>
<p>{</p>
<p>MessageBox.Show(&#34;An error occurred while querying for WMI data: &#34; + err.Message);</p>
<p>}</p>
<p>catch(System.UnauthorizedAccessException unauthorizedErr)</p>
<p>{</p>
<p>MessageBox.Show(&#34;Connection error (user name or password might be incorrect): &#34; + unauthorizedErr.Message);</p>
<p>}</p>
</div>]]></content:encoded>
</item>
<item>
<title><![CDATA[WMI: Get desktop details of the computer]]></title>
<link>http://dotnetgeeks.wordpress.com/2009/11/19/wmi-get-desktop-details-of-the-computer/</link>
<pubDate>Thu, 19 Nov 2009 14:57:09 +0000</pubDate>
<dc:creator>dotnetgeeks</dc:creator>
<guid>http://dotnetgeeks.wordpress.com/2009/11/19/wmi-get-desktop-details-of-the-computer/</guid>
<description><![CDATA[try { ConnectionOptions connection = new ConnectionOptions(); connection.Username = userNameBox.Text]]></description>
<content:encoded><![CDATA[<div class='snap_preview'><p>try</p>
<p>{</p>
<p>ConnectionOptions connection = new ConnectionOptions();</p>
<p>connection.Username = userNameBox.Text;</p>
<p>connection.Password = passwordBox.Text;</p>
<p>connection.Authority = &#34;ntlmdomain:Finance123&#34;;</p>
<p>ManagementScope scope = new ManagementScope(</p>
<p>&#34;\\dell417\root\CIMV2&#34;, connection);</p>
<p>scope.Connect();</p>
<p>ObjectQuery query= new ObjectQuery(</p>
<p>&#34;SELECT * FROM Win32_Desktop&#34;);</p>
<p>ManagementObjectSearcher searcher =</p>
<p>new ManagementObjectSearcher(scope, query);</p>
<p>foreach (ManagementObject queryObj in searcher.Get())</p>
<p>{</p>
<p>Console.WriteLine(&#34;&#34;);</p>
<p>Console.WriteLine(&#34;Win32_Desktop instance&#34;);</p>
<p>Console.WriteLine(&#34;&#34;);</p>
<p>Console.WriteLine(&#34;BorderWidth: {0}&#34;, queryObj[&#34;BorderWidth&#34;]);</p>
<p>Console.WriteLine(&#34;Caption: {0}&#34;, queryObj[&#34;Caption&#34;]);</p>
<p>Console.WriteLine(&#34;CoolSwitch: {0}&#34;, queryObj[&#34;CoolSwitch&#34;]);</p>
<p>Console.WriteLine(&#34;CursorBlinkRate: {0}&#34;, queryObj[&#34;CursorBlinkRate&#34;]);</p>
<p>Console.WriteLine(&#34;Description: {0}&#34;, queryObj[&#34;Description&#34;]);</p>
<p>Console.WriteLine(&#34;DragFullWindows: {0}&#34;, queryObj[&#34;DragFullWindows&#34;]);</p>
<p>Console.WriteLine(&#34;GridGranularity: {0}&#34;, queryObj[&#34;GridGranularity&#34;]);</p>
<p>Console.WriteLine(&#34;IconSpacing: {0}&#34;, queryObj[&#34;IconSpacing&#34;]);</p>
<p>Console.WriteLine(&#34;IconTitleFaceName: {0}&#34;, queryObj[&#34;IconTitleFaceName&#34;]);</p>
<p>Console.WriteLine(&#34;IconTitleSize: {0}&#34;, queryObj[&#34;IconTitleSize&#34;]);</p>
<p>Console.WriteLine(&#34;IconTitleWrap: {0}&#34;, queryObj[&#34;IconTitleWrap&#34;]);</p>
<p>Console.WriteLine(&#34;Name: {0}&#34;, queryObj[&#34;Name&#34;]);</p>
<p>Console.WriteLine(&#34;Pattern: {0}&#34;, queryObj[&#34;Pattern&#34;]);</p>
<p>Console.WriteLine(&#34;ScreenSaverActive: {0}&#34;, queryObj[&#34;ScreenSaverActive&#34;]);</p>
<p>Console.WriteLine(&#34;ScreenSaverExecutable: {0}&#34;, queryObj[&#34;ScreenSaverExecutable&#34;]);</p>
<p>Console.WriteLine(&#34;ScreenSaverSecure: {0}&#34;, queryObj[&#34;ScreenSaverSecure&#34;]);</p>
<p>Console.WriteLine(&#34;ScreenSaverTimeout: {0}&#34;, queryObj[&#34;ScreenSaverTimeout&#34;]);</p>
<p>Console.WriteLine(&#34;SettingID: {0}&#34;, queryObj[&#34;SettingID&#34;]);</p>
<p>Console.WriteLine(&#34;Wallpaper: {0}&#34;, queryObj[&#34;Wallpaper&#34;]);</p>
<p>Console.WriteLine(&#34;WallpaperStretched: {0}&#34;, queryObj[&#34;WallpaperStretched&#34;]);</p>
<p>Console.WriteLine(&#34;WallpaperTiled: {0}&#34;, queryObj[&#34;WallpaperTiled&#34;]);</p>
<p>}</p>
<p>Close();</p>
<p>}</p>
<p>catch(ManagementException err)</p>
<p>{</p>
<p>MessageBox.Show(&#34;An error occurred while querying for WMI data: &#34; + err.Message);</p>
<p>}</p>
<p>catch(System.UnauthorizedAccessException unauthorizedErr)</p>
<p>{</p>
<p>MessageBox.Show(&#34;Connection error (user name or password might be incorrect): &#34; + unauthorizedErr.Message);</p>
<p>}</p>
</div>]]></content:encoded>
</item>
<item>
<title><![CDATA[WMI : Get CD-ROM details of the Computer]]></title>
<link>http://dotnetgeeks.wordpress.com/2009/11/19/wmi-get-cd-rom-details-of-the-computer/</link>
<pubDate>Thu, 19 Nov 2009 14:55:53 +0000</pubDate>
<dc:creator>dotnetgeeks</dc:creator>
<guid>http://dotnetgeeks.wordpress.com/2009/11/19/wmi-get-cd-rom-details-of-the-computer/</guid>
<description><![CDATA[try { ConnectionOptions connection = new ConnectionOptions(); connection.Username = userNameBox.Text]]></description>
<content:encoded><![CDATA[<div class='snap_preview'><p>try</p>
<p>{</p>
<p>ConnectionOptions connection = new ConnectionOptions();</p>
<p>connection.Username = userNameBox.Text;</p>
<p>connection.Password = passwordBox.Text;</p>
<p>connection.Authority = &#34;ntlmdomain:Finance123&#34;;</p>
<p>ManagementScope scope = new ManagementScope(</p>
<p>&#34;\\dell417\root\CIMV2&#34;, connection);</p>
<p>scope.Connect();</p>
<p>ObjectQuery query= new ObjectQuery(</p>
<p>&#34;SELECT * FROM Win32_CDROMDrive&#34;);</p>
<p>ManagementObjectSearcher searcher =</p>
<p>new ManagementObjectSearcher(scope, query);</p>
<p>foreach (ManagementObject queryObj in searcher.Get())</p>
<p>{</p>
<p>Console.WriteLine(&#34;&#34;);</p>
<p>Console.WriteLine(&#34;Win32_CDROMDrive instance&#34;);</p>
<p>Console.WriteLine(&#34;&#34;);</p>
<p>Console.WriteLine(&#34;Availability: {0}&#34;, queryObj[&#34;Availability&#34;]);</p>
<p>if(queryObj[&#34;Capabilities&#34;] == null)</p>
<p>Console.WriteLine(&#34;Capabilities: {0}&#34;, queryObj[&#34;Capabilities&#34;]);</p>
<p>else</p>
<p>{</p>
<p>UInt16[] arrCapabilities = (UInt16[])(queryObj[&#34;Capabilities&#34;]);</p>
<p>foreach (UInt16 arrValue in arrCapabilities)</p>
<p>{</p>
<p>Console.WriteLine(&#34;Capabilities: {0}&#34;, arrValue);</p>
<p>}</p>
<p>}</p>
<p>if(queryObj[&#34;CapabilityDescriptions&#34;] == null)</p>
<p>Console.WriteLine(&#34;CapabilityDescriptions: {0}&#34;, queryObj[&#34;CapabilityDescriptions&#34;]);</p>
<p>else</p>
<p>{</p>
<p>String[] arrCapabilityDescriptions = (String[])(queryObj[&#34;CapabilityDescriptions&#34;]);</p>
<p>foreach (String arrValue in arrCapabilityDescriptions)</p>
<p>{</p>
<p>Console.WriteLine(&#34;CapabilityDescriptions: {0}&#34;, arrValue);</p>
<p>}</p>
<p>}</p>
<p>Console.WriteLine(&#34;Caption: {0}&#34;, queryObj[&#34;Caption&#34;]);</p>
<p>Console.WriteLine(&#34;CompressionMethod: {0}&#34;, queryObj[&#34;CompressionMethod&#34;]);</p>
<p>Console.WriteLine(&#34;ConfigManagerErrorCode: {0}&#34;, queryObj[&#34;ConfigManagerErrorCode&#34;]);</p>
<p>Console.WriteLine(&#34;ConfigManagerUserConfig: {0}&#34;, queryObj[&#34;ConfigManagerUserConfig&#34;]);</p>
<p>Console.WriteLine(&#34;CreationClassName: {0}&#34;, queryObj[&#34;CreationClassName&#34;]);</p>
<p>Console.WriteLine(&#34;DefaultBlockSize: {0}&#34;, queryObj[&#34;DefaultBlockSize&#34;]);</p>
<p>Console.WriteLine(&#34;Description: {0}&#34;, queryObj[&#34;Description&#34;]);</p>
<p>Console.WriteLine(&#34;DeviceID: {0}&#34;, queryObj[&#34;DeviceID&#34;]);</p>
<p>Console.WriteLine(&#34;Drive: {0}&#34;, queryObj[&#34;Drive&#34;]);</p>
<p>Console.WriteLine(&#34;DriveIntegrity: {0}&#34;, queryObj[&#34;DriveIntegrity&#34;]);</p>
<p>Console.WriteLine(&#34;ErrorCleared: {0}&#34;, queryObj[&#34;ErrorCleared&#34;]);</p>
<p>Console.WriteLine(&#34;ErrorDescription: {0}&#34;, queryObj[&#34;ErrorDescription&#34;]);</p>
<p>Console.WriteLine(&#34;ErrorMethodology: {0}&#34;, queryObj[&#34;ErrorMethodology&#34;]);</p>
<p>Console.WriteLine(&#34;FileSystemFlags: {0}&#34;, queryObj[&#34;FileSystemFlags&#34;]);</p>
<p>Console.WriteLine(&#34;FileSystemFlagsEx: {0}&#34;, queryObj[&#34;FileSystemFlagsEx&#34;]);</p>
<p>Console.WriteLine(&#34;Id: {0}&#34;, queryObj[&#34;Id&#34;]);</p>
<p>Console.WriteLine(&#34;InstallDate: {0}&#34;, queryObj[&#34;InstallDate&#34;]);</p>
<p>Console.WriteLine(&#34;LastErrorCode: {0}&#34;, queryObj[&#34;LastErrorCode&#34;]);</p>
<p>Console.WriteLine(&#34;Manufacturer: {0}&#34;, queryObj[&#34;Manufacturer&#34;]);</p>
<p>Console.WriteLine(&#34;MaxBlockSize: {0}&#34;, queryObj[&#34;MaxBlockSize&#34;]);</p>
<p>Console.WriteLine(&#34;MaximumComponentLength: {0}&#34;, queryObj[&#34;MaximumComponentLength&#34;]);</p>
<p>Console.WriteLine(&#34;MaxMediaSize: {0}&#34;, queryObj[&#34;MaxMediaSize&#34;]);</p>
<p>Console.WriteLine(&#34;MediaLoaded: {0}&#34;, queryObj[&#34;MediaLoaded&#34;]);</p>
<p>Console.WriteLine(&#34;MediaType: {0}&#34;, queryObj[&#34;MediaType&#34;]);</p>
<p>Console.WriteLine(&#34;MfrAssignedRevisionLevel: {0}&#34;, queryObj[&#34;MfrAssignedRevisionLevel&#34;]);</p>
<p>Console.WriteLine(&#34;MinBlockSize: {0}&#34;, queryObj[&#34;MinBlockSize&#34;]);</p>
<p>Console.WriteLine(&#34;Name: {0}&#34;, queryObj[&#34;Name&#34;]);</p>
<p>Console.WriteLine(&#34;NeedsCleaning: {0}&#34;, queryObj[&#34;NeedsCleaning&#34;]);</p>
<p>Console.WriteLine(&#34;NumberOfMediaSupported: {0}&#34;, queryObj[&#34;NumberOfMediaSupported&#34;]);</p>
<p>Console.WriteLine(&#34;PNPDeviceID: {0}&#34;, queryObj[&#34;PNPDeviceID&#34;]);</p>
<p>if(queryObj[&#34;PowerManagementCapabilities&#34;] == null)</p>
<p>Console.WriteLine(&#34;PowerManagementCapabilities: {0}&#34;, queryObj[&#34;PowerManagementCapabilities&#34;]);</p>
<p>else</p>
<p>{</p>
<p>UInt16[] arrPowerManagementCapabilities = (UInt16[])(queryObj[&#34;PowerManagementCapabilities&#34;]);</p>
<p>foreach (UInt16 arrValue in arrPowerManagementCapabilities)</p>
<p>{</p>
<p>Console.WriteLine(&#34;PowerManagementCapabilities: {0}&#34;, arrValue);</p>
<p>}</p>
<p>}</p>
<p>Console.WriteLine(&#34;PowerManagementSupported: {0}&#34;, queryObj[&#34;PowerManagementSupported&#34;]);</p>
<p>Console.WriteLine(&#34;RevisionLevel: {0}&#34;, queryObj[&#34;RevisionLevel&#34;]);</p>
<p>Console.WriteLine(&#34;SCSIBus: {0}&#34;, queryObj[&#34;SCSIBus&#34;]);</p>
<p>Console.WriteLine(&#34;SCSILogicalUnit: {0}&#34;, queryObj[&#34;SCSILogicalUnit&#34;]);</p>
<p>Console.WriteLine(&#34;SCSIPort: {0}&#34;, queryObj[&#34;SCSIPort&#34;]);</p>
<p>Console.WriteLine(&#34;SCSITargetId: {0}&#34;, queryObj[&#34;SCSITargetId&#34;]);</p>
<p>Console.WriteLine(&#34;Size: {0}&#34;, queryObj[&#34;Size&#34;]);</p>
<p>Console.WriteLine(&#34;Status: {0}&#34;, queryObj[&#34;Status&#34;]);</p>
<p>Console.WriteLine(&#34;StatusInfo: {0}&#34;, queryObj[&#34;StatusInfo&#34;]);</p>
<p>Console.WriteLine(&#34;SystemCreationClassName: {0}&#34;, queryObj[&#34;SystemCreationClassName&#34;]);</p>
<p>Console.WriteLine(&#34;SystemName: {0}&#34;, queryObj[&#34;SystemName&#34;]);</p>
<p>Console.WriteLine(&#34;TransferRate: {0}&#34;, queryObj[&#34;TransferRate&#34;]);</p>
<p>Console.WriteLine(&#34;VolumeName: {0}&#34;, queryObj[&#34;VolumeName&#34;]);</p>
<p>Console.WriteLine(&#34;VolumeSerialNumber: {0}&#34;, queryObj[&#34;VolumeSerialNumber&#34;]);</p>
<p>}</p>
<p>Close();</p>
<p>}</p>
<p>catch(ManagementException err)</p>
<p>{</p>
<p>MessageBox.Show(&#34;An error occurred while querying for WMI data: &#34; + err.Message);</p>
<p>}</p>
<p>catch(System.UnauthorizedAccessException unauthorizedErr)</p>
<p>{</p>
<p>MessageBox.Show(&#34;Connection error (user name or password might be incorrect): &#34; + unauthorizedErr.Message);</p>
<p>}</p>
</div>]]></content:encoded>
</item>
<item>
<title><![CDATA[WMI: Get the cache memory details of the Computer]]></title>
<link>http://dotnetgeeks.wordpress.com/2009/11/19/wmi-get-the-cache-memory-details-of-the-computer/</link>
<pubDate>Thu, 19 Nov 2009 14:54:51 +0000</pubDate>
<dc:creator>dotnetgeeks</dc:creator>
<guid>http://dotnetgeeks.wordpress.com/2009/11/19/wmi-get-the-cache-memory-details-of-the-computer/</guid>
<description><![CDATA[try { ConnectionOptions connection = new ConnectionOptions(); connection.Username = userNameBox.Text]]></description>
<content:encoded><![CDATA[<div class='snap_preview'><p>try</p>
<p>{</p>
<p>ConnectionOptions connection = new ConnectionOptions();</p>
<p>connection.Username = userNameBox.Text;</p>
<p>connection.Password = passwordBox.Text;</p>
<p>connection.Authority = &#34;ntlmdomain:Finance123&#34;;</p>
<p>ManagementScope scope = new ManagementScope(</p>
<p>&#34;\\dell417\root\CIMV2&#34;, connection);</p>
<p>scope.Connect();</p>
<p>ObjectQuery query= new ObjectQuery(</p>
<p>&#34;SELECT * FROM Win32_CacheMemory&#34;);</p>
<p>ManagementObjectSearcher searcher =</p>
<p>new ManagementObjectSearcher(scope, query);</p>
<p>foreach (ManagementObject queryObj in searcher.Get())</p>
<p>{</p>
<p>Console.WriteLine(&#34;&#34;);</p>
<p>Console.WriteLine(&#34;Win32_CacheMemory instance&#34;);</p>
<p>Console.WriteLine(&#34;&#34;);</p>
<p>Console.WriteLine(&#34;Access: {0}&#34;, queryObj[&#34;Access&#34;]);</p>
<p>if(queryObj[&#34;AdditionalErrorData&#34;] == null)</p>
<p>Console.WriteLine(&#34;AdditionalErrorData: {0}&#34;, queryObj[&#34;AdditionalErrorData&#34;]);</p>
<p>else</p>
<p>{</p>
<p>Byte[] arrAdditionalErrorData = (Byte[])(queryObj[&#34;AdditionalErrorData&#34;]);</p>
<p>foreach (Byte arrValue in arrAdditionalErrorData)</p>
<p>{</p>
<p>Console.WriteLine(&#34;AdditionalErrorData: {0}&#34;, arrValue);</p>
<p>}</p>
<p>}</p>
<p>Console.WriteLine(&#34;Associativity: {0}&#34;, queryObj[&#34;Associativity&#34;]);</p>
<p>Console.WriteLine(&#34;Availability: {0}&#34;, queryObj[&#34;Availability&#34;]);</p>
<p>Console.WriteLine(&#34;BlockSize: {0}&#34;, queryObj[&#34;BlockSize&#34;]);</p>
<p>Console.WriteLine(&#34;CacheSpeed: {0}&#34;, queryObj[&#34;CacheSpeed&#34;]);</p>
<p>Console.WriteLine(&#34;CacheType: {0}&#34;, queryObj[&#34;CacheType&#34;]);</p>
<p>Console.WriteLine(&#34;Caption: {0}&#34;, queryObj[&#34;Caption&#34;]);</p>
<p>Console.WriteLine(&#34;ConfigManagerErrorCode: {0}&#34;, queryObj[&#34;ConfigManagerErrorCode&#34;]);</p>
<p>Console.WriteLine(&#34;ConfigManagerUserConfig: {0}&#34;, queryObj[&#34;ConfigManagerUserConfig&#34;]);</p>
<p>Console.WriteLine(&#34;CorrectableError: {0}&#34;, queryObj[&#34;CorrectableError&#34;]);</p>
<p>Console.WriteLine(&#34;CreationClassName: {0}&#34;, queryObj[&#34;CreationClassName&#34;]);</p>
<p>if(queryObj[&#34;CurrentSRAM&#34;] == null)</p>
<p>Console.WriteLine(&#34;CurrentSRAM: {0}&#34;, queryObj[&#34;CurrentSRAM&#34;]);</p>
<p>else</p>
<p>{</p>
<p>UInt16[] arrCurrentSRAM = (UInt16[])(queryObj[&#34;CurrentSRAM&#34;]);</p>
<p>foreach (UInt16 arrValue in arrCurrentSRAM)</p>
<p>{</p>
<p>Console.WriteLine(&#34;CurrentSRAM: {0}&#34;, arrValue);</p>
<p>}</p>
<p>}</p>
<p>Console.WriteLine(&#34;Description: {0}&#34;, queryObj[&#34;Description&#34;]);</p>
<p>Console.WriteLine(&#34;DeviceID: {0}&#34;, queryObj[&#34;DeviceID&#34;]);</p>
<p>Console.WriteLine(&#34;EndingAddress: {0}&#34;, queryObj[&#34;EndingAddress&#34;]);</p>
<p>Console.WriteLine(&#34;ErrorAccess: {0}&#34;, queryObj[&#34;ErrorAccess&#34;]);</p>
<p>Console.WriteLine(&#34;ErrorAddress: {0}&#34;, queryObj[&#34;ErrorAddress&#34;]);</p>
<p>Console.WriteLine(&#34;ErrorCleared: {0}&#34;, queryObj[&#34;ErrorCleared&#34;]);</p>
<p>Console.WriteLine(&#34;ErrorCorrectType: {0}&#34;, queryObj[&#34;ErrorCorrectType&#34;]);</p>
<p>if(queryObj[&#34;ErrorData&#34;] == null)</p>
<p>Console.WriteLine(&#34;ErrorData: {0}&#34;, queryObj[&#34;ErrorData&#34;]);</p>
<p>else</p>
<p>{</p>
<p>Byte[] arrErrorData = (Byte[])(queryObj[&#34;ErrorData&#34;]);</p>
<p>foreach (Byte arrValue in arrErrorData)</p>
<p>{</p>
<p>Console.WriteLine(&#34;ErrorData: {0}&#34;, arrValue);</p>
<p>}</p>
<p>}</p>
<p>Console.WriteLine(&#34;ErrorDataOrder: {0}&#34;, queryObj[&#34;ErrorDataOrder&#34;]);</p>
<p>Console.WriteLine(&#34;ErrorDescription: {0}&#34;, queryObj[&#34;ErrorDescription&#34;]);</p>
<p>Console.WriteLine(&#34;ErrorInfo: {0}&#34;, queryObj[&#34;ErrorInfo&#34;]);</p>
<p>Console.WriteLine(&#34;ErrorMethodology: {0}&#34;, queryObj[&#34;ErrorMethodology&#34;]);</p>
<p>Console.WriteLine(&#34;ErrorResolution: {0}&#34;, queryObj[&#34;ErrorResolution&#34;]);</p>
<p>Console.WriteLine(&#34;ErrorTime: {0}&#34;, queryObj[&#34;ErrorTime&#34;]);</p>
<p>Console.WriteLine(&#34;ErrorTransferSize: {0}&#34;, queryObj[&#34;ErrorTransferSize&#34;]);</p>
<p>Console.WriteLine(&#34;FlushTimer: {0}&#34;, queryObj[&#34;FlushTimer&#34;]);</p>
<p>Console.WriteLine(&#34;InstallDate: {0}&#34;, queryObj[&#34;InstallDate&#34;]);</p>
<p>Console.WriteLine(&#34;InstalledSize: {0}&#34;, queryObj[&#34;InstalledSize&#34;]);</p>
<p>Console.WriteLine(&#34;LastErrorCode: {0}&#34;, queryObj[&#34;LastErrorCode&#34;]);</p>
<p>Console.WriteLine(&#34;Level: {0}&#34;, queryObj[&#34;Level&#34;]);</p>
<p>Console.WriteLine(&#34;LineSize: {0}&#34;, queryObj[&#34;LineSize&#34;]);</p>
<p>Console.WriteLine(&#34;Location: {0}&#34;, queryObj[&#34;Location&#34;]);</p>
<p>Console.WriteLine(&#34;MaxCacheSize: {0}&#34;, queryObj[&#34;MaxCacheSize&#34;]);</p>
<p>Console.WriteLine(&#34;Name: {0}&#34;, queryObj[&#34;Name&#34;]);</p>
<p>Console.WriteLine(&#34;NumberOfBlocks: {0}&#34;, queryObj[&#34;NumberOfBlocks&#34;]);</p>
<p>Console.WriteLine(&#34;OtherErrorDescription: {0}&#34;, queryObj[&#34;OtherErrorDescription&#34;]);</p>
<p>Console.WriteLine(&#34;PNPDeviceID: {0}&#34;, queryObj[&#34;PNPDeviceID&#34;]);</p>
<p>if(queryObj[&#34;PowerManagementCapabilities&#34;] == null)</p>
<p>Console.WriteLine(&#34;PowerManagementCapabilities: {0}&#34;, queryObj[&#34;PowerManagementCapabilities&#34;]);</p>
<p>else</p>
<p>{</p>
<p>UInt16[] arrPowerManagementCapabilities = (UInt16[])(queryObj[&#34;PowerManagementCapabilities&#34;]);</p>
<p>foreach (UInt16 arrValue in arrPowerManagementCapabilities)</p>
<p>{</p>
<p>Console.WriteLine(&#34;PowerManagementCapabilities: {0}&#34;, arrValue);</p>
<p>}</p>
<p>}</p>
<p>Console.WriteLine(&#34;PowerManagementSupported: {0}&#34;, queryObj[&#34;PowerManagementSupported&#34;]);</p>
<p>Console.WriteLine(&#34;Purpose: {0}&#34;, queryObj[&#34;Purpose&#34;]);</p>
<p>Console.WriteLine(&#34;ReadPolicy: {0}&#34;, queryObj[&#34;ReadPolicy&#34;]);</p>
<p>Console.WriteLine(&#34;ReplacementPolicy: {0}&#34;, queryObj[&#34;ReplacementPolicy&#34;]);</p>
<p>Console.WriteLine(&#34;StartingAddress: {0}&#34;, queryObj[&#34;StartingAddress&#34;]);</p>
<p>Console.WriteLine(&#34;Status: {0}&#34;, queryObj[&#34;Status&#34;]);</p>
<p>Console.WriteLine(&#34;StatusInfo: {0}&#34;, queryObj[&#34;StatusInfo&#34;]);</p>
<p>if(queryObj[&#34;SupportedSRAM&#34;] == null)</p>
<p>Console.WriteLine(&#34;SupportedSRAM: {0}&#34;, queryObj[&#34;SupportedSRAM&#34;]);</p>
<p>else</p>
<p>{</p>
<p>UInt16[] arrSupportedSRAM = (UInt16[])(queryObj[&#34;SupportedSRAM&#34;]);</p>
<p>foreach (UInt16 arrValue in arrSupportedSRAM)</p>
<p>{</p>
<p>Console.WriteLine(&#34;SupportedSRAM: {0}&#34;, arrValue);</p>
<p>}</p>
<p>}</p>
<p>Console.WriteLine(&#34;SystemCreationClassName: {0}&#34;, queryObj[&#34;SystemCreationClassName&#34;]);</p>
<p>Console.WriteLine(&#34;SystemLevelAddress: {0}&#34;, queryObj[&#34;SystemLevelAddress&#34;]);</p>
<p>Console.WriteLine(&#34;SystemName: {0}&#34;, queryObj[&#34;SystemName&#34;]);</p>
<p>Console.WriteLine(&#34;WritePolicy: {0}&#34;, queryObj[&#34;WritePolicy&#34;]);</p>
<p>}</p>
<p>Close();</p>
<p>}</p>
<p>catch(ManagementException err)</p>
<p>{</p>
<p>MessageBox.Show(&#34;An error occurred while querying for WMI data: &#34; + err.Message);</p>
<p>}</p>
<p>catch(System.UnauthorizedAccessException unauthorizedErr)</p>
<p>{</p>
<p>MessageBox.Show(&#34;Connection error (user name or password might be incorrect): &#34; + unauthorizedErr.Message);</p>
<p>}</p>
</div>]]></content:encoded>
</item>
<item>
<title><![CDATA[WMI : Get BUS details of the Computer]]></title>
<link>http://dotnetgeeks.wordpress.com/2009/11/19/wmi-get-bus-details-of-the-computer/</link>
<pubDate>Thu, 19 Nov 2009 14:53:52 +0000</pubDate>
<dc:creator>dotnetgeeks</dc:creator>
<guid>http://dotnetgeeks.wordpress.com/2009/11/19/wmi-get-bus-details-of-the-computer/</guid>
<description><![CDATA[try { ConnectionOptions connection = new ConnectionOptions(); connection.Username = userNameBox.Text]]></description>
<content:encoded><![CDATA[<div class='snap_preview'><p>try</p>
<p>{</p>
<p>ConnectionOptions connection = new ConnectionOptions();</p>
<p>connection.Username = userNameBox.Text;</p>
<p>connection.Password = passwordBox.Text;</p>
<p>connection.Authority = &#34;ntlmdomain:Finance123&#34;;</p>
<p>ManagementScope scope = new ManagementScope(</p>
<p>&#34;\\dell417\root\CIMV2&#34;, connection);</p>
<p>scope.Connect();</p>
<p>ObjectQuery query= new ObjectQuery(</p>
<p>&#34;SELECT * FROM Win32_Bus&#34;);</p>
<p>ManagementObjectSearcher searcher =</p>
<p>new ManagementObjectSearcher(scope, query);</p>
<p>foreach (ManagementObject queryObj in searcher.Get())</p>
<p>{</p>
<p>Console.WriteLine(&#34;&#34;);</p>
<p>Console.WriteLine(&#34;Win32_Bus instance&#34;);</p>
<p>Console.WriteLine(&#34;&#34;);</p>
<p>Console.WriteLine(&#34;Availability: {0}&#34;, queryObj[&#34;Availability&#34;]);</p>
<p>Console.WriteLine(&#34;BusNum: {0}&#34;, queryObj[&#34;BusNum&#34;]);</p>
<p>Console.WriteLine(&#34;BusType: {0}&#34;, queryObj[&#34;BusType&#34;]);</p>
<p>Console.WriteLine(&#34;Caption: {0}&#34;, queryObj[&#34;Caption&#34;]);</p>
<p>Console.WriteLine(&#34;ConfigManagerErrorCode: {0}&#34;, queryObj[&#34;ConfigManagerErrorCode&#34;]);</p>
<p>Console.WriteLine(&#34;ConfigManagerUserConfig: {0}&#34;, queryObj[&#34;ConfigManagerUserConfig&#34;]);</p>
<p>Console.WriteLine(&#34;CreationClassName: {0}&#34;, queryObj[&#34;CreationClassName&#34;]);</p>
<p>Console.WriteLine(&#34;Description: {0}&#34;, queryObj[&#34;Description&#34;]);</p>
<p>Console.WriteLine(&#34;DeviceID: {0}&#34;, queryObj[&#34;DeviceID&#34;]);</p>
<p>Console.WriteLine(&#34;ErrorCleared: {0}&#34;, queryObj[&#34;ErrorCleared&#34;]);</p>
<p>Console.WriteLine(&#34;ErrorDescription: {0}&#34;, queryObj[&#34;ErrorDescription&#34;]);</p>
<p>Console.WriteLine(&#34;InstallDate: {0}&#34;, queryObj[&#34;InstallDate&#34;]);</p>
<p>Console.WriteLine(&#34;LastErrorCode: {0}&#34;, queryObj[&#34;LastErrorCode&#34;]);</p>
<p>Console.WriteLine(&#34;Name: {0}&#34;, queryObj[&#34;Name&#34;]);</p>
<p>Console.WriteLine(&#34;PNPDeviceID: {0}&#34;, queryObj[&#34;PNPDeviceID&#34;]);</p>
<p>if(queryObj[&#34;PowerManagementCapabilities&#34;] == null)</p>
<p>Console.WriteLine(&#34;PowerManagementCapabilities: {0}&#34;, queryObj[&#34;PowerManagementCapabilities&#34;]);</p>
<p>else</p>
<p>{</p>
<p>UInt16[] arrPowerManagementCapabilities = (UInt16[])(queryObj[&#34;PowerManagementCapabilities&#34;]);</p>
<p>foreach (UInt16 arrValue in arrPowerManagementCapabilities)</p>
<p>{</p>
<p>Console.WriteLine(&#34;PowerManagementCapabilities: {0}&#34;, arrValue);</p>
<p>}</p>
<p>}</p>
<p>Console.WriteLine(&#34;PowerManagementSupported: {0}&#34;, queryObj[&#34;PowerManagementSupported&#34;]);</p>
<p>Console.WriteLine(&#34;Status: {0}&#34;, queryObj[&#34;Status&#34;]);</p>
<p>Console.WriteLine(&#34;StatusInfo: {0}&#34;, queryObj[&#34;StatusInfo&#34;]);</p>
<p>Console.WriteLine(&#34;SystemCreationClassName: {0}&#34;, queryObj[&#34;SystemCreationClassName&#34;]);</p>
<p>Console.WriteLine(&#34;SystemName: {0}&#34;, queryObj[&#34;SystemName&#34;]);</p>
<p>}</p>
<p>Close();</p>
<p>}</p>
<p>catch(ManagementException err)</p>
<p>{</p>
<p>MessageBox.Show(&#34;An error occurred while querying for WMI data: &#34; + err.Message);</p>
<p>}</p>
<p>catch(System.UnauthorizedAccessException unauthorizedErr)</p>
<p>{</p>
<p>MessageBox.Show(&#34;Connection error (user name or password might be incorrect): &#34; + unauthorizedErr.Message);</p>
<p>}</p>
</div>]]></content:encoded>
</item>
<item>
<title><![CDATA[WMI : Get boot configuration details of the computer]]></title>
<link>http://dotnetgeeks.wordpress.com/2009/11/19/wmi-get-boot-configuration-details-of-the-computer/</link>
<pubDate>Thu, 19 Nov 2009 14:53:01 +0000</pubDate>
<dc:creator>dotnetgeeks</dc:creator>
<guid>http://dotnetgeeks.wordpress.com/2009/11/19/wmi-get-boot-configuration-details-of-the-computer/</guid>
<description><![CDATA[try { ConnectionOptions connection = new ConnectionOptions(); connection.Username = userNameBox.Text]]></description>
<content:encoded><![CDATA[<div class='snap_preview'><p>try</p>
<p>{</p>
<p>ConnectionOptions connection = new ConnectionOptions();</p>
<p>connection.Username = userNameBox.Text;</p>
<p>connection.Password = passwordBox.Text;</p>
<p>connection.Authority = &#34;ntlmdomain:Finance123&#34;;</p>
<p>ManagementScope scope = new ManagementScope(</p>
<p>&#34;\\dell417\root\CIMV2&#34;, connection);</p>
<p>scope.Connect();</p>
<p>ObjectQuery query= new ObjectQuery(</p>
<p>&#34;SELECT * FROM Win32_BootConfiguration&#34;);</p>
<p>ManagementObjectSearcher searcher =</p>
<p>new ManagementObjectSearcher(scope, query);</p>
<p>foreach (ManagementObject queryObj in searcher.Get())</p>
<p>{</p>
<p>Console.WriteLine(&#34;&#34;);</p>
<p>Console.WriteLine(&#34;Win32_BootConfiguration instance&#34;);</p>
<p>Console.WriteLine(&#34;&#34;);</p>
<p>Console.WriteLine(&#34;BootDirectory: {0}&#34;, queryObj[&#34;BootDirectory&#34;]);</p>
<p>Console.WriteLine(&#34;Caption: {0}&#34;, queryObj[&#34;Caption&#34;]);</p>
<p>Console.WriteLine(&#34;ConfigurationPath: {0}&#34;, queryObj[&#34;ConfigurationPath&#34;]);</p>
<p>Console.WriteLine(&#34;Description: {0}&#34;, queryObj[&#34;Description&#34;]);</p>
<p>Console.WriteLine(&#34;LastDrive: {0}&#34;, queryObj[&#34;LastDrive&#34;]);</p>
<p>Console.WriteLine(&#34;Name: {0}&#34;, queryObj[&#34;Name&#34;]);</p>
<p>Console.WriteLine(&#34;ScratchDirectory: {0}&#34;, queryObj[&#34;ScratchDirectory&#34;]);</p>
<p>Console.WriteLine(&#34;SettingID: {0}&#34;, queryObj[&#34;SettingID&#34;]);</p>
<p>Console.WriteLine(&#34;TempDirectory: {0}&#34;, queryObj[&#34;TempDirectory&#34;]);</p>
<p>}</p>
<p>Close();</p>
<p>}</p>
<p>catch(ManagementException err)</p>
<p>{</p>
<p>MessageBox.Show(&#34;An error occurred while querying for WMI data: &#34; + err.Message);</p>
<p>}</p>
<p>catch(System.UnauthorizedAccessException unauthorizedErr)</p>
<p>{</p>
<p>MessageBox.Show(&#34;Connection error (user name or password might be incorrect): &#34; + unauthorizedErr.Message);</p>
<p>}</p>
</div>]]></content:encoded>
</item>
<item>
<title><![CDATA[Recursion with Linq]]></title>
<link>http://codetheory.wordpress.com/2009/05/10/recursion-with-linq/</link>
<pubDate>Sun, 10 May 2009 16:15:00 +0000</pubDate>
<dc:creator>Greg</dc:creator>
<guid>http://codetheory.wordpress.com/2009/05/10/recursion-with-linq/</guid>
<description><![CDATA[Have you ever needed a way to re-curse an object hierarchy in a very generic and simple way.&#160; I]]></description>
<content:encoded><![CDATA[<div class='snap_preview'><p>Have you ever needed a way to re-curse an object hierarchy in a very generic and simple way.&#160; I can show you how to do this and have it so simple to use that its just another part of you Linq query infrastructure.</p>
<p>Recursion can be a very useful operation if you need to dig deep into an object Hierarchy. If recursion is used in conjunction with Linq, it can be a very powerful way to extract collections or very specific items that you are looking for but don&#8217;t know the exact location to. There are a few simple things that I implemented to achieve this effect in my Theorem framework. I will break them down and explain why the particular technique was used.</p>
<p>One thing that I needed to do was establish a way to get at children on my base classes. BusinessBase is an abstract class that I derive all my business objects from, but it can be anything in your case. I added an interact to my BusinessBase class called IBusinessBase. Notice the ChildCollections being enforced here. That class will become one of the cornerstones required to make this all work.</p>
<div style="display:inline;float:none;margin:0;padding:0;" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:95068d94-d88f-49b2-a18a-d1e0678120ad" class="wlWriterEditableSmartContent">
<div style="border:#000080 1px solid;color:#000;font-family:'Courier New', Courier, Monospace;font-size:10pt;">
<div style="background:#fff;max-height:500px;overflow:auto;">
<ol style="background:#ffffff;margin:0;padding:0 0 0 5px;">
<li>&#160;</li>
<li style="background:#f3f3f3;">public interface IBusinessBase </li>
<li>{ </li>
<li style="background:#f3f3f3;">&#160;&#160;&#160;&#160;string Id { get; } </li>
<li>&#160;&#160;&#160;&#160;ChildCollections ChildCollections { get; } </li>
<li style="background:#f3f3f3;">}</li>
</ol></div>
</p></div>
</p></div>
<p>Now, lets take a look at the ChildCollections class and see what it does. Its very simply really. It creates a collection of all the BusinessCollectionBase&#60;&#62; objects that I have defined as properties on my object. In this case you can substitute ListBase&#60;&#62; for List&#60;&#62;, which is a custom list implementation I use in Theorem.&#160; This class simple acts as a container for the collections and exposes and object[] to contain all the items in the collection.&#160; This important for the recursion to work properly.</p>
<div style="display:inline;float:none;margin:0;padding:0;" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:223b47f5-105d-43f3-ae93-444d87e46beb" class="wlWriterEditableSmartContent">
<div style="border:#000080 1px solid;color:#000;font-family:'Courier New', Courier, Monospace;font-size:10pt;">
<div style="background:#fff;max-height:500px;overflow:auto;">
<ol style="background:#ffffff;margin:0;padding:0 0 0 5px;">
<li>&#160;</li>
<li style="background:#f3f3f3;">public class ChildCollections : ListBase, IChildCollections </li>
<li>{ </li>
<li style="background:#f3f3f3;">&#160;&#160;&#160;&#160;public object[] AllItems </li>
<li>&#160;&#160;&#160;&#160;{ </li>
<li style="background:#f3f3f3;">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;get </li>
<li>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;{ </li>
<li style="background:#f3f3f3;">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;List&#60; object&#62; items = new List&#60; object&#62;(); </li>
<li>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;for (int i = 0; i &#60; this.Count; i++) </li>
<li style="background:#f3f3f3;">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;{ </li>
<li>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;IEnumerator e = this[i].GetEnumerator(); </li>
<li style="background:#f3f3f3;">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;while (e.MoveNext()) </li>
<li>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;items.Add(e.Current); </li>
<li style="background:#f3f3f3;">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;} </li>
<li>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;return items.ToArray(); </li>
<li style="background:#f3f3f3;">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;} </li>
<li>&#160;&#160;&#160;&#160;} </li>
<li style="background:#f3f3f3;">}</li>
</ol></div>
</p></div>
</p></div>
<p>The interface IChildCollections looks like this.&#160; It cab be used to create your own custom collection containers in any way you like.</p>
<div style="display:inline;float:none;margin:0;padding:0;" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:a9cd363c-7423-4fae-9160-33a4a57a8ed6" class="wlWriterEditableSmartContent">
<div style="border:#000080 1px solid;color:#000;font-family:'Courier New', Courier, Monospace;font-size:10pt;">
<div style="background:#fff;max-height:500px;overflow:auto;">
<ol style="background:#ffffff;margin:0;padding:0 0 0 5px;">
<li>&#160;</li>
<li style="background:#f3f3f3;">public interface IChildCollections </li>
<li>{ </li>
<li style="background:#f3f3f3;">&#160;&#160;&#160;&#160;object[] AllItems { get; } </li>
<li>}</li>
</ol></div>
</p></div>
</p></div>
<p>Once you have this all established we can move on to the extension method that will allow us to extend Linq in a way that will allow recursion on out the object models.&#160; Simple create a namespace and add the following code.&#160; The extension method takes advantage of a few very cool features of .net.&#160; For example the<strong> </strong><a href="http://msdn.microsoft.com/en-us/library/9k7k7cf0.aspx"><strong>yield</strong></a> statement and <a href="http://msdn.microsoft.com/en-us/library/bb549151.aspx"><strong>Func</strong></a> Delegate.</p>
<p>We are simply going to iterate over the IEnumerable objects of Type T, which I will demonstrate later.&#160; The enumeration item discovered happens to be another IEnumerable collection then we will yield each item and re-curse if necessary.</p>
<div style="display:inline;float:none;margin:0;padding:0;" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:85c99b1c-9e71-446a-9612-37554aa7833f" class="wlWriterEditableSmartContent">
<div style="border:#000080 1px solid;color:#000;font-family:'Courier New', Courier, Monospace;font-size:10pt;">
<div style="background:#fff;max-height:500px;overflow:auto;">
<ol style="background:#ffffff;margin:0;padding:0 0 0 5px;">
<li>&#160;</li>
<li style="background:#f3f3f3;">namespace Theorem.Linq </li>
<li>{ </li>
<li style="background:#f3f3f3;">&#160;&#160;&#160;&#160;static public class LinqExtensions </li>
<li>&#160;&#160;&#160;&#160;{ </li>
<li style="background:#f3f3f3;">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;public static IEnumerable Recurse(this IEnumerable source,&#160;&#160;</li>
<li>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;Func&#60; T, IEnumerable &#62; recurse) </li>
<li style="background:#f3f3f3;">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;{ </li>
<li>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;foreach (T item in source) </li>
<li style="background:#f3f3f3;">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;{ </li>
<li>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;yield return item; </li>
<li style="background:#f3f3f3;">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;IEnumerable enumerable = recurse(item);</li>
<li>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;if (enumerable != null) </li>
<li style="background:#f3f3f3;">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;{ </li>
<li>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;foreach (T itemRecurse in </li>
<li style="background:#f3f3f3;">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;Recurse(enumerable, recurse)) </li>
<li>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;yield return itemRecurse; </li>
<li style="background:#f3f3f3;">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;} </li>
<li>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;} </li>
<li style="background:#f3f3f3;">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;} </li>
<li>&#160;&#160;&#160;&#160;} </li>
<li style="background:#f3f3f3;">}</li>
</ol></div>
</p></div>
</p></div>
</p>
<p>I have a BusinessBase object in my framework that implements the IBusinessBase interface.&#160; This forces me to create an implementation that looks like this.&#160; In my case I wanted to constrain my ChildCollection to typeof(IBusinessCollectionBase&#60;&#62;).&#160; By doing this, I am only extracting out framework collections, which is what I want in my case.&#160; But you could very easily open this up to IEnumerable&#60;&#62; and or more for recursion.</p>
<div style="display:inline;float:none;margin:0;padding:0;" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:f964598a-f406-48e4-afb9-7be83d6953b3" class="wlWriterEditableSmartContent">
<div style="border:#000080 1px solid;color:#000;font-family:'Courier New', Courier, Monospace;font-size:10pt;">
<div style="background:#fff;max-height:500px;overflow:auto;">
<ol style="background:#ffffff;margin:0;padding:0 0 0 5px;">
<li>&#160;</li>
<li style="background:#f3f3f3;">public ChildCollections ChildCollections </li>
<li>{ </li>
<li style="background:#f3f3f3;">&#160;&#160;&#160;&#160;get </li>
<li>&#160;&#160;&#160;&#160;{ </li>
<li style="background:#f3f3f3;">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;if (_children == null) </li>
<li>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;{ </li>
<li style="background:#f3f3f3;">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;_children = new ChildCollections(); </li>
<li>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;PropertyInfo[] props = this.GetType().GetProperties(); </li>
<li style="background:#f3f3f3;">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;for (int i = 0; i &#60; props.Length; i++) </li>
<li>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;{ </li>
<li style="background:#f3f3f3;">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;if (props[i].PropertyType.GetInterface( </li>
<li>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;typeof(IBusinessCollectionBase&#60;&#62;).Name) != null) </li>
<li style="background:#f3f3f3;">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;{ </li>
<li>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;_children.Add((IEnumerable)</li>
<li style="background:#f3f3f3;">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;props[i].GetValue(this, null)); </li>
<li>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;} </li>
<li style="background:#f3f3f3;">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;} </li>
<li>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;} </li>
<li style="background:#f3f3f3;">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;return _children; </li>
<li>&#160;&#160;&#160;&#160;} </li>
<li style="background:#f3f3f3;">}</li>
</ol></div>
</p></div>
</p></div>
<p>Ok, so on to a use case for this code and a demonstration of the output.&#160; Lets take an example from Theorem where we have a Group object that contains a collection of Groups as a property.&#160; We will then re-curse the structure with very little code.&#160; Here is a test method from Theorem.&#160; The lines to note are highlighted that demonstrate the recursion call.</p>
<div style="display:inline;float:none;margin:0;padding:0;" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:453ff9bd-279c-4163-966d-582c96989192" class="wlWriterEditableSmartContent">
<div style="border:#000080 1px solid;color:#000;font-family:'Courier New', Courier, Monospace;font-size:10pt;">
<div style="background:#fff;max-height:500px;overflow:auto;">
<ol style="background:#ffffff;margin:0;padding:0 0 0 5px;">
<li>&#160;</li>
<li style="background:#f3f3f3;">using System; </li>
<li>using System.Linq; </li>
<li style="background:#f3f3f3;">using System.Security; </li>
<li>using System.Security.Permissions; </li>
<li style="background:#f3f3f3;">using System.Transactions; </li>
<li>using Microsoft.VisualStudio.TestTools.UnitTesting; </li>
<li style="background:#f3f3f3;">using Theorem.Application.Security.Authorization; </li>
<li>using Theorem.Core; </li>
<li style="background:#f3f3f3;">using Theorem.Core.Data; </li>
<li>using Theorem.Linq;</li>
<li style="background:#f3f3f3;">&#8230;</li>
<li>[TestMethod] </li>
<li style="background:#f3f3f3;">public void Autorization_Core_Recursion() </li>
<li>{ </li>
<li style="background:#f3f3f3;">&#160;&#160;&#160;&#160;AuthorizationController ac = new AuthorizationController(); </li>
<li>&#160;&#160;&#160;&#160;Groups groups = ac.GetGroups();</li>
<li style="background:#f3f3f3;">&#160;&#160;&#160;&#160;Assert.IsNotNull(groups); </li>
<li>&#160;&#160;&#160;&#160;Group group = (from g in groups </li>
<li style="background:#f3f3f3;">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;where g.Name == &#34;Administrators&#34; </li>
<li>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;select g).FirstOrDefault(); </li>
<li style="background:#f3f3f3;">&#160;&#160;&#160;&#160;</li>
<li>&#160;&#160;&#160;&#160;Assert.AreEqual(&#34;Administrators&#34;, group.Name);</li>
<li style="background:#f3f3f3;">&#160;&#160;&#160;&#160;</li>
<li>&#160;&#160;&#160;&#160;Group groupA = new Group() { Name = &#34;test1&#34; }; </li>
<li style="background:#f3f3f3;">&#160;&#160;&#160;&#160;groupA.Groups.Add(new Group() { Name = &#34;test2&#34; }); </li>
<li>&#160;&#160;&#160;&#160;groupA.Groups.Add(new Group() { Name = &#34;test6&#34; });</li>
<li style="background:#f3f3f3;">&#160;&#160;&#160;&#160;Group groupB = new Group() { Name = &#34;test5&#34; }; </li>
<li>&#160;&#160;&#160;&#160;groupB.Groups.Add(new Group() { Name = &#34;test7&#34; }); </li>
<li style="background:#f3f3f3;">&#160;&#160;&#160;&#160;groupB.Groups.Add(new Group() { Name = &#34;test8&#34; });</li>
<li>&#160;&#160;&#160;&#160;groupA.Groups.Add(groupB);</li>
<li style="background:#f3f3f3;">&#160;&#160;&#160;&#160;group.Groups.Add(new Group() { Name = &#34;test3&#34; }); </li>
<li>&#160;&#160;&#160;&#160;group.Groups.Add(groupA); </li>
<li style="background:#f3f3f3;">&#160;&#160;&#160;&#160;group.Groups.Add(new Group() { Name = &#34;test4&#34; });</li>
<li>&#160;&#160;&#160;&#160;</li>
<li style="background:#f3f3f3;">&#160;&#160;&#160;&#160;var items = group.ChildCollections.AllItems.Cast( </li>
<li>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;Group).Recurse( x =&#62; x.ChildCollections.AllItems.Cast( </li>
<li style="background:#f3f3f3;">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;Group)).OrderBy( x =&#62; x.Name);</li>
<li>&#160;&#160;&#160;&#160;</li>
<li style="background:#f3f3f3;">&#160;&#160;&#160;&#160;foreach (Group item in items) </li>
<li>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;Console.WriteLine(item.Name); </li>
<li style="background:#f3f3f3;">}</li>
</ol></div>
</p></div>
</p></div>
</p>
<p>And here are the results.&#160; You can see that I am specifically casting into group objects, because I know that is what I am working with in this case.&#160; But I could very easily cast into BusinessBase if I wanted to and get items of all types.</p>
<p>test1    <br />test2     <br />test3     <br />test4     <br />test5     <br />test6     <br />test7     <br />test8</p>
<p>As you can see, one simple line of code is all that you need to extract out all the items of a specific type to a collection that you can work with.&#160; This has been tremendously valuable in many cases.&#160; I hope you see the value as well.</p>
</div>]]></content:encoded>
</item>

</channel>
</rss>
