<?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>Andreas Gehrke – web developer</title>
	<atom:link href="http://www.agehrke.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.agehrke.com</link>
	<description></description>
	<lastBuildDate>Wed, 09 Nov 2011 12:42:24 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>Setting Content-Type in an Umbraco /Base service</title>
		<link>http://www.agehrke.com/2011/09/set-content-type-in-umbraco-base-service/</link>
		<comments>http://www.agehrke.com/2011/09/set-content-type-in-umbraco-base-service/#comments</comments>
		<pubDate>Mon, 12 Sep 2011 07:03:01 +0000</pubDate>
		<dc:creator>Andreas Gehrke</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[/base]]></category>
		<category><![CDATA[content-type]]></category>

		<guid isPermaLink="false">http://www.agehrke.com/?p=71</guid>
		<description><![CDATA[The Umbraco /Base system is great for creating simple REST-like services. You can use the RestExtensionMethod attribute to instruct Umbraco to return your response as XML or not. But what is “not”? Apparently it means set Response.ContentType to “text/html”. But what if &#8230;<p class="read-more"><a href="http://www.agehrke.com/2011/09/set-content-type-in-umbraco-base-service/">Read more &#187;</a></p>]]></description>
			<content:encoded><![CDATA[<p>The <a href="http://our.umbraco.org/wiki/reference/umbraco-base" target="_blank">Umbraco /Base system</a> is great for creating simple REST-like services. You can use the RestExtensionMethod attribute to instruct Umbraco to return your response as XML or not. But what is “not”? Apparently it means set Response.ContentType to “text/html”. But what if the returned data should be sent using a different mime type? Setting the ContentType manually like</p>
<pre class="brush: csharp; title: ; notranslate">
HttpContext.Current.Response.ContentType = &quot;application/json&quot;
</pre>
<p>will not do the trick. Umbraco /Base will override it with “text/html” if you are returning a string from your service method.</p>
<p>What you need to do is to change your method return signature to “void” and write your data directly to the HttpResponse, like:</p>
<pre class="brush: csharp; title: ; notranslate">
HttpContext.Current.Response.ContentType = &quot;application/json&quot;;
HttpContext.Current.Response.Write(stringWriter.ToString());
</pre>
<p>Umbraco will not override the content type for “void”-methods. Below is a full example.</p>
<pre class="brush: csharp; title: ; notranslate">
[RestExtension(&quot;Member&quot;)]
public class MemberService
{
	[RestExtensionMethod(returnXml = false, allowAll = true)]
	public static void Json()
	{
		var json = &quot;{ \&quot;firstName\&quot;: \&quot;John\&quot;, \&quot;lastName\&quot;: \&quot;Smith\&quot;, \&quot;age\&quot;: 25 }&quot;;

		// Write response and set content type
		HttpContext.Current.Response.ContentType = &quot;application/json&quot;;
		HttpContext.Current.Response.Write(json);
	}
}
</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.agehrke.com/2011/09/set-content-type-in-umbraco-base-service/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>ILSpy plugin for Visual Studio</title>
		<link>http://www.agehrke.com/2011/09/ilspy-plugin-for-visual-studio/</link>
		<comments>http://www.agehrke.com/2011/09/ilspy-plugin-for-visual-studio/#comments</comments>
		<pubDate>Fri, 02 Sep 2011 06:57:47 +0000</pubDate>
		<dc:creator>Andreas Gehrke</dc:creator>
				<category><![CDATA[.NET development]]></category>
		<category><![CDATA[ILSpy]]></category>
		<category><![CDATA[reflector]]></category>
		<category><![CDATA[Visual Studio]]></category>

		<guid isPermaLink="false">http://www.agehrke.com/?p=63</guid>
		<description><![CDATA[ILSpy is an open-source .NET assembly browser and decompiler like Red Gates Reflector which recently dropped their free version. ILSpy is very easy to use and can decompile a .NET assembly to IL or C# code. I often use it &#8230;<p class="read-more"><a href="http://www.agehrke.com/2011/09/ilspy-plugin-for-visual-studio/">Read more &#187;</a></p>]]></description>
			<content:encoded><![CDATA[<p><a href="http://wiki.sharpdevelop.net/ilspy.ashx" target="_blank">ILSpy</a> is an open-source .NET assembly browser and decompiler like Red Gates <a href="http://www.reflector.net/" target="_blank">Reflector</a> which recently dropped their free version. ILSpy is very easy to use and can decompile a .NET assembly to IL or C# code. I often use it to learn more of the internals of the .NET framework or a third party plugin/framework. However I found it tedious to locate the assembly I wanted to decompile in Windows Explorer and open it in ILSpy. Then I came across Eric Carr’s <a href="http://community.sharpdevelop.net/forums/t/13720.aspx" target="_blank">Visual Studio plugin for ILSpy</a>. It creates a “Browse source”-shortcut in the “Tools” menu of Visual Studio and opens the currently highlighted class, property, or method in ILSpy.</p>
<p>I have encouraged Eric Carr to release the plugin as open source, but at the moment you can <a href="http://community.sharpdevelop.net/forums/t/13720.aspx" target="_blank">download a MSI installer of the plugin</a>.</p>
<p><a href="http://www.agehrke.com/wp-content/uploads/2011/11/ilspy_type_decompilation1.png"><img class="alignnone size-medium wp-image-66" title="ILSpy screenshot" src="http://www.agehrke.com/wp-content/uploads/2011/11/ilspy_type_decompilation1-300x180.png" alt="" width="300" height="180" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.agehrke.com/2011/09/ilspy-plugin-for-visual-studio/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Nested Set in Propel 1.3</title>
		<link>http://www.agehrke.com/2009/04/nested-set-in-propel-13/</link>
		<comments>http://www.agehrke.com/2009/04/nested-set-in-propel-13/#comments</comments>
		<pubDate>Sun, 19 Apr 2009 13:21:07 +0000</pubDate>
		<dc:creator>Andreas Gehrke</dc:creator>
				<category><![CDATA[Symfony]]></category>
		<category><![CDATA[nested set]]></category>
		<category><![CDATA[propel]]></category>

		<guid isPermaLink="false">http://www.agehrke.com/blog/?p=3</guid>
		<description><![CDATA[Im currently working on a Symfony project with a lot of hierarchical data. For this I have taken advance of the new Nested Set implementation in Propel 1.3. Even though some initial research on Google showed a few people complaining &#8230;<p class="read-more"><a href="http://www.agehrke.com/2009/04/nested-set-in-propel-13/">Read more &#187;</a></p>]]></description>
			<content:encoded><![CDATA[<p>Im currently working on a <a href="http://www.symfony-project.org/">Symfony</a> project with a lot of <a href="http://dev.mysql.com/tech-resources/articles/hierarchical-data.html">hierarchical data</a>. For this I have taken advance of the new <a href="http://propel.phpdb.org/trac/wiki/Users/Documentation/1.3/Tree/NestedSet">Nested Set implementation in Propel 1.3</a>. Even though some initial research on Google showed a few people complaining about Propels implementation, I decided to give it a try.<br />
<span id="more-3"></span><br />
My schema.yml</p>
<pre class="brush: plain; title: ; notranslate">
team:
  _attributes:
    treeMode: NestedSet
  id:
  company_id:
    type: integer
    treeScopeKey: true
  name:
    type: VARCHAR
    size: 128
    required: true
  lft:
    type: integer
    required: true
    default: 0
    nestedSetLeftKey: true
  rgt:
    type: integer
    required: true
    default: 0
    nestedSetRightKey: true
</pre>
<p>Currently the only problem I have had is when I need to reassign a new node as root node. My first thought was to make the new node root and add the old root node as child, but Propel doesn&#8217;t like that and messes up the left-right values. What I have done is to insert the new node as child of the root node and then swap left-right values, like this:</p>
<pre class="brush: php; title: ; notranslate">
$node = new Team();
$root = TeamPeer::retrieveRoot($scopeId);
$node-&gt;insertAsFirstChildOf($root);

// Swap left-right values
$rootRight = $root-&gt;getRightValue();
$root-&gt;setLeftValue($node-&gt;getLeftValue());
$root-&gt;setRightValue($node-&gt;getRightValue());

// Make node root
$node-&gt;setLeftValue(1);
$node-&gt;setRightValue($rootRight);
</pre>
<h3>Display tree using RecursiveIteratorIterator</h3>
<p>I retrieve the tree with the static peer method <code>retrieveTree()</code> and display it using the <a href="http://www.php.net/~helly/php/ext/spl/classRecursiveIteratorIterator.html">RecursiveIteratorIterator</a>.</p>
<pre class="brush: php; title: ; notranslate">
$tree = TeamPeer::retrieveTree($scopeId);
$it = new RecursiveIteratorIterator($tree, RecursiveIteratorIterator::SELF_FIRST);
foreach ($it as $item) {
  echo $item;
}
</pre>
<p>However I wanted to print the items as an indented &#8220;list&#8221; in a dropdown box. For this I extended the <code>RecursiveIteratorIterator</code> class and implemented its <code>beginChildren()</code> and <code>endChildren()</code> methods.</p>
<pre class="brush: php; title: ; notranslate">
class MyIndentRecursiveIteratorIterator extends RecursiveIteratorIterator
{
	private $indent = '';
	private $indentStr = '&amp;nbsp;&amp;nbsp;';

	public function getIndent()
	{
		return $this-&gt;indent;
	}

	public function beginChildren()
	{
		$this-&gt;indent = str_repeat($this-&gt;indentStr, $this-&gt;getDepth());
	}

	public function endChildren()
	{
		$this-&gt;indent = str_repeat($this-&gt;indentStr, $this-&gt;getDepth() - 1);
	}
}

$tree = TeamPeer::retrieveTree($scopeId);
$it = new MyIndentRecursiveIteratorIterator($tree, MyIndentRecursiveIteratorIterator::SELF_FIRST);
foreach ($it as $item) {
  echo $it-&gt;getIndent() . $item;
}
</pre>
<p>Which produces something like below which can be used in a dropdown or similar.</p>
<pre class="brush: xml; title: ; notranslate">
Root
  Child 1
    Child 1.1
    Child 1.2
  Child 2
</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.agehrke.com/2009/04/nested-set-in-propel-13/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>

