<?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>Matt Uliasz&#039;s few small ideas</title>
	<atom:link href="http://uliasz.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://uliasz.com</link>
	<description>...skill to do comes of doing...</description>
	<lastBuildDate>Mon, 30 Jan 2012 19:41:17 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	
		<item>
		<title>How to delete all stored procedures from MSSQL database using cursor</title>
		<link>http://uliasz.com/2012/01/how-to-delete-all-stored-procedures-from-mssql-database-using-cursor/</link>
		<comments>http://uliasz.com/2012/01/how-to-delete-all-stored-procedures-from-mssql-database-using-cursor/#comments</comments>
		<pubDate>Tue, 24 Jan 2012 10:29:08 +0000</pubDate>
		<dc:creator>Matt</dc:creator>
				<category><![CDATA[SQL]]></category>

		<guid isPermaLink="false">http://uliasz.com/?p=330</guid>
		<description><![CDATA[Here is a code for deleting all stored procedures in SQL Server database using cursor. DECLARE @name varchar(500) DECLARE @sql varchar(max) SET @sql = '' DECLARE cur CURSOR FOR SELECT [name] FROM sys.procedures OPEN cur FETCH NEXT FROM cur INTO @name WHILE @@fetch_status = 0 BEGIN SET @sql = 'DROP PROC ' + @name PRINT…]]></description>
			<content:encoded><![CDATA[<p>Here is a code for deleting all stored procedures in SQL Server database using cursor.</p>
<pre>
DECLARE @name varchar(500)
DECLARE @sql varchar(max)
SET @sql = ''

DECLARE cur CURSOR
      FOR SELECT [name] FROM sys.procedures
      OPEN cur

      FETCH NEXT FROM cur INTO @name
      WHILE @@fetch_status = 0
      BEGIN
			SET @sql = 'DROP PROC ' + @name
			PRINT @sql
			EXEC (@sql)
            FETCH NEXT FROM cur INTO @name
      END
      CLOSE cur
      DEALLOCATE cur</pre>
]]></content:encoded>
			<wfw:commentRss>http://uliasz.com/2012/01/how-to-delete-all-stored-procedures-from-mssql-database-using-cursor/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to close all connections to a MSSQL database</title>
		<link>http://uliasz.com/2011/09/how-to-close-all-connections-to-a-mssql-database/</link>
		<comments>http://uliasz.com/2011/09/how-to-close-all-connections-to-a-mssql-database/#comments</comments>
		<pubDate>Mon, 05 Sep 2011 09:40:22 +0000</pubDate>
		<dc:creator>Matt</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://uliasz.com/?p=326</guid>
		<description><![CDATA[This script closes all connections to MS SQL database USE master; GO ALTER DATABASE dbName SET SINGLE_USER WITH ROLLBACK IMMEDIATE; GO ALTER DATABASE dbName SET MULTI_USER; GO]]></description>
			<content:encoded><![CDATA[<p>This script closes all connections to MS SQL database</p>
<pre>USE master;
GO
ALTER DATABASE dbName
SET SINGLE_USER
WITH ROLLBACK IMMEDIATE;
GO
ALTER DATABASE dbName
SET MULTI_USER;
GO</pre>
]]></content:encoded>
			<wfw:commentRss>http://uliasz.com/2011/09/how-to-close-all-connections-to-a-mssql-database/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Animated iPhone-style ImageButton with Silverlight 4</title>
		<link>http://uliasz.com/2011/07/animated-iphone-style-imagebutton-with-silverlight-4/</link>
		<comments>http://uliasz.com/2011/07/animated-iphone-style-imagebutton-with-silverlight-4/#comments</comments>
		<pubDate>Tue, 05 Jul 2011 17:02:26 +0000</pubDate>
		<dc:creator>Matt</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[Silverlight]]></category>
		<category><![CDATA[Work]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[XAML]]></category>

		<guid isPermaLink="false">http://uliasz.com/?p=290</guid>
		<description><![CDATA[In this article I am presenting a way to create animated iPhone-style ImageButton control in Silverlight 4. Button will have icon on it, rounded corners and will zoom-in/zoom-out on hover. It will be done programmatically, with very minimum amount of XAML. I start with creating ImageButton class. I use ButtonBase as base class: I want…]]></description>
			<content:encoded><![CDATA[<p>In this article I am presenting a way to create animated iPhone-style ImageButton control in Silverlight 4. Button will have icon on it, rounded corners and will zoom-in/zoom-out on hover. It will be done programmatically, with very minimum amount of XAML.</p>
<p>I start with creating ImageButton class. I use ButtonBase as base class:</p>
<p><a href="http://uliasz.com/wp-content/uploads/2011/07/image-button-1.png"><img class="alignnone size-full wp-image-296" title="image-button-1" src="http://uliasz.com/wp-content/uploads/2011/07/image-button-1.png" alt="Class declaration" width="430" height="132" /></a></p>
<p>I want my button to contain rounded rectangle with shadow and image on it. I add these items in constructor:</p>
<p><a href="http://uliasz.com/wp-content/uploads/2011/07/image-button-2.png"><img class="alignnone size-full wp-image-297" title="image-button-2" src="http://uliasz.com/wp-content/uploads/2011/07/image-button-2.png" alt="Class constructor" width="710" height="569" /></a></p>
<p>Now my control contains rectangle and image laid out over a grid to ensure proper items positioning. Next step is to add animation to enable zoom-in/out on hovering. This can be achieved with storyboards and double animations:</p>
<p><a href="http://uliasz.com/wp-content/uploads/2011/07/image-button-3.png"><img class="alignnone size-full wp-image-298" title="image-button-3" src="http://uliasz.com/wp-content/uploads/2011/07/image-button-3.png" alt="Animations" width="761" height="542" /></a></p>
<p>To start animations I need to start animations when mouse cursor enters or leaves control:</p>
<p><a href="http://uliasz.com/wp-content/uploads/2011/07/image-button-4.png"><img class="alignnone size-full wp-image-299" title="image-button-4" src="http://uliasz.com/wp-content/uploads/2011/07/image-button-4.png" alt="Events" width="300" height="155" /></a></p>
<p>Very last step is making ImageSource property &#8220;bindable&#8221; so you can specify image from XAML. In order to do this I register new dependency property on my class:</p>
<p><a href="http://uliasz.com/wp-content/uploads/2011/07/image-button-5.png"><img class="alignnone size-full wp-image-300" title="image-button-5" src="http://uliasz.com/wp-content/uploads/2011/07/image-button-5.png" alt="Dependency property" width="715" height="315" /></a></p>
<p>The control then can be used in a following way:</p>
<p><a href="http://uliasz.com/wp-content/uploads/2011/07/image-button-6.png"><img class="alignnone size-full wp-image-301" title="image-button-6" src="http://uliasz.com/wp-content/uploads/2011/07/image-button-6.png" alt="Usage" width="904" height="97" /></a></p>
<p>And ready controls looks like this:</p>
<p><a href="http://uliasz.com/wp-content/uploads/2011/07/image-button-7.png"><img class="alignnone size-full wp-image-302" title="image-button-7" src="http://uliasz.com/wp-content/uploads/2011/07/image-button-7.png" alt="Final effect" width="211" height="165" /></a></p>
<p>&nbsp;</p>
]]></content:encoded>
			<wfw:commentRss>http://uliasz.com/2011/07/animated-iphone-style-imagebutton-with-silverlight-4/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Using Sets in .Net</title>
		<link>http://uliasz.com/2011/06/using-sets-in-net/</link>
		<comments>http://uliasz.com/2011/06/using-sets-in-net/#comments</comments>
		<pubDate>Mon, 27 Jun 2011 08:44:05 +0000</pubDate>
		<dc:creator>Matt</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[C#]]></category>

		<guid isPermaLink="false">http://uliasz.com/?p=287</guid>
		<description><![CDATA[Great post by James Michael Hare I came across about using Sets in .Net. Definitely worth taking a look. http://geekswithblogs.net/BlackRabbitCoder/archive/2011/02/03/c.net-little-wonders-the-useful-but-overlooked-sets.aspx]]></description>
			<content:encoded><![CDATA[<p>Great post by James Michael Hare I came across about using Sets in .Net. Definitely worth taking a look.</p>
<p><a href="http://geekswithblogs.net/BlackRabbitCoder/archive/2011/02/03/c.net-little-wonders-the-useful-but-overlooked-sets.aspx" target="_blank">http://geekswithblogs.net/BlackRabbitCoder/archive/2011/02/03/c.net-little-wonders-the-useful-but-overlooked-sets.aspx</a></p>
]]></content:encoded>
			<wfw:commentRss>http://uliasz.com/2011/06/using-sets-in-net/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>WCF Custom tool error: Failed to generate code for the service reference.</title>
		<link>http://uliasz.com/2011/06/wcf-custom-tool-error-failed-to-generate-code-for-the-service-reference/</link>
		<comments>http://uliasz.com/2011/06/wcf-custom-tool-error-failed-to-generate-code-for-the-service-reference/#comments</comments>
		<pubDate>Thu, 23 Jun 2011 15:24:04 +0000</pubDate>
		<dc:creator>Matt</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[WCF]]></category>
		<category><![CDATA[Web]]></category>
		<category><![CDATA[Work]]></category>

		<guid isPermaLink="false">http://uliasz.com/?p=266</guid>
		<description><![CDATA[Very recently, building multi-tier application involving Silverlight front-end inter-operating with WCF back-end, I encountered very odd, yet annoying behaviour of Visual Studio 2010. I was building new functionality using Telerik RadMap for Silverlight control that was to display some spartial data supplied by WCF service. To achieve this my Silverlight application had to reference few…]]></description>
			<content:encoded><![CDATA[<p>Very recently, building multi-tier application involving Silverlight front-end inter-operating with WCF back-end, I encountered very odd, yet annoying behaviour of Visual Studio 2010. I was building new functionality using Telerik RadMap for Silverlight control that was to display some spartial data supplied by WCF service. To achieve this my Silverlight application had to reference few Telerik assemblies (Telerik.Windows.Controls.DataVisualization.dll). What is important is fact, that Service Reference for WCF service had been there already, project built and everything was working nicely, until I added extra method to WCF. After using &#8220;Update Service Reference&#8221; VS command, I started getting following error.</p>
<p><a href="http://uliasz.com/wp-content/uploads/2011/06/WCF-error-screen-1.png"><img class="size-full wp-image-268 alignnone" title="WCF error screen 1" src="http://uliasz.com/wp-content/uploads/2011/06/WCF-error-screen-1.png" alt="WCF error Screenshot no.1" width="799" height="197" /></a></p>
<p>Lack of further details with regards to this error and appropriate feedback from Visual Studio certainly does not help to get to the bottom of the problem, however after some investigation it turned out that one of Telerik assemblies caused this problem. When VS2010 creates service reference, default settings are that it should &#8220;reuse&#8221; all available types in reference. Excluding certain types from serialization allows service reference to be added successfully.</p>
<p><a href="http://uliasz.com/wp-content/uploads/2011/06/WCF-error-screen-3.png"><img class="alignnone size-full wp-image-270" title="WCF error screen 3" src="http://uliasz.com/wp-content/uploads/2011/06/WCF-error-screen-3.png" alt="WCF error screen 2" width="557" height="528" /></a></p>
<p>I hope this helps anybody who got stuck with this problem.</p>
]]></content:encoded>
			<wfw:commentRss>http://uliasz.com/2011/06/wcf-custom-tool-error-failed-to-generate-code-for-the-service-reference/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>SQL Data Types vs. C# Data Types</title>
		<link>http://uliasz.com/2011/04/sql-data-types-vs-c-data-types/</link>
		<comments>http://uliasz.com/2011/04/sql-data-types-vs-c-data-types/#comments</comments>
		<pubDate>Fri, 15 Apr 2011 12:27:28 +0000</pubDate>
		<dc:creator>Matt</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[SQL]]></category>

		<guid isPermaLink="false">http://uliasz.com/?p=238</guid>
		<description><![CDATA[This article is just a reference of SQL Data Types to C# Data Types. SQL Server data type CLR data type (SQL Server) CLR data type (.NET Framework) varbinary SqlBytes, SqlBinary Byte[] binary SqlBytes, SqlBinary Byte[] varbinary(1), binary(1) SqlBytes, SqlBinary byte, Byte[] image None None varchar None None char None None nvarchar(1), nchar(1) SqlChars, SqlString…]]></description>
			<content:encoded><![CDATA[<p>This article is just a reference of SQL Data Types to C# Data Types.</p>
<table width="529">
<tbody>
<tr>
<td><strong>SQL Server data type</strong></td>
<td><strong>CLR data type (SQL Server)</strong></td>
<td><strong>CLR data type (.NET Framework)</strong></td>
</tr>
<tr>
<td>varbinary</td>
<td>SqlBytes, SqlBinary</td>
<td>Byte[]</td>
</tr>
<tr>
<td>binary</td>
<td>SqlBytes, SqlBinary</td>
<td>Byte[]</td>
</tr>
<tr>
<td>varbinary(1), binary(1)</td>
<td>SqlBytes, SqlBinary</td>
<td>byte, Byte[]</td>
</tr>
<tr>
<td>image</td>
<td>None</td>
<td>None</td>
</tr>
<tr>
<td>varchar</td>
<td>None</td>
<td>None</td>
</tr>
<tr>
<td>char</td>
<td>None</td>
<td>None</td>
</tr>
<tr>
<td>nvarchar(1), nchar(1)</td>
<td>SqlChars, SqlString</td>
<td>Char, String, Char[]</td>
</tr>
<tr>
<td>nvarchar</td>
<td>SqlChars, SqlString</td>
<td>String, Char[]</td>
</tr>
<tr>
<td>nchar</td>
<td>SqlChars, SqlString</td>
<td>String, Char[]</td>
</tr>
<tr>
<td>text</td>
<td>None</td>
<td>None</td>
</tr>
<tr>
<td>ntext</td>
<td>None</td>
<td>None</td>
</tr>
<tr>
<td>uniqueidentifier</td>
<td>SqlGuid</td>
<td>Guid</td>
</tr>
<tr>
<td>rowversion</td>
<td>None</td>
<td>Byte[]</td>
</tr>
<tr>
<td>bit</td>
<td>SqlBoolean</td>
<td>Boolean</td>
</tr>
<tr>
<td>tinyint</td>
<td>SqlByte</td>
<td>Byte</td>
</tr>
<tr>
<td>smallint</td>
<td>SqlInt16</td>
<td>Int16</td>
</tr>
<tr>
<td>int</td>
<td>SqlInt32</td>
<td>Int32</td>
</tr>
<tr>
<td>bigint</td>
<td>SqlInt64</td>
<td>Int64</td>
</tr>
<tr>
<td>smallmoney</td>
<td>SqlMoney</td>
<td>Decimal</td>
</tr>
<tr>
<td>money</td>
<td>SqlMoney</td>
<td>Decimal</td>
</tr>
<tr>
<td>numeric</td>
<td>SqlDecimal</td>
<td>Decimal</td>
</tr>
<tr>
<td>decimal</td>
<td>SqlDecimal</td>
<td>Decimal</td>
</tr>
<tr>
<td>real</td>
<td>SqlSingle</td>
<td>Single</td>
</tr>
<tr>
<td>float</td>
<td>SqlDouble</td>
<td>Double</td>
</tr>
<tr>
<td>smalldatetime</td>
<td>SqlDateTime</td>
<td>DateTime</td>
</tr>
<tr>
<td>datetime</td>
<td>SqlDateTime</td>
<td>DateTime</td>
</tr>
<tr>
<td>sql_variant</td>
<td>None</td>
<td>Object</td>
</tr>
<tr>
<td>User-defined type(UDT)</td>
<td>user-defined type</td>
<td>None</td>
</tr>
<tr>
<td>table</td>
<td>None</td>
<td>None</td>
</tr>
<tr>
<td>cursor</td>
<td>None</td>
<td>None</td>
</tr>
<tr>
<td>timestamp</td>
<td>None</td>
<td>None</td>
</tr>
<tr>
<td>xml</td>
<td>SqlXml</td>
<td>None</td>
</tr>
</tbody>
</table>
<pre></pre>
]]></content:encoded>
			<wfw:commentRss>http://uliasz.com/2011/04/sql-data-types-vs-c-data-types/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Interface vs. Abstract Class in .Net</title>
		<link>http://uliasz.com/2010/11/interface-vs-abstract-class-in-net/</link>
		<comments>http://uliasz.com/2010/11/interface-vs-abstract-class-in-net/#comments</comments>
		<pubDate>Fri, 26 Nov 2010 22:08:30 +0000</pubDate>
		<dc:creator>Matt</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[C#]]></category>

		<guid isPermaLink="false">http://uliasz.com/?p=206</guid>
		<description><![CDATA[In this article I will try to briefly explain main differences between interface and abstract class concepts in .Net. Although the differences can appear to be very subtle and little important, badly design inheritance can lead to massive problems and great mess in the code. Abstract Class Accordingly to MSDN abstract classes “are classes that…]]></description>
			<content:encoded><![CDATA[<p>In this article I will try to briefly explain main differences between interface and abstract class concepts in .Net. Although the differences can appear to be very subtle and little important, badly design inheritance can lead to massive problems and great mess in the code.</p>
<h3>Abstract Class</h3>
<p>Accordingly to <a href="http://msdn.microsoft.com/en-us/library/k535acbf(v=vs.71).aspx" target="_blank">MSDN</a> abstract classes “are classes that cannot be instantiated (…), useful when creating components because they allow you specify an invariant level of functionality in some methods, but leave the implementation of other methods until a specific implementation of that class is needed. They also version well, because if additional functionality is needed in derived classes, it can be added to the base class without breaking code.”</p>
<p>Do declare abstract class following syntax is required:</p>
<pre class="csharpcode"><span class="kwrd">abstract</span> <span class="kwrd">class</span> Car()
{
    <span class="kwrd">public</span> Car() { };
    <span class="kwrd">public string</span> Make { get; set; }
    <span class="kwrd">abstract</span> <span class="kwrd">public</span> <span class="kwrd">void</span> Drive();
}</pre>
<p>This class cannot be instantiated so following line will cause compiler throwing error:</p>
<pre class="csharpcode">Car a = <span class="kwrd">new</span> Car(); <span style="color: #ff0000;">// this won’t compile</span></pre>
<p><!-- .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; } -->The only way to instantiate class Car is by creating child class that will inherit from it:</p>
<pre class="csharpcode"><span class="kwrd">public</span> <span class="kwrd">class</span> OffRoadCar : Car
{
    <span class="kwrd">public</span> OffRoadCar();
    <span class="kwrd">public</span> <span class="kwrd">void</span> Switch4WD(<span class="kwrd">bool</span> On)
    {
        <span class="rem">// method code</span>
    };
}</pre>
<p>Because class OffRoadCar inherits from Car, following code will work:</p>
<pre class="csharpcode">OffRoadCar offroader = <span class="kwrd">new</span> OffRoadCar();
offroader.Switch4WD(<span class="kwrd">true</span>); <span class="rem">// from OffRoadClass</span>
offroader.Drive(); <span class="rem">// from Car class</span></pre>
<h3>Interface</h3>
<p>Interface, after <a href="http://msdn.microsoft.com/en-us/library/dyc5b94e(v=VS.71).aspx" target="_blank">MSDN</a>, is a “definition that can never change after the interface definition has been released. This <em>interface invariance</em> is an important principle of component design, because it protects existing systems that have been written to use the interface.”</p>
<p>Interface cannot be instantiated, but serve as sort of pattern for derived classes, that share and implement specific features. Derived classes can also extend interface functionality, by defining extra members. Following code demonstrates sample interface:</p>
<pre class="csharpcode"><span class="kwrd">public</span> <span class="kwrd">interface</span> ICar
{
    <span class="kwrd">string</span> Make { get; set; }
    <span class="kwrd">void</span> Drive();
}</pre>
<p>Because interface can serve as a “template” for series of classes, implementing it is a way of ensuring that all derived object will have set of common features. In example:</p>
<pre class="csharpcode"><span class="kwrd">public</span> <span class="kwrd">class</span> SportsCar : ICar
{
    <span class="kwrd">public</span> <span class="kwrd">string</span> Make { get; set; } <span class="rem">// required from ICar</span>
    <span class="kwrd">public</span> <span class="kwrd">bool</span> IsConvertible { get; set; } <span class="rem">// adds extra feature</span>
    <span class="kwrd">public</span> <span class="kwrd">void</span> Drive() <span class="rem">// required by ICar</span>
    { 

    };
}

<span class="kwrd">public</span> <span class="kwrd">class</span> Van : ICar
{
    <span class="kwrd">public</span> <span class="kwrd">string</span> Make { get; set; } <span class="rem">// required from ICar</span>
    <span class="kwrd">public</span> <span class="kwrd">double</span> LoadWeight { get; set; } <span class="rem">// adds extra feature</span>
    <span class="kwrd">public</span> <span class="kwrd">void</span> Drive() <span class="rem">// required by ICar</span>
    { 

    };
}</pre>
<p><!-- .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; } -->Because both SportsCar and Van classes inherit from ICar interface, they are forced to have common set of features (Make property and Drive() method). Thanks to that it is possible to write:</p>
<pre class="csharpcode">List&lt;ICar&gt; vehicles = <span class="kwrd">new</span> {
    <span class="kwrd">new</span> SportsCar() { Make = <span class="str">"Ferrari"</span>, IsConvertible = <span class="kwrd">false</span> },
    <span class="kwrd">new</span> Van() { Make = <span class="str">"Ford"</span>, LoadWeight = 3000 }
};

<span class="kwrd">foreach</span>(ICar car <span class="kwrd">in</span> vehicles)
{
    Console.WriteLine(car.Make);
}</pre>
<h3>Conclusion</h3>
<p>In opposite to abstract class, <strong>interface cannot implement any default functionality</strong> in its methods. It also cannot implement default constructor. This is why we say we <strong>implement interface</strong> and <strong>inherit from abstract class</strong>.</p>
<p>Class may implement an <strong>unlimited number of interfaces</strong>, but may <strong>inherit from only one abstract class</strong>. A class that is derived from an abstract class may still implement interfaces.</p>
<p>Abstract classes and interfaces play extremely important role in programming concept called <strong>polymorphism</strong>, which in essence is “ability for classes to provide different implementations of methods that are called by the same name” (<a href="http://msdn.microsoft.com/en-us/library/9w2ctx1s(v=VS.71).aspx" target="_blank">MSDN</a>).</p>
<h3>Resources</h3>
<ul>
<li><a title="http://msdn.microsoft.com/en-us/library/k535acbf(v=vs.71).aspx" href="http://msdn.microsoft.com/en-us/library/k535acbf%28v=vs.71%29.aspx" target="_blank">http://msdn.microsoft.com/en-us/library/k535acbf(v=vs.71).aspx</a></li>
<li><a title="http://msdn.microsoft.com/en-us/library/dyc5b94e(v=VS.71).aspx" href="http://msdn.microsoft.com/en-us/library/dyc5b94e(v=VS.71).aspx" target="_blank">http://msdn.microsoft.com/en-us/library/dyc5b94e(v=VS.71).aspx</a></li>
<li><a title="http://www.codeproject.com/KB/cs/abstractsvsinterfaces.aspx" href="http://www.codeproject.com/KB/cs/abstractsvsinterfaces.aspx" target="_blank">http://www.codeproject.com/KB/cs/abstractsvsinterfaces.aspx</a></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://uliasz.com/2010/11/interface-vs-abstract-class-in-net/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Web service proxy in ASP.NET MVC &#8211; how to avoid cross-site script warnings</title>
		<link>http://uliasz.com/2010/10/web-service-proxy-in-asp-net-mvc-how-to-avoid-cross-site-script-warnings/</link>
		<comments>http://uliasz.com/2010/10/web-service-proxy-in-asp-net-mvc-how-to-avoid-cross-site-script-warnings/#comments</comments>
		<pubDate>Tue, 19 Oct 2010 11:28:56 +0000</pubDate>
		<dc:creator>Matt</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[Ajax]]></category>
		<category><![CDATA[Web]]></category>
		<category><![CDATA[ASP.NET MVC]]></category>
		<category><![CDATA[jQuery]]></category>
		<category><![CDATA[Web Services]]></category>

		<guid isPermaLink="false">http://uliasz.com/?p=105</guid>
		<description><![CDATA[In this article I will walk through the process of creation of web service proxy in ASP.NET MVC. This is specifically useful as a method of preventing cross-site scripting (XSS) warnings on web page. This is a feature of all modern web browsers and cannot be easily omitted as it enforces same origin policy. This sort…]]></description>
			<content:encoded><![CDATA[<p>In this article I will walk through the process of creation of web service proxy in ASP.NET MVC. This is specifically useful as a method of preventing <a title="Cross-site scripting at Wikipedia" href="http://en.wikipedia.org/wiki/Cross-site_scripting" target="_blank">cross-site scripting (XSS)</a> warnings on web page. This is a feature of all modern web browsers and cannot be easily omitted as it enforces same origin policy. This sort of attack can happen when browser tries to download client script from outside of application domain &#8211; simply speaking when web browser downloads script from different location.</p>
<p>For the purpose of this demo I will use IP look-up web service available at <a href="http://ipinfodb.com/">http://ipinfodb.com/</a>. This web service allows to obtain <a title="lookup Wikipedia for geodata" href="http://en.wikipedia.org/wiki/Geoinformation" target="_blank">geodata </a>for given IP address and can be extremely useful for in example centralizing map (i.e. Google maps or Bing maps) on user&#8217;s location.</p>
<p>Valid request should look like this: http://ipinfodb.com/ip_query.php?ip=213.180.146.27</p>
<p>Of course it is possible to call this web service at Ajax request level, by simply writing:</p>
<pre>    var ipaddress = '213.180.146.27';
    $.get('http://ipinfodb.com/ip_query.php?ip=' + ipaddress + '&amp;timezone=false',
        function(data) {...}
    );</pre>
<p>although on all most recent web browsers (IE 8, FF 3.6, Chrome, Safari) user will get very ugly security warning every time browser executes this code. This is due to XSS vulnerability mentioned above and can be extremely annoying to user when application performs this operation on very first page load.</p>
<p>Thankfully ASP.NET provides set of mechanisms to overcome this problem. In simplest words there is an extra layer between web service and Ajax call needed, and this layer is web service proxy.</p>
<p>The core component of proposed solution is a HTTP handler class, in this example named LocationProxyHandler. This class will create and execute HTTP request to web service and return response to client. It needs to implement two interfaces: IHttpHandler and IRouteHandler. First interface guarantees that class can process HTTP request, second allows to use class in routing rule that will be required to redirect requests to the handler class. Implementation of class is as follows:</p>
<pre>    public class LocaionProxyHandler : IHttpHandler, IRouteHandler
    {
        public bool IsReusable
        {
            get { return true; }
        }

        public void ProcessRequest(HttpContext context)
        {
            string ipAddress = context.Request.QueryString["ipaddress"];

            string str = string.Format(@"http://ipinfodb.com/ip_query.php?ip={0}",
                ipAddress);

            HttpWebRequest request = (HttpWebRequest)WebRequest.Create(str);
            request.Method = "GET";
            HttpWebResponse response = (HttpWebResponse)request.GetResponse();
            StreamReader reader = new StreamReader(response.GetResponseStream());

            HttpResponse res = context.Response;
            res.ContentType = "application/xml; charcode=utf8";
            res.StatusCode = 200;
            res.Write(reader.ReadToEnd());
        }

        public IHttpHandler GetHttpHandler(RequestContext requestContext)
        {
            return this;
        }
    }</pre>
<p>The most important method in the class is ProcessRequest(). It takes current HttpContext as parameter and for this context it executes HTTP request to external web service and builds and returns response. Before it fires HTTP request, it takes IP address as parameter from URL.</p>
<p>There is one more thing that needs doing before this proxy can serve the purpose. It has to be registered in ASP.NET MVC routing table within the application. To accomplish this the following code is needed in RegisterRoutes() method inside Global.asax.cs:</p>
<pre>    routes.Add(new Route("{action}.proxy", new SocialCitiProxy.LocaionProxyHandler()))</pre>
<p>This makes calls like http://localhost:1431/myApp/Service.proxy understandable for MVC engine and ensures the request is redirected to LocationProxyHandler.</p>
<p>Very final step is Ajax request to LocationProxyHandler:</p>
<pre>var ipaddress = '213.180.146.27';
$.ajax({
        url: 'GetUserLocation.proxy',
        data: 'ipAddress=' + ipaddress,
        dataType: 'xml',
        contentType: 'application/xml; charset=utf8',
        error: function (xhr, status, e) {...},
        success: function (data) {...}
});</pre>
<p>No security warning messages appears now and this is exactly what we wanted to achieve.</p>
]]></content:encoded>
			<wfw:commentRss>http://uliasz.com/2010/10/web-service-proxy-in-asp-net-mvc-how-to-avoid-cross-site-script-warnings/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Clustered vs. Non-clustered indexes in SQL Server</title>
		<link>http://uliasz.com/2010/10/clustered-vs-non-clustered-indexes-in-sql-server/</link>
		<comments>http://uliasz.com/2010/10/clustered-vs-non-clustered-indexes-in-sql-server/#comments</comments>
		<pubDate>Thu, 14 Oct 2010 19:44:16 +0000</pubDate>
		<dc:creator>Matt</dc:creator>
				<category><![CDATA[SQL]]></category>
		<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[T-SQL]]></category>

		<guid isPermaLink="false">http://uliasz.com/?p=195</guid>
		<description><![CDATA[In this article I will make attempt to outline differences between clustered and non-clustered indexes in SQL Server. Be fully aware that it is not going to be comprehensive explanation, but rather brief overview highlighting purpose of both types of indexes. Indexes Indexes are one of the most important part of database optimization, especially for large…]]></description>
			<content:encoded><![CDATA[<p>In this article I will make attempt to outline differences between clustered and non-clustered indexes in SQL Server. Be fully aware that it is not going to be comprehensive explanation, but rather brief overview highlighting purpose of both types of indexes.</p>
<p><strong>Indexes</strong></p>
<p>Indexes are one of the most important part of database optimization, especially for large and growing database tables. They work in very similar way to index in a book - just imagine massive address book, with thousands pages but no index. Searching this book for specific address is nearly impossible without index.</p>
<p>When query is ran against SQL Server database, Query Optimizer analyses all available indexes for tables involved, and creates most efficient execution plan to run statement. SQL Server reads data in 8KB pages, so if table is small enough to fit on one or two pages, there is no need for an index at all, as SQL Server will only have to make one or two read operations. This operation is called Full Table Scan and for small table it is the most efficient way of pulling the data out. On the other hand, if table has 1,000,000 records and size of row allows reading only 50 rows per page, number of read operations rises to 20,000. That clearly will take a lot of time and this is where indexes come into play. Indexes can massively improve SQL query, however is worth mentioning, that it does not come for free - indexes can take a lot of storage. When index is involved in selecting data from table, this operation is called Index Seek. In general we can distinguish two types of indexes: clustered and non-clustered.</p>
<p><strong>Clustered Index</strong></p>
<p>This index assumes that data in a table is physically sorted in specific order. This means that when new row is inserted, it physically goes to the place determined by index, allowing data after new row to be moved to next page if required. The table can only have one clustered index. This index is specifically useful if we use BETWEEN statement in WHERE clause of our statement (i.e. SELECT * FROM Table WHERE Col1 BETWEEN &#8216;A&#8217; AND &#8216;Z&#8217;).</p>
<p><strong>Non-clustered Index</strong></p>
<p>When this type of index is used logical order of index does not match physical order of data stored on the disk. Index plays a role of &#8220;pointer to row&#8221;, allowing faster access to the row that is requested.</p>
<p>A non-clustered index is a special type of index in which the logical order of the index does not match the physical stored order of the rows on disk. The leaf node of a non-clustered index does not consist of the data pages. Instead, the leaf nodes contain index rows. This type of index works best when used having = in WHERE clause (i.e. SELECT * FROM Table WHERE Col1 = &#8216;A&#8217;) or if the column is used in JOIN.</p>
<p><strong>Reference</strong></p>
<ul>
<li><a href="http://msdn.microsoft.com/en-us/library/ms188783.aspx">http://msdn.microsoft.com/en-us/library/ms188783.aspx</a> - MSDN on indexes</li>
<li><a href="http://en.wikipedia.org/wiki/Index_(database">http://en.wikipedia.org/wiki/Index_(database</a>) &#8211; Wikipedia on indexes</li>
<li><a href="http://www.sql-server-performance.com/articles/per/index_data_structures_p1.aspx">http://www.sql-server-performance.com/articles/per/index_data_structures_p1.aspx</a> - good article explaining difference between clustered and non-clustered indexes much deeper</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://uliasz.com/2010/10/clustered-vs-non-clustered-indexes-in-sql-server/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to refer to previous row in SQL 2005</title>
		<link>http://uliasz.com/2010/09/how-to-refer-to-previous-row-in-sql-2005/</link>
		<comments>http://uliasz.com/2010/09/how-to-refer-to-previous-row-in-sql-2005/#comments</comments>
		<pubDate>Wed, 22 Sep 2010 11:40:50 +0000</pubDate>
		<dc:creator>Matt</dc:creator>
				<category><![CDATA[SQL]]></category>
		<category><![CDATA[CTE]]></category>
		<category><![CDATA[T-SQL]]></category>

		<guid isPermaLink="false">http://uliasz.com/?p=56</guid>
		<description><![CDATA[In this post I will describe simple mechanism allowing to refer back to previous row in SQL Server 2005/2008 database table.   For the purpose of this article let&#8217;s create a table dbo.AgentLog:   create table dbo.AgentLog ( AgentID int ,LogInTime datetime ,LogOutTime datetime ) go insert dbo.AgentLog select 1, '2010-09-08 09:40:00.000', '2010-09-08 10:14:00.000' union all select…]]></description>
			<content:encoded><![CDATA[<p>In this post I will describe simple mechanism allowing to refer back to previous row in SQL Server 2005/2008 database table.  </p>
<p>For the purpose of this article let&#8217;s create a table dbo.AgentLog:  </p>
<pre>create table dbo.AgentLog (
	 AgentID	int
	,LogInTime	datetime
	,LogOutTime	datetime
	)
go

insert dbo.AgentLog
select 1, '2010-09-08 09:40:00.000', '2010-09-08 10:14:00.000'
union all
select 1, '2010-09-08 10:35:00.000', '2010-09-08 12:04:00.000'
union all select 1, '2010-09-08 13:11:00.000', '2010-09-08 14:24:00.000'
union all select 1, '2010-09-08 14:35:00.000', '2010-09-08 16:08:00.000'
union all select 2, '2010-09-08 09:00:00.000', '2010-09-08 09:23:00.000'
union all select 2, '2010-09-08 10:12:00.000', '2010-09-08 12:05:00.000'
union all select 2, '2010-09-08 13:12:00.000', '2010-09-08 15:07:00.000'
union all select 2, '2010-09-08 15:10:00.000', '2010-09-08 16:25:00.000'
go</pre>
<p>Our table will look like this:  </p>
<pre>AgentID LogInTime LogOutTime
----------- ----------------------- -----------------------
1           2010-09-08 09:40:00.000 2010-09-08 10:14:00.000
1           2010-09-08 10:35:00.000 2010-09-08 12:04:00.000
1           2010-09-08 13:11:00.000 2010-09-08 14:24:00.000
1           2010-09-08 14:35:00.000 2010-09-08 16:08:00.000
2           2010-09-08 09:00:00.000 2010-09-08 09:23:00.000
2           2010-09-08 10:12:00.000 2010-09-08 12:05:00.000
2           2010-09-08 13:12:00.000 2010-09-08 15:07:00.000
2           2010-09-08 15:10:00.000 2010-09-08 16:25:00.000</pre>
<p>The task is to <strong>for each agent list all breaks the person made and its length</strong>. To do this I need to somehow refer back to previous row to calculate difference in minutes between login and previous logout.  </p>
<p>To accomplish the task I will use two features new to SQL Server 2005 (when compared to SQL Server 2000). These are <a href="http://msdn.microsoft.com/en-us/library/ms190766.aspx">CTE (Common Table Expression)</a> and <a href="http://msdn.microsoft.com/en-us/library/ms186734(v=SQL.90).aspx">Row_Number() </a>function.  </p>
<p>First one in essence can be thought as variable table of results from SELECT statement. This data set only exists in current scope.  </p>
<p>Row_Number() is a SQL Server built-in function that adds extra identity column to data set retrieved with SELECT statement.  </p>
<pre>SELECT
     Row_Number() over (partition by AgentID order by LogInTime) AS RowID
    ,*
FROM dbo.AgentLog</pre>
<p>Row_Number() takes partition by argument, which tells function that you want unique row numbers against specific column. If this isn&#8217;t provided, SQL Server will just number all rows on one-by-one basis. Combining CTE and Row_Number() we can now get the following: </p>
<p> ;with AgentLogCTE as<br />
(select Row_Number() over (partition by AgentID order by LogInTime) as RowID, * from dbo.AgentLog )</p>
<p>This CTE then contains following information:</p>
<pre>RowID                AgentID     LogInTime               LogOutTime
-------------------- ----------- ----------------------- -----------------------
1                    1           2010-09-08 09:40:00.000 2010-09-08 10:14:00.000
2                    1           2010-09-08 10:35:00.000 2010-09-08 12:04:00.000
3                    1           2010-09-08 13:11:00.000 2010-09-08 14:24:00.000
4                    1           2010-09-08 14:35:00.000 2010-09-08 16:08:00.000
1                    2           2010-09-08 09:00:00.000 2010-09-08 09:23:00.000
2                    2           2010-09-08 10:12:00.000 2010-09-08 12:05:00.000
3                    2           2010-09-08 13:12:00.000 2010-09-08 15:07:00.000
4                    2           2010-09-08 15:10:00.000 2010-09-08 16:25:00.000</pre>
<p>Now what we need to do is just join this table to itself in some clever way, linking current row to previous one:</p>
<pre>select
    t1.AgentID
   ,t2.LogOutTime as PrevLogout
   ,t1.LogInTime as Login
   ,convert(varchar, t1.LogInTime - t2.LogOutTime, 108) as BreakTime
from AgentLogCTE t1
   join AgentLogCTE t2
      on t2.RowID = (t1.RowID-1) and t1.AgentID = t2.AgentID
go</pre>
<p>And this is it! Resultset looks like the following:</p>
<pre>AgentID     PrevLogout              Login                   BreakTime
----------- ----------------------- ----------------------- ------------------------------
1           2010-09-08 10:14:00.000 2010-09-08 10:35:00.000 00:21:00
1           2010-09-08 12:04:00.000 2010-09-08 13:11:00.000 01:07:00
1           2010-09-08 14:24:00.000 2010-09-08 14:35:00.000 00:11:00
2           2010-09-08 09:23:00.000 2010-09-08 10:12:00.000 00:49:00
2           2010-09-08 12:05:00.000 2010-09-08 13:12:00.000 01:07:00
2           2010-09-08 15:07:00.000 2010-09-08 15:10:00.000 00:03:00</pre>
<p>Whole SQL script explained in this article can be obtained from <a href="http://uliasz.com/wp-content/uploads/2010/10/previous_row_with_CTE.txt">here</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://uliasz.com/2010/09/how-to-refer-to-previous-row-in-sql-2005/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

