<?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>IBlog &#187; .NET</title>
	<atom:link href="http://blog.objectpattern.com/category/dot-net/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.objectpattern.com</link>
	<description>Just another WordPress weblog</description>
	<lastBuildDate>Sat, 17 Apr 2010 18:49:03 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.4</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Ignorance is not bliss. EventWaitHandle.OpenExisting throws WaitHandleCannotBeOpenedException</title>
		<link>http://blog.objectpattern.com/dot-net/ignorance-is-not-bliss-eventwaithandle-openexisting-throws-waithandlecannotbeopenedexception/?utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=ignorance-is-not-bliss-eventwaithandle-openexisting-throws-waithandlecannotbeopenedexception</link>
		<comments>http://blog.objectpattern.com/dot-net/ignorance-is-not-bliss-eventwaithandle-openexisting-throws-waithandlecannotbeopenedexception/#comments</comments>
		<pubDate>Tue, 02 Feb 2010 06:36:25 +0000</pubDate>
		<dc:creator>Himanshu</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[Windows Plateform]]></category>

		<guid isPermaLink="false">http://blog.objectpattern.com/uncategorized/ignorance-is-not-bliss-eventwaithandle-openexisting-throws-waithandlecannotbeopenedexception/</guid>
		<description><![CDATA[My development computer got upgraded to Windows 7, Windows 7 is good experience.
For one of our client, I needed to setup mechanics such that admin users should be able to initiate a process in Windows Service using GDI based .NET application. We had also developed the windows service in .NET. As both of them are [...]]]></description>
			<content:encoded><![CDATA[<p>My development computer got upgraded to Windows 7, Windows 7 is good experience.</p>
<p>For one of our client, I needed to setup mechanics such that admin users should be able to initiate a process in Windows Service using GDI based .NET application. We had also developed the windows service in .NET. As both of them are .NET applications, there are more than one ways to IPC between them. As in this case there was only need to give signal to the service, I choose to do it through <a href="http://msdn.microsoft.com/en-us/library/ms686915(VS.85).aspx">Windows Event</a>. .NET BCL provides wrapper around Win32 functions to do this through type named <a href="http://msdn.microsoft.com/en-us/library/system.threading.eventwaithandle.aspx">EventWaitHandle</a>.</p>
<p>I completed the code like I used to do in my old days, and tried the first use of it. On call to OpenExisting, client application failed with exception &#8220;No handle of the given name exists”. My first thought was that this could be because of UAC, but in that case it should say something like access violation. I tried running application in Windows 2003 Server and it worked perfectly. I decided to check with Google and documentation. I found <a href="http://social.msdn.microsoft.com/Forums/en/clr/thread/91810489-d932-4e4f-bbb7-4a5f02c39cf9">this</a>, which gave me a relieving thought &#8211; “I’m not the only one in this world!” <img src='http://blog.objectpattern.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> .</p>
<p>After some time I landed to <a href="http://msdn.microsoft.com/en-us/library/aa382954(VS.85).aspx">msdn</a> page for namespaces of kernel objects, which indicates that:</p>
<blockquote><p><em>For processes started under a client session, the system uses the session namespace by default. However, these processes can use the global namespace by prepending the &#8220;Global\&#8221; prefix to the object name</em></p></blockquote>
<p>changed my client code to have name prefixed with “Global\”, and everything started behaving the way I wanted it to in Windows 7 as well.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.objectpattern.com/dot-net/ignorance-is-not-bliss-eventwaithandle-openexisting-throws-waithandlecannotbeopenedexception/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Extending code readability by extension methods</title>
		<link>http://blog.objectpattern.com/dot-net/extending-code-readability-by-extension-methods/?utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=extending-code-readability-by-extension-methods</link>
		<comments>http://blog.objectpattern.com/dot-net/extending-code-readability-by-extension-methods/#comments</comments>
		<pubDate>Thu, 12 Nov 2009 05:40:56 +0000</pubDate>
		<dc:creator>Himanshu</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://blog.objectpattern.com/?p=50</guid>
		<description><![CDATA[If you haven’t noticed, note that extension methods can also be called on null objects. Meaning, there can be extension method which checks whether an object is null or not. So, 
public void Operate(InputType inputObject)
{
    if (null != inputObject)
    {
        . . [...]]]></description>
			<content:encoded><![CDATA[<p>If you haven’t noticed, note that extension methods can also be called on null objects. Meaning, there can be extension method which checks whether an object is null or not. So, </p>
<pre class="csharpcode"><span class="kwrd">public</span> <span class="kwrd">void</span> Operate(InputType inputObject)
{
    <span class="kwrd">if</span> (<span class="kwrd">null</span> != inputObject)
    {
        . . .
    }
} 

<span class="kwrd">public</span> <span class="kwrd">void</span> Operate(InputType inputObject)
{
    <span class="kwrd">if</span> (<span class="kwrd">null</span> == inputObject)
    {
        . . .
    }
} </pre>
<pre class="csharpcode">&nbsp;</pre>
<style type="text/css">.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }
</style>
<style type="text/css">
.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }</style>
<p>Can be replaced by</p>
<pre class="csharpcode"><span class="kwrd"></span>&nbsp;</pre>
<pre class="csharpcode"><span class="kwrd">public</span> <span class="kwrd">void</span> Operate(InputType inputObject)
{
    <span class="kwrd">if</span> (inputObject.IsNotNull())
    {
        . . .
    }
} 

<span class="kwrd">public</span> <span class="kwrd">void</span> Operate(InputType inputObject)
{
    <span class="kwrd">if</span> (inputObject.IsNull())
    {
        . . .
    }
} </pre>
<style type="text/css">.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }
</style>
<style type="text/css">
.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }</style>
]]></content:encoded>
			<wfw:commentRss>http://blog.objectpattern.com/dot-net/extending-code-readability-by-extension-methods/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Sending email message having embedded image (.NET)</title>
		<link>http://blog.objectpattern.com/dot-net/sending-email-message-having-embedded-image-net/?utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=sending-email-message-having-embedded-image-net</link>
		<comments>http://blog.objectpattern.com/dot-net/sending-email-message-having-embedded-image-net/#comments</comments>
		<pubDate>Fri, 15 May 2009 05:16:25 +0000</pubDate>
		<dc:creator>Himanshu</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[ASP.NET]]></category>
		<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">/post/Sending-email-message-having-embedded-image-(NET).aspx</guid>
		<description><![CDATA[Does your .net application send email messages? Does it send formatted email messages? I think applications should always send formatted email messages instead of text only. (Are asking why? Simple, formatted messages are much more capable, presentable, &#8230;).
Counter argument: Some user uses email client that are not capable to show HTML messages. Or someone is [...]]]></description>
			<content:encoded><![CDATA[<p>Does your .net application send email messages? Does it send formatted email messages? I think applications should always send formatted email messages instead of text only. (Are asking why? Simple, formatted messages are much more capable, presentable, &#8230;).</p>
<p>Counter argument: Some user uses email client that are not capable to show HTML messages. Or someone is doing it for security purpose. Okay, I agree, then send both the views; text view as well as HTML view. Using .NET, one can send multi view email messages, depending on email client settings and/or capability, client is expected to pick the right view and shows that to the user.</p>
<p>Next question is, say we have decided to send email in html and text view, can we send images and style sheets embedded with email? Answers is yes. Here is how one can send multi-part email message using .net libraries that has embedded image.</p>
<p>Here goes the first step, create MailMessage object and setup that with appropriate values</p>
<div style="line-height: 12pt; background-color: #f4f4f4; margin: 20px 0px 10px; width: 97.3%; font-family: consolas, 'Courier New', courier, monospace; height: 60px; max-height: 200px; font-size: 8pt; overflow: auto; cursor: text; border: gray 1px solid; padding: 4px;">
<div style="line-height: 12pt; background-color: #f4f4f4; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">
<pre style="line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #606060">   1:</span> var from = <span style="color: #0000ff">new</span> MailAddress(<span style="color: #006080">"admin@objectpattern.com"</span>, <span style="color: #006080">"Himanshu"</span>);</pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #606060">   2:</span> var to = <span style="color: #0000ff">new</span> MailAddress(<span style="color: #006080">"himanshu@objectpattern.net"</span>);</pre>
<pre style="line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #606060">   3:</span> var message = <span style="color: #0000ff">new</span> MailMessage(from, to) { Subject = <span style="color: #006080">"Hi from ObjectPattern"</span>};</pre>
</div>
</div>
<p>next step changes. As we want to have two views &#8211; text and html, we will have to create email body differently.</p>
<p>in these lines of code, there are certain important points</p>
<div style="line-height: 12pt; background-color: #f4f4f4; margin: 20px 0px 10px; width: 97.59%; font-family: consolas, 'Courier New', courier, monospace; height: 281px; max-height: 200px; font-size: 8pt; overflow: auto; cursor: text; border: gray 1px solid; padding: 4px;">
<div style="line-height: 12pt; background-color: #f4f4f4; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">
<pre style="line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #606060">   1:</span> <span style="color: #008000">//creating text view</span></pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #606060">   2:</span> var textViewContent = <span style="color: #006080">"Test content for text view"</span>;</pre>
<pre style="line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #606060">   3:</span> var textView = AlternateView.CreateAlternateViewFromString(textViewContent, Encoding.UTF8,</pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #606060">   4:</span>                                                            MediaTypeNames.Text.Plain);</pre>
<pre style="line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #606060">   5:</span> <span style="color: #008000">//creating html view </span></pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #606060">   6:</span> var htmlViewContent = <span style="color: #006080">"

Html content containing image logo

Thanks,
ObjectPattern
<img src="cid:logo.png" alt="logo" />"</span>;</pre>
<pre style="line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #606060">   7:</span> var htmlView = AlternateView.CreateAlternateViewFromString(htmlViewContent, Encoding.UTF8,</pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #606060">   8:</span>                                                            MediaTypeNames.Text.Html);</pre>
</div>
</div>
<p>that I would like to bring in to your notice.</p>
<ul>
<li>Notice that we are not assigning Body property of MailMessage type</li>
<li>While creating view, we are specifying media type name as either plain text or html text, it can also be rich text.</li>
<li>We have created an img tag that referring to source as &#8216;cid:logo.png&#8217;</li>
</ul>
<p>okay now how we will embed image into email message? That&#8217;s easy as well:</p>
<div style="line-height: 12pt; background-color: #f4f4f4; margin: 20px 0px 10px; width: 97.66%; font-family: consolas, 'Courier New', courier, monospace; height: 76px; max-height: 200px; font-size: 8pt; overflow: auto; cursor: text; border: gray 1px solid; padding: 4px;">
<div style="line-height: 12pt; background-color: #f4f4f4; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">
<pre style="line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #606060">   1:</span> var logo = <span style="color: #0000ff">new</span> LinkedResource(<span style="color: #006080">"images/logo.png"</span>, MediaTypeNames.Image.Jpeg) {ContentId = <span style="color: #006080">"logo.png"</span>};</pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #606060">   2:</span> htmlView.LinkedResources.Add(logo);</pre>
</div>
</div>
<p>here in first line, first parameter of constructor (&#8221;image/logo.png&#8221; text) specifies the path of the image file. One can also supply image content as stream if its not coming directly from the file. Now remember, in above section, we had specified the src attribute of img tag, that should match with content id. Else image will not be shown correctly in email client. Also notice that we are adding this image to html view.</p>
<p>We are almost done now. All we need to do now is to add views to message object and sending using SMTP client.</p>
<div style="line-height: 12pt; background-color: #f4f4f4; margin: 20px 0px 10px; width: 99.11%; font-family: consolas, 'Courier New', courier, monospace; height: 58px; max-height: 200px; font-size: 8pt; overflow: auto; cursor: text; border: gray 1px solid; padding: 4px;">
<div style="line-height: 12pt; background-color: #f4f4f4; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">
<pre style="line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #606060">   1:</span> message.AlternateViews.Add(textView);</pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #606060">   2:</span> message.AlternateViews.Add(htmlView);</pre>
<pre style="line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #606060">   3:</span></pre>
</div>
</div>
]]></content:encoded>
			<wfw:commentRss>http://blog.objectpattern.com/dot-net/sending-email-message-having-embedded-image-net/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Changing version of .net framework dependency for setup and deployment project in visual studio 2008</title>
		<link>http://blog.objectpattern.com/dot-net/changing-version-of-net-framework-dependency-for-setup-and-deployment-project-in-visual-studio-2008/?utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=changing-version-of-net-framework-dependency-for-setup-and-deployment-project-in-visual-studio-2008</link>
		<comments>http://blog.objectpattern.com/dot-net/changing-version-of-net-framework-dependency-for-setup-and-deployment-project-in-visual-studio-2008/#comments</comments>
		<pubDate>Tue, 13 Jan 2009 15:50:40 +0000</pubDate>
		<dc:creator>Himanshu</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[VS.NET]]></category>

		<guid isPermaLink="false">/post/Changing-version-of-net-framework-dependency-for-setup-and-deployment-project-in-visual-studio-2008.aspx</guid>
		<description><![CDATA[Its easy to do, but not obvious to locate, at least to me. It took a while for me to find, so I thought let&#8217;s log it, in case if I need it in future, or someone else might need it. I need to create setup that depends on .NET framework 2.0. instead of 3.5 [...]]]></description>
			<content:encoded><![CDATA[<p>Its easy to do, but not obvious to locate, at least to me. It took a while for me to find, so I thought let&#8217;s log it, in case if I need it in future, or someone else might need it. I need to create setup that depends on .NET framework 2.0. instead of 3.5 which is default in VS.NET 2008.</p>
<p>After creating setup and deployment project, double click on dependency of .net framework in solution explorer:</p>
<p><img class="alignnone size-full wp-image-54" title="doubleClickDependency" src="http://blog.objectpattern.com/wp-content/uploads/2009/01/doubleClickDependency.png" alt="doubleClickDependency" width="304" height="117" /></p>
<p>Now, you should be able to see launch condition for .net framework in <em>&#8220;Launch Conditions&#8221; </em>tab. Until you double click for the first time, node do not appear in launch conditions. And that&#8217;s where I wasted some hours:</p>
<p><img class="alignnone size-full wp-image-55" title="lauch condition" src="http://blog.objectpattern.com/wp-content/uploads/2009/01/lauch-condition.png" alt="lauch condition" width="248" height="107" /></p>
<p>Select the node and see the property window, where you will find the answer of the question:</p>
<p><img class="alignnone size-full wp-image-56" title="version" src="http://blog.objectpattern.com/wp-content/uploads/2009/01/version.png" alt="version" width="562" height="250" /></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.objectpattern.com/dot-net/changing-version-of-net-framework-dependency-for-setup-and-deployment-project-in-visual-studio-2008/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Navigate and injecting C# code using visual studio macro</title>
		<link>http://blog.objectpattern.com/dot-net/navigate-and-injecting-c-code-using-visual-studio-macro/?utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=navigate-and-injecting-c-code-using-visual-studio-macro</link>
		<comments>http://blog.objectpattern.com/dot-net/navigate-and-injecting-c-code-using-visual-studio-macro/#comments</comments>
		<pubDate>Fri, 21 Nov 2008 19:32:00 +0000</pubDate>
		<dc:creator>Himanshu</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[RoboCoding]]></category>
		<category><![CDATA[Software Engineering]]></category>
		<category><![CDATA[VS.NET]]></category>

		<guid isPermaLink="false">/post/Navigate-and-injecting-C-code-using-visual-studio-macro.aspx</guid>
		<description><![CDATA[Visual studio macros are great, probably I will write this in all posts that I write for macros  . Sometime back, I need to change a fairly big CF.NET application such a way that it will log a line on each function entry and on function exit. We were tracing for cause of intermittently [...]]]></description>
			<content:encoded><![CDATA[<p>Visual studio macros are great, probably I will write this in all posts that I write for macros <img src='http://blog.objectpattern.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> . Sometime back, I need to change a fairly big CF.NET application such a way that it will log a line on each function entry and on function exit. We were tracing for cause of intermittently occurring GWES.EXE error, and we were tracing it from multiple directions. The error code of GWES was 0xC0000005, which means someone was trying to access something, which was never allocated or is being accessed after releasing it. Application was multi-threaded, and hence it was difficult to understand which thread will do what at what time.</p>
<p>Moving back to original point, we wanted to log entry and exit of each functions. There can be more then one way to do that, but we have selected to change each functions. And to change each functions I have selected to use developer named <em>&#8220;VS.NET macro&#8221;.</em></p>
<p>From macro it is possible to navigate through solution and projects. So macro first needs to find out all class types from a project, and then for each class, iterate through its member and find out functions that has body. If function has body, inject the code that logs line on function entry and exit.</p>
<p>It was easy to find function entry, but there can be many way function ends, like exception is being thrown, or based of some condition it may execute &#8220;return&#8221;, or body of the function is ended and hence return. To accommodate such cases, we decide to use &#8220;<em>using statement&#8221; </em>of C#.</p>
<p>All right, enough of the background, have look at Macro code <a title="VS.NET Macro" href="http://download.objectpattern.com/LoggingInjection-VS8Macro.vb" target="_blank">here</a></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.objectpattern.com/dot-net/navigate-and-injecting-c-code-using-visual-studio-macro/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Paging of SQL Server records</title>
		<link>http://blog.objectpattern.com/dot-net/paging-of-sql-server-records/?utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=paging-of-sql-server-records</link>
		<comments>http://blog.objectpattern.com/dot-net/paging-of-sql-server-records/#comments</comments>
		<pubDate>Tue, 05 Aug 2008 06:29:41 +0000</pubDate>
		<dc:creator>Himanshu</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[ASP.NET]]></category>
		<category><![CDATA[Sql Server 2005]]></category>

		<guid isPermaLink="false">/post/Paging-of-SQL-Server-records.aspx</guid>
		<description><![CDATA[In one of my ASP.NET, SQL Server project, we were expected to provide paging in the ASP.NET GridView. Microsoft&#8217;s very common sample will do this using Dataset filled with all records. If someone is doing GridView paging, s/he is doing it not waste server&#8217;s or client&#8217;s precious resources, Isn&#8217;t it?
To me, it make more sense [...]]]></description>
			<content:encoded><![CDATA[<p>In one of my ASP.NET, SQL Server project, we were expected to provide paging in the ASP.NET GridView. Microsoft&#8217;s very common sample will do this using Dataset filled with all records. If someone is doing GridView paging, s/he is doing it not waste server&#8217;s or client&#8217;s precious resources, Isn&#8217;t it?</p>
<p>To me, it make more sense to do paging of records being fetched in server memory along with view paging. What if table in question has more then 100,000 (1 lack) records?</p>
<p>Digging a bit further, I found a resource which explains how to do paging of records being sent from stored procedure. But it was expecting to have auto identity as primary key in the table. And we were so fortunate that we couldn&#8217;t have db design such that we can afford to have auto identity primary key, and so that solution to the paging problem. On doing some more finding, we all agreed to a solution that is described below. It&#8217;s not fully optimized, as it do not have any optimization for SQL Server to prepare result sets. But worked for our need in specific project as even in 100,000 records it was working very fast.</p>
<p>In our solution, stored procedure that will fetch records from table and return to caller will needs to have two addition parameters, @RowIndexFrom and @RowIndexTo</p>
<p>Getting customers by page will look like following,</p>
<div style="line-height: 12pt; background-color: #f4f4f4; margin: 20px 0px 10px; width: 97.5%; font-family: consolas, 'Courier New', courier, monospace; height: 242px; max-height: 200px; font-size: 8pt; overflow: auto; cursor: text; border: gray 1px solid; padding: 4px;">
<div style="line-height: 12pt; background-color: #f4f4f4; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">
<pre style="line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #0000ff">CREATE</span> <span style="color: #0000ff">PROCEDURE</span> [dbo].[GetCustomersPage]</pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">(</pre>
<pre style="line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">    @RowIndexFrom <span style="color: #0000ff">int</span>,</pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">    @RowIndexTo <span style="color: #0000ff">int</span></pre>
<pre style="line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">)</pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #0000ff">AS</span></pre>
<pre style="line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #0000ff">BEGIN</span></pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">    <span style="color: #0000ff">SET</span> NOCOUNT <span style="color: #0000ff">ON</span>;</pre>
<pre style="line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"> </pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">    <span style="color: #0000ff">WITH</span> IndexedCustomers <span style="color: #0000ff">AS</span></pre>
<pre style="line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">    (</pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">        <span style="color: #0000ff">SELECT</span></pre>
<pre style="line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">            ROW_NUMBER() <span style="color: #0000ff">OVER</span> (<span style="color: #0000ff">ORDER</span> <span style="color: #0000ff">BY</span> Id) <span style="color: #0000ff">AS</span> rowIndex,</pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">            Customers.*</pre>
<pre style="line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">        <span style="color: #0000ff">FROM</span></pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">            Customers</pre>
<pre style="line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">    )</pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">    <span style="color: #0000ff">SELECT</span> * <span style="color: #0000ff">FROM</span> IndexedCustomers <span style="color: #0000ff">WHERE</span> rowIndex <span style="color: #0000ff">BETWEEN</span> @RowIndexFrom <span style="color: #0000ff">AND</span> @RowIndexTo</pre>
<pre style="line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"> </pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">    <span style="color: #0000ff">SELECT</span> <span style="color: #0000ff">COUNT</span>(*)</pre>
<pre style="line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">    <span style="color: #0000ff">FROM</span></pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">        Customers</pre>
<pre style="line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #0000ff">END</span></pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #0000ff">GO</span></pre>
</div>
</div>
<p> </p>
<p>The stored procedure returns two result set, first will be records for given page (defined by different between @RowIndexFrom and @RowIndexTo parameters). And the second result set will give total number of records for give query. Second result set will help preparing pages list. So, if first page needs to be retrieved of page size 10, parameter values should be 1 and 10 respectively.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.objectpattern.com/dot-net/paging-of-sql-server-records/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Sending keystrokes (Key press) from .Net to active application</title>
		<link>http://blog.objectpattern.com/dot-net/sending-keystrokes-key-press-from-net-to-active-application/?utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=sending-keystrokes-key-press-from-net-to-active-application</link>
		<comments>http://blog.objectpattern.com/dot-net/sending-keystrokes-key-press-from-net-to-active-application/#comments</comments>
		<pubDate>Thu, 27 Mar 2008 17:32:39 +0000</pubDate>
		<dc:creator>Himanshu</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[RoboCoding]]></category>

		<guid isPermaLink="false">/post/Sending-keystrokes-(Key-press)-from-Net-to-active-application.aspx</guid>
		<description><![CDATA[Many of the part of windows works on messages &#8211; windows messages. One code can send different kind of messages to another application using Windows API. Keyboard messages and mouse messages are one of them.
.NET is one more layer above OS, e.g. Windows. If someone needs to emulate keyboard strokes to another application from .NET [...]]]></description>
			<content:encoded><![CDATA[<p>Many of the part of windows works on messages &#8211; windows messages. One code can send different kind of messages to another application using Windows API. Keyboard messages and mouse messages are one of them.</p>
<p>.NET is one more layer above OS, e.g. Windows. If someone needs to emulate keyboard strokes to another application from .NET there is a choice of using .NET class library. To emulate keyboard events from .NET it&#8217;s easier to use</p>
<ul>
<li>System.Windows.Forms.SendKeys.Send(string) and </li>
<li>System.Windows.Forms.SendKeys.SendWait(string) </li>
</ul>
<p>Recently, I used this to auto log into a application that I&#8217;m developing if it&#8217;s debug build. Just to get a change from AutoHotKey. </p>
<p>The problem of this is it sends keystrokes to only active application.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.objectpattern.com/dot-net/sending-keystrokes-key-press-from-net-to-active-application/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>VS.NET, macro creating string const, and macro creating string resource entry</title>
		<link>http://blog.objectpattern.com/dot-net/vs-net-macro-creating-string-const-and-macro-creating-string-resource-entry/?utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=vs-net-macro-creating-string-const-and-macro-creating-string-resource-entry</link>
		<comments>http://blog.objectpattern.com/dot-net/vs-net-macro-creating-string-const-and-macro-creating-string-resource-entry/#comments</comments>
		<pubDate>Mon, 17 Mar 2008 14:08:00 +0000</pubDate>
		<dc:creator>Himanshu</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[RoboCoding]]></category>
		<category><![CDATA[VS.NET]]></category>

		<guid isPermaLink="false">/post/VSNET-Macro-creating-const-of-string-and-resource-entry-for-string.aspx</guid>
		<description><![CDATA[
Per me, macro is one of the most important feature for any text editor or software IDE. And hence, it is very import for VS.NET user to understand and then use macros available in VS.NET. VS.NET macros are very powerfully tool and they help in lot more different ways.


I have created two macros that are [...]]]></description>
			<content:encoded><![CDATA[<p>
Per me, macro is one of the most important feature for any text editor or software IDE. And hence, it is very import for VS.NET user to understand and then use macros available in VS.NET. VS.NET macros are very powerfully tool and they help in lot more different ways.
</p>
<p>
I have created two macros that are very common in their need. While programming, we need to create string const on regular bases. It becomes inconvenient to go to top of the class while writing a method body for same class and create constant. Macro in library attached with this post becomes handy at that time.
</p>
<p>
Same use case hold very much true for creating string resources while writing method body. And it becomes really very easy if string resource can be created while writing method body.
</p>
<p>
For those who thinks like me (or want to <img src='http://blog.objectpattern.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />  ), I have attached two macros with this post. Macro works for VS.NET 2005, haven&#39;t tested in any other version. But should work fine in VS.NET 2003 or VS.NET 2008</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.objectpattern.com/dot-net/vs-net-macro-creating-string-const-and-macro-creating-string-resource-entry/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
