<?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>Pressing the Red Button &#187; .Net</title>
	<atom:link href="http://www.pressthered.com/tag/net/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.pressthered.com</link>
	<description>Adventures in Software Development</description>
	<lastBuildDate>Sun, 08 Jan 2012 21:28:09 +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>Rejected-By-UrlScan 404 Errors</title>
		<link>http://www.pressthered.com/rejected-by-urlscan_404_errors/</link>
		<comments>http://www.pressthered.com/rejected-by-urlscan_404_errors/#comments</comments>
		<pubDate>Sat, 04 Jul 2009 05:59:56 +0000</pubDate>
		<dc:creator>jim.richmond</dc:creator>
				<category><![CDATA[Tech Tips]]></category>
		<category><![CDATA[.Net]]></category>
		<category><![CDATA[IIS]]></category>

		<guid isPermaLink="false">http://www.pressthered.com/?p=446</guid>
		<description><![CDATA[If you are getting some unexplainable 404 errors when accessing html or asp.net pages in IIS, and have exhausted the more common issues, check out your log file for URLScan errors. URLScan is a Microsoft security tool to help protect Internet Information Server. On your developer environment it might be getting in the way. How [...]]]></description>
			<content:encoded><![CDATA[<p>If you are getting some unexplainable 404 errors when accessing html or asp.net pages in IIS, and have exhausted the more common issues, check out your log file for URLScan errors. <a href="technet.microsoft.com/en-us/security/cc242650.aspx">URLScan</a> is a Microsoft security tool to help protect Internet Information Server. On your developer environment it might be getting in the way.</p>
<ol>
<strong>How Can I Disable URLScan</strong></p>
<li>Go to the Control Panel -> Administrative Tools -> Internet Information Services </li>
<li>Click WebSites folder, right click to get Properties</li>
<li>Click ISAPI Filters tab, find URLScan in the list, click Remove button, then OK to save</li>
<li>From Command Prompt (Start -> Run -> Cmd), type &#8220;iisreset&#8221;, to restart IIS</li>
</ol>
<p><strong>How Do I Configure URL Scan</strong><br />
<em>There is a configuration file located here:<br />
&lt;Windows Folder&gt;\system32\inetsrv\urlscan\UrlScan.ini</em><br />
Additional log files are also stored in that directory.<br />
If you want to keep URLScan on your computer, you can check out <a href="http://msdn.microsoft.com/en-us/library/aa302368.aspx">Microsoft&#8217;s documentation</a>.</p>
<p><strong>How Did It Get Installed</strong><br />
I have no idea in my case. I didn&#8217;t bother to look into it further. I am guessing through some Windows Update or some unintentionally clicking.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.pressthered.com/rejected-by-urlscan_404_errors/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Rounding Numbers in C#</title>
		<link>http://www.pressthered.com/rounding_numbers_in_c/</link>
		<comments>http://www.pressthered.com/rounding_numbers_in_c/#comments</comments>
		<pubDate>Tue, 30 Jun 2009 06:51:44 +0000</pubDate>
		<dc:creator>jim.richmond</dc:creator>
				<category><![CDATA[Tech Tips]]></category>
		<category><![CDATA[.Net]]></category>
		<category><![CDATA[C#]]></category>

		<guid isPermaLink="false">http://www.pressthered.com/?p=396</guid>
		<description><![CDATA[A quick overview on rounding numbers in C# with examples: // To Round 3.1415 to nearest integer -> 3 decimal result1 = Math.Round(3.1415m); // To Round 3.1415 to the third decimal place -> 3.142 decimal result2 = Math.Round(3.1415m, 3); // To Round 18.5m Up -> 19 decimal result3 = Math.Round(18.5m, 0, MidpointRounding.AwayFromZero); // The default [...]]]></description>
			<content:encoded><![CDATA[<p>A quick overview on <strong>rounding numbers in C#</strong> with examples:</p>
<pre name="code" class="c-sharp">
// To Round 3.1415 to nearest integer -> 3
decimal result1 = Math.Round(3.1415m);

// To Round 3.1415 to the third decimal place -> 3.142
decimal result2 = Math.Round(3.1415m, 3);

// To Round 18.5m Up -> 19
decimal result3 = Math.Round(18.5m, 0, MidpointRounding.AwayFromZero);

// The default will round down (ToEven) -> 18
decimal result4 = Math.Round(18.5m, 0);
</pre>
<p>One advantage of the default for mid point rounding down, is if you are working with numerous fractions, the sums could be more accurate (if you keep rounding up all your numbers it could skew your results).  </p>
<p><strong>More Information:</strong><br />
You can round numbers of type decimal or double using .Net&#8217;s System.Math.Round() method. Returns a decimal. See <a href="http://msdn.microsoft.com/en-us/library/system.math.round.aspx">MSDN doc</a> for additional reference.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.pressthered.com/rounding_numbers_in_c/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Working with Null Characters in C# / .Net</title>
		<link>http://www.pressthered.com/working_with_null_characters_in_c_net/</link>
		<comments>http://www.pressthered.com/working_with_null_characters_in_c_net/#comments</comments>
		<pubDate>Sat, 20 Dec 2008 05:26:30 +0000</pubDate>
		<dc:creator>jim.richmond</dc:creator>
				<category><![CDATA[Tech Tips]]></category>
		<category><![CDATA[.Net]]></category>
		<category><![CDATA[C#]]></category>

		<guid isPermaLink="false">http://www.pressingtheredbutton.com/?p=49</guid>
		<description><![CDATA[Here is one method to manipulate Null characters in C#: To Search a String for a Null character: mystring.Contains(Convert.ToChar(0x0).ToString() ); //The hexidecimal 0x0 is the null character To Replace all Null Characters in a String: mystring.Replace(Convert.ToChar(0x0).ToString(), ""); Why Do I Need This? It might help. I needed it when I got a nasty error message [...]]]></description>
			<content:encoded><![CDATA[<p>Here is one method to manipulate Null characters in C#:</p>
<p><strong>To Search a String for a Null character:</strong></p>
<pre name="code" class="c-sharp">
mystring.Contains(Convert.ToChar(0x0).ToString() );
//The hexidecimal 0x0 is the null character
</pre>
<p><strong>To Replace all Null Characters in a String:</strong></p>
<pre name="code" class="c-sharp">
mystring.Replace(Convert.ToChar(0x0).ToString(), "");
</pre>
<p><strong>Why Do I Need This?</strong><br />
It might help. I needed it when I got a nasty error message in a data layer that was using asp.net web services and soap to retrieve the data:<br />
&#8220;There is an error in XML document  hexadecimal value 0&#215;00, is an invalid character&#8221;<br />
Basically what happened is that a null character was pasted into a SQL Server database via an Access front end. When my asp.net app was pulling the data via a SOAP data layer, the null character can not be used in a XML document with UTF encoding. Which is the transport method of this particualr service. So the quick hack was to strip out the null character after the data pull but before the soap transfer back to the client.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.pressthered.com/working_with_null_characters_in_c_net/feed/</wfw:commentRss>
		<slash:comments>12</slash:comments>
		</item>
		<item>
		<title>Flexible Business Logic with a .Net Math Parser</title>
		<link>http://www.pressthered.com/flexible_business_logic_with_a_net_math_parser/</link>
		<comments>http://www.pressthered.com/flexible_business_logic_with_a_net_math_parser/#comments</comments>
		<pubDate>Tue, 28 Nov 2006 08:12:50 +0000</pubDate>
		<dc:creator>jim.richmond</dc:creator>
				<category><![CDATA[Tech Tips]]></category>
		<category><![CDATA[.Net]]></category>
		<category><![CDATA[math]]></category>

		<guid isPermaLink="false">http://www.pressingtheredbutton.com/flexible_business_logic_with_a_net_math_parser/</guid>
		<description><![CDATA[Modifying code due to business logic changes is a never ending process. In this entry I discuss the merit's of using a math parser to dynamically calculate business logic at run time. This allows for quicker updates and flexible code. I use a real world example of a coupon component that I added to an [...]]]></description>
			<content:encoded><![CDATA[<p>Modifying code due to business logic changes is a never ending process. In this entry I discuss the merit's of using a math parser to dynamically calculate business logic at run time. This allows for quicker updates and flexible code. I use a real world example of a coupon component that I added to an online shopping cart.</p>
<p><strong>What's a Math Parser</strong><br />
A math parser is simply a group of functions that you can use in your code to parse mathematical expressions. I shouldn't say simple because these libraries are fast and capable of complex calculations. In my case I am just interested in algaebraic functions (or math you would use in business). They still fit the bill perfectly.</p>
<p>I have been wanting to test a math parser to define and execute business logic for some time now. I finally had a chance when I client had requested some coupon functionality to be added to an online shopping cart. </p>
<p><strong>Where Can I Get One</strong><br />
So the first step was to find a free math parser I could use in .Net. This was harder then I expected as there were no <a href="http://en.wikipedia.org/wiki/FLOSS">FOSS</a> math parsers available. <a href="http://muparser.sourceforge.net/">muParser</a> was what I was looking for, but no .Net version.</p>
<p>I eventually found a inexpensive parser ($19.95) that included the source. I downloaded the demo, ran some tests, and found a winner (<a href="http://www.bestcode.com/">bcParser.NET</a>). </p>
<p><strong>So Now What</strong><br />
Here is how I used the math parser in the coupon component I did for my client. First off, let me give you a brief overview of basic functionality. The customer would be at the shopping cart page and would have a text box to enter a special coupon code. Once applied this coupon would discount the sub total on the shopping cart.</p>
<p>Here is a simple object for a coupon:</p>
<div class="igBar"><span id="lcsharp-3"><a href="#" onclick="javascript:showPlainTxt('csharp-3'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">C#:</span>
<div id="csharp-3">
<div class="csharp">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #0600FF;">public</span> <span style="color: #FF0000;">class</span> CouponCode</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #000000;">&#123;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #FF0000;">string</span> couponCode <span style="color: #008080; font-style: italic;">//the coupon code&nbsp;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; MathParser parserApply = <a href="http://www.google.com/search?q=new+msdn.microsoft.com"><span style="color: #008000;">new</span></a> MathParser<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>; <span style="color: #008080; font-style: italic;">// The formula to determine when to apply the coupon</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; MathParser parserDiscountCalculation = <a href="http://www.google.com/search?q=new+msdn.microsoft.com"><span style="color: #008000;">new</span></a> MathParser<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>; <span style="color: #008080; font-style: italic;">// The formula to calculate the discount</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #000000;">&#125;</span> </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p>The three values above would be entered by the store admin for each coupon. The coupon code is the code the end user would enter to acitvate the coupon. The parserApply will contain the formala to determine when to apply the coupon. Now these formulas will be standard alegabraic functions as shown below but the really aren't useful unless you introduce optional variables that can be used in the formula. Some common ones would be the item category, item sku, an item total.</p>
<p>Here is an  example:<br />
1) A coupon for $5 off $10 or more in CD's:</p>
<div class="igBar"><span id="lcsharp-4"><a href="#" onclick="javascript:showPlainTxt('csharp-4'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">C#:</span>
<div id="csharp-4">
<div class="csharp">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">coupon.<span style="color: #0000FF;">parserApply</span>.<span style="color: #0000FF;">formula</span> = <span style="color: #808080;">"(varItemCategory = 5) and (varItemTotal&gt; 10)"</span>; <span style="color: #008080; font-style: italic;">//5 is the item category for CD's and the item total must be greater then $10.</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">coupon.<span style="color: #0000FF;">parserApply</span>.<span style="color: #0000FF;">CreateVar</span><span style="color: #000000;">&#40;</span><span style="color: #808080;">"varItemCategory"</span>, <span style="color: #FF0000;color:#800000;">5</span>&nbsp; , <span style="color: #0600FF;">null</span><span style="color: #000000;">&#41;</span>; <span style="color: #008080; font-style: italic;">//5 is the item category of an item in the cart</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">coupon.<span style="color: #0000FF;">parserApply</span>.<span style="color: #0000FF;">CreateVar</span><span style="color: #000000;">&#40;</span><span style="color: #808080;">"varItemTotal "</span>, <span style="color: #FF0000;color:#800000;">20</span>&nbsp; , <span style="color: #0600FF;">null</span><span style="color: #000000;">&#41;</span>; <span style="color: #008080; font-style: italic;">//20 is the item total (item price * qty)</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">coupon.<span style="color: #0000FF;">parserApply</span>.<span style="color: #0000FF;">Evaluate</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>; <span style="color: #008080; font-style: italic;">//this will evaluate to true because the item in the cart is a CD and it's total is&gt; 10</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #008080; font-style: italic;">//now calculate the item discount if the coupon should be applied</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #0600FF;">if</span> <span style="color: #000000;">&#40;</span>coupon.<span style="color: #0000FF;">parserApply</span>.<span style="color: #0000FF;">Value</span>&gt; <span style="color: #FF0000;color:#800000;">0</span><span style="color: #000000;">&#41;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #000000;">&#123;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; coupon.<span style="color: #0000FF;">parserDiscountCalculation</span>.<span style="color: #0000FF;">formula</span> = <span style="color: #808080;">"varItemTotal - 5"</span>; <span style="color: #008080; font-style: italic;">//subtract $5</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; coupon.<span style="color: #0000FF;">parserDiscountCalculation</span>.<span style="color: #0000FF;">CreateVar</span><span style="color: #000000;">&#40;</span><span style="color: #808080;">"varItemTotal "</span>, <span style="color: #FF0000;color:#800000;">20</span>&nbsp; , <span style="color: #0600FF;">null</span><span style="color: #000000;">&#41;</span>; <span style="color: #008080; font-style: italic;">//the item total</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; coupon.<span style="color: #0000FF;">parserDiscountCalculation</span>.<span style="color: #0000FF;">Evaluate</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>; <span style="color: #008080; font-style: italic;">// the customer's item will be discounted to $15</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; itemTotal = coupon.<span style="color: #0000FF;">parserDiscountCalculation</span>.<span style="color: #0000FF;">Value</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #000000;">&#125;</span> </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p>So at this point you should be seeing that there is a lot of flexibility in the code. If the client wants to change the logic, it is simply a matter of updating the above formulas in the database. No code changes needed.</p>
<p>The coupon component that I put in place is obviously a little more detailed. As of date, it is working well and the client is very happy with the functionality.</p>
<p>Let me know if you have any questions or comments.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.pressthered.com/flexible_business_logic_with_a_net_math_parser/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

