<?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>Elzaris Technologies</title>
	<atom:link href="http://www.elzaris.co.za/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.elzaris.co.za</link>
	<description>All things Elzaris</description>
	<lastBuildDate>Mon, 21 Jun 2010 09:16:09 +0000</lastBuildDate>
	
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Using Web Services in SQL Server CLR assemblies</title>
		<link>http://www.elzaris.co.za/using-web-services-in-sql-server-clr-assemblies/</link>
		<comments>http://www.elzaris.co.za/using-web-services-in-sql-server-clr-assemblies/#comments</comments>
		<pubDate>Mon, 21 Jun 2010 09:16:09 +0000</pubDate>
		<dc:creator>andrewr</dc:creator>
				<category><![CDATA[News]]></category>

		<guid isPermaLink="false">http://www.elzaris.co.za/?p=100</guid>
		<description><![CDATA[SQL Server 2005 introduced a nifty new feature called CLR Integration, which essentially allows you to write triggers, procedures and functions in managed code. So why would you want to do this? To answer that question, I&#8217;ll quote from the MSDN documentation:
Managed code is better suited than Transact-SQL for calculations and complicated execution logic, and [...]]]></description>
			<content:encoded><![CDATA[<p>SQL Server 2005 introduced a nifty new feature called CLR Integration, which essentially allows you to write triggers, procedures and functions in managed code. So why would you want to do this? To answer that question, I&#8217;ll quote from the <a href="http://msdn.microsoft.com/en-us/library/ms254498(VS.80).aspx">MSDN documentation</a>:</p>
<blockquote><p>Managed code is better suited than Transact-SQL for calculations and complicated execution logic, and features extensive support for many complex tasks, including string handling and regular expressions. With the functionality found in the .NET Framework Library, you have access to thousands of pre-built classes and routines. These can be easily accessed from any stored procedure, trigger or user defined function.</p></blockquote>
<p>Ok, so how does one go about using this great functionality? For security reasons, CLR integration is not enabled by default. To enable it, run the following SQL statements on your database:<br />
<span style="font-size: 10.0pt; font-family: &amp;amp;amp;"><br />
<span style="color: maroon;">sp_configure </span><span style="color: red;">&#8216;clr enabled&#8217;</span><span style="color: gray;">, </span><span>1</span><br />
<span style="color: blue;"><span>GO</span><br />
<span>reconfigure</span><br />
<span>GO</span><br />
</span></span><br />
If your code is going to require external access, like using a Web Service, you will also need to execute this SQL:<br />
<span style="font-size: 10.0pt; font-family: &amp;amp;amp;"><br />
<span style="color: blue;">ALTER DATABASE </span><span>MyDb </span><span style="color: blue;">SET TRUSTWORTHY ON</span><br />
<span style="color: blue;">GO</span><br />
</span><br />
Be sure to check with your database administrator first, as this may introduce an unwanted security risk. See the <a href="http://msdn.microsoft.com/en-us/library/ms187861.aspx">MSDN documentation</a> for more information.</p>
<p>So how do we write code for SQL Server? Visual Studio 2005 introduced a new project template called &#8216;SQL Server Project&#8217; for this purpose. In Visual Studio 2005/2008 you click File-&gt;New-&gt;Project and then select &#8216;Database&#8217; under the Visual C# node in the Project types tree. In the Templates area on the right, select &#8216;SQL Server Project&#8217;:</p>
<p><a href="http://www.elzaris.co.za/wp-content/uploads/2010/06/New-Project.png"><img class="alignnone size-full wp-image-309" title="New Project" src="http://www.elzaris.co.za/wp-content/uploads/2010/06/New-Project.png" alt="" width="608" height="204" /></a></p>
<p>In Visual Studio 2010 you follow the same procedure, but the New Project dialog has changed: under Installed Templates on the left, click Database, then SQL Server and finally select &#8216;Visual C# SQL CLR Database Project&#8217;:</p>
<p><a href="http://www.elzaris.co.za/wp-content/uploads/2010/06/New-Project-2010.png"><img class="alignnone size-full wp-image-311" title="New Project 2010" src="http://www.elzaris.co.za/wp-content/uploads/2010/06/New-Project-2010.png" alt="" width="608" height="202" /></a></p>
<p>Click Ok and you should get a Database Reference dialog where you can enter the details of your SQL Server database. Once you&#8217;ve completed that you may get a dialog asking if you&#8217;d like to enable debugging &#8211; just click yes and you should be presented with a your new project. Before we start coding, we&#8217;re going to need a reference to a Web Service so lets go add that now. For this example we&#8217;ll use a currency converter from <a href="http://www.webservicex.net/">www.webservicex.net</a>. Right click the &#8216;References&#8217; node in Solution Explorer and select &#8216;Add Web Reference&#8217; (VS 2005) or &#8216;Add Service Reference&#8217; (VS 2008/2010). Type the following into the URL combo box: <a href="http://www.webservicex.net/CurrencyConvertor.asmx">http://www.webservicex.net/CurrencyConvertor.asmx</a> and click &#8216;Go&#8217;. After a short while the service description should appear at which point you can type in the name you&#8217;d like to use for the service, or just accept the default. I called mine &#8216;CurrencyService&#8217;. Note that the service has only one method, ConversionRate, which when given 2 currency codes will return the conversion rate between them. Click the &#8216;Add Reference&#8217; button to finish.</p>
<p><a href="http://www.elzaris.co.za/wp-content/uploads/2010/06/Add-Web-Reference1.png"><img class="alignnone size-full wp-image-144" title="Add Web Reference" src="http://www.elzaris.co.za/wp-content/uploads/2010/06/Add-Web-Reference1.png" alt="" width="825" height="408" /></a></p>
<p>If you are using VS 2008/2010 and are unfamiliar with the new &#8216;Add Service&#8217; dialog, simply click the &#8216;Advanced&#8217; button at the bottom of the dialog and then click &#8216;Add Web Reference&#8217; &#8211; this will display the old dialog shown above.</p>
<p>Notice in your Solution Explorer tree that there are no code files, so let&#8217;s go add one. Right click the project node, select &#8216;Add&#8217; and you should get a context menu listing the types of items available:</p>
<p><a href="http://www.elzaris.co.za/wp-content/uploads/2010/06/Add-Function1.png"><img class="alignnone size-full wp-image-312" title="Add Function" src="http://www.elzaris.co.za/wp-content/uploads/2010/06/Add-Function1.png" alt="" width="608" height="438" /></a></p>
<p>For this example I&#8217;m selecting &#8216;User-Defined Function&#8217; and calling it &#8216;ConvertCurrency&#8217;. When you click Ok you will be presented with a .cs file defining a partial class called &#8216;UserDefinedFunctions&#8217; which contains a single method called &#8216;ConvertCurrency&#8217;. Take note of the method attribute which indicates that this is a SQL CLR function, and the default return type, SqlString (defined in System.Data.SqlTypes).</p>
<p>The service exposes a class, &#8216;CurrencyConverter&#8217;, which has the &#8216;ConversionRate&#8217; method, and an enum called &#8216;Currency&#8217;. The ConversionRate method takes in 2 Currency enum values and returns the conversion rate between the currencies. We&#8217;ll have to convert our string parameters to Currency enum values, instantiate the service, pass the enums into the method call, and multiply our amount parameter by the rate returned from the method. Here is the code (remember to add your own error-handling):</p>
<p>using System.Data;<br />
using System.Data.SqlClient;<br />
using System.Data.SqlTypes;<br />
using Microsoft.SqlServer.Server;<br />
using SqlServerProject1.CurrencyService;</p>
<p>public partial class UserDefinedFunctions<br />
{<br />
[Microsoft.SqlServer.Server.SqlFunction]<br />
public static SqlDouble ConvertCurrency(SqlDouble amount, SqlString fromCurrency, SqlString toCurrency)<br />
{<br />
string from = fromCurrency.Value.ToUpper();<br />
string to = toCurrency.Value.ToUpper();<br />
Currency f = (Currency)Enum.Parse(typeof(Currency), from);<br />
Currency t = (Currency)Enum.Parse(typeof(Currency), to);<br />
CurrencyConvertor converter = new CurrencyConvertor();<br />
double rate = converter.ConversionRate(f, t);<br />
return new SqlDouble(amount.Value * rate);<br />
}<br />
};</p>
<p>Ok, with any luck, our code compiles. The next step is to get the dll deployed to SQL Server. Fortunately, Visual Studio make this trivial &#8211; simply right click the project in Solution Explorer and click &#8216;Deploy&#8217;. Open your database in SQL Server Management Studio and expand the &#8216;Programmability&#8217; node, then &#8216;Functions&#8217; and finally &#8216;Scalar-valued Functions&#8217;:</p>
<p><a href="http://www.elzaris.co.za/wp-content/uploads/2010/06/Programmability1.png"><img class="alignnone size-full wp-image-313" title="Programmability" src="http://www.elzaris.co.za/wp-content/uploads/2010/06/Programmability1.png" alt="" width="608" height="150" /></a></p>
<p>&#8230;and there&#8217;s our function. Now expand the &#8216;Assemblies&#8217; node and you should see the project dll:</p>
<p><a href="http://www.elzaris.co.za/wp-content/uploads/2010/06/Assemblies1.png"><img class="alignnone size-full wp-image-314" title="Assemblies" src="http://www.elzaris.co.za/wp-content/uploads/2010/06/Assemblies1.png" alt="" width="608" height="40" /></a></p>
<p>To test the function, execute the following SQL:</p>
<p><span style="color: blue;">select</span> dbo.ConvertCurrency(100, <span style="color: red;">&#8216;USD&#8217;, &#8216;ZAR&#8217;</span>)</p>
<p>&#8230;and we get this osbscure error:</p>
<p><a href="http://www.elzaris.co.za/wp-content/uploads/2010/06/Error1.png"><img class="size-full wp-image-156 alignnone" style="display: block; margin-left: auto; margin: right; float: none; clear: both;" title="Error1" src="http://www.elzaris.co.za/wp-content/uploads/2010/06/Error1.png" alt="" width="733" height="60" /></a></p>
<p>What this is saying is that SQL Server requires a special dll called a &#8217;serialization assembly&#8217;, which will enable it to perform the serialization of objects that is necessary for web services. Once again, Visual Studio comes to the rescue. Right-click the project in Solution Explorer and select Properties. At the very bottom of the &#8216;Build&#8217; tab is a dropdown labeled &#8216;Generate serialization assembly&#8217;. Switch this to &#8216;On&#8217; and rebuild the project. If you now browse to the &#8216;bin\debug&#8217; folder of the project you will see a new dll called &#8216;SqlServerProject1.XmlSerializers.dll&#8217;. Unfortunately, the &#8216;Deploy&#8217; command will not register this dll with SQL Server, so we have to do that ourselves. Deploy the regular dll as normal, then copy the serialization dll to your SQL Server machine and execute this SQL (change the path in the FROM clause to match the location of the dll):</p>
<p><span style="color: blue;">CREATE ASSEMBLY</span> [SqlServerProject1.XmlSerializers]<br />
<span style="color: blue;">FROM</span> <span style="color: red;">&#8216;C:\SqlServerProject1.XmlSerializers.dll&#8217;</span><br />
<span style="color: blue;">WITH PERMISSION_SET=SAFE<br />
GO</span></p>
<p>Execute the previous SQL to test the function again, and we now get a SecurityException (shortened for brevity):</p>
<p><a href="http://www.elzaris.co.za/wp-content/uploads/2010/06/Error21.png"><img class="alignnone size-full wp-image-315" title="Error2" src="http://www.elzaris.co.za/wp-content/uploads/2010/06/Error21.png" alt="" width="608" height="19" /></a></p>
<p>This is because SQL Server&#8217;s security model does not allow external access by default. To enable external access, open the project properties in Visual Studio again, and this time go to the &#8216;Database&#8217; tab. Set the &#8216;Permission Level&#8217; dropdown to &#8216;External&#8217; and rebuild the project. Deploy the dll&#8217;s as before (don&#8217;t forget the serialization assembly), execute the SQL to test the function, and finally success! At the time of writing this article, the conversion rate between US Dollars and South African Rands was 7.7485, giving me a result of 774.85 which is to say: $100 = R774.85</p>
]]></content:encoded>
			<wfw:commentRss>http://www.elzaris.co.za/using-web-services-in-sql-server-clr-assemblies/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Creating Trac tickets remotely with XML-RPC</title>
		<link>http://www.elzaris.co.za/creating-trac-tickets-remotely-with-xml-rpc/</link>
		<comments>http://www.elzaris.co.za/creating-trac-tickets-remotely-with-xml-rpc/#comments</comments>
		<pubDate>Tue, 01 Jun 2010 12:11:02 +0000</pubDate>
		<dc:creator>andrewr</dc:creator>
				<category><![CDATA[Dev]]></category>
		<category><![CDATA[Tech]]></category>
		<category><![CDATA[.Net]]></category>
		<category><![CDATA[Trac]]></category>
		<category><![CDATA[XML-RPC]]></category>

		<guid isPermaLink="false">http://www.elzaris.co.za/?p=68</guid>
		<description><![CDATA[Trac is a simple but powerful open source issue tracking and wiki system for software projects. We have used it successfully in our own internal projects and in projects for clients. Trac runs on a web server and is accessed via any browser, which means minimal deployment hassle and relatively painless upgrades. It is written in [...]]]></description>
			<content:encoded><![CDATA[<p><a title="trac.edgewall.org" href="http://trac.edgewall.org/" target="_blank">Trac</a> is a simple but powerful open source issue tracking and wiki system for software projects. We have used it successfully in our own internal projects and in projects for clients. Trac runs on a web server and is accessed via any browser, which means minimal deployment hassle and relatively painless upgrades. It is written in Python and is easily customized by means of plugins,  or, if you need even more customization than plugins can provide,  by editing the source code.</p>
<p>Larger organisations often make use of a number of disparate tools which do not natively talk nicely to each other and it is not always possible to replace legacy tools with a new enterprise-wide system. Such a scenario was presented to us by a client where the developers were using Trac to manage software issues and the ops team were using a third-party help desk system to log technical issues. What the client wanted was a way for a Trac ticket to be created automatically from a help desk request.</p>
<p>Fortunately, Trac provides a useful Remote Procedure Call API, the details of which are nicely summarized <a title="svn.youngguns.nl/trac/findem.nl/xmlrpc" href="http://svn.youngguns.nl/trac/findem.nl/xmlrpc" target="_blank">here</a>. The API supports both <a title="www.xmlrpc.com" href="http://www.xmlrpc.com/" target="_blank">XML-RPC</a> and <a title="json-rpc.org" href="http://json-rpc.org/" target="_blank">JSON-RPC</a> protocols. We went the XML-RPC route. In order to use XML-RPC with Trac, one must first install the <a title="trac-hacks.org/wiki/XmlRpcPlugin" href="http://trac-hacks.org/wiki/XmlRpcPlugin" target="_blank">XML-RPC Plugin</a>. Installing Trac plugins is pretty easy &#8211; the official instructions can be found <a title="trac.edgewall.org/wiki/TracPlugins" href="http://trac.edgewall.org/wiki/TracPlugins" target="_blank">here</a>. So now your nice secure Trac system is open to all and sundry to mess with from afar&#8230;well, not quite. In order to access the XML-RPC API, you need the right permissions. Permissions can be assigned using the <a title="trac.edgewall.org/wiki/TracAdmin" href="http://trac.edgewall.org/wiki/TracAdmin" target="_blank">trac-admin tool</a>. In addition to the regular <a title="trac.edgewall.org/wiki/TracPermissions" href="http://trac.edgewall.org/wiki/TracPermissions" target="_blank">trac permissions</a>, a special permission, <acronym title="Extensible Markup Language">XML</acronym>_RPC, is required in order to use the API. In our case we also assigned the TICKET_CREATE permission as that is the functionality we required.</p>
<p>Right, so you&#8217;ve hopefully managed to install the plugin and setup your permissions. How do you go about using the API? Well, there are a number of ways to go about doing this depending on your scenario, but it basically boils down to sending an xml-rpc message to the correct url, which should look something like this:</p>
<p>http://&lt;tracServerIPaddress&gt;:&lt;portNumber&gt;/trac/&lt;yourTracInstanceName&gt;/login/xmlrpc</p>
<p>an example might be: http://192.168.0.1:8181/trac/myTrac/login/xmlrpc</p>
<p>In our scenario, the client&#8217;s platform was Microsoft .Net, so we created an ASP.Net web service to access the API. Charles Cook of <a title="www.cookcomputing.com" href="http://www.cookcomputing.com/blog/index.html" target="_blank">Cook Computing </a> has kindly made available an <a title="xml-rpc.net" href="http://xml-rpc.net/" target="_blank">XML-RPC library for .Net</a> which takes care of the nitty gritty of creating and sending XML-RPC messages. This <a title="trac-hacks.org/wiki/DotNet" href="http://trac-hacks.org/wiki/DotNet" target="_blank">page</a> has some useful information on using the library with Trac. The lads over at CodeResort.com also have some good information <a title="www.coderesort.com/p/api/wiki/XmlRpcDotNet" href="https://www.coderesort.com/p/api/wiki/XmlRpcDotNet" target="_blank">here</a> and <a title="www.coderesort.com/p/api/xmlrpc" href="https://www.coderesort.com/p/api/xmlrpc" target="_blank">here</a> (registration required).</p>
<p>I hope this article has provided useful information for other seekers. Be sure to check back for a follow-up article.</p>
<p>Andrew Rudman</p>
]]></content:encoded>
			<wfw:commentRss>http://www.elzaris.co.za/creating-trac-tickets-remotely-with-xml-rpc/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Welcome</title>
		<link>http://www.elzaris.co.za/welcome-2/</link>
		<comments>http://www.elzaris.co.za/welcome-2/#comments</comments>
		<pubDate>Thu, 27 May 2010 08:26:20 +0000</pubDate>
		<dc:creator>andrewr</dc:creator>
				<category><![CDATA[News]]></category>
		<category><![CDATA[Elzaris]]></category>
		<category><![CDATA[Welcome]]></category>

		<guid isPermaLink="false">http://www.elzaris.co.za/?p=46</guid>
		<description><![CDATA[Welcome to the brand new Elzaris website.
- the Elzaris team
]]></description>
			<content:encoded><![CDATA[<p>Welcome to the brand new Elzaris website.</p>
<p>- the Elzaris team</p>
]]></content:encoded>
			<wfw:commentRss>http://www.elzaris.co.za/welcome-2/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

