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

<channel>
	<title>try {} except &#187; .net 3.5</title>
	<atom:link href="http://www.tryexcept.com/tag/net-35/feed" rel="self" type="application/rss+xml" />
	<link>http://www.tryexcept.com</link>
	<description>Tools and information for software developers</description>
	<lastBuildDate>Sun, 18 Sep 2011 20:33:29 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3</generator>
		<item>
		<title>Using Templates in ASP.NET MVC 2.0</title>
		<link>http://www.tryexcept.com/articles/2010/05/12/asp-net-mvc-2-0-templating.html</link>
		<comments>http://www.tryexcept.com/articles/2010/05/12/asp-net-mvc-2-0-templating.html#comments</comments>
		<pubDate>Wed, 12 May 2010 14:00:57 +0000</pubDate>
		<dc:creator>Manuel Gomes</dc:creator>
				<category><![CDATA[The others]]></category>
		<category><![CDATA[.net 3.5]]></category>
		<category><![CDATA[.net 4.0]]></category>
		<category><![CDATA[asp.net mvc]]></category>

		<guid isPermaLink="false">http://www.tryexcept.com/?p=161</guid>
		<description><![CDATA[Templating is now in the ASP.NET MVC 2.0 framework, for .NET framework 3.5 and 4.0.  Brian Mains explains. ASP.NET dynamic data featured a new way to develop applications, especially for the UI. The templating feature sets up a new way &#8230; <a href="http://www.tryexcept.com/articles/2010/05/12/asp-net-mvc-2-0-templating.html">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.pheedcontent.com/click.phdo?i=08cd1ab79a996c6b1dce63be9cf123aa">Templating is now in the ASP.NET MVC 2.0 framework</a>, for .NET framework 3.5 and 4.0.  <a href="http://dotnetslackers.com/community/members/bmains.aspx" target="_blank">Brian Mains</a> explains.</p>
<p><span id="more-161"></span></p>
<blockquote><p>ASP.NET dynamic data featured a new way to develop applications, especially for the UI. The templating feature sets up a new way to render the UI, whether in display or edit mode, based the object to display&#8217;s data type. For instance, if you wanted to render a LINQ object in dynamic data, the framework extracts information about all of the properties, looks up the template to for the data type of that property (an in-built user control or possibly a custom template you setup), and renders this UI for that property of a given type.<br />
This feature is now in the ASP.NET MVC 2.0 framework, for .NET framework 3.5 and 4.0. <a href="http://www.pheedcontent.com/click.phdo?i=08cd1ab79a996c6b1dce63be9cf123aa">We are going to take a look at these features</a>.</p></blockquote>
]]></content:encoded>
			<wfw:commentRss>http://www.tryexcept.com/articles/2010/05/12/asp-net-mvc-2-0-templating.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Check if a service is installed with ServiceController using LINQ</title>
		<link>http://www.tryexcept.com/articles/2008/07/27/check-if-a-service-is-installed-with-servicecontroller-using-linq.html</link>
		<comments>http://www.tryexcept.com/articles/2008/07/27/check-if-a-service-is-installed-with-servicecontroller-using-linq.html#comments</comments>
		<pubDate>Sun, 27 Jul 2008 18:40:12 +0000</pubDate>
		<dc:creator>Manuel Gomes</dc:creator>
				<category><![CDATA[Articles]]></category>
		<category><![CDATA[.net 3.5]]></category>
		<category><![CDATA[linq]]></category>

		<guid isPermaLink="false">http://www.tryexcept.com/articles/2008/07/27/check-if-a-service-is-installed-with-servicecontroller-using-linq.html</guid>
		<description><![CDATA[If you want to check if a specific NT Service is installed you will need to use the ServiceController class (from System.ServiceProcess). The first problem you will encounter is that the ServiceController has no static method, that would return a &#8230; <a href="http://www.tryexcept.com/articles/2008/07/27/check-if-a-service-is-installed-with-servicecontroller-using-linq.html">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>If you want to check if a specific NT Service is installed you will need to use the <a title="ServiceController class @msdn" href="http://msdn.microsoft.com/en-us/library/system.serviceprocess.servicecontroller.aspx" target="_blank">ServiceController </a>class (from System.ServiceProcess). The first problem you will encounter is that the ServiceController has no static method, that would return a Boolean, specifying if the service is installed or not (e.g. ServiceController.IsInstalled(‘MyService’);) – so, to solve this you need to fetch the list of all installed services, using the static method ServiceController.GetServices(), which returns an array of ServiceController[], and then iterate thru all the elements to see if “MyService” is on that list. Now, this is not a problem, is just too much code for such a simple task. If you use LINQ things are simple: basically you will iterate thru the list, but in a much focused and simple way.</p>
<p><span id="more-37"></span></p>
<pre name="code" class="c-sharp">var temp = from sc in ServiceController.GetServices()
where sc.ServiceName == "MyService"
select sc;
// temp.Count() is 0 if the service is not installed
Boolean isInstalled = temp.Count() != 0;</pre>
<p>If you want to manipulate the service (if installed, obviously), you don’t need to instantiate a new ServiceController(servicename), as the LINQ query returned a ServiceController ready to go. Add the following lines to the example:</p>
<pre name="code"  class="c-sharp">if (isInstalled)
{
    ServiceController myController =
        // the LINQ query only returns one element - we can use First&lt;&gt;()
        temp.First();
    Console.WriteLine("Service is installed and " +
        myController.Status.ToString());
    if (myController.Status == ServiceControllerStatus.Stopped)
    {
        Console.WriteLine("Starting the service...");
        myController.Start();
    }
}
else
{
    Console.WriteLine("The service is not installed");
}</pre>
<p>[ad#468x60]</p>
<p>You can change this LINQ query to search for any of the ServiceController’s properties. The following example returns the list of all started services:</p>
<pre name="code"  class="c-sharp">// Get all installed services
var startedServices = from sc in ServiceController.GetServices()
    where sc.Status == ServiceControllerStatus.Running
    select sc;
Console.WriteLine("And the installed services are:");
// now lets iterate thru all the started services
foreach (ServiceController startedService
    in startedServices.ToList())
{
    Console.WriteLine("  " + startedService.ServiceName +
        ": " + startedService.DisplayName);
}</pre>
<p>The major (and only) drawback when using LINQ is that it&#8217;s only available in .net framework 3.5.</p>
<p>For more on LINQ see also: <a href="http://weblogs.asp.net/scottgu/archive/2007/05/19/using-linq-to-sql-part-1.aspx" target="_blank">ScottGu&#8217;s introduction to LINQ</a> (focused on SQL LINQ), Introducing <a href="/books/view/0735623910/Introducing+Microsoft++LINQ.html">Microsoft LINQ</a>, <a href="/books/view/0596519249/LINQ+Pocket+Reference+(Pocket+Reference+(O'Reilly)).html">LINQ Pocket Reference</a>, <a href="/books/view/1590597893/Pro+LINQ%3A+Language+Integrated+Query+in+C%23+2008.html">Language Integrated Query in C#2008</a>, <a href="/books/view/0735624003/Programming+Microsoft®+LINQ+(PRO-Developer).html">Programming Microsoft LINQ </a>or the <a href="http://en.wikipedia.org/wiki/Linq" target="_blank">LINQ page in Wikipedia</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.tryexcept.com/articles/2008/07/27/check-if-a-service-is-installed-with-servicecontroller-using-linq.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

