<?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>Greg Does IT &#187; Tips &amp; tricks</title>
	<atom:link href="http://gregdoesit.com/category/tips-tricks/feed/" rel="self" type="application/rss+xml" />
	<link>http://gregdoesit.com</link>
	<description>Do it to get it</description>
	<lastBuildDate>Sun, 22 Apr 2012 16:48:10 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>Using Google App Engine as Proxy for Silverlight and Flash Cross-Domain Requests</title>
		<link>http://gregdoesit.com/2010/12/using-google-app-engine-as-proxy-for-cross-domain-requests/</link>
		<comments>http://gregdoesit.com/2010/12/using-google-app-engine-as-proxy-for-cross-domain-requests/#comments</comments>
		<pubDate>Wed, 15 Dec 2010 17:51:25 +0000</pubDate>
		<dc:creator>Gergely Orosz</dc:creator>
				<category><![CDATA[Tips & tricks]]></category>
		<category><![CDATA[code snipplet]]></category>
		<category><![CDATA[Google App Engine]]></category>
		<category><![CDATA[proxy]]></category>
		<category><![CDATA[python]]></category>
		<category><![CDATA[utility]]></category>

		<guid isPermaLink="false">http://gregdoesit.com/?p=708</guid>
		<description><![CDATA[When using Silverlight or Flash to fetch data from other domains one often runs into cross-domain access restrictions. For security reasons in order to access data from different domains, the remote server explicitly has to allow this by defining a crossdomain.xml (or, for Silverlight, clientaccesspolicy.xml is good as well). If this file cannot be found [...]]]></description>
			<content:encoded><![CDATA[<p>When using Silverlight or Flash to fetch data from other domains one often runs into cross-domain access restrictions. For security reasons in order to access data from different domains, the remote server explicitly has to allow this by defining a crossdomain.xml (or, for Silverlight, clientaccesspolicy.xml is good as well). If this file cannot be found on the remote domain, the request is not executed.</p>
<p>This can be fustrating when querying against RSS feeds or JSON/XML web APIs that don&#8217;t define any of these files. The workaround for this issue is to use some sort of proxying service. In this article I&#8217;ll be showing how to use Google App Engine to create a simple proxy that will forward these requests for free &#8211; within a reasonable daily load.</p>
<h2>Google App Engine Overview</h2>
<p>The reason I&#8217;ve chose to implement the proxy using Google App Engine is because it has a <a href="http://code.google.com/appengine/docs/quotas.html">free daily quota</a> and getting started using it is really simple: all you need is a Google account and to download and install the Google App Engine SDK.</p>
<p>Google App Engine supports developing in both Java and Python. In my example I&#8217;ll be using Python. In order to use and deploy the code yourself as well, follow these steps:<br />
<span id="more-708"></span></p>
<ul>
<li>If you don&#8217;t yet have a Google account, <a href="https://www.google.com/accounts/NewAccount">register for one</a>.</li>
<li>Download and install Python <a href="http://www.python.org/download/">from python.org</a></li>
<li>Download and install the <a href="http://code.google.com/appengine/downloads.html#Google_App_Engine_SDK_for_Python">Google App Engine Python SDK</a></li>
<li>Register an application on <a href="https://appengine.google.com/">Google App Engine</a> (click on <em>Create Application</em>). When done, run the Google App Engine Launcher and create an application with the same name you&#8217;ve just created.
</ul>
<h2>Creating the Proxy In Python</h2>
<p>Creating a simple proxy is pretty straightforward by using the <a href="http://code.google.com/appengine/docs/python/urlfetch/">urlfetch</a> library:</p>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;"><span style="color: #ff7700;font-weight:bold;">try</span>:
	response = urlfetch.<span style="color: black;">fetch</span><span style="color: black;">&#40;</span>url<span style="color: black;">&#41;</span>
<span style="color: #ff7700;font-weight:bold;">except</span> <span style="color: black;">&#40;</span>urlfetch.<span style="color: black;">Error</span>, apiproxy_errors.<span style="color: black;">Error</span><span style="color: black;">&#41;</span>:
	<span style="color: #808080; font-style: italic;"># an error occured</span></pre></div></div>

<p>In order to make the proxy a bit smarter, I&#8217;ll implement some caching using the App Engine&#8217;s <a href="http://code.google.com/appengine/docs/python/memcache/usingmemcache.html">memcache</a>:</p>
<pre language="python">
proxiedContent = memcache.get(memcacheKey)
proxiedContentInMemcache = True
if proxiedContent is None:
   # not in memcache: execute request
   # ...
   # add the result content to memcache for CACHE_TIME minutes
   memcache.add(memcacheKey,proxiedContent,CACHE_TIME)
else:
   # use the content from memcache
</pre>
<p>Using these snipplets, here&#8217;s how the main file of the proxy webapp will look like:</p>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;"><span style="color: #ff7700;font-weight:bold;">import</span> <span style="color: #dc143c;">datetime</span>
<span style="color: #ff7700;font-weight:bold;">import</span> hashlib
<span style="color: #ff7700;font-weight:bold;">import</span> <span style="color: #dc143c;">logging</span>
<span style="color: #ff7700;font-weight:bold;">import</span> <span style="color: #dc143c;">pickle</span>
<span style="color: #ff7700;font-weight:bold;">import</span> <span style="color: #dc143c;">urllib</span>
<span style="color: #ff7700;font-weight:bold;">import</span> <span style="color: #dc143c;">re</span>
<span style="color: #ff7700;font-weight:bold;">import</span> <span style="color: #dc143c;">time</span>
<span style="color: #ff7700;font-weight:bold;">import</span> <span style="color: #dc143c;">urllib</span>
<span style="color: #ff7700;font-weight:bold;">import</span> wsgiref.<span style="color: black;">handlers</span>
&nbsp;
<span style="color: #ff7700;font-weight:bold;">from</span> google.<span style="color: black;">appengine</span>.<span style="color: black;">api</span> <span style="color: #ff7700;font-weight:bold;">import</span> memcache
<span style="color: #ff7700;font-weight:bold;">from</span> google.<span style="color: black;">appengine</span>.<span style="color: black;">api</span> <span style="color: #ff7700;font-weight:bold;">import</span> urlfetch
<span style="color: #ff7700;font-weight:bold;">from</span> google.<span style="color: black;">appengine</span>.<span style="color: black;">ext</span> <span style="color: #ff7700;font-weight:bold;">import</span> db
<span style="color: #ff7700;font-weight:bold;">from</span> google.<span style="color: black;">appengine</span>.<span style="color: black;">ext</span> <span style="color: #ff7700;font-weight:bold;">import</span> webapp
<span style="color: #ff7700;font-weight:bold;">from</span> google.<span style="color: black;">appengine</span>.<span style="color: black;">ext</span>.<span style="color: black;">webapp</span> <span style="color: #ff7700;font-weight:bold;">import</span> template
<span style="color: #ff7700;font-weight:bold;">from</span> google.<span style="color: black;">appengine</span>.<span style="color: black;">runtime</span> <span style="color: #ff7700;font-weight:bold;">import</span> apiproxy_errors
&nbsp;
CACHE_TIME = <span style="color: #ff4500;">1</span> <span style="color: #808080; font-style: italic;"># number of minutes to cache content for</span>
&nbsp;
URL_PREFIXES = <span style="color: black;">&#91;</span><span style="color: #483d8b;">&quot;http://www.google.com/finance&quot;</span><span style="color: black;">&#93;</span> <span style="color: #808080; font-style: italic;"># only allow URLs to be queried from certain domain(s)</span>
&nbsp;
<span style="color: #ff7700;font-weight:bold;">def</span> getMemcacheKey<span style="color: black;">&#40;</span>url<span style="color: black;">&#41;</span>:
  url_hash = hashlib.<span style="color: black;">sha256</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
  url_hash.<span style="color: black;">update</span><span style="color: black;">&#40;</span>url<span style="color: black;">&#41;</span>
  <span style="color: #ff7700;font-weight:bold;">return</span> <span style="color: #483d8b;">&quot;hash_&quot;</span> + url_hash.<span style="color: black;">hexdigest</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
&nbsp;
<span style="color: #ff7700;font-weight:bold;">class</span> ProxyHandler<span style="color: black;">&#40;</span>webapp.<span style="color: black;">RequestHandler</span><span style="color: black;">&#41;</span>:
  <span style="color: #ff7700;font-weight:bold;">def</span> get<span style="color: black;">&#40;</span><span style="color: #008000;">self</span><span style="color: black;">&#41;</span>:
    url = <span style="color: #008000;">self</span>.<span style="color: black;">request</span>.<span style="color: black;">get</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">'url'</span><span style="color: black;">&#41;</span>
    url = <span style="color: #dc143c;">urllib</span>.<span style="color: black;">unquote</span><span style="color: black;">&#40;</span>url<span style="color: black;">&#41;</span>
    <span style="color: #808080; font-style: italic;"># only allow urls that start with prefixes defined in URL_PREFIXES to be used</span>
    <span style="color: #ff7700;font-weight:bold;">if</span> <span style="color: #ff7700;font-weight:bold;">not</span> <span style="color: #008000;">self</span>.<span style="color: black;">isUrlAllowed</span><span style="color: black;">&#40;</span>url<span style="color: black;">&#41;</span>:
      <span style="color: #008000;">self</span>.<span style="color: black;">response</span>.<span style="color: black;">out</span>.<span style="color: black;">write</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;The URL passed can not be proxied due to security reasons.&quot;</span><span style="color: black;">&#41;</span>
      <span style="color: #ff7700;font-weight:bold;">return</span>
    memcacheKey = getMemcacheKey<span style="color: black;">&#40;</span>url<span style="color: black;">&#41;</span> 
&nbsp;
    <span style="color: #808080; font-style: italic;"># Use memcache to store the request for CACHE_TIME</span>
    proxiedContent = memcache.<span style="color: black;">get</span><span style="color: black;">&#40;</span>memcacheKey<span style="color: black;">&#41;</span>
    proxiedContentInMemcache = <span style="color: #008000;">True</span>
    <span style="color: #ff7700;font-weight:bold;">if</span> proxiedContent <span style="color: #ff7700;font-weight:bold;">is</span> <span style="color: #008000;">None</span>:
      proxiedContentInMemcache = <span style="color: #008000;">False</span>
      <span style="color: #ff7700;font-weight:bold;">try</span>:
        response = urlfetch.<span style="color: black;">fetch</span><span style="color: black;">&#40;</span>url<span style="color: black;">&#41;</span>
      <span style="color: #ff7700;font-weight:bold;">except</span> <span style="color: black;">&#40;</span>urlfetch.<span style="color: black;">Error</span>, apiproxy_errors.<span style="color: black;">Error</span><span style="color: black;">&#41;</span>:
        <span style="color: #ff7700;font-weight:bold;">return</span> <span style="color: #008000;">self</span>.<span style="color: black;">error</span><span style="color: black;">&#40;</span><span style="color: #ff4500;">404</span><span style="color: black;">&#41;</span>
      proxiedContent = response.<span style="color: black;">content</span>
    <span style="color: #ff7700;font-weight:bold;">if</span> proxiedContent <span style="color: #ff7700;font-weight:bold;">is</span> <span style="color: #008000;">None</span>:
      <span style="color: #ff7700;font-weight:bold;">return</span> <span style="color: #008000;">self</span>.<span style="color: black;">error</span><span style="color: black;">&#40;</span><span style="color: #ff4500;">404</span><span style="color: black;">&#41;</span>
&nbsp;
    <span style="color: #808080; font-style: italic;"># Add the fetched content to memcache</span>
    <span style="color: #ff7700;font-weight:bold;">if</span> <span style="color: black;">&#40;</span><span style="color: #ff7700;font-weight:bold;">not</span> proxiedContentInMemcache<span style="color: black;">&#41;</span>:
      memcache.<span style="color: black;">add</span><span style="color: black;">&#40;</span>memcacheKey,proxiedContent,CACHE_TIME<span style="color: black;">&#41;</span>
    <span style="color: #008000;">self</span>.<span style="color: black;">response</span>.<span style="color: black;">out</span>.<span style="color: black;">write</span><span style="color: black;">&#40;</span>proxiedContent<span style="color: black;">&#41;</span>
&nbsp;
<span style="color: #ff7700;font-weight:bold;">def</span> isUrlAllowed<span style="color: black;">&#40;</span><span style="color: #008000;">self</span>, url<span style="color: black;">&#41;</span>:
  <span style="color: #ff7700;font-weight:bold;">for</span> urlPrefix <span style="color: #ff7700;font-weight:bold;">in</span> URL_PREFIXES:
    <span style="color: #ff7700;font-weight:bold;">if</span> url.<span style="color: black;">startswith</span><span style="color: black;">&#40;</span>urlPrefix<span style="color: black;">&#41;</span>:
      <span style="color: #ff7700;font-weight:bold;">return</span> <span style="color: #008000;">True</span>
  <span style="color: #ff7700;font-weight:bold;">return</span> <span style="color: #008000;">False</span>
&nbsp;
app = webapp.<span style="color: black;">WSGIApplication</span><span style="color: black;">&#40;</span><span style="color: black;">&#91;</span>
  <span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;/proxy&quot;</span>, ProxyHandler<span style="color: black;">&#41;</span>,
<span style="color: black;">&#93;</span>, debug=<span style="color: #008000;">True</span><span style="color: black;">&#41;</span>
&nbsp;
<span style="color: #ff7700;font-weight:bold;">def</span> main<span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>:
  wsgiref.<span style="color: black;">handlers</span>.<span style="color: black;">CGIHandler</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>.<span style="color: black;">run</span><span style="color: black;">&#40;</span>app<span style="color: black;">&#41;</span>
&nbsp;
<span style="color: #ff7700;font-weight:bold;">if</span> __name__ == <span style="color: #483d8b;">&quot;__main__&quot;</span>:
  main<span style="color: black;">&#40;</span><span style="color: black;">&#41;</span></pre></div></div>

<p>The proxy can now be called by passing the URL to be proxied via the url parameter. So to proxy e.g. http://google.com, the following request should be made: http://myapplication.appspot.com/proxy?url=http://google.com.</p>
<h2>Adding crossdomain.xml to the Application</h2>
<p>Now that the proxy class is ready, all we need to do is wire it into the web application and include a crossdomain.xml static file which will allow requests from all hosts (it is advisable to change this to the URL the requests are actually made). Based on this, here is how the crossdomain.xml would look like:</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #00bbdd;">&lt;!DOCTYPE cross-domain-policy SYSTEM &quot;http://www.macromedia.com/xml/dtds/cross-domain-policy.dtd&quot;&gt;</span> 
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;cross-domain-policy<span style="color: #000000; font-weight: bold;">&gt;</span></span></span> 
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;allow-access-from</span> <span style="color: #000066;">domain</span>=<span style="color: #ff0000;">&quot;*&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span> 
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/cross-domain-policy<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<p>And here is how the modified app.yaml descriptior will look like:</p>
<pre lang="">
application: yourappname
version: proxyv1
runtime: python
api_version: 1

handlers:
- url: /crossdomain.xml
  static_files: crossdomain.xml
  upload: crossdomain.xml
- url: /.*
  script: proxy.py
  secure: optional
</pre>
<h2>Download the Code</h2>
<p>The code for the application can be downloaded here: <a href="http://gregdoesit.com/files/GoogleAppEngineProxy_v2.zip">Proxy Using Google App Engine.zip</a>. After unzipping be sure to change the &#8220;yourappname&#8221; name in app.yaml in order to be able to deploy it on Google App Engine.</p>
<h3>Update: Security Issues</h3>
<p>Andrew noted in the comment that the original solution raised security concerns as it would have been easy for someone to hijack this proxy and use it for their purpose as no authentication or authorization is done. I&#8217;ve added a small fix where the proxy only forwards to URLs that start from a list of prefixes. This is probably a sufficient solution for common cases, however more sophisticated authorization methods may be needed in other cases.</p>
]]></content:encoded>
			<wfw:commentRss>http://gregdoesit.com/2010/12/using-google-app-engine-as-proxy-for-cross-domain-requests/feed/</wfw:commentRss>
		<slash:comments>12</slash:comments>
		</item>
		<item>
		<title>Setting the StrokeDashArray using a Style in Silverlight</title>
		<link>http://gregdoesit.com/2010/09/setting-the-strokedasharray-using-a-style-in-silverlight/</link>
		<comments>http://gregdoesit.com/2010/09/setting-the-strokedasharray-using-a-style-in-silverlight/#comments</comments>
		<pubDate>Thu, 02 Sep 2010 14:10:12 +0000</pubDate>
		<dc:creator>Gergely Orosz</dc:creator>
				<category><![CDATA[Silverlight]]></category>
		<category><![CDATA[Tips & tricks]]></category>
		<category><![CDATA[bug]]></category>

		<guid isPermaLink="false">http://gregdoesit.com/?p=587</guid>
		<description><![CDATA[I&#8217;ve recently ran into an issue: I wanted to draw an element with a dashed stroke using a Style I&#8217;ve created on the fly. To my surprise I couldn&#8217;t. The Problem The type of the StrokeDashArray (that is defined on Shape) is a DoubleCollection. So naturally I tried setting a DoubleCollection instance as the Value [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve recently ran into an issue:  I wanted to draw an element with a dashed stroke using a Style I&#8217;ve created on the fly. To my surprise I couldn&#8217;t.</p>
<h3>The Problem</h3>
<p>The type of the StrokeDashArray (that is defined on Shape) is a DoubleCollection. So naturally I tried setting a DoubleCollection instance as the Value of the Setter on the Style I created:</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;">Style ellipse2Style <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> Style<span style="color: #000000;">&#40;</span><span style="color: #008000;">typeof</span><span style="color: #000000;">&#40;</span>Ellipse<span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
<span style="color: #008080; font-style: italic;">// Setting a DoubleCollection as the Value of the Setter for StrokeDashArrayProperty doesn't work!</span>
ellipse2Style.<span style="color: #0000FF;">Setters</span>.<span style="color: #0000FF;">Add</span><span style="color: #000000;">&#40;</span><span style="color: #008000;">new</span> Setter<span style="color: #000000;">&#40;</span>Ellipse.<span style="color: #0000FF;">StrokeDashArrayProperty</span>,<span style="color: #008000;">new</span> DoubleCollection<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span> <span style="color: #FF0000;">2</span>, <span style="color: #FF0000;">2</span> <span style="color: #000000;">&#125;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
Ellipse2.<span style="color: #0000FF;">Style</span> <span style="color: #008000;">=</span> ellipse2Style<span style="color: #008000;">;</span></pre></div></div>

<p><span id="more-587"></span></p>
<p>This is interesting enough as setting the StrokeDashArray property directly seems to work just fine:</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #008080; font-style: italic;">// Works fine</span>
Ellipse1.<span style="color: #0000FF;">StrokeDashArray</span> <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> DoubleCollection<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span> <span style="color: #FF0000;">2</span>, <span style="color: #FF0000;">2</span> <span style="color: #000000;">&#125;</span><span style="color: #008000;">;</span></pre></div></div>

<p>This issue definitely suggests that this is a bug that is still present in Silverlight 4. A little searching revealed that <a href="http://forums.silverlight.net/forums/t/53869.aspx" target='_blank'>this issue has been reported in version 2</a> (almost 2 years ago!), but is still not fixed.</p>
<h3>The Workaround</h3>
<p>After some playing around I&#8217;ve found a workaround: the Setter property needs to be passed as a string, rather then a DoubleCollection. </p>
<p>The fact that this helps solve the issue is quite surprising as it suggests that there is some logic built in to the styling mechanism that in case of the StrokeDashArray property does some funky conversion from string to DoubleCollection. Personally I would&#8217;ve thought that only the XAML parser would do something similar, but it looks like this isn&#8217;t a case.</p>
<p>So the (strange) workaround is to set the value of the Setter for the StrokeDashArrayProperty to a string, just like one would do when declaring the Style in XAML. The above example can be made working using this code:</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;">Style ellipse3Style <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> Style<span style="color: #000000;">&#40;</span><span style="color: #008000;">typeof</span><span style="color: #000000;">&#40;</span>Ellipse<span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
<span style="color: #008080; font-style: italic;">// Setting a string as the Value of the Setter for StrokeDashArrayProperty works - odd!</span>
ellipse3Style.<span style="color: #0000FF;">Setters</span>.<span style="color: #0000FF;">Add</span><span style="color: #000000;">&#40;</span><span style="color: #008000;">new</span> Setter<span style="color: #000000;">&#40;</span>Ellipse.<span style="color: #0000FF;">StrokeDashArrayProperty</span>, <span style="color: #666666;">&quot;2,2&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
Ellipse3.<span style="color: #0000FF;">Style</span> <span style="color: #008000;">=</span> ellipse3Style<span style="color: #008000;">;</span></pre></div></div>

<p>As for a demo of the bug, see the following application:</p>
<p>The code behind for the application is as follows:</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #008080; font-style: italic;">// Works fine</span>
Ellipse1.<span style="color: #0000FF;">StrokeDashArray</span> <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> DoubleCollection<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span> <span style="color: #FF0000;">2</span>, <span style="color: #FF0000;">2</span> <span style="color: #000000;">&#125;</span><span style="color: #008000;">;</span>
&nbsp;
Style ellipse2Style <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> Style<span style="color: #000000;">&#40;</span><span style="color: #008000;">typeof</span><span style="color: #000000;">&#40;</span>Ellipse<span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
<span style="color: #008080; font-style: italic;">// Setting a DoubleCollection as the Value of the Setter for StrokeDashArrayProperty doesn't work!</span>
ellipse2Style.<span style="color: #0000FF;">Setters</span>.<span style="color: #0000FF;">Add</span><span style="color: #000000;">&#40;</span><span style="color: #008000;">new</span> Setter<span style="color: #000000;">&#40;</span>Ellipse.<span style="color: #0000FF;">StrokeDashArrayProperty</span>,<span style="color: #008000;">new</span> DoubleCollection<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span> <span style="color: #FF0000;">2</span>, <span style="color: #FF0000;">2</span> <span style="color: #000000;">&#125;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
Ellipse2.<span style="color: #0000FF;">Style</span> <span style="color: #008000;">=</span> ellipse2Style<span style="color: #008000;">;</span>
&nbsp;
Style ellipse3Style <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> Style<span style="color: #000000;">&#40;</span><span style="color: #008000;">typeof</span><span style="color: #000000;">&#40;</span>Ellipse<span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
<span style="color: #008080; font-style: italic;">// Setting a string as the Value of the Setter for StrokeDashArrayProperty works - odd!</span>
ellipse3Style.<span style="color: #0000FF;">Setters</span>.<span style="color: #0000FF;">Add</span><span style="color: #000000;">&#40;</span><span style="color: #008000;">new</span> Setter<span style="color: #000000;">&#40;</span>Ellipse.<span style="color: #0000FF;">StrokeDashArrayProperty</span>, <span style="color: #666666;">&quot;2,2&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
Ellipse3.<span style="color: #0000FF;">Style</span> <span style="color: #008000;">=</span> ellipse3Style<span style="color: #008000;">;</span></pre></div></div>

<p><object type="application/x-silverlight-2" data="data:application/x-silverlight,"  width="500" height="110"><param name="source" value="http://gregdoesit.com/wp-content/uploads/2010/09/StrokeDashArrayBug.xap"/></object> </p>
<p>Download the source of the example here: <a href="http://gregdoesit.com/wp-content/uploads/2010/09/StrokeDashArrayBug.zip">StrokeDashArray Bug in Silverlight.zip</a></p>
<p>Hope this helps anyone coming across this issue!</p>
]]></content:encoded>
			<wfw:commentRss>http://gregdoesit.com/2010/09/setting-the-strokedasharray-using-a-style-in-silverlight/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Ten Cool Visual Studio 2010 Features</title>
		<link>http://gregdoesit.com/2010/04/ten-cool-visual-studio-2010-features/</link>
		<comments>http://gregdoesit.com/2010/04/ten-cool-visual-studio-2010-features/#comments</comments>
		<pubDate>Thu, 08 Apr 2010 15:55:46 +0000</pubDate>
		<dc:creator>Gergely Orosz</dc:creator>
				<category><![CDATA[Tips & tricks]]></category>
		<category><![CDATA[Tools]]></category>
		<category><![CDATA[Microsoft]]></category>
		<category><![CDATA[Visual Studio]]></category>

		<guid isPermaLink="false">http://gregdoesit.com/?p=422</guid>
		<description><![CDATA[I&#8217;ve attended an event late March in Glasgow where Scott Guthrie, Microsoft vice president showed off some of the new fewatures of Visual Studio 2010. Based on this talk and my experience using Visual Studio 2010 Beta 2 and the Release Candidate I&#8217;ve collected the ten most useful new features of this edition. These are: [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve attended an event late March in Glasgow where Scott Guthrie, Microsoft vice president showed off some of the new fewatures of Visual Studio 2010. Based on this talk and my experience using Visual Studio 2010 Beta 2 and the Release Candidate I&#8217;ve collected the ten most useful new features of this edition. These are:</p>
<ul>
<li>Pinning variables when debugging</li>
<li>Box selection</li>
<li>On-the-fly search</li>
<li>Zooming</li>
<li>View call hierarchy</li>
<li>Sequence diagrams</li>
<li>Dependency graphs</li>
<li>IntelliTrace and dump debugging</li>
<li>Multi-monitor support</li>
<li>Intellisense improvements</li>
</ul>
<p>For a detailed description of each of these features read my blog post <a href="http://www.scottlogic.co.uk/blog/gergely/2010/04/ten-cool-things-you-didnt-know-about-visual-studio-2010/">Ten Cool Things You Didn&#8217;t Know About Visual Studio</a> at my Scott Logic blog.</p>
]]></content:encoded>
			<wfw:commentRss>http://gregdoesit.com/2010/04/ten-cool-visual-studio-2010-features/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>Querying many-to-many relations in NHibernate</title>
		<link>http://gregdoesit.com/2009/04/querying-many-to-many-relations-in-nhibernate/</link>
		<comments>http://gregdoesit.com/2009/04/querying-many-to-many-relations-in-nhibernate/#comments</comments>
		<pubDate>Thu, 02 Apr 2009 09:30:40 +0000</pubDate>
		<dc:creator>Gergely Orosz</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[ORM]]></category>
		<category><![CDATA[Tips & tricks]]></category>
		<category><![CDATA[NHibernate]]></category>

		<guid isPermaLink="false">http://gregdoesit.com/?p=130</guid>
		<description><![CDATA[I&#8217;ve ran into a querying scenario with NHibernate that was much less obvious to solve with the NHibernate query API than it would have been with SQL &#8211; for me at least. In my model I&#8217;ve had a simple many-to-many relation: Entries that had multiple Categories each and Categories that belonged to multiple Entries as [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve ran into a querying scenario with NHibernate that was much less obvious to solve with the NHibernate query API than it would have been with SQL &#8211; for me at least.</p>
<p>In my model I&#8217;ve had a simple many-to-many relation: Entries that had multiple Categories each and Categories that belonged to multiple Entries as well.</p>
<div id="attachment_131" class="wp-caption aligncenter" style="width: 360px"><img class="size-full wp-image-131" title="NHibernate many-to-many example entity relationship diagram" src="http://gregdoesit.com/wp-content/uploads/2009/04/nhmanytomanyexampleer.jpg" alt="Categories and Entries: an Entity-Relationship Diagram" width="350" height="80" /><p class="wp-caption-text">Categories and Entries: a many-to-many relationship</p></div>
<p>In the underlying SQL model the many-to-many relationship was implemented via a relationship table:</p>
<div id="attachment_136" class="wp-caption aligncenter" style="width: 480px"><img class="size-full wp-image-136" title="Many-to-many relationship table structure" src="http://gregdoesit.com/wp-content/uploads/2009/04/nhmanytomanyexample1.jpg" alt="Many-to-many relationship table structure" width="470" height="97" /><p class="wp-caption-text">Categories and Entries table structure</p></div>
<p>Now I wanted to find all entites within a given category. Pretty simple, right? In SQL it would have been a simple join:</p>

<div class="wp_syntax"><div class="code"><pre class="sql" style="font-family:monospace;"><span style="color: #993333; font-weight: bold;">SELECT</span> Entry<span style="color: #66cc66;">.*</span> <span style="color: #993333; font-weight: bold;">FROM</span> Entry <span style="color: #993333; font-weight: bold;">JOIN</span> Category_rel_Entry <span style="color: #993333; font-weight: bold;">ON</span> Category_rel_Entry<span style="color: #66cc66;">.</span>Entry_ID <span style="color: #66cc66;">=</span> Entry<span style="color: #66cc66;">.</span>ID <span style="color: #993333; font-weight: bold;">WHERE</span> Category_rel_Entry<span style="color: #66cc66;">.</span>Category_ID <span style="color: #66cc66;">=</span> @CategoryId</pre></div></div>

<p>In Nhibernate this query is a bit more tricky, let me share how it can be done.</p>
<p><em>Note: this post is also a good example of how to define a many to many relationship schema in NHibernate.</em></p>
<p><span id="more-130"></span><br />
My NHibernate model looked like the following:<br />
The Category entity:</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;">&nbsp;</pre></div></div>

<p>The Enity entry:</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;">&nbsp;</pre></div></div>

<p>To do query all entites of a given category, the Restrictions class has to be used for the categories property of the Entity class. For me it took a while to figure out this solution so here is the code:</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;">Category category<span style="color: #008000;">;</span> <span style="color: #008080; font-style: italic;">// The category of which its entities wanted to  be retreived</span>
IList nodes <span style="color: #008000;">=</span> NHHttpModule.<span style="color: #0000FF;">CurrentSession</span>.<span style="color: #0000FF;">CreateCriteria</span><span style="color: #000000;">&#40;</span><span style="color: #008000;">typeof</span><span style="color: #000000;">&#40;</span>Entity<span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>
                            .<span style="color: #0000FF;">CreateCriteria</span><span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;categories&quot;</span><span style="color: #000000;">&#41;</span>
                           .<span style="color: #0000FF;">Add</span><span style="color: #000000;">&#40;</span>NHibernate.<span style="color: #0000FF;">Criterion</span>.<span style="color: #0000FF;">Restrictions</span>.<span style="color: #0000FF;">IdEq</span><span style="color: #000000;">&#40;</span>category.<span style="color: #0000FF;">ID</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>
                           .<span style="color: #0000FF;">List</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span></pre></div></div>

<p>In the end the NHibernate code seems cleaner than the SQL one regarding semantics. However figuring out the syntax of these not so everyday queries is not so self explanatory.</p>
<p><strong>Update (2009. 04. 09.)</strong> to have the example working you need to code the the <strong>NHttpModule</strong> class as well. The code is as follows:</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF;">using</span> <span style="color: #008080;">System</span><span style="color: #008000;">;</span>
<span style="color: #0600FF;">using</span> <span style="color: #008080;">System.Collections.Generic</span><span style="color: #008000;">;</span>
<span style="color: #0600FF;">using</span> <span style="color: #008080;">System.Text</span><span style="color: #008000;">;</span>
<span style="color: #0600FF;">using</span> <span style="color: #008080;">System.Web</span><span style="color: #008000;">;</span>
<span style="color: #0600FF;">using</span> <span style="color: #008080;">NHibernate</span><span style="color: #008000;">;</span>
&nbsp;
<span style="color: #0600FF;">namespace</span> NHibernateApp
<span style="color: #000000;">&#123;</span>
    <span style="color: #008080; font-style: italic;">/// </span>
    <span style="color: #008080; font-style: italic;">/// NHibernateHttpModule</span>
    <span style="color: #008080; font-style: italic;">/// </span>
    <span style="color: #0600FF;">public</span> <span style="color: #FF0000;">class</span> NHHttpModule <span style="color: #008000;">:</span> IHttpModule
    <span style="color: #000000;">&#123;</span>
        <span style="color: #0600FF;">public</span> <span style="color: #0600FF;">const</span> <span style="color: #FF0000;">string</span> KEY <span style="color: #008000;">=</span> <span style="color: #666666;">&quot;_TheSession_&quot;</span><span style="color: #008000;">;</span>
        <span style="color: #0600FF;">private</span> <span style="color: #0600FF;">static</span> ISession _session<span style="color: #008000;">;</span>
&nbsp;
        <span style="color: #0600FF;">private</span> <span style="color: #0600FF;">void</span> context_BeginRequest<span style="color: #000000;">&#40;</span><span style="color: #FF0000;">object</span> sender, EventArgs e<span style="color: #000000;">&#41;</span>
        <span style="color: #000000;">&#123;</span>
            HttpApplication application <span style="color: #008000;">=</span> <span style="color: #000000;">&#40;</span>HttpApplication<span style="color: #000000;">&#41;</span>sender<span style="color: #008000;">;</span>
            HttpContext context <span style="color: #008000;">=</span> application.<span style="color: #0000FF;">Context</span><span style="color: #008000;">;</span>
            context.<span style="color: #0000FF;">Items</span><span style="color: #000000;">&#91;</span>KEY<span style="color: #000000;">&#93;</span> <span style="color: #008000;">=</span> NHSessionHelper.<span style="color: #0000FF;">OpenSession</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
        <span style="color: #000000;">&#125;</span>
&nbsp;
        <span style="color: #0600FF;">public</span> <span style="color: #0600FF;">static</span> ISession CurrentSession
        <span style="color: #000000;">&#123;</span>
            get
            <span style="color: #000000;">&#123;</span>
                <span style="color: #0600FF;">if</span> <span style="color: #000000;">&#40;</span>HttpContext.<span style="color: #0000FF;">Current</span> <span style="color: #008000;">==</span> <span style="color: #0600FF;">null</span><span style="color: #000000;">&#41;</span>
                <span style="color: #000000;">&#123;</span>
                    <span style="color: #0600FF;">if</span> <span style="color: #000000;">&#40;</span>_session <span style="color: #008000;">!=</span> <span style="color: #0600FF;">null</span> <span style="color: #008000;">&amp;</span>amp<span style="color: #008000;">;&amp;</span>amp<span style="color: #008000;">;</span> _session.<span style="color: #0000FF;">IsOpen</span><span style="color: #000000;">&#41;</span>
                        <span style="color: #0600FF;">return</span> _session<span style="color: #008000;">;</span>
&nbsp;
                    _session <span style="color: #008000;">=</span> NHSessionHelper.<span style="color: #0000FF;">OpenSession</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
                    <span style="color: #0600FF;">return</span> _session<span style="color: #008000;">;</span>
                <span style="color: #000000;">&#125;</span>
                <span style="color: #0600FF;">else</span>
                <span style="color: #000000;">&#123;</span>
                    HttpContext currentContext <span style="color: #008000;">=</span> HttpContext.<span style="color: #0000FF;">Current</span><span style="color: #008000;">;</span>
                    ISession session <span style="color: #008000;">=</span> currentContext.<span style="color: #0000FF;">Items</span><span style="color: #000000;">&#91;</span>KEY<span style="color: #000000;">&#93;</span> <span style="color: #0600FF;">as</span> ISession<span style="color: #008000;">;</span>
                    <span style="color: #0600FF;">if</span> <span style="color: #000000;">&#40;</span>session <span style="color: #008000;">==</span> <span style="color: #0600FF;">null</span> <span style="color: #008000;">||</span> <span style="color: #008000;">!</span>session.<span style="color: #0000FF;">IsOpen</span><span style="color: #000000;">&#41;</span>
                    <span style="color: #000000;">&#123;</span>
                        session <span style="color: #008000;">=</span> NHSessionHelper.<span style="color: #0000FF;">OpenSession</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
                        currentContext.<span style="color: #0000FF;">Items</span><span style="color: #000000;">&#91;</span>KEY<span style="color: #000000;">&#93;</span> <span style="color: #008000;">=</span> session<span style="color: #008000;">;</span>
                    <span style="color: #000000;">&#125;</span>
                    <span style="color: #0600FF;">return</span> session<span style="color: #008000;">;</span>
                <span style="color: #000000;">&#125;</span>
            <span style="color: #000000;">&#125;</span>
        <span style="color: #000000;">&#125;</span>
&nbsp;
        <span style="color: #0600FF;">private</span> <span style="color: #0600FF;">void</span> context_EndRequest<span style="color: #000000;">&#40;</span><span style="color: #FF0000;">object</span> sender, EventArgs e<span style="color: #000000;">&#41;</span>
        <span style="color: #000000;">&#123;</span>
            HttpApplication application <span style="color: #008000;">=</span> <span style="color: #000000;">&#40;</span>HttpApplication<span style="color: #000000;">&#41;</span>sender<span style="color: #008000;">;</span>
            HttpContext context <span style="color: #008000;">=</span> application.<span style="color: #0000FF;">Context</span><span style="color: #008000;">;</span>
&nbsp;
            ISession session <span style="color: #008000;">=</span> context.<span style="color: #0000FF;">Items</span><span style="color: #000000;">&#91;</span>KEY<span style="color: #000000;">&#93;</span> <span style="color: #0600FF;">as</span> ISession<span style="color: #008000;">;</span>
            <span style="color: #0600FF;">if</span> <span style="color: #000000;">&#40;</span>session <span style="color: #008000;">!=</span> <span style="color: #0600FF;">null</span><span style="color: #000000;">&#41;</span>
            <span style="color: #000000;">&#123;</span>
                <span style="color: #0600FF;">try</span>
                <span style="color: #000000;">&#123;</span>
                    session.<span style="color: #0000FF;">Flush</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
                    session.<span style="color: #0000FF;">Close</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
                <span style="color: #000000;">&#125;</span>
                <span style="color: #0600FF;">catch</span> <span style="color: #000000;">&#123;</span> <span style="color: #000000;">&#125;</span>
            <span style="color: #000000;">&#125;</span>
            context.<span style="color: #0000FF;">Items</span><span style="color: #000000;">&#91;</span>KEY<span style="color: #000000;">&#93;</span> <span style="color: #008000;">=</span> null<span style="color: #008000;">;</span>
        <span style="color: #000000;">&#125;</span>
&nbsp;
        <span style="color: #0600FF;">public</span> <span style="color: #0600FF;">void</span> Init<span style="color: #000000;">&#40;</span><span style="color: #000000;">System.<span style="color: #0000FF;">Web</span></span>.<span style="color: #0000FF;">HttpApplication</span> app<span style="color: #000000;">&#41;</span>
        <span style="color: #000000;">&#123;</span>
        <span style="color: #000000;">&#125;</span>
&nbsp;
        <span style="color: #0600FF;">public</span> <span style="color: #0600FF;">void</span> Dispose<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>
        <span style="color: #000000;">&#123;</span>
        <span style="color: #000000;">&#125;</span>
    <span style="color: #000000;">&#125;</span>
&nbsp;
<span style="color: #000000;">&#125;</span></pre></div></div>

<p>And you will also need to create the <strong>NSessionHelper</strong> class as well. In this class replace MyNHibernateAppAssembly with the name of your assembly that contains NHibernate definitions.</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF;">using</span> <span style="color: #008080;">System</span><span style="color: #008000;">;</span>
<span style="color: #0600FF;">using</span> <span style="color: #008080;">System.Collections.Generic</span><span style="color: #008000;">;</span>
<span style="color: #0600FF;">using</span> <span style="color: #008080;">System.Text</span><span style="color: #008000;">;</span>
<span style="color: #0600FF;">using</span> <span style="color: #008080;">NHibernate</span><span style="color: #008000;">;</span>
<span style="color: #0600FF;">using</span> <span style="color: #008080;">NHibernate.Cfg</span><span style="color: #008000;">;</span>
&nbsp;
<span style="color: #0600FF;">namespace</span> NHibernateApp
<span style="color: #000000;">&#123;</span>
&nbsp;
    <span style="color: #008080; font-style: italic;">/// </span>
    <span style="color: #008080; font-style: italic;">/// Summary description for SessionHelper</span>
    <span style="color: #008080; font-style: italic;">/// </span>
    <span style="color: #0600FF;">public</span> <span style="color: #FF0000;">class</span> NHSessionHelper
    <span style="color: #000000;">&#123;</span>
        <span style="color: #0600FF;">private</span> <span style="color: #0600FF;">static</span> ISessionFactory _sessionFactory <span style="color: #008000;">=</span> null<span style="color: #008000;">;</span>
        <span style="color: #0600FF;">private</span> <span style="color: #0600FF;">static</span> ISessionFactory SessionFactory
        <span style="color: #000000;">&#123;</span>
            get
            <span style="color: #000000;">&#123;</span>
                <span style="color: #0600FF;">if</span> <span style="color: #000000;">&#40;</span>_sessionFactory <span style="color: #008000;">==</span> <span style="color: #0600FF;">null</span><span style="color: #000000;">&#41;</span>
                <span style="color: #000000;">&#123;</span>
                    Configuration config <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> Configuration<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
                    config.<span style="color: #0000FF;">AddAssembly</span><span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;VizsgTervNHibernate&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
                    _sessionFactory <span style="color: #008000;">=</span> config.<span style="color: #0000FF;">BuildSessionFactory</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
                    <span style="color: #0600FF;">if</span> <span style="color: #000000;">&#40;</span>_sessionFactory <span style="color: #008000;">==</span> <span style="color: #0600FF;">null</span><span style="color: #000000;">&#41;</span>
                        <span style="color: #0600FF;">throw</span> <span style="color: #008000;">new</span> InvalidOperationException<span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;Could not build SessionFactory&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
                <span style="color: #000000;">&#125;</span>
                <span style="color: #0600FF;">return</span> _sessionFactory<span style="color: #008000;">;</span>
            <span style="color: #000000;">&#125;</span>
&nbsp;
        <span style="color: #000000;">&#125;</span>
&nbsp;
        <span style="color: #0600FF;">public</span> <span style="color: #0600FF;">static</span> ISession OpenSession<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>
        <span style="color: #000000;">&#123;</span>
            ISession session<span style="color: #008000;">;</span>
            session <span style="color: #008000;">=</span> SessionFactory.<span style="color: #0000FF;">OpenSession</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
            <span style="color: #0600FF;">if</span> <span style="color: #000000;">&#40;</span>session <span style="color: #008000;">==</span> <span style="color: #0600FF;">null</span><span style="color: #000000;">&#41;</span>
                <span style="color: #0600FF;">throw</span> <span style="color: #008000;">new</span> InvalidOperationException<span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;Cannot open session&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
            <span style="color: #0600FF;">return</span> session<span style="color: #008000;">;</span>
        <span style="color: #000000;">&#125;</span>
&nbsp;
    <span style="color: #000000;">&#125;</span>
&nbsp;
<span style="color: #000000;">&#125;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://gregdoesit.com/2009/04/querying-many-to-many-relations-in-nhibernate/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>How to resample images &#8211; a simple algorithm</title>
		<link>http://gregdoesit.com/2009/03/how-to-resample-images-a-simple-algorithm/</link>
		<comments>http://gregdoesit.com/2009/03/how-to-resample-images-a-simple-algorithm/#comments</comments>
		<pubDate>Tue, 24 Mar 2009 17:08:22 +0000</pubDate>
		<dc:creator>Gergely Orosz</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Tips & tricks]]></category>
		<category><![CDATA[code snipplet]]></category>
		<category><![CDATA[Sense/Net 6.0]]></category>

		<guid isPermaLink="false">http://gregdoesit.com/?p=125</guid>
		<description><![CDATA[When working with images I sooner or later usually run into the problem of creating thumbnails. Resampling images is not really difficult in the major programming languages however I have not found built-in support for caclulating thumbnail dimensions neither in .NET nor in PHP. And it seems that this made me re-invent the wheel over [...]]]></description>
			<content:encoded><![CDATA[<p>When working with images I sooner or later usually run into the problem of creating thumbnails. Resampling images is not really difficult in the major programming languages however I have not found built-in support for caclulating thumbnail dimensions neither in .NET nor in PHP. And it seems that this made me re-invent the wheel over and over again creating codes with various lengths just for this simple task.</p>
<p>In <a href="http://www.sensenet.hu">Sense/Net 6.0</a>, the open source ECMS I am working on I came across the exact same problem: I wanted to resize images, this time on the fly. This time however I decided to do it a bit less complicated as in previous cases and create a clean and simple solution. After a good deal of googling, tutorial reading and planning I came up with a fairly simple and good code snipplet.</p>
<p><span id="more-125"></span></p>
<p>The way I intended the thumbnail generation to work is to always fit the thumbnail into the target dimensions. So if there was a 600&#215;400 picture and the target thumbnail size was 200&#215;200 the generated picture would be 200&#215;133. Similarly if the image size was 100&#215;500 and the target thumbnail size 200&#215;200 the generated picture&#8217;s width and height would be 40&#215;200.</p>
<p>The idea behind the algorithm was to first determine whid dimension (width or height) is the &#8220;more critical&#8221; dimension. In the above examples at the 600&#215;400 picture this dimension is the first one, width. In the second case (100&#215;500) it is the second dimension, the height.</p>
<p>In the algorithm the first step is to determine this &#8220;critical&#8221; dimension by comapring current size/target size splits. Which ever is larger will be the dimension that will be resized to the thumbnails same dimension size and the other dimension will be shrinked accordingly. This might sound a little confusing so let the code speak for itself.</p>
<p>The C# code:</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF;">private</span> <span style="color: #0600FF;">static</span> <span style="color: #0600FF;">void</span> GetRealXY<span style="color: #000000;">&#40;</span><span style="color: #FF0000;">double</span> imgX, <span style="color: #FF0000;">double</span> imgY, <span style="color: #FF0000;">double</span> targetX, <span style="color: #FF0000;">double</span> targetY, <span style="color: #0600FF;">out</span> <span style="color: #FF0000;">double</span> realX, <span style="color: #0600FF;">out</span> <span style="color: #FF0000;">double</span> realY<span style="color: #000000;">&#41;</span>
<span style="color: #000000;">&#123;</span>
	<span style="color: #FF0000;">double</span> xScale <span style="color: #008000;">=</span> imgX <span style="color: #008000;">/</span> targetX<span style="color: #008000;">;</span>
	<span style="color: #FF0000;">double</span> yScale <span style="color: #008000;">=</span> imgY <span style="color: #008000;">/</span> targetY<span style="color: #008000;">;</span>
&nbsp;
	<span style="color: #008080; font-style: italic;">// Do not enlarge image</span>
	<span style="color: #0600FF;">if</span> <span style="color: #000000;">&#40;</span>yScale <span style="color: #008000;">&amp;</span>lt<span style="color: #008000;">;</span> <span style="color: #FF0000;">1</span><span style="color: #000000;">&#41;</span>
		yScale <span style="color: #008000;">=</span> <span style="color: #FF0000;">1</span><span style="color: #008000;">;</span>
	<span style="color: #0600FF;">if</span> <span style="color: #000000;">&#40;</span>xScale <span style="color: #008000;">&amp;</span>lt<span style="color: #008000;">;</span> <span style="color: #FF0000;">1</span><span style="color: #000000;">&#41;</span>
		xScale <span style="color: #008000;">=</span> <span style="color: #FF0000;">1</span><span style="color: #008000;">;</span>
&nbsp;
	<span style="color: #0600FF;">if</span> <span style="color: #000000;">&#40;</span>yScale <span style="color: #008000;">&amp;</span>gt<span style="color: #008000;">;</span> xScale<span style="color: #000000;">&#41;</span> <span style="color: #008080; font-style: italic;">// Image has to be shrinked based on height</span>
	<span style="color: #000000;">&#123;</span>
		realX <span style="color: #008000;">=</span> imgX <span style="color: #008000;">*</span> <span style="color: #FF0000;">1</span> <span style="color: #008000;">/</span> yScale<span style="color: #008000;">;</span>
		realY <span style="color: #008000;">=</span> imgY <span style="color: #008000;">*</span> <span style="color: #FF0000;">1</span> <span style="color: #008000;">/</span> yScale<span style="color: #008000;">;</span>
	<span style="color: #000000;">&#125;</span>
	<span style="color: #0600FF;">else</span> <span style="color: #008080; font-style: italic;">// xScale &amp;gt; yScale // Image has to be shrinked based on width</span>
	<span style="color: #000000;">&#123;</span>
		realX <span style="color: #008000;">=</span> imgX <span style="color: #008000;">*</span> <span style="color: #FF0000;">1</span> <span style="color: #008000;">/</span> xScale<span style="color: #008000;">;</span>
		realY <span style="color: #008000;">=</span> imgY <span style="color: #008000;">*</span> <span style="color: #FF0000;">1</span> <span style="color: #008000;">/</span> xScale<span style="color: #008000;">;</span>
	<span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span></pre></div></div>

<p>And here&#8217;s how the same code in PHP would look like:</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;">function getRealXY<span style="color: #000000;">&#40;</span>$imgX,$imgY,$targetX,$targetY<span style="color: #000000;">&#41;</span>
<span style="color: #000000;">&#123;</span>
	$xScale <span style="color: #008000;">=</span> $imgX <span style="color: #008000;">/</span> $targetX<span style="color: #008000;">;</span>
	$yScale <span style="color: #008000;">=</span> $imgY <span style="color: #008000;">/</span> $targetY<span style="color: #008000;">;</span>
&nbsp;
	<span style="color: #008080; font-style: italic;">// Do not enlarge image</span>
	<span style="color: #0600FF;">if</span> <span style="color: #000000;">&#40;</span>$yScale <span style="color: #008000;">&amp;</span>lt<span style="color: #008000;">;</span> <span style="color: #FF0000;">1</span><span style="color: #000000;">&#41;</span>
		$yScale <span style="color: #008000;">=</span> <span style="color: #FF0000;">1</span><span style="color: #008000;">;</span>
	<span style="color: #0600FF;">if</span> <span style="color: #000000;">&#40;</span>$xScale <span style="color: #008000;">&amp;</span>lt<span style="color: #008000;">;</span> <span style="color: #FF0000;">1</span><span style="color: #000000;">&#41;</span>
		$xScale <span style="color: #008000;">=</span> <span style="color: #FF0000;">1</span><span style="color: #008000;">;</span>
&nbsp;
	<span style="color: #0600FF;">if</span> <span style="color: #000000;">&#40;</span>$yScale <span style="color: #008000;">&amp;</span>gt<span style="color: #008000;">;</span> $xScale<span style="color: #000000;">&#41;</span> <span style="color: #008080; font-style: italic;">// Image has to be shrinked based on height</span>
	<span style="color: #000000;">&#123;</span>
		$realX <span style="color: #008000;">=</span> $imgX <span style="color: #008000;">*</span> <span style="color: #FF0000;">1</span> <span style="color: #008000;">/</span> $yScale<span style="color: #008000;">;</span>
		$realY <span style="color: #008000;">=</span> $imgY <span style="color: #008000;">*</span> <span style="color: #FF0000;">1</span> <span style="color: #008000;">/</span> $yScale<span style="color: #008000;">;</span>
	<span style="color: #000000;">&#125;</span>
	<span style="color: #0600FF;">else</span> <span style="color: #008080; font-style: italic;">// $xScale &amp;gt; $yScale // Image has to be shrinked based on width</span>
	<span style="color: #000000;">&#123;</span>
		$realX <span style="color: #008000;">=</span> $imgX <span style="color: #008000;">*</span> <span style="color: #FF0000;">1</span> <span style="color: #008000;">/</span> $xScale<span style="color: #008000;">;</span>
		$realY <span style="color: #008000;">=</span> $imgY <span style="color: #008000;">*</span> <span style="color: #FF0000;">1</span> <span style="color: #008000;">/</span> $xScale<span style="color: #008000;">;</span>
	<span style="color: #000000;">&#125;</span>
	<span style="color: #0600FF;">return</span> array<span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;x&quot;</span><span style="color: #008000;">=&amp;</span>gt<span style="color: #008000;">;</span>$realX,<span style="color: #666666;">&quot;y&quot;</span><span style="color: #008000;">=&amp;</span>gt<span style="color: #008000;">;</span>$realY<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
<span style="color: #000000;">&#125;</span></pre></div></div>

<p>Hope this snipplet helps. If you&#8217;re interested for the whole image resampling process you will be able to access it in the <a href="http://www.sensenet.hu">Sense/Net 6.0 Beta 3</a> source code which will be coming out in a few days.</p>
]]></content:encoded>
			<wfw:commentRss>http://gregdoesit.com/2009/03/how-to-resample-images-a-simple-algorithm/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>ASP.NET server side element names changed?</title>
		<link>http://gregdoesit.com/2009/03/aspnet-server-side-element-names-changed/</link>
		<comments>http://gregdoesit.com/2009/03/aspnet-server-side-element-names-changed/#comments</comments>
		<pubDate>Wed, 04 Mar 2009 17:51:48 +0000</pubDate>
		<dc:creator>Gergely Orosz</dc:creator>
				<category><![CDATA[ASP.NET]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[Tips & tricks]]></category>
		<category><![CDATA[bug]]></category>
		<category><![CDATA[JQuery]]></category>
		<category><![CDATA[postback]]></category>

		<guid isPermaLink="false">http://gregdoesit.com/?p=111</guid>
		<description><![CDATA[As far as I&#8217;ve known if the ClientID of a server control looked someting like this: ctl00_WebPartManager1_184c801b_7c67_4967_be37_3ab10406f967_ctl00_linkVote1 . Then the name sent on postback (which identified the control on the server side) was: ctl00$WebPartManager1$184c801b$7c67$4967$be37$3ab10406f967$ctl00$linkVote1 . But since some time the _ to $ conversion is not true any more. Instead the _ signs are randomly [...]]]></description>
			<content:encoded><![CDATA[<p>As far as I&#8217;ve known if the ClientID of a server control looked someting like this:</p>
<pre>ctl00_WebPartManager1_184c801b_7c67_4967_be37_3ab10406f967_ctl00_linkVote1
.</pre>
<p>Then the name sent on postback (which identified the control on the server side) was:</p>
<pre>ctl00$WebPartManager1$184c801b$7c67$4967$be37$3ab10406f967$ctl00$linkVote1
.</pre>
<p>But since some time the <strong>_</strong> to <strong>$</strong> conversion is not true any more. Instead the <strong>_</strong> signs are randomly replaced by dollar signs. Recently the name sent back on postback is:</p>
<pre>ctl00$WebPartManager1$184c801b_7c67_4967_be37_3ab10406f967$ctl00$linkVote1
.</pre>
<p>This change screwed up quite a lot of client side manual __doPostback() codes I&#8217;ve written &#8211; most of the making these invokes due to JQuery addons.<br />
<span id="more-111"></span></p>
<p>I was notified by a client that recently a voting control I developed for them is not working any more. The control itself was a list of radio buttons transformed to stars with some javascript magic. On the client side I had to code that when the user clicks any radio button a the form gets submitted by imitating a LinkButton being clicked.</p>
<p>So this is the code I had in the aspx page that worked like a charm so far:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">function</span> SubmitVote<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
__doPostBack<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">''</span><span style="color: #339933;">,</span><span style="color: #3366CC;">''</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Now after this change no events were fired on the server side because of the control name not being valid.</p>
<p>Next try: instead of transforming the ID lets just get the name property from the control:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">function</span> SubmitVote<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
__doPostBack<span style="color: #009900;">&#40;</span>$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;#&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">attr</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;name&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span><span style="color: #3366CC;">''</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>This solution didn&#8217;t work either as the control did not have a name attribute. So the way I dot the thing solved was by invoking the click event of the LinkButton:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">function</span> SubmitVote<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
<span style="color: #000066; font-weight: bold;">eval</span><span style="color: #009900;">&#40;</span>$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;#&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">attr</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;href&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>And this was the way I managed to successfully invoke the __doPostback() method from client side. Actually it wasn&#8217;t really invoking but only immitating the user clicking.</p>
<p>If you&#8217;ve information on when (and why) this server control naming convention has been changed feel free to share within the comments.</p>
]]></content:encoded>
			<wfw:commentRss>http://gregdoesit.com/2009/03/aspnet-server-side-element-names-changed/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Deleting a one-to-many relationship in NHibernate</title>
		<link>http://gregdoesit.com/2009/01/deleting-a-one-to-many-relationship-in-nhibernate/</link>
		<comments>http://gregdoesit.com/2009/01/deleting-a-one-to-many-relationship-in-nhibernate/#comments</comments>
		<pubDate>Wed, 28 Jan 2009 10:49:22 +0000</pubDate>
		<dc:creator>Gergely Orosz</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[Tips & tricks]]></category>
		<category><![CDATA[Mapping]]></category>
		<category><![CDATA[NHibernate]]></category>
		<category><![CDATA[Schema]]></category>

		<guid isPermaLink="false">http://gregdoesit.com/?p=80</guid>
		<description><![CDATA[I have had some trouble deleting the child in a one-to-many relationship in NHibernate. My schema described a simple parent-child relationship: a parent can have multiple children and every child has exactly one parent. In the database schema I had two tables parentTable and childTable. ParentTable had an ID column and some other columns. The [...]]]></description>
			<content:encoded><![CDATA[<p>I have had some trouble deleting the child in a one-to-many relationship in NHibernate. My schema described a simple parent-child relationship: a parent can have multiple children and every child has exactly one parent.</p>
<p>In the database schema I had two tables parentTable and childTable. ParentTable had an ID column and some other columns. The childTable had an ID primary key column, some other columns and a parentId NOT NULL column which had a foreign key constraint against the ID column in the parentTable.</p>
<p><img class="aligncenter size-full wp-image-82" title="Parent-Child Database Relationship (One-to-many)" src="http://gregdoesit.com/wp-content/uploads/2009/01/parent_child_database_relationship.jpg" alt="Parent-Child Database Relationship (One-to-many)" width="497" height="170" /></p>
<p><span id="more-80"></span></p>
<p><strong>The NHibernate schema</strong> describing the relationship was the following:</p>
<ul>
<li><strong>Parent schema</strong> (the relevant part):

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;">&nbsp;</pre></div></div>

</li>
<li><strong>Child schema</strong> (the relevant part):

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;">&nbsp;</pre></div></div>

</li>
</ul>
<p>I was trying to delete the child the following way:</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;">ParentClass parent<span style="color: #008000;">;</span>
ChildClass child<span style="color: #008000;">;</span>
parent.<span style="color: #0000FF;">children</span>.<span style="color: #0000FF;">Remove</span><span style="color: #000000;">&#40;</span>child<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
session.<span style="color: #0000FF;">Delete</span><span style="color: #000000;">&#40;</span>child<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
session.<span style="color: #0000FF;">Save</span><span style="color: #000000;">&#40;</span>parent<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
session.<span style="color: #0000FF;">Flush</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span></pre></div></div>

<p>When executing the code I got an exception saying</p>

<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">Cannot insert the value NULL into column 'parentId', table 'childTable'; column does not allow nulls. UPDATE fails.
The statement has been terminated.</pre></div></div>

<p>It took me some googling to find out what I was doing wrong. The NHibernate schema was incomplete. The errors were:</p>
<ul>
<li>I did not specify that the parentId column in the childTable cannot be NULL. This can be done using the <strong>not-null=&#8221;true&#8221;</strong> attribute</li>
<li>I did not specify that the one-to-many relation was <strong>inverse</strong> even though it was: the child knew its parent but the parent did not directly know its children in the database schema. (See <a href="http://bchavez.bitarmory.com/archive/2007/10/06/nhibernate-and-inversetruefalse-attribute.aspx" target="_blank">this article</a> on what this inverse attribute means in more of depth).</li>
<li>It is obvious that no child can exist without a parent. NHibernate will take care of deleting the child once it is removed from the children collection of the parent if the <strong>on-delete=&#8221;cascade&#8221;</strong> is set on the key element within the children collection.</li>
</ul>
<p><strong>The NHibernate schema that solved my problem</strong> finally is the following:</p>
<ul>
<li><strong>Parent schema</strong> (the relevant part):

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;">&nbsp;</pre></div></div>

</li>
<li></li>
<li><strong>Child schema</strong> (the relevant part):

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;">&nbsp;</pre></div></div>

</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://gregdoesit.com/2009/01/deleting-a-one-to-many-relationship-in-nhibernate/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>TFS &#8211; deleting old workspaces</title>
		<link>http://gregdoesit.com/2009/01/tfs-deleting-old-workspaces/</link>
		<comments>http://gregdoesit.com/2009/01/tfs-deleting-old-workspaces/#comments</comments>
		<pubDate>Mon, 12 Jan 2009 17:06:00 +0000</pubDate>
		<dc:creator>Gergely Orosz</dc:creator>
				<category><![CDATA[Tips & tricks]]></category>
		<category><![CDATA[bug]]></category>
		<category><![CDATA[TFS]]></category>
		<category><![CDATA[Visual Studio]]></category>

		<guid isPermaLink="false">http://gregdoesit.com/?p=20</guid>
		<description><![CDATA[I use Visual Studio 2008 on a daily basis however for some older projects I have to work with VS 2005. Recently our company has set a new Team Foundation Server in use and all active projects have been migrated there. In VS 2008 everything worked just fine. However when trying to re-map a project [...]]]></description>
			<content:encoded><![CDATA[<p>I use Visual Studio 2008 on a daily basis however for some older projects I have to work with VS 2005. Recently our company has set a new Team Foundation Server in use and all active projects have been migrated there. In VS 2008 everything worked just fine.</p>
<p>However when trying to re-map a project to the same localtion as before (only from the new TFS server) I got the following error message: &#8220;The path [yourpath] is already mapped in workspace [yourworkspace]&#8220;. It took me a while to figure out what the resolution of the problem was.<br />
<span id="more-20"></span></p>
<h3>Attempts not working</h3>
<p>It was obvios that a conflict occured with the previos workspace. However I had no access to the previos TFS server and could not view or delete the previos workspace. (When having access to the existing TFS server the workspace uses it is easy to delete it either with the <a href="http://blogs.microsoft.co.il/blogs/tfsidekicks/archive/2006/07/30/1776.aspx" target="_blank">Team Foundation Sidekick</a> &#8211; get latest version <a href="http://www.attrice.info/cm/tfs/">here</a>).</p>
<p>When <em>not being able to connect to the TFS</em> server <em>workspaces</em> associated to that server <em>cannot be accessed</em> with the GUI (or at least I found no way) and cannot be deleted. However this can be done with command line. I borrowed the idea from a <a href="http://blog.maheshm.net/2008/06/how-to-delete-workspace-from-tfs-team.html" target="_blank">post by Mahesh Mitkari</a> and first checked if the workspace is indeed mapped. To <strong>list the workspaces</strong> mapped in the system use this command:</p>
<p><code> </code></p>
<p><code></p>
<pre>tf workspaces</pre>
<p></code></p>
<p>(Note that tf.exe is either located within C:\Program Files\Microsoft Visual Studio 8\Common7\IDE for VS2005 or C:\Program Files\Microsoft Visual Studio 9.0\Common7\IDE for VS2008).</p>
<p>To <strong>delete a workspace</strong> simply type<br />
<code> </code></p>
<pre><code>tf workspace /delete [/server:servername] workspacename[;workspaceowner]</code></pre>
<p>After typing this command I got the error &#8220;Unable to connect to the remote server. Command cancelled&#8221;. Something was definitely not right: why can&#8217;t I delete any workspace without connecting to it?</p>
<h3>The solution</h3>
<p>It turned out that I was on the wrong track all the time. After searching I ran into the solution by <a href="http://geekswithblogs.net/aaronsblog/archive/2006/09/11/90878.aspx" target="_blank">Buck Hodges in a comment on a blog</a>. Turned out that getting rid of disconnected workspaces isn&#8217;t done by deleting but by <strong>removing</strong> them with the following command:</p>
<p><code> </code></p>
<pre><code>tf workspaces /remove:*</code></pre>
<p>This command cleans out all <strong>cached</strong> workspaces. And this was the thing that solved my problem. (Actually it didn&#8217;t make that much sense why there are these two distinct commands&#8230; here&#8217;s a good <a href="http://blogs.msdn.com/granth/archive/2008/10/14/what-s-the-difference-between-tf-workspace-delete-and-tf-workspaces-remove.aspx" target="_blank">blog post on this topic</a>)</p>
]]></content:encoded>
			<wfw:commentRss>http://gregdoesit.com/2009/01/tfs-deleting-old-workspaces/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
	</channel>
</rss>

