<?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>dotnet thoughts &#187; C#</title>
	<atom:link href="http://www.dotnetthoughts.net/tag/c/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.dotnetthoughts.net</link>
	<description>a dotnet developer&#039;s technical blog</description>
	<lastBuildDate>Thu, 02 Feb 2012 03:18:00 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>How to write an NUnit Addin</title>
		<link>http://www.dotnetthoughts.net/2012/01/23/how-to-write-an-nunit-addin/</link>
		<comments>http://www.dotnetthoughts.net/2012/01/23/how-to-write-an-nunit-addin/#comments</comments>
		<pubDate>Tue, 24 Jan 2012 04:51:09 +0000</pubDate>
		<dc:creator>Anuraj P</dc:creator>
				<category><![CDATA[.Net]]></category>
		<category><![CDATA[Miscellaneous]]></category>
		<category><![CDATA[Unit Testing]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[C#.Net]]></category>
		<category><![CDATA[NUnit]]></category>
		<category><![CDATA[NUnit AddIn]]></category>

		<guid isPermaLink="false">http://www.dotnetthoughts.net/?p=2309</guid>
		<description><![CDATA[From version 2.2.x NUnit supports AddIns. Addins can customize NUnit’s internal behavior such as the creation of tests and their execution. An Addin should to implement the interface NUnit.Core.Extensibility.IAddin, which can be found in the assembly nunit.core.interfaces. Also the NUnit.Core.Extensibility.NUnitAddinAttribute &#8230; <a href="http://www.dotnetthoughts.net/2012/01/23/how-to-write-an-nunit-addin/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p style="text-align: justify;">From version 2.2.x NUnit supports AddIns. Addins can customize NUnit’s internal behavior such as the creation of tests and their execution. An Addin should to implement the interface <em>NUnit.Core.Extensibility.IAddin</em>, which can be found in the assembly <em>nunit.core.interfaces</em>. Also the <em>NUnit.Core.Extensibility.NUnitAddinAttribute</em> must be applied to Addin class. The attribute parameters Name and Description represent the name of the extension and a description of what it does. The NUnit.Core.Extensibility.IAddin has only one method, Install(). The Install method is called by each host for which the addin has specified an ExtensionType. The addin should check that the necessary extension points are available and install itself, returning true for success or false for failure to install. The method will be called once for each extension host and &#8211; for Core extensions &#8211; each time a new test domain is loaded. Here is a minimal addin.</p>
<pre class="brush: csharp; title: ; notranslate">
namespace SampleAddIn
{
    using NUnit.Core.Extensibility;

    [NUnitAddin(Name = &quot;SampleAddIn&quot;, Description = &quot;This is a Sample AddIn&quot;)]
    public class SampleNUnitAddin : IAddin
    {
        #region IAddin Members

        public bool Install(IExtensionHost host)
        {
            return true;
        }

        #endregion
    }
}
</pre>
<p>You can install the Addin, by copying the assembly to bin\Addins folder, relative to NUnit installation directory. You can verify your addin by starting NUnit, Tools &gt; Addins menu.</p>
<div id="attachment_2311" class="wp-caption aligncenter" style="width: 310px"><img class="size-medium wp-image-2311" title="Registered AddIns Dialog" src="http://www.dotnetthoughts.net/wp-content/uploads/2012/01/nunit_addin-300x258.jpg" alt="Registered AddIns Dialog" width="300" height="258" /><p class="wp-caption-text">Registered AddIns Dialog</p></div>
<p>This Addin does nothing. It simply registers itself to NUnit. You can more details about NUnit Addins <a href="http://nunit.org/index.php?p=nunitAddins&amp;r=2.6">here</a><br />
If you are using VS2010, then please make sure your target framework is .Net 2.0. Otherwise Addin won&#8217;t work.</p>
<div class="betterrelated"><p><strong>Related content:</strong></p>
<ol><li> <a href="http://www.dotnetthoughts.net/2011/01/05/how-to-compare-equality-between-two-objects-in-nunit/" title="Permanent link to How to compare equality between two objects in NUnit">How to compare equality between two objects in NUnit</a>  </li>
<li> <a href="http://www.dotnetthoughts.net/2011/11/02/debugging-nunit-tests-in-visual-studio-2010/" title="Permanent link to Debugging NUnit Tests in Visual Studio 2010">Debugging NUnit Tests in Visual Studio 2010</a>  </li>
<li> <a href="http://www.dotnetthoughts.net/2010/12/23/how-to-do-code-coverage-with-nunit-tests/" title="Permanent link to How to do code coverage with NUnit tests">How to do code coverage with NUnit tests</a>  </li>
<li> <a href="http://www.dotnetthoughts.net/2010/12/15/how-to-integrate-nunit-with-visual-studio-2008/" title="Permanent link to How to integrate Nunit with Visual Studio 2008">How to integrate Nunit with Visual Studio 2008</a>  </li>
<li> <a href="http://www.dotnetthoughts.net/2011/09/25/getting-code-coverage-using-open-cover-and-nunit/" title="Permanent link to Getting Code coverage using Open Cover and NUnit">Getting Code coverage using Open Cover and NUnit</a>  </li>
</ol></div>]]></content:encoded>
			<wfw:commentRss>http://www.dotnetthoughts.net/2012/01/23/how-to-write-an-nunit-addin/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>How to add MEX endpoints programmatically</title>
		<link>http://www.dotnetthoughts.net/2012/01/22/how-to-add-mex-endpoints-programmatically/</link>
		<comments>http://www.dotnetthoughts.net/2012/01/22/how-to-add-mex-endpoints-programmatically/#comments</comments>
		<pubDate>Mon, 23 Jan 2012 02:49:13 +0000</pubDate>
		<dc:creator>Anuraj P</dc:creator>
				<category><![CDATA[.Net]]></category>
		<category><![CDATA[.Net 4.0]]></category>
		<category><![CDATA[WCF]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[Mex]]></category>
		<category><![CDATA[Mex EndPoint]]></category>

		<guid isPermaLink="false">http://www.dotnetthoughts.net/?p=2303</guid>
		<description><![CDATA[The Metadata Exchange Endpoint (MEX) is a special endpoint in WCF that exposes metadata used to describe a service.Without the MEX, you will not be able to use svcutil.exe to automatically generate a proxy class. Fortunately, it is a simply &#8230; <a href="http://www.dotnetthoughts.net/2012/01/22/how-to-add-mex-endpoints-programmatically/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>The Metadata Exchange Endpoint (MEX) is a special endpoint in WCF that exposes metadata used to describe a service.Without the MEX, you will not be able to use svcutil.exe to automatically generate a proxy class.  Fortunately, it is a simply process to enable the MEX for your service. Here is the code which will add Mex endpoint programmatically. </p>
<pre class="brush: csharp; title: ; notranslate">
var metadataBehavior = serviceHost.Description.Behaviors.Find&lt;ServiceMetadataBehavior&gt;()
    ?? new ServiceMetadataBehavior();
serviceHost.Description.Behaviors.Add(metadataBehavior);
serviceHost.AddServiceEndpoint(typeof(IMetadataExchange),
    MetadataExchangeBindings.CreateMexHttpBinding(),
    &quot;http://localhost:8080/IService/Mex&quot;);
</pre>
<p>It should be noted that you are not required to enable HttpGet.  SvcUtil will still be able to access the MEX without it.  However, it is useful if you want to view the WSDL from a browser by going to the address of the service.  You cannot do so without enabling the HttpGet.</p>
<div class="betterrelated"><p><strong>Related content:</strong></p>
<ol><li> <a href="http://www.dotnetthoughts.net/2011/12/26/how-to-configure-a-wcf-service-to-use-port-sharing/" title="Permanent link to How to configure a WCF service to use Port Sharing">How to configure a WCF service to use Port Sharing</a>  </li>
<li> <a href="http://www.dotnetthoughts.net/2011/06/24/wcf-callbacks-%e2%80%93-a-quick-introduction/" title="Permanent link to WCF Callbacks – A quick introduction">WCF Callbacks – A quick introduction</a>  </li>
<li> <a href="http://www.dotnetthoughts.net/2011/03/20/how-to-create-restful-wcf-services/" title="Permanent link to How to create RESTful WCF services">How to create RESTful WCF services</a>  </li>
<li> <a href="http://www.dotnetthoughts.net/2011/04/01/how-to-post-data-to-restful-wcf-service/" title="Permanent link to How to post data to RESTful WCF service">How to post data to RESTful WCF service</a>  </li>
</ol></div>]]></content:encoded>
			<wfw:commentRss>http://www.dotnetthoughts.net/2012/01/22/how-to-add-mex-endpoints-programmatically/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>How to compress JPEG image using C#</title>
		<link>http://www.dotnetthoughts.net/2012/01/07/how-to-compress-jpeg-image-using-c/</link>
		<comments>http://www.dotnetthoughts.net/2012/01/07/how-to-compress-jpeg-image-using-c/#comments</comments>
		<pubDate>Sat, 07 Jan 2012 14:32:37 +0000</pubDate>
		<dc:creator>Anuraj P</dc:creator>
				<category><![CDATA[.Net]]></category>
		<category><![CDATA[.Net 3.0 / 3.5]]></category>
		<category><![CDATA[.Net 4.0]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[Compress]]></category>
		<category><![CDATA[Image Compression]]></category>

		<guid isPermaLink="false">http://www.dotnetthoughts.net/?p=2227</guid>
		<description><![CDATA[Here is a C# snippet which helps to compress JPEG image. Also displays how much size got reduced. Related content: Writing File with Non Cache mode in C# Upload multiple files using Silverlight Raven DB &#8211; Introduction How to compile &#8230; <a href="http://www.dotnetthoughts.net/2012/01/07/how-to-compress-jpeg-image-using-c/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Here is a C# snippet which helps to compress JPEG image. Also displays how much size got reduced.</p>
<pre class="brush: csharp; title: ; notranslate">
public static void CompressJpeg(string path, int quality)
{
    if (quality &lt; 0 || quality &gt; 100)
    {
        throw new
            ArgumentOutOfRangeException(&quot;Quality must be between 0 and 100.&quot;);
    }
    //Creating temp. file and
    string tempFile = Path.GetTempFileName();
    File.Copy(path, tempFile, true);
    using (var image = Image.FromFile(tempFile))
    {
        // Encoder parameter for image quality
        var qualityParam =
            new EncoderParameter(Encoder.Quality, quality);
        // Jpeg image codec
        var jpegCodec = ImageCodecInfo.GetImageEncoders()
            .Where(imageCodecInfo =&gt; imageCodecInfo.MimeType == &quot;image/jpeg&quot;)
            .FirstOrDefault();
        var encoderParams = new EncoderParameters(1);
        encoderParams.Param[0] = qualityParam;
        //Save the compressed image.
        image.Save(path, jpegCodec, encoderParams);
        //Getting the file image sizes.
        var prevImageSize = new FileInfo(tempFile).Length;
        var nextImageSize = new FileInfo(path).Length;
        Console.WriteLine(&quot;Image compressed. Size saved :{0} bytes&quot;,
            prevImageSize - nextImageSize);
    }
    //Removing the temp. file.
    File.Delete(tempFile);
}
</pre>
<div class="betterrelated"><p><strong>Related content:</strong></p>
<ol><li> <a href="http://www.dotnetthoughts.net/2010/01/19/writing_file_with_non_cache_mode_in_c/" title="Permanent link to Writing File with Non Cache mode in C#">Writing File with Non Cache mode in C#</a>  </li>
<li> <a href="http://www.dotnetthoughts.net/2011/07/17/upload-multiple-files-using-silverlight/" title="Permanent link to Upload multiple files using Silverlight">Upload multiple files using Silverlight</a>  </li>
<li> <a href="http://www.dotnetthoughts.net/2010/11/25/raven-db-introduction/" title="Permanent link to Raven DB &#8211; Introduction">Raven DB &#8211; Introduction</a>  </li>
<li> <a href="http://www.dotnetthoughts.net/2011/01/09/how-to-compile-c-code-snippet-in-runtime/" title="Permanent link to How to compile C# code snippet in runtime">How to compile C# code snippet in runtime</a>  </li>
<li> <a href="http://www.dotnetthoughts.net/2011/11/03/argumentexception-this-row-already-belongs-to-another-table/" title="Permanent link to ArgumentException &#8211; This row already belongs to another table">ArgumentException &#8211; This row already belongs to another table</a>  </li>
</ol></div>]]></content:encoded>
			<wfw:commentRss>http://www.dotnetthoughts.net/2012/01/07/how-to-compress-jpeg-image-using-c/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>How to get Build Definitions and Build Details from TFS 2010</title>
		<link>http://www.dotnetthoughts.net/2012/01/05/how-to-get-build-definitions-and-build-details-from-tfs-2010/</link>
		<comments>http://www.dotnetthoughts.net/2012/01/05/how-to-get-build-definitions-and-build-details-from-tfs-2010/#comments</comments>
		<pubDate>Thu, 05 Jan 2012 17:55:32 +0000</pubDate>
		<dc:creator>Anuraj P</dc:creator>
				<category><![CDATA[.Net]]></category>
		<category><![CDATA[.Net 4.0]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[Team Foundation Server]]></category>
		<category><![CDATA[TFS]]></category>
		<category><![CDATA[TFS API]]></category>

		<guid isPermaLink="false">http://www.dotnetthoughts.net/?p=2221</guid>
		<description><![CDATA[This snippet which will connect to TFS Server and get all running builds for all build definitions, using TFS Client API. Please make sure you are adding of the following assemblies. Microsoft.TeamFoundation.dll Microsoft.TeamFoundation.Build.Client.dll Microsoft.TeamFoundation.Build.Common.dll Microsoft.TeamFoundation.dll which will be available under &#8230; <a href="http://www.dotnetthoughts.net/2012/01/05/how-to-get-build-definitions-and-build-details-from-tfs-2010/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>This snippet which will connect to TFS Server and get all running builds for all build definitions, using TFS Client API.</p>
<pre class="brush: csharp; title: ; notranslate">
try
{
    var tfsName = &quot;http://dotnetthoughts:8080/tfs/defaultcollection&quot;;
    var tfs = new TeamFoundationServer(tfsName, new UICredentialsProvider());
    tfs.EnsureAuthenticated();
    if (tfs.HasAuthenticated)
    {
        var bs = tfs.GetService(typeof(IBuildServer)) as IBuildServer;
        //Select all Build definitions
        var spec = bs.CreateBuildQueueSpec(&quot;*&quot;, &quot;*&quot;);
        var buildResults = bs.QueryQueuedBuilds(spec);
        foreach (IQueuedBuild queuedBuild in buildResults.QueuedBuilds)
        {
            Console.WriteLine(&quot;Status :{0} - {1} - Requested by : {2} Controller :{3}&quot;,
                queuedBuild.Status, queuedBuild.BuildDefinition.Name,
                queuedBuild.RequestedBy, queuedBuild.BuildController.Name);
        }
    }
}
catch (Exception exception)
{
    MessageBox.Show(exception.Message);
    throw;
}
</pre>
<p>Please make sure you are adding of the following assemblies.</p>
<ol>
<li>Microsoft.TeamFoundation.dll</li>
<li>Microsoft.TeamFoundation.Build.Client.dll</li>
<li>Microsoft.TeamFoundation.Build.Common.dll</li>
<li>Microsoft.TeamFoundation.dll</li>
</ol>
<p>which will be available under &#8211; C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE\ReferenceAssemblies\v2.0\ location.</p>
<p>Happy <span style="color: #00ff00;"><strong>GREEN</strong></span> builds <img src='http://www.dotnetthoughts.net/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<div class="betterrelated"><p><strong>Related content:</strong></p>
<ol><li> <a href="http://www.dotnetthoughts.net/2012/01/12/how-to-queue-a-new-build-using-tfs-api/" title="Permanent link to How to queue a new build using TFS API">How to queue a new build using TFS API</a>  </li>
<li> <a href="http://www.dotnetthoughts.net/2011/02/21/how-to-store-tfs-credentials/" title="Permanent link to How to store TFS credentials">How to store TFS credentials</a>  </li>
<li> <a href="http://www.dotnetthoughts.net/2011/01/04/tfs-build-notification-tool/" title="Permanent link to TFS Build Notification Tool">TFS Build Notification Tool</a>  </li>
</ol></div>]]></content:encoded>
			<wfw:commentRss>http://www.dotnetthoughts.net/2012/01/05/how-to-get-build-definitions-and-build-details-from-tfs-2010/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Webcams in Silverlight 4.0</title>
		<link>http://www.dotnetthoughts.net/2012/01/03/webcams-in-silverlight-4/</link>
		<comments>http://www.dotnetthoughts.net/2012/01/03/webcams-in-silverlight-4/#comments</comments>
		<pubDate>Tue, 03 Jan 2012 17:58:32 +0000</pubDate>
		<dc:creator>Anuraj P</dc:creator>
				<category><![CDATA[.Net]]></category>
		<category><![CDATA[ASP.Net]]></category>
		<category><![CDATA[Silverlight]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[Web cam]]></category>

		<guid isPermaLink="false">http://www.dotnetthoughts.net/?p=2209</guid>
		<description><![CDATA[Microsoft Silverlight 4.0 supports Webcam and microphone access from Web Applications like Flash. This feature enables a number of scenarios, such as capturing and displaying images, uploading profile pictures to social networking applications etc. Here is code part, which will &#8230; <a href="http://www.dotnetthoughts.net/2012/01/03/webcams-in-silverlight-4/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p style="text-align: justify;">Microsoft Silverlight 4.0 supports Webcam and microphone access from Web Applications like Flash. This feature enables a number of scenarios, such as capturing and displaying images, uploading profile pictures to social networking applications etc. Here is code part, which will start the webcam, stop the webcam and captures the image.</p>
<p>Initialize the web cam</p>
<pre class="brush: csharp; title: ; notranslate">
private CaptureSource _captureSource;
private VideoBrush _videoBrush;
private ImageBrush _imageBrush;

_captureSource = new CaptureSource();
_captureSource.CaptureImageCompleted += (o, e) =&gt;
{
    _imageBrush = new ImageBrush();
    _imageBrush.ImageSource = e.Result;
    rectWebCamView.Fill = _imageBrush;
};
_captureSource.CaptureFailed += (o, e) =&gt;
{
    MessageBox.Show(e.ErrorException.Message);
};
</pre>
<p>Start the web cam, the rectWebCamView is a Rectangle.</p>
<pre class="brush: csharp; title: ; notranslate">
if (_captureSource.State != CaptureState.Started)
{
    _captureSource.VideoCaptureDevice =
        CaptureDeviceConfiguration.GetDefaultVideoCaptureDevice();
    _videoBrush = new VideoBrush();
    _videoBrush.SetSource(_captureSource);
    rectWebCamView.Fill = _videoBrush;

    if (CaptureDeviceConfiguration.RequestDeviceAccess())
    {
        _captureSource.Start();
    }
}
</pre>
<p>The RequestDeviceAccess() method invokes a request dialog for accessing the webcame like this.</p>
<div id="attachment_2211" class="wp-caption aligncenter" style="width: 310px"><img class="size-medium wp-image-2211" title="Request Access dialog " src="http://www.dotnetthoughts.net/wp-content/uploads/2012/01/request_access_opt-300x115.jpg" alt="Request Access dialog " width="300" height="115" /><p class="wp-caption-text">Request Access dialog</p></div>
<p>Note: The RequestAccess must be called in response to a user initiated event, such as a Button Click event.</p>
<p>Stop the web cam</p>
<pre class="brush: csharp; title: ; notranslate">
_captureSource.Stop();
</pre>
<p>And finally the capture image.</p>
<pre class="brush: csharp; title: ; notranslate">
if (_captureSource.State == CaptureState.Started)
{
    _captureSource.CaptureImageAsync();
}
</pre>
<p>The method will invoke CaptureImageCompleted event, and which will capture the image and display it in the rectangle. The XAML code contains only 3 buttons and one rectangle, so I am not posting the XAML code.</p>
<p>Happy programming <img src='http://www.dotnetthoughts.net/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<div class="betterrelated"><p><strong>Related content:</strong></p>
<ol><li> <a href="http://www.dotnetthoughts.net/2010/09/20/drag-and-drop-in-silverlight-3/" title="Permanent link to Drag and Drop in Silverlight 3">Drag and Drop in Silverlight 3</a>  </li>
<li> <a href="http://www.dotnetthoughts.net/2009/11/10/post-data-using-httpwebrequest-in-c-sharp/" title="Permanent link to Post data using HttpWebRequest in C#">Post data using HttpWebRequest in C#</a>  </li>
<li> <a href="http://www.dotnetthoughts.net/2010/01/06/file-uploader-using-silverlight-and-wcf/" title="Permanent link to File Uploader using Silverlight and WCF">File Uploader using Silverlight and WCF</a>  </li>
<li> <a href="http://www.dotnetthoughts.net/2010/11/04/how-to-access-sharepoint-list-items-using-silverlight-object-model/" title="Permanent link to How to access SharePoint List Items using Silverlight Object Model">How to access SharePoint List Items using Silverlight Object Model</a>  </li>
<li> <a href="http://www.dotnetthoughts.net/2010/11/05/hosting-silverlight-application-in-sharepoint-2010/" title="Permanent link to Hosting Silverlight application in Sharepoint 2010">Hosting Silverlight application in Sharepoint 2010</a>  </li>
</ol></div>]]></content:encoded>
			<wfw:commentRss>http://www.dotnetthoughts.net/2012/01/03/webcams-in-silverlight-4/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

