<?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>Art Of Creation - Dynamics AX Blog &#187; CLR</title>
	<atom:link href="http://www.artofcreation.be/tag/clr/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.artofcreation.be</link>
	<description>The everyday life of a Dynamics AX developer</description>
	<lastBuildDate>Fri, 23 Jul 2010 16:29:55 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>Get folders and subfolders</title>
		<link>http://www.artofcreation.be/2010/01/08/get-folders-and-subfolders/</link>
		<comments>http://www.artofcreation.be/2010/01/08/get-folders-and-subfolders/#comments</comments>
		<pubDate>Fri, 08 Jan 2010 18:34:13 +0000</pubDate>
		<dc:creator>Klaas Deforche</dc:creator>
				<category><![CDATA[Dynamics AX]]></category>
		<category><![CDATA[CLR]]></category>
		<category><![CDATA[System.IO]]></category>

		<guid isPermaLink="false">http://www.artofcreation.be/?p=402</guid>
		<description><![CDATA[Someone on the Microsoft AX newsgroups asked how to get a list of directories and subdirectories given a folder. Here a job that does that: static void KlForLoopFoldersSystemIO&#40;Args _args&#41; &#123; &#160; &#160; int &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; k; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160;// counter for result loop [...]]]></description>
			<content:encoded><![CDATA[<p>Someone on the Microsoft AX newsgroups asked how to get a list of directories and subdirectories given a folder. Here a job that does that:</p>
<div class="codecolorer-container xpp default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="xpp codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #0000ff;">static</span> <span style="color: #0000ff;">void</span> KlForLoopFoldersSystemIO<span style="color: #000000;">&#40;</span>Args _args<span style="color: #000000;">&#41;</span><br />
<span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #0000ff;">int</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; k; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #007f00;">// counter for result loop</span><br />
&nbsp; &nbsp; <span style="color: #0000ff;">container</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; dirs; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #007f00;">// container for result</span><br />
&nbsp; &nbsp; filePath &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;path <span style="color: #00007f;">=</span> @<span style="color: #ff0000;">&quot;C:<span style="color: #000000;">\t</span>emp&quot;</span>; &nbsp;<span style="color: #007f00;">// input path</span><br />
<br />
&nbsp; &nbsp; <span style="color: #0000ff;">container</span> getDirectories<span style="color: #000000;">&#40;</span><span style="color: #0000ff;">str</span> _dir<span style="color: #00007f;">,</span> <span style="color: #0000ff;">boolean</span> _inclSubDirs <span style="color: #00007f;">=</span> <span style="color: #0000ff;">true</span><span style="color: #000000;">&#41;</span><br />
&nbsp; &nbsp; <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">container</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; dList; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #007f00;">// container to cast array into</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">int</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; i; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #007f00;">// counter for array loop</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; System.<span style="color: #000000;">Array</span> &nbsp; &nbsp; &nbsp; &nbsp;directories; &nbsp; &nbsp;<span style="color: #007f00;">// array for result from .NET call</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; #Define.<span style="color: #000000;">Pattern</span><span style="color: #000000;">&#40;</span><span style="color: #ff0000;">&quot;*&quot;</span><span style="color: #000000;">&#41;</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #007f00;">// input pattern: * = all</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; ;<br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #007f00;">// assert interoppermissions for .NET interop</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">new</span> InteropPermission<span style="color: #000000;">&#40;</span>InteropKind<span style="color: #00007f;">::</span><span style="color: #000000;">ClrInterop</span><span style="color: #000000;">&#41;</span>.<span style="color: #000000;">assert</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;<br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #007f00;">// get directories using .NET interop</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">if</span><span style="color: #000000;">&#40;</span>_inclSubDirs<span style="color: #000000;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #007f00;">// include subdirectories</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; directories <span style="color: #00007f;">=</span> System.<span style="color: #000000;">IO</span>.<span style="color: #000000;">Directory</span><span style="color: #00007f;">::</span><span style="color: #000000;">GetDirectories</span><span style="color: #000000;">&#40;</span>_dir<span style="color: #00007f;">,</span> #Pattern<span style="color: #00007f;">,</span> System.<span style="color: #000000;">IO</span>.<span style="color: #000000;">SearchOption</span><span style="color: #00007f;">::</span><span style="color: #000000;">AllDirectories</span><span style="color: #000000;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">else</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #007f00;">// only top directory</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; directories <span style="color: #00007f;">=</span> System.<span style="color: #000000;">IO</span>.<span style="color: #000000;">Directory</span><span style="color: #00007f;">::</span><span style="color: #000000;">GetDirectories</span><span style="color: #000000;">&#40;</span>_dir<span style="color: #00007f;">,</span> #Pattern<span style="color: #00007f;">,</span> System.<span style="color: #000000;">IO</span>.<span style="color: #000000;">SearchOption</span><span style="color: #00007f;">::</span><span style="color: #000000;">TopDirectoryOnly</span><span style="color: #000000;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#125;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #007f00;">// loog .NET array and put the values in a container for easier use in x++</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">for</span><span style="color: #000000;">&#40;</span> i<span style="color: #00007f;">=</span><span style="color: #000000;">0</span>;i<span style="color: #00007f;">&lt;</span>ClrInterop<span style="color: #00007f;">::</span><span style="color: #000000;">getAnyTypeForObject</span><span style="color: #000000;">&#40;</span>directories.<span style="color: #000000;">get_Length</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>; i<span style="color: #00007f;">++</span> <span style="color: #000000;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; dList <span style="color: #00007f;">=</span> <span style="color: #0000ff;">conins</span><span style="color: #000000;">&#40;</span>dList<span style="color: #00007f;">,</span> <span style="color: #0000ff;">conlen</span><span style="color: #000000;">&#40;</span>dList<span style="color: #000000;">&#41;</span><span style="color: #00007f;">+</span><span style="color: #000000;">1</span><span style="color: #00007f;">,</span> ClrInterop<span style="color: #00007f;">::</span><span style="color: #000000;">getAnyTypeForObject</span><span style="color: #000000;">&#40;</span>directories.<span style="color: #000000;">GetValue</span><span style="color: #000000;">&#40;</span>i<span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#125;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #007f00;">// revert assertion to prevent multiple calls to the assert() method</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; CodeAccessPermission<span style="color: #00007f;">::</span><span style="color: #000000;">revertAssert</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;<br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #007f00;">// return result container</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">return</span> dList;<br />
&nbsp; &nbsp; <span style="color: #000000;">&#125;</span><br />
&nbsp; &nbsp; ;<br />
<br />
&nbsp; &nbsp; <span style="color: #007f00;">// get directories</span><br />
&nbsp; &nbsp; dirs <span style="color: #00007f;">=</span> getDirectories<span style="color: #000000;">&#40;</span>path<span style="color: #000000;">&#41;</span>;<br />
<br />
&nbsp; &nbsp; <span style="color: #007f00;">// use optional parameter to disable sub directories</span><br />
&nbsp; &nbsp; <span style="color: #007f00;">// dirs = getDirectories(path, false);</span><br />
<br />
&nbsp; &nbsp; <span style="color: #007f00;">// print the result</span><br />
&nbsp; &nbsp; <span style="color: #0000ff;">for</span><span style="color: #000000;">&#40;</span>k<span style="color: #00007f;">=</span><span style="color: #000000;">1</span>;k<span style="color: #00007f;">&lt;=</span> <span style="color: #0000ff;">conlen</span><span style="color: #000000;">&#40;</span>dirs<span style="color: #000000;">&#41;</span>; k<span style="color: #00007f;">++</span><span style="color: #000000;">&#41;</span><br />
&nbsp; &nbsp; <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #007f00;">// print the result to screen</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; info<span style="color: #000000;">&#40;</span><span style="color: #0000ff;">conpeek</span><span style="color: #000000;">&#40;</span>dirs<span style="color: #00007f;">,</span> k<span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>;<br />
&nbsp; &nbsp; <span style="color: #000000;">&#125;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #007f00;">// we're done</span><br />
&nbsp; &nbsp; info<span style="color: #000000;">&#40;</span><span style="color: #ff0000;">&quot;done&quot;</span><span style="color: #000000;">&#41;</span>;<br />
<span style="color: #000000;">&#125;</span></div></div>
<p>Also check my post about <a href="http://www.artofcreation.be/2009/04/08/winapi-rpc-1702-and-findfirstfilew/">how to loop files in a folder</a> (method loopfilesSystemIO)</p>
]]></content:encoded>
			<wfw:commentRss>http://www.artofcreation.be/2010/01/08/get-folders-and-subfolders/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Append text from one file to an other</title>
		<link>http://www.artofcreation.be/2009/10/31/append-text-from-one-file-to-an-other/</link>
		<comments>http://www.artofcreation.be/2009/10/31/append-text-from-one-file-to-an-other/#comments</comments>
		<pubDate>Sat, 31 Oct 2009 07:28:24 +0000</pubDate>
		<dc:creator>Klaas Deforche</dc:creator>
				<category><![CDATA[Dynamics AX]]></category>
		<category><![CDATA[CLR]]></category>
		<category><![CDATA[System.IO]]></category>

		<guid isPermaLink="false">http://www.artofcreation.be/?p=310</guid>
		<description><![CDATA[This method will append all text from the original file to the destination file. While this is a very easy task, the method shows many of the things you come across when you are working with files in AX, like: - Using the #File macro - Asserting FileIOPermission to be able to access files - [...]]]></description>
			<content:encoded><![CDATA[<p>This method will append all text from the original file to the destination file.<br />
While this is a very easy task, the method shows many of the things you come across when you are working with files in AX, like:</p>
<p>- Using the #File macro<br />
- Asserting FileIOPermission to be able to access files<br />
- Asserting InteropPermission to be able to use .NET Interop<br />
- Using a set to assert multiple permissions at once<br />
- Using .NET Clr Interop in AX (better than winapi and winapiserver)<br />
- Optional cleaning up after you&#8217;re done using reverAssert()</p>
<div class="codecolorer-container xpp default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="xpp codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #0000ff;">void</span> AppendFileToFile<span style="color: #000000;">&#40;</span>FileName original<span style="color: #00007f;">,</span> FileName distination<span style="color: #000000;">&#41;</span><br />
<span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; #File<br />
&nbsp; &nbsp; FileIOPermission &nbsp; &nbsp;FileIOPermissionA &nbsp; <span style="color: #00007f;">=</span> <span style="color: #0000ff;">new</span> FileIOPermission<span style="color: #000000;">&#40;</span>distination<span style="color: #00007f;">,</span> #io_append<span style="color: #000000;">&#41;</span>;<br />
&nbsp; &nbsp; FileIOPermission &nbsp; &nbsp;FileIOPermissionR &nbsp; <span style="color: #00007f;">=</span> <span style="color: #0000ff;">new</span> FileIOPermission<span style="color: #000000;">&#40;</span>original<span style="color: #00007f;">,</span> #io_read<span style="color: #000000;">&#41;</span>;<br />
&nbsp; &nbsp; InteropPermission &nbsp; InteropPermission &nbsp; <span style="color: #00007f;">=</span> <span style="color: #0000ff;">new</span> InteropPermission<span style="color: #000000;">&#40;</span>InteropKind<span style="color: #00007f;">::</span><span style="color: #000000;">ClrInterop</span><span style="color: #000000;">&#41;</span>;<br />
&nbsp; &nbsp; Set &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; permissionset &nbsp; &nbsp; &nbsp; <span style="color: #00007f;">=</span> <span style="color: #0000ff;">new</span> set<span style="color: #000000;">&#40;</span>types<span style="color: #00007f;">::</span><span style="color: #0000ff;">Class</span><span style="color: #000000;">&#41;</span>;<br />
&nbsp; &nbsp; ;<br />
<br />
&nbsp; &nbsp; <span style="color: #007f00;">// create permissionset</span><br />
&nbsp; &nbsp; permissionset.<span style="color: #000000;">add</span><span style="color: #000000;">&#40;</span>FileIOPermissionA<span style="color: #000000;">&#41;</span>;<br />
&nbsp; &nbsp; permissionset.<span style="color: #000000;">add</span><span style="color: #000000;">&#40;</span>FileIOPermissionR<span style="color: #000000;">&#41;</span>;<br />
&nbsp; &nbsp; permissionset.<span style="color: #000000;">add</span><span style="color: #000000;">&#40;</span>InteropPermission<span style="color: #000000;">&#41;</span>;<br />
&nbsp; &nbsp; <span style="color: #007f00;">// assert permissions</span><br />
&nbsp; &nbsp; CodeAccessPermission<span style="color: #00007f;">::</span><span style="color: #000000;">assertMultiple</span><span style="color: #000000;">&#40;</span>permissionset<span style="color: #000000;">&#41;</span>;<br />
&nbsp; &nbsp; <span style="color: #007f00;">// append text from source file to destination file</span><br />
&nbsp; &nbsp; System.<span style="color: #000000;">IO</span>.<span style="color: #000000;">File</span><span style="color: #00007f;">::</span><span style="color: #000000;">AppendAllText</span><span style="color: #000000;">&#40;</span>distination<span style="color: #00007f;">,</span> System.<span style="color: #000000;">IO</span>.<span style="color: #000000;">File</span><span style="color: #00007f;">::</span><span style="color: #000000;">ReadAllText</span><span style="color: #000000;">&#40;</span>original<span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>;<br />
<br />
&nbsp; &nbsp; <span style="color: #007f00;">// limit the scope of the assert </span><br />
&nbsp; &nbsp; CodeAccessPermission<span style="color: #00007f;">::</span><span style="color: #000000;">revertAssert</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;<br />
<span style="color: #000000;">&#125;</span></div></div>
<p>Because all permissions are taken care of, this code will run client side as well as server side.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.artofcreation.be/2009/10/31/append-text-from-one-file-to-an-other/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Five nice-to-haves in Dynamics AX</title>
		<link>http://www.artofcreation.be/2009/10/20/five-nice-to-haves-in-dynamics-ax/</link>
		<comments>http://www.artofcreation.be/2009/10/20/five-nice-to-haves-in-dynamics-ax/#comments</comments>
		<pubDate>Tue, 20 Oct 2009 19:06:23 +0000</pubDate>
		<dc:creator>Klaas Deforche</dc:creator>
				<category><![CDATA[Dynamics AX]]></category>
		<category><![CDATA[CLR]]></category>
		<category><![CDATA[Nice-to-haves]]></category>

		<guid isPermaLink="false">http://www.artofcreation.be/?p=248</guid>
		<description><![CDATA[Here a some functionalities that I think are nice-to-haves in future versions of AX from a developer point of view. I hope they make sense :). 1. Select table where field in set Consider a situation where you have a set or container filled with recId&#8217;s. When you want to loop all records that have [...]]]></description>
			<content:encoded><![CDATA[<p>Here a some functionalities that I think are nice-to-haves in future versions of AX from a developer point of view. I hope they make sense :).</p>
<p><strong>1. Select table where field in set</strong><br />
Consider a situation where you have a set or container filled with recId&#8217;s. When you want to loop all records that have one of these recId&#8217;s, it would be nice to be able to write something like this:</p>
<div class="codecolorer-container xpp default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="xpp codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">Set &nbsp; &nbsp; &nbsp; &nbsp; set <span style="color: #00007f;">=</span> <span style="color: #0000ff;">new</span> Set<span style="color: #000000;">&#40;</span>Types<span style="color: #00007f;">::</span><span style="color: #0000ff;">Int64</span><span style="color: #000000;">&#41;</span>;<br />
CustTable &nbsp; custTable;<br />
;<br />
<br />
set.<span style="color: #000000;">add</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">5637166082</span><span style="color: #000000;">&#41;</span>;<br />
set.<span style="color: #000000;">add</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">5637166083</span><span style="color: #000000;">&#41;</span>;<br />
<br />
<span style="color: #0000ff;">while</span> <span style="color: #0000ff;">select</span> custTable<br />
<span style="color: #0000ff;">where</span> custTable.<span style="color: #000000;">RecId</span> IN set <span style="color: #007f00;">// this will not compile!</span><br />
<span style="color: #000000;">&#123;</span><br />
<span style="color: #007f00;">// do stuff</span><br />
<span style="color: #000000;">&#125;</span></div></div>
<p>The only problem is that there is no &#8216;in&#8217; operator in AX. You will either have to loop the set and select each record one at the time, or you&#8217;ll have to use the Query and QueryBuildRange classes to make this work.<br />
The above example would be much nicer in my opinion.</p>
<p><strong>2. Throwable exception classes</strong><br />
It would be nice to be able to create your own exceptions.<br />
Java, for example, has Throwable and Exception classes that can be extended.<br />
I won&#8217;t say that I completely understand these java classes (I&#8217;m not a Java guy), but I believe it would force developers to catch only exceptions they can handle, and not just all exceptions.<br />
It would also make it possible to have more information as to why an exception has occoured when you catch it.</p>
<p><strong>3. Try &#8211; catch &#8211; finally</strong><br />
This is a classic: the try-catch-finally is not supported in AX. When we look at C# for example, a try-catch can have a &#8216;finally&#8217; block at the end. The code in this block is always executed, even if an exception occoured.</p>
<p><strong>4. Events using CLR Interop</strong><br />
CLR Interop does not support event handling in AX. It would be nice to be able to assign an event handler to an event, so an event can trigger functionality in AX without complicated workarounds involving .NET wrapper classes, infinite loops, services or other creative solutions. (I&#8217;m thinking about things like FileSystemWatcher).</p>
<p><strong>5. Code refactoring</strong><br />
When you rename an object in AX (Table, field, class, method, etc), there is no refactoring option. You have to manually rename all other instances of that object.<br />
For example: it would be nice if, when you rename a field, AX had the option to automatically update all methods, forms, etc, where this field was used.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.artofcreation.be/2009/10/20/five-nice-to-haves-in-dynamics-ax/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>
